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")
@web_browser.clickLinkWithText("/login")
@web_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

#absolutify_url, #absolutize_page, #absolutize_page_hpricot, #ajax_wait_for_element, #allow, #attach_browser, #begin_at, #cell_with_id, #click_button_with_image_src_contains, #close_all_browsers, #close_browser, #contains_text, #context, #dump_response, #element_by_id, #element_text, #ends_with?, #enter_text_with_id, #expect_page, #failsafe, #firefox, #goto_page, #goto_url, #ie, #is_firefox?, #is_linux?, #is_mac?, #is_windows?, #label_with_id, #new_popup_window, #on, #open_browser, #page_source, #page_title, #repeat_try, #save_current_page, #shall_not_allow, #span_with_id, #substitute_relative_path_in_src_line, #support_utf8, #symbol_to_sequence, #try, #use_current_browser, #wait_for_element, #wait_until

Methods included from Popup

#check_for_popups, #check_for_security_alerts, #click_button_in_javascript_popup, #click_button_in_popup_after, #click_button_in_security_alert_popup, #click_button_in_security_information_popup, #click_popup_window, #ie_popup_clicker, #prepare_to_click_button_in_popup, #start_checking_js_dialog, #verify_alert

Methods included from ITestPlugin

#connect_to_itest, #debug, #dump_caller_stack, #operation_delay

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_equals, #assert_exists, #assert_hidden, #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, #assert_not_exists, #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_field_value, #assert_text_in_element, #assert_text_not_present, #assert_text_not_present_in_table, #assert_text_present, #assert_text_present_in_table, #assert_title_equals, #assert_visible, #fail

Constructor Details

#initialize(the_browser, page_text = nil) ⇒ AbstractWebPage

Returns a new instance of AbstractWebPage.



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

def initialize(the_browser, page_text = nil)
  @web_browser = the_browser
  @web_tester = the_browser
  @page_text = page_text
  begin
    snapshot if $ITEST2_DUMP_PAGE
    delay = $ITEST2_PAGE_DELAY
    sleep(delay)
  rescue => e
  end
  assert_on_page
end

Instance Attribute Details

#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



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

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

#assert_on_pageObject



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

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

#browserObject



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

def browser
  @web_browser
end

#contains?(ary) ⇒ Boolean

TO validate

Returns:

  • (Boolean)


77
78
79
80
81
82
83
84
# File 'lib/rwebunit/web_page.rb', line 77

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

#dump(stream = nil) ⇒ Object



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

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

#snapshot(replace_css = false) ⇒ Object



86
87
88
# File 'lib/rwebunit/web_page.rb', line 86

def	snapshot(replace_css = false)    
  save_current_page(:filename => Time.now.strftime("%m%d%H%M%S") + "_" + self.class.name.gsub(" ", "") + ".html" )
end

#sourceObject



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

def source
  @web_browser.page_source
end

#textObject

return current page text



72
73
74
# File 'lib/rwebunit/web_page.rb', line 72

def text
  @web_browser.text
end

#titleObject

return current page title



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

def title
  @web_browser.page_title
end