Module: PageObject
- Includes:
- ElementLocators, LoadsPlatform, PagePopulator
- Defined in:
- lib/page-object.rb,
lib/page-object/version.rb,
lib/page-object/elements.rb,
lib/page-object/platforms.rb,
lib/page-object/accessors.rb,
lib/page-object/elements/div.rb,
lib/page-object/page_factory.rb,
lib/page-object/elements/span.rb,
lib/page-object/elements/form.rb,
lib/page-object/elements/link.rb,
lib/page-object/page_populator.rb,
lib/page-object/loads_platform.rb,
lib/page-object/elements/label.rb,
lib/page-object/elements/table.rb,
lib/page-object/elements/image.rb,
lib/page-object/nested_elements.rb,
lib/page-object/elements/button.rb,
lib/page-object/elements/option.rb,
lib/page-object/elements/element.rb,
lib/page-object/elements/heading.rb,
lib/page-object/element_locators.rb,
lib/page-object/javascript/jquery.rb,
lib/page-object/elements/paragraph.rb,
lib/page-object/elements/text_area.rb,
lib/page-object/elements/table_row.rb,
lib/page-object/elements/list_item.rb,
lib/page-object/elements/check_box.rb,
lib/page-object/elements/file_field.rb,
lib/page-object/elements/table_cell.rb,
lib/page-object/elements/text_field.rb,
lib/page-object/javascript/prototype.rb,
lib/page-object/elements/select_list.rb,
lib/page-object/elements/radio_button.rb,
lib/page-object/elements/hidden_field.rb,
lib/page-object/elements/ordered_list.rb,
lib/page-object/elements/unordered_list.rb,
lib/page-object/platforms/watir_webdriver.rb,
lib/page-object/javascript_framework_facade.rb,
lib/page-object/platforms/selenium_webdriver.rb,
lib/page-object/platforms/watir_webdriver/form.rb,
lib/page-object/platforms/watir_webdriver/table.rb,
lib/page-object/platforms/watir_webdriver/image.rb,
lib/page-object/platforms/selenium_webdriver/link.rb,
lib/page-object/platforms/watir_webdriver/element.rb,
lib/page-object/platforms/selenium_webdriver/form.rb,
lib/page-object/platforms/selenium_webdriver/image.rb,
lib/page-object/platforms/selenium_webdriver/table.rb,
lib/page-object/platforms/selenium_webdriver/button.rb,
lib/page-object/platforms/watir_webdriver/check_box.rb,
lib/page-object/platforms/watir_webdriver/text_area.rb,
lib/page-object/platforms/watir_webdriver/table_row.rb,
lib/page-object/platforms/watir_webdriver/file_field.rb,
lib/page-object/platforms/watir_webdriver/text_field.rb,
lib/page-object/platforms/selenium_webdriver/element.rb,
lib/page-object/platforms/watir_webdriver/page_object.rb,
lib/page-object/platforms/watir_webdriver/select_list.rb,
lib/page-object/platforms/selenium_webdriver/check_box.rb,
lib/page-object/platforms/selenium_webdriver/table_row.rb,
lib/page-object/platforms/watir_webdriver/ordered_list.rb,
lib/page-object/platforms/watir_webdriver/radio_button.rb,
lib/page-object/platforms/selenium_webdriver/text_area.rb,
lib/page-object/platforms/selenium_webdriver/text_field.rb,
lib/page-object/platforms/selenium_webdriver/file_field.rb,
lib/page-object/platforms/watir_webdriver/unordered_list.rb,
lib/page-object/platforms/selenium_webdriver/page_object.rb,
lib/page-object/platforms/selenium_webdriver/select_list.rb,
lib/page-object/platforms/selenium_webdriver/radio_button.rb,
lib/page-object/platforms/selenium_webdriver/ordered_list.rb,
lib/page-object/platforms/selenium_webdriver/unordered_list.rb,
lib/page-object/platforms/selenium_webdriver/surrogate_selenium_element.rb
Overview
Module that when included adds functionality to a page object. This module will add numerous class and instance methods that you use to define and interact with web pages.
If we have a login page with a username and password textfield and a login button we might define our page like the one below. We can then interact with the object using the generated methods.
Defined Under Namespace
Modules: Accessors, ElementLocators, Elements, Javascript, JavascriptFrameworkFacade, LoadsPlatform, NestedElements, PageFactory, PagePopulator, Platforms
Constant Summary
- VERSION =
"0.6.6"
Instance Attribute Summary (collapse)
-
- (Watir::Browser or Selenium::WebDriver::Driver) browser
readonly
The platform browser passed to the constructor.
-
- (PageObject::WatirPageObject or PageObject::SeleniumPageObject) platform
readonly
The platform page object.
Class Method Summary (collapse)
-
+ (Object) add_framework(key, framework)
Add a new javascript framework to page-object.
- + (Object) included(cls)
-
+ (Object) javascript_framework=(framework)
Set the javascript framework to use when determining number of ajax requests.
Instance Method Summary (collapse)
-
- (String) alert(frame = nil, &block)
Override the normal alert popup so it does not occurr.
-
- (Object) attach_to_window(identifier, &block)
Attach to a running window.
-
- (Object) back
Go back to the previous page.
-
- (Object) clear_cookies
Clear the cookies from the browser.
-
- (String) confirm(response, frame = nil, &block)
Override the normal confirm popup so it does not occurr.
-
- (Object) current_url
get the current page url.
-
- (Object) element_with_focus
Find the element that has focus on the page.
-
- (Object) execute_script(script)
Execute javascript on the browser.
-
- (Object) forward
Go forward to the next page.
-
- (Object) html
Returns the html of the current page.
-
- (Object) in_frame(identifier, frame = nil, &block)
Identify an element as existing within a frame or iframe.
-
- (PageObject) initialize(browser, visit = false)
Construct a new page object.
-
- (Object) modal_dialog(&block)
Override the normal showModalDialog call is it opens a window instead of a dialog.
-
- (Object) navigate_to(url)
navigate to the provided url.
-
- (Hash) prompt(answer, frame = nil, &block)
Override the normal promp popup so it does not occurr.
-
- (Object) refresh
Refresh to current page.
-
- (Object) save_screenshot(file_name)
Save the current screenshot to the provided url.
-
- (Object) text
Returns the text of the current page.
-
- (Object) title
Returns the title of the current page.
-
- (Object) wait_for_ajax(timeout = 30, message = nil)
Wait until there are no pending ajax requests.
-
- (Object) wait_until(timeout = 30, message = nil, &block)
Wait until the block returns true or times out.
Methods included from PagePopulator
Methods included from ElementLocators
#button_element, #button_elements, #cell_element, #cell_elements, #checkbox_element, #checkbox_elements, #div_element, #div_elements, #element, #file_field_element, #file_field_elements, #form_element, #form_elements, #h1_element, #h1_elements, #h2_element, #h2_elements, #h3_element, #h3_elements, #h4_element, #h4_elements, #h5_element, #h5_elements, #h6_element, #h6_elements, #hidden_field_element, #hidden_field_elements, #image_element, #image_elements, #label_element, #label_elements, #link_element, #link_elements, #list_item_element, #list_item_elements, #ordered_list_element, #ordered_list_elements, #paragraph_element, #paragraph_elements, #radio_button_element, #radio_button_elements, #select_list_element, #select_list_elements, #span_element, #span_elements, #table_element, #table_elements, #text_area_element, #text_area_elements, #text_field_element, #text_field_elements, #unordered_list_element, #unordered_list_elements
Methods included from LoadsPlatform
Instance Attribute Details
- (Watir::Browser or Selenium::WebDriver::Driver) browser (readonly)
The platform browser passed to the constructor
44 45 46 |
# File 'lib/page-object.rb', line 44 def browser @browser end |
- (PageObject::WatirPageObject or PageObject::SeleniumPageObject) platform (readonly)
The platform page object
46 47 48 |
# File 'lib/page-object.rb', line 46 def platform @platform end |
Class Method Details
+ (Object) add_framework(key, framework)
Add a new javascript framework to page-object. The module passed in must adhere to the same prototype as the JQuery and Prototype modules.
subsequent calls the required actions.
85 86 87 |
# File 'lib/page-object.rb', line 85 def self.add_framework(key, framework) PageObject::JavascriptFrameworkFacade.add_framework(key, framework) end |
+ (Object) included(cls)
63 64 65 |
# File 'lib/page-object.rb', line 63 def self.included(cls) cls.extend PageObject::Accessors end |
+ (Object) javascript_framework=(framework)
Set the javascript framework to use when determining number of ajax requests. Valid frameworks are :jquery and :prototype
71 72 73 |
# File 'lib/page-object.rb', line 71 def self.javascript_framework=(framework) PageObject::JavascriptFrameworkFacade.framework = framework end |
Instance Method Details
- (String) alert(frame = nil, &block)
Override the normal alert popup so it does not occurr.
173 174 175 |
# File 'lib/page-object.rb', line 173 def alert(frame=nil, &block) platform.alert(frame, &block) end |
- (Object) attach_to_window(identifier, &block)
Attach to a running window. You can locate the window using either the window's title or url. If it failes to connect to a window it will pause for 1 second and try again.
be the entire url - it can just be the page name like index.html calling window
278 279 280 281 282 283 284 285 |
# File 'lib/page-object.rb', line 278 def attach_to_window(identifier, &block) begin platform.attach_to_window(identifier, &block) rescue sleep 1 platform.attach_to_window(identifier, &block) end end |
- (Object) back
Go back to the previous page
304 305 306 |
# File 'lib/page-object.rb', line 304 def back platform.back end |
- (Object) clear_cookies
Clear the cookies from the browser
318 319 320 |
# File 'lib/page-object.rb', line 318 def platform. end |
- (String) confirm(response, frame = nil, &block)
Override the normal confirm popup so it does not occurr.
190 191 192 |
# File 'lib/page-object.rb', line 190 def confirm(response, frame=nil, &block) platform.confirm(response, frame, &block) end |
- (Object) current_url
get the current page url
92 93 94 |
# File 'lib/page-object.rb', line 92 def current_url platform.current_url end |
- (Object) element_with_focus
Find the element that has focus on the page
290 291 292 |
# File 'lib/page-object.rb', line 290 def element_with_focus platform.element_with_focus end |
- (Object) execute_script(script)
Execute javascript on the browser
215 216 217 |
# File 'lib/page-object.rb', line 215 def execute_script(script) platform.execute_script(script) end |
- (Object) forward
Go forward to the next page
311 312 313 |
# File 'lib/page-object.rb', line 311 def forward platform.forward end |
- (Object) html
Returns the html of the current page
115 116 117 |
# File 'lib/page-object.rb', line 115 def html platform.html end |
- (Object) in_frame(identifier, frame = nil, &block)
Identify an element as existing within a frame or iframe. A frame parameter is passed to the block and must be passed to the other calls to PageObject. You can nest calls to in_frame by passing the frame to the next level.
236 237 238 |
# File 'lib/page-object.rb', line 236 def in_frame(identifier, frame=nil, &block) platform.in_frame(identifier, frame, &block) end |
- (PageObject) initialize(browser, visit = false)
Construct a new page object. Upon initialization of the page it will call a method named initialize_page if it exists.
55 56 57 58 59 60 |
# File 'lib/page-object.rb', line 55 def initialize(browser, visit=false) @browser = browser include_platform_driver(browser) goto if visit && respond_to?(:goto) initialize_page if respond_to?(:initialize_page) end |
- (Object) modal_dialog(&block)
Override the normal showModalDialog call is it opens a window instead of a dialog. You will need to attach to the new window in order to continue.
252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/page-object.rb', line 252 def modal_dialog(&block) script = %Q{ window.showModalDialog = function(sURL, vArguments, sFeatures) { window.dialogArguments = vArguments; modalWin = window.open(sURL, 'modal', sFeatures); return modalWin; } } browser.execute_script script yield if block_given? end |
- (Object) navigate_to(url)
navigate to the provided url
101 102 103 |
# File 'lib/page-object.rb', line 101 def navigate_to(url) platform.navigate_to(url) end |
- (Hash) prompt(answer, frame = nil, &block)
Override the normal promp popup so it does not occurr.
:default_value contains the default value for the prompt if provided
208 209 210 |
# File 'lib/page-object.rb', line 208 def prompt(answer, frame=nil, &block) platform.prompt(answer, frame, &block) end |
- (Object) refresh
Refresh to current page
297 298 299 |
# File 'lib/page-object.rb', line 297 def refresh platform.refresh end |
- (Object) save_screenshot(file_name)
Save the current screenshot to the provided url. File is saved as a png file.
326 327 328 |
# File 'lib/page-object.rb', line 326 def save_screenshot(file_name) platform.save_screenshot file_name end |
- (Object) text
Returns the text of the current page
108 109 110 |
# File 'lib/page-object.rb', line 108 def text platform.text end |
- (Object) title
Returns the title of the current page
122 123 124 |
# File 'lib/page-object.rb', line 122 def title platform.title end |
- (Object) wait_for_ajax(timeout = 30, message = nil)
Wait until there are no pending ajax requests. This requires you to set the javascript framework in advance.
the timeout duration.
151 152 153 154 155 156 157 158 159 |
# File 'lib/page-object.rb', line 151 def wait_for_ajax(timeout = 30, = nil) end_time = ::Time.now + timeout until ::Time.now > end_time return if browser.execute_script(::PageObject::JavascriptFrameworkFacade.pending_requests) == 0 sleep 0.5 end = "Timed out waiting for ajax requests to complete" unless raise end |
- (Object) wait_until(timeout = 30, message = nil, &block)
Wait until the block returns true or times out
138 139 140 |
# File 'lib/page-object.rb', line 138 def wait_until(timeout = 30, = nil, &block) platform.wait_until(timeout, , &block) end |