Class: RWebSpec::AbstractWebPage
- Inherits:
-
Object
- Object
- RWebSpec::AbstractWebPage
- Defined in:
- lib/rwebspec-common/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
login_page = home_page.clickLoginLink
login_page.enterUserName("sa")
So you only need change in LoingPage class if UI changes, which happen quite often.
Constant Summary
Constants included from Core
Instance Attribute Summary collapse
-
#page_specific_text ⇒ Object
browser: passed to do assertion within the page page_text: text used to identify the page, title will be the first candidate.
Instance Method Summary collapse
- #assert_not_on_page ⇒ Object
-
#assert_on_page ⇒ Object
Assert is on current page Example home_page = HomePage.new(“Welcome to iTest2”) .…
-
#browser ⇒ Object
return the browser instance in page objects.
-
#contains?(ary) ⇒ Boolean
TO validate.
- #dump(stream = nil) ⇒ Object
-
#initialize(the_browser, page_specific_text = nil) ⇒ AbstractWebPage
constructor
A new instance of AbstractWebPage.
-
#snapshot(replace_css = false) ⇒ Object
Will save current page source to a file home_page = HomePage.new(“Welcome to iTest2”) …
-
#source ⇒ Object
(also: #html)
Page source (html).
-
#text ⇒ Object
return current page text.
-
#title ⇒ Object
return current page title.
- #url ⇒ Object
Methods included from Core
#allow, #days_before, #days_from_now, #failsafe, #interpret_value, #on, #open_browser, #paragraphs, #random_boolean, #random_char, #random_digit, #random_number, #random_str, #random_string_in, #sentences, #shall_not_allow, #symbol_to_sequence, #today, #tomorrow, #try_for, #use_current_browser, #value_in_range, #words, #yesterday
Methods included from Assert
#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_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_in_page_source, #assert_text_not_in_page_source, #assert_text_not_present, #assert_text_not_present_in_table, #assert_text_present, #assert_text_present_in_table, #assert_title_equals, #assert_visible, #element_name, #element_value, #fail, #is_selenium_element?
Constructor Details
#initialize(the_browser, page_specific_text = nil) ⇒ AbstractWebPage
Returns a new instance of AbstractWebPage.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rwebspec-common/web_page.rb', line 37 def initialize(the_browser, page_specific_text = nil) @web_browser = @browser = @web_tester = the_browser @page_specific_text = page_specific_text begin snapshot if $TESTWISE_DUMP_PAGE || $TESTWISE_DUMP_PAGE delay = $TESTWISE_PAGE_DELAY || $TESTWISE_PAGE_DELAY sleep(delay) if delay rescue => e puts e.backtrace end assert_on_page end |
Instance Attribute Details
#page_specific_text ⇒ Object
browser: passed to do assertion within the page page_text: text used to identify the page, title will be the first candidate
35 36 37 |
# File 'lib/rwebspec-common/web_page.rb', line 35 def page_specific_text @page_specific_text end |
Instance Method Details
#assert_not_on_page ⇒ Object
65 66 67 |
# File 'lib/rwebspec-common/web_page.rb', line 65 def assert_not_on_page() assert_text_not_present(@page_specific_text) if @page_specific_text end |
#assert_on_page ⇒ Object
Assert is on current page Example
home_page = HomePage.new("Welcome to iTest2")
....
home_page.assert_on_page # will check the text 'Welcome to iTest2' still present on the page
61 62 63 |
# File 'lib/rwebspec-common/web_page.rb', line 61 def assert_on_page() assert_text_present(@page_specific_text) if @page_specific_text end |
#browser ⇒ Object
return the browser instance in page objects
52 53 54 |
# File 'lib/rwebspec-common/web_page.rb', line 52 def browser @web_browser end |
#contains?(ary) ⇒ Boolean
TO validate
94 95 96 97 98 99 100 101 102 |
# File 'lib/rwebspec-common/web_page.rb', line 94 def contains?(ary) return true if ary.nil? the_page_source = source found = false ary.each_line do |str| found ||= the_page_source.include?(str) end return found end |
#dump(stream = nil) ⇒ Object
69 70 71 |
# File 'lib/rwebspec-common/web_page.rb', line 69 def dump(stream = nil) @web_browser.dump_response(stream) end |
#snapshot(replace_css = false) ⇒ Object
Will save current page source to a file
home_page = HomePage.new("Welcome to iTest2")
...
home_page.snapshot() # => save to 20090830100102_HomePage.html
108 109 110 |
# File 'lib/rwebspec-common/web_page.rb', line 108 def snapshot(replace_css = false) save_current_page(:filename => Time.now.strftime("%m%d%H%M%S") + "_" + self.class.name.gsub(" ", "") + ".html" ) end |
#source ⇒ Object Also known as: html
Page source (html)
74 75 76 |
# File 'lib/rwebspec-common/web_page.rb', line 74 def source @web_browser.page_source end |
#text ⇒ Object
return current page text
85 86 87 |
# File 'lib/rwebspec-common/web_page.rb', line 85 def text @web_browser.text end |
#title ⇒ Object
return current page title
80 81 82 |
# File 'lib/rwebspec-common/web_page.rb', line 80 def title @web_browser.page_title end |
#url ⇒ Object
89 90 91 |
# File 'lib/rwebspec-common/web_page.rb', line 89 def url @web_browser.url end |