Class: RWebUnit::AbstractWebPage

Inherits:
Object
  • Object
show all
Includes:
Assert, Driver
Defined in:
lib/rwebunit/web_page.rb

Overview

WebPage (children of AbstractWebPage) encapsulates a real web page. For example,

beginAt("/home")
@browser.clickLinkWithText("/login")
@browser.setFormElement("username", "sa")

Can be rewritten to

begin_at("/home")
home_page = HomePage.new
 = home_page.clickLoginLink
.enterUserName("sa")

So you only need change in LoingPage class if UI changes, which happen quite often.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Driver

#ajax_wait_for_element, #allow, #attach_browser, #begin_at, #click_button_with_image_src_contains, #click_popup_window, #close_browser, #contains_text, #context, #dump_response, #element_text, #failsafe, #goto_page, #ie, #new_popup_window, #on, #operation_delay, #save_current_page, #shall_not_allow, #wait_for_element

Methods included from Assert

#assert_button_not_present, #assert_button_not_present_with_text, #assert_button_present, #assert_button_present_with_text, #assert_checkbox_not_selected, #assert_checkbox_selected, #assert_element_not_present, #assert_element_present, #assert_equals, #assert_link_not_present_with_exact, #assert_link_not_present_with_text, #assert_link_present_with_exact, #assert_link_present_with_text, #assert_nil, #assert_not_nil, #assert_option_equals, #assert_option_not_present, #assert_option_present, #assert_option_value_equals, #assert_option_value_not_present, #assert_option_value_present, #assert_radio_option_not_present, #assert_radio_option_not_selected, #assert_radio_option_present, #assert_radio_option_selected, #assert_text_in_element, #assert_text_in_table, #assert_text_not_in_table, #assert_text_not_present, #assert_text_present, #assert_text_present_in_text_field, #assert_title_equals, #fail

Constructor Details

#initialize(web_tester, page_text = nil) ⇒ AbstractWebPage

Returns a new instance of AbstractWebPage.



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rwebunit/web_page.rb', line 32

def initialize(web_tester, page_text=nil)
  @web_tester = web_tester
  @page_text = page_text
  begin
    snapshot if ENV['ITEST_DUMP_PAGE'] == 'true'
    delay = ENV['ITEST_PAGE_DELAY'].to_i
    sleep(delay)
  rescue => e
  end
  assert_on_page
end

Instance Attribute Details

#browserObject

browser: passed to do assertion within the page page_text: text used to identify the page, title will be the first candidate



30
31
32
# File 'lib/rwebunit/web_page.rb', line 30

def browser
  @browser
end

#page_textObject

browser: passed to do assertion within the page page_text: text used to identify the page, title will be the first candidate



30
31
32
# File 'lib/rwebunit/web_page.rb', line 30

def page_text
  @page_text
end

Instance Method Details

#assert_not_on_pageObject



52
53
54
# File 'lib/rwebunit/web_page.rb', line 52

def assert_not_on_page()
  assert_text_not_present(@page_text) if @page_text
end

#assert_on_pageObject



48
49
50
# File 'lib/rwebunit/web_page.rb', line 48

def assert_on_page()
  assert_text_present(@page_text) if @page_text
end

#contains?(ary) ⇒ Boolean Also known as: include

TO validate

Returns:

  • (Boolean)


73
74
75
76
77
78
79
80
# File 'lib/rwebunit/web_page.rb', line 73

def contains?(ary)
  page_source = source
  found = false
  ary.each do |str|
    found ||= page_source.include?(str)
  end
  return found
end

#dump(stream = nil) ⇒ Object



56
57
58
# File 'lib/rwebunit/web_page.rb', line 56

def dump(stream = nil)
  @web_tester.dump_response(stream)
end

#expect_page(page_clazz) ⇒ Object



68
69
70
# File 'lib/rwebunit/web_page.rb', line 68

def expect_page(page_clazz)
  page_clazz.new(@web_tester)
end

#snapshotObject



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/rwebunit/web_page.rb', line 84

def	snapshot
  if ENV['ITEST_DUMP_DIR']
    spec_run_id = ENV['ITEST_RUNNING_SPEC_ID'] || "unknown"
    spec_run_dir_name = spec_run_id.to_s.rjust(4, "0") unless spec_run_id == "unknown"
    spec_run_dir = File.join(ENV['ITEST_DUMP_DIR'], spec_run_dir_name)
    Dir.mkdir(spec_run_dir) unless File.exists?(spec_run_dir)
    file_name = Time.now.strftime("%m%d%H%M%S") + "_" + self.class.name.gsub("", "") + ".html"
    file = File.join(ENV['ITEST_DUMP_DIR'], spec_run_dir_name, file_name)
    page_source = browser.page_source
    File.new(file, "w").puts source
  end
end

#sourceObject



60
61
62
# File 'lib/rwebunit/web_page.rb', line 60

def source
  @web_tester.page_source
end

#titleObject



64
65
66
# File 'lib/rwebunit/web_page.rb', line 64

def title
  @web_tester.page_title
end