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, #area, #attach_browser, #begin_at, #button, #buttons, #cell, #check_checkbox, #checkbox, #checkboxes, #clear_radio_option, #click_button_with_caption, #click_button_with_id, #click_button_with_image_src_contains, #click_button_with_value, #click_link_with_id, #click_link_with_text, #click_popup_window, #click_radio_option, #close_browser, #contains_text, #div, #dump_response, #element_text, #enter_text, #file_field, #form, #frame, #go_back, #go_forward, #goto_page, #h1, #h2, #h3, #h4, #h5, #h6, #hidden, #ie, #image, #images, #label, #li, #link, #links, #map, #new_popup_window, #on, #operation_delay, #paragraph, #pre, #radio, #radios, #refresh, #row, #select_file_for_upload, #select_list, #select_lists, #select_option, #shall_not_allow, #span, #submit, #table, #test_context, #text_field, #text_fields, #uncheck_checkbox, #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.



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

def initialize(web_tester, page_text=nil)
  @web_tester = web_tester
  @page_text = page_text
  begin
    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



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

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



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

def page_text
  @page_text
end

Instance Method Details

#assert_not_on_pageObject



50
51
52
# File 'lib/rwebunit/web_page.rb', line 50

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

#assert_on_pageObject



46
47
48
# File 'lib/rwebunit/web_page.rb', line 46

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

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

TO validate

Returns:

  • (Boolean)


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

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



54
55
56
# File 'lib/rwebunit/web_page.rb', line 54

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

#expect_page(page_clazz) ⇒ Object



66
67
68
# File 'lib/rwebunit/web_page.rb', line 66

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

#sourceObject



58
59
60
# File 'lib/rwebunit/web_page.rb', line 58

def source
  @web_tester.page_source
end

#titleObject



62
63
64
# File 'lib/rwebunit/web_page.rb', line 62

def title
  @web_tester.page_title
end