Module: PageObject
- Includes:
- ElementLocators, LoadsPlatform, PagePopulator
- Included in:
- IndexedProperties::TableOfElements
- Defined in:
- lib/page-object-lds.rb,
lib/page-object/version.rb,
lib/page-object/widgets.rb,
lib/page-object/elements.rb,
lib/page-object/accessors.rb,
lib/page-object/platforms.rb,
lib/page-object/elements/div.rb,
lib/page-object/page_factory.rb,
lib/page-object/elements/area.rb,
lib/page-object/elements/bold.rb,
lib/page-object/elements/form.rb,
lib/page-object/elements/link.rb,
lib/page-object/elements/span.rb,
lib/page-object/elements/audio.rb,
lib/page-object/elements/image.rb,
lib/page-object/elements/label.rb,
lib/page-object/elements/media.rb,
lib/page-object/elements/table.rb,
lib/page-object/elements/video.rb,
lib/page-object/javascript/yui.rb,
lib/page-object/loads_platform.rb,
lib/page-object/page_populator.rb,
lib/page-object/elements/button.rb,
lib/page-object/elements/canvas.rb,
lib/page-object/elements/option.rb,
lib/page-object/nested_elements.rb,
lib/page-object/element_locators.rb,
lib/page-object/elements/element.rb,
lib/page-object/elements/heading.rb,
lib/page-object/javascript/jquery.rb,
lib/page-object/locator_generator.rb,
lib/page-object/elements/check_box.rb,
lib/page-object/elements/list_item.rb,
lib/page-object/elements/paragraph.rb,
lib/page-object/elements/table_row.rb,
lib/page-object/elements/text_area.rb,
lib/page-object/indexed_properties.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/elements/select_list.rb,
lib/page-object/javascript/angularjs.rb,
lib/page-object/javascript/prototype.rb,
lib/page-object/elements/hidden_field.rb,
lib/page-object/elements/ordered_list.rb,
lib/page-object/elements/radio_button.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/lds_watir_webdriver.rb,
lib/page-object/platforms/watir_webdriver/form.rb,
lib/page-object/platforms/watir_webdriver/link.rb,
lib/page-object/platforms/watir_webdriver/image.rb,
lib/page-object/platforms/watir_webdriver/table.rb,
lib/page-object/platforms/selenium_webdriver/form.rb,
lib/page-object/platforms/selenium_webdriver/link.rb,
lib/page-object/platforms/watir_webdriver/element.rb,
lib/page-object/platforms/lds_watir_webdriver/form.rb,
lib/page-object/platforms/lds_watir_webdriver/link.rb,
lib/page-object/platforms/selenium_webdriver/image.rb,
lib/page-object/platforms/selenium_webdriver/table.rb,
lib/page-object/platforms/lds_watir_webdriver/image.rb,
lib/page-object/platforms/lds_watir_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/table_row.rb,
lib/page-object/platforms/watir_webdriver/text_area.rb,
lib/page-object/platforms/selenium_webdriver/element.rb,
lib/page-object/platforms/watir_webdriver/file_field.rb,
lib/page-object/platforms/watir_webdriver/text_field.rb,
lib/page-object/platforms/lds_watir_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/selenium_webdriver/text_area.rb,
lib/page-object/platforms/watir_webdriver/ordered_list.rb,
lib/page-object/platforms/watir_webdriver/radio_button.rb,
lib/page-object/platforms/lds_watir_webdriver/check_box.rb,
lib/page-object/platforms/lds_watir_webdriver/table_row.rb,
lib/page-object/platforms/lds_watir_webdriver/text_area.rb,
lib/page-object/platforms/selenium_webdriver/file_field.rb,
lib/page-object/platforms/selenium_webdriver/text_field.rb,
lib/page-object/platforms/lds_watir_webdriver/file_field.rb,
lib/page-object/platforms/lds_watir_webdriver/text_field.rb,
lib/page-object/platforms/selenium_webdriver/page_object.rb,
lib/page-object/platforms/selenium_webdriver/select_list.rb,
lib/page-object/platforms/watir_webdriver/unordered_list.rb,
lib/page-object/platforms/lds_watir_webdriver/page_object.rb,
lib/page-object/platforms/lds_watir_webdriver/select_list.rb,
lib/page-object/platforms/selenium_webdriver/ordered_list.rb,
lib/page-object/platforms/selenium_webdriver/radio_button.rb,
lib/page-object/platforms/lds_watir_webdriver/ordered_list.rb,
lib/page-object/platforms/lds_watir_webdriver/radio_button.rb,
lib/page-object/platforms/selenium_webdriver/unordered_list.rb,
lib/page-object/platforms/lds_watir_webdriver/unordered_list.rb,
lib/page-object/platforms/selenium_webdriver/surrogate_selenium_element.rb
Overview
Defined Under Namespace
Modules: Accessors, ElementLocators, Elements, IndexedProperties, Javascript, JavascriptFrameworkFacade, LoadsPlatform, LocatorGenerator, NestedElements, PageFactory, PagePopulator, Platforms, Widgets
Constant Summary collapse
- VERSION =
"0.0.14"
Instance Attribute Summary collapse
-
#browser ⇒ Watir::Browser or Selenium::WebDriver::Driver
readonly
The platform browser passed to the constructor.
-
#platform ⇒ PageObject::WatirPageObject or PageObject::SeleniumPageObject
readonly
The platform page object.
Class Method Summary collapse
-
.add_framework(key, framework) ⇒ Object
Add a new javascript framework to page-object.
-
.default_element_wait ⇒ Object
Returns the default timeout for element level waits.
-
.default_element_wait=(timeout) ⇒ Object
Sets the default timeout for element level waits.
-
.default_page_wait ⇒ Object
Returns the default timeout for page lavel waits.
-
.default_page_wait=(timeout) ⇒ Object
Set the default timeout for page level waits.
- .included(cls) ⇒ Object
-
.javascript_framework=(framework) ⇒ Object
Set the javascript framework to use when determining number of ajax requests.
- .register_widget(widget_tag, widget_class, base_element_tag) ⇒ Object
Instance Method Summary collapse
-
#alert(frame = nil, &block) ⇒ String
Override the normal alert popup so it does not occur.
-
#attach_to_window(identifier, &block) ⇒ Object
Attach to a running window.
-
#back ⇒ Object
Go back to the previous page.
-
#clear_cookies ⇒ Object
Clear the cookies from the browser.
-
#confirm(response, frame = nil, &block) ⇒ String
Override the normal confirm popup so it does not occur.
-
#current_url ⇒ Object
get the current page url.
-
#element_with_focus ⇒ Object
Find the element that has focus on the page.
-
#execute_script(script, *args) ⇒ Object
Execute javascript on the browser.
-
#forward ⇒ Object
Go forward to the next page.
-
#html ⇒ Object
Returns the html of the current page.
-
#in_frame(identifier, frame = nil, &block) ⇒ Object
Identify an element as existing within a frame.
-
#in_iframe(identifier, frame = nil, &block) ⇒ Object
Identify an element as existing within an iframe.
-
#initialize(browser, visit = false) ⇒ Object
Construct a new page object.
- #initialize_browser(browser) ⇒ Object
-
#modal_dialog(&block) ⇒ Object
Override the normal showModalDialog call is it opens a window instead of a dialog.
-
#navigate_to(url) ⇒ Object
navigate to the provided url.
-
#prompt(answer, frame = nil, &block) ⇒ Hash
Override the normal prompt popup so it does not occur.
-
#refresh ⇒ Object
Refresh to current page.
-
#save_screenshot(file_name) ⇒ Object
Save the current screenshot to the provided url.
- #testModif ⇒ Object
-
#text ⇒ Object
Returns the text of the current page.
-
#title ⇒ Object
Returns the title of the current page.
-
#wait_for_ajax(timeout = 30, message = nil) ⇒ Object
Wait until there are no pending ajax requests.
-
#wait_until(timeout = PageObject.default_page_wait, message = nil, &block) ⇒ Object
Wait until the block returns true or times out.
Methods included from PagePopulator
Methods included from ElementLocators
Methods included from LoadsPlatform
Instance Attribute Details
#browser ⇒ Watir::Browser or Selenium::WebDriver::Driver (readonly)
Returns the platform browser passed to the constructor.
54 55 56 |
# File 'lib/page-object-lds.rb', line 54 def browser @browser end |
#platform ⇒ PageObject::WatirPageObject or PageObject::SeleniumPageObject (readonly)
Returns the platform page object.
56 57 58 |
# File 'lib/page-object-lds.rb', line 56 def platform @platform end |
Class Method Details
.add_framework(key, framework) ⇒ Object
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.
134 135 136 |
# File 'lib/page-object-lds.rb', line 134 def self.add_framework(key, framework) PageObject::JavascriptFrameworkFacade.add_framework(key, framework) end |
.default_element_wait ⇒ Object
Returns the default timeout for element level waits
111 112 113 |
# File 'lib/page-object-lds.rb', line 111 def self.default_element_wait @element_wait ||= 5 end |
.default_element_wait=(timeout) ⇒ Object
Sets the default timeout for element level waits
104 105 106 |
# File 'lib/page-object-lds.rb', line 104 def self.default_element_wait=(timeout) @element_wait = timeout end |
.default_page_wait ⇒ Object
Returns the default timeout for page lavel waits
97 98 99 |
# File 'lib/page-object-lds.rb', line 97 def self.default_page_wait @page_wait ||= 30 end |
.default_page_wait=(timeout) ⇒ Object
Set the default timeout for page level waits
90 91 92 |
# File 'lib/page-object-lds.rb', line 90 def self.default_page_wait=(timeout) @page_wait = timeout end |
.included(cls) ⇒ Object
83 84 85 |
# File 'lib/page-object-lds.rb', line 83 def self.included(cls) cls.extend PageObject::Accessors end |
.javascript_framework=(framework) ⇒ Object
Set the javascript framework to use when determining number of ajax requests. Valid frameworks are :jquery, :prototype, :yui, and :angularjs
120 121 122 |
# File 'lib/page-object-lds.rb', line 120 def self.javascript_framework=(framework) PageObject::JavascriptFrameworkFacade.framework = framework end |
.register_widget(widget_tag, widget_class, base_element_tag) ⇒ Object
408 409 410 |
# File 'lib/page-object-lds.rb', line 408 def self.(, , base_element_tag) Widgets.(, , base_element_tag) end |
Instance Method Details
#alert(frame = nil, &block) ⇒ String
Override the normal alert popup so it does not occur.
223 224 225 |
# File 'lib/page-object-lds.rb', line 223 def alert(frame=nil, &block) platform.alert(frame, &block) end |
#attach_to_window(identifier, &block) ⇒ Object
Attach to a running window. You can locate the window using either the window’s title or url. If it fails 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
356 357 358 359 360 361 362 363 |
# File 'lib/page-object-lds.rb', line 356 def attach_to_window(identifier, &block) begin platform.attach_to_window(identifier, &block) rescue sleep 1 platform.attach_to_window(identifier, &block) end end |
#back ⇒ Object
Go back to the previous page
382 383 384 |
# File 'lib/page-object-lds.rb', line 382 def back platform.back end |
#clear_cookies ⇒ Object
Clear the cookies from the browser
396 397 398 |
# File 'lib/page-object-lds.rb', line 396 def platform. end |
#confirm(response, frame = nil, &block) ⇒ String
Override the normal confirm popup so it does not occur.
240 241 242 |
# File 'lib/page-object-lds.rb', line 240 def confirm(response, frame=nil, &block) platform.confirm(response, frame, &block) end |
#current_url ⇒ Object
get the current page url
141 142 143 |
# File 'lib/page-object-lds.rb', line 141 def current_url platform.current_url end |
#element_with_focus ⇒ Object
Find the element that has focus on the page
368 369 370 |
# File 'lib/page-object-lds.rb', line 368 def element_with_focus platform.element_with_focus end |
#execute_script(script, *args) ⇒ Object
Execute javascript on the browser
270 271 272 273 |
# File 'lib/page-object-lds.rb', line 270 def execute_script(script, *args) args.map! { |e| e.kind_of?(PageObject::Elements::Element) ? e.element : e } platform.execute_script(script, *args) end |
#forward ⇒ Object
Go forward to the next page
389 390 391 |
# File 'lib/page-object-lds.rb', line 389 def forward platform.forward end |
#html ⇒ Object
Returns the html of the current page
165 166 167 |
# File 'lib/page-object-lds.rb', line 165 def html platform.html end |
#in_frame(identifier, frame = nil, &block) ⇒ Object
Identify an element as existing within a frame. 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.
293 294 295 |
# File 'lib/page-object-lds.rb', line 293 def in_frame(identifier, frame=nil, &block) platform.in_frame(identifier, frame, &block) end |
#in_iframe(identifier, frame = nil, &block) ⇒ Object
Identify an element as existing within an 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_iframe by passing the frame to the next level.
314 315 316 |
# File 'lib/page-object-lds.rb', line 314 def in_iframe(identifier, frame=nil, &block) platform.in_iframe(identifier, frame, &block) end |
#initialize(browser, visit = false) ⇒ Object
Construct a new page object. Prior to browser initialization it will call a method named initialize_accessors if it exists. Upon initialization of the page it will call a method named initialize_page if it exists.
66 67 68 69 70 71 |
# File 'lib/page-object-lds.rb', line 66 def initialize(browser, visit=false) initialize_accessors if respond_to?(:initialize_accessors) initialize_browser(browser) goto if visit && respond_to?(:goto) initialize_page if respond_to?(:initialize_page) end |
#initialize_browser(browser) ⇒ Object
77 78 79 80 |
# File 'lib/page-object-lds.rb', line 77 def initialize_browser(browser) @browser = browser include_platform_driver(browser) end |
#modal_dialog(&block) ⇒ Object
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.
330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/page-object-lds.rb', line 330 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 |
#navigate_to(url) ⇒ Object
navigate to the provided url
150 151 152 153 |
# File 'lib/page-object-lds.rb', line 150 def navigate_to(url) if!platform[:platform] == :lds_watir_webdriver platform.navigate_to(url) end |
#prompt(answer, frame = nil, &block) ⇒ Hash
Override the normal prompt popup so it does not occur.
:default_value contains the default value for the prompt if provided
258 259 260 |
# File 'lib/page-object-lds.rb', line 258 def prompt(answer, frame=nil, &block) platform.prompt(answer, frame, &block) end |
#refresh ⇒ Object
Refresh to current page
375 376 377 |
# File 'lib/page-object-lds.rb', line 375 def refresh platform.refresh end |
#save_screenshot(file_name) ⇒ Object
Save the current screenshot to the provided url. File is saved as a png file.
404 405 406 |
# File 'lib/page-object-lds.rb', line 404 def save_screenshot(file_name) platform.save_screenshot file_name end |
#testModif ⇒ Object
73 74 75 |
# File 'lib/page-object-lds.rb', line 73 def testModif puts 'test' end |
#text ⇒ Object
Returns the text of the current page
158 159 160 |
# File 'lib/page-object-lds.rb', line 158 def text platform.text end |
#title ⇒ Object
Returns the title of the current page
172 173 174 |
# File 'lib/page-object-lds.rb', line 172 def title platform.title end |
#wait_for_ajax(timeout = 30, message = nil) ⇒ Object
Wait until there are no pending ajax requests. This requires you to set the javascript framework in advance.
the timeout duration.
201 202 203 204 205 206 207 208 209 |
# File 'lib/page-object-lds.rb', line 201 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 |
#wait_until(timeout = PageObject.default_page_wait, message = nil, &block) ⇒ Object
Wait until the block returns true or times out
188 189 190 |
# File 'lib/page-object-lds.rb', line 188 def wait_until(timeout = PageObject.default_page_wait, = nil, &block) platform.wait_until(timeout, , &block) end |