class RWebSpec::AbstractWebPage
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.
Attributes
page_specific_text[RW]
browser: passed to do assertion within the page page_text: text used to identify the page, title will be the first candidate
Public Class Methods
new(the_browser, page_specific_text = nil)
click to toggle source
# 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
Public Instance Methods
assert_not_on_page()
click to toggle source
# 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()
click to toggle source
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
# 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()
click to toggle source
return the browser instance in page objects
# File lib/rwebspec-common/web_page.rb, line 52 def browser @web_browser end
contains?(ary)
click to toggle source
TO validate
# 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)
click to toggle source
# File lib/rwebspec-common/web_page.rb, line 69 def dump(stream = nil) @web_browser.dump_response(stream) end
snapshot(replace_css = false)
click to toggle source
Will save current page source to a file
home_page = HomePage.new("Welcome to iTest2") ... home_page.snapshot() # => save to 20090830100102_HomePage.html
# 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()
click to toggle source
Page source (html)
# File lib/rwebspec-common/web_page.rb, line 74 def source @web_browser.page_source end
Also aliased as: html
text()
click to toggle source
return current page text
# File lib/rwebspec-common/web_page.rb, line 85 def text @web_browser.text end
title()
click to toggle source
return current page title
# File lib/rwebspec-common/web_page.rb, line 80 def title @web_browser.page_title end
url()
click to toggle source
# File lib/rwebspec-common/web_page.rb, line 89 def url @web_browser.url end