Class: Citronella::Web::WebPage
- Inherits:
-
Object
- Object
- Citronella::Web::WebPage
- Defined in:
- lib/web_page.rb
Overview
An object class that is used across the tests. ‘webdriver_wait` is set to ’10’ seconds by default. ‘logger` is set to ’true’ by default.
Usage:
driver = Selenium::WebDriver.for :chrome
web = WebPage.new(driver)
Instance Method Summary collapse
-
#driver ⇒ Webdriver
Returns the original Selenium driver.
-
#initialize(driver, webdriver_wait: 10, logger: true) ⇒ WebPage
constructor
A new instance of WebPage.
-
#locate(args) ⇒ Citronella::Ui::WebUi
An alternative way for testing without using page objects.
-
#page ⇒ Citronella::Wrapper::PageDecorator
Returns the wrapped page object model.
-
#page=(page) ⇒ Object
Sets the page object model.
-
#ready_state(wait) ⇒ Object
Executes JavaScript to wait for the page to fully load.
-
#webdriver_wait(wait) ⇒ Object
Overrides the ‘webdriver_wait` value.
Constructor Details
#initialize(driver, webdriver_wait: 10, logger: true) ⇒ WebPage
Returns a new instance of WebPage.
42 43 44 45 46 47 |
# File 'lib/web_page.rb', line 42 def initialize(driver, webdriver_wait:10, logger:true) @driver = driver @webdriver_wait = webdriver_wait @page = nil @logger = logger end |
Instance Method Details
#driver ⇒ Webdriver
Returns the original Selenium driver.
53 54 55 |
# File 'lib/web_page.rb', line 53 def driver @driver end |
#locate(args) ⇒ Citronella::Ui::WebUi
An alternative way for testing without using page objects. It returns a WebUi class, but can’t use ‘page` and may cause an error. It’s good for quick prototypes or writing tests.
Usage:
web.ui(name: 'q').get_element.text
web.ui(name: 'q').get_element.click
85 86 87 88 |
# File 'lib/web_page.rb', line 85 def locate(args) Citronella::Ui::WebUi.new(@driver, @webdriver_wait, @logger, args, args, __method__.to_s) end |
#page ⇒ Citronella::Wrapper::PageDecorator
Returns the wrapped page object model.
61 62 63 64 |
# File 'lib/web_page.rb', line 61 def page Citronella::Wrapper::PageDecorator.new(@driver, @webdriver_wait, @page, @logger) end |
#page=(page) ⇒ Object
Sets the page object model.
70 71 72 |
# File 'lib/web_page.rb', line 70 def page=(page) @page = page end |
#ready_state(wait) ⇒ Object
Executes JavaScript to wait for the page to fully load.
94 95 96 97 98 99 100 |
# File 'lib/web_page.rb', line 94 def ready_state(wait) wait.times do |i| return if driver.execute_script( "return document.readyState") == "complete" sleep(1) end end |
#webdriver_wait(wait) ⇒ Object
Overrides the ‘webdriver_wait` value.
106 107 108 |
# File 'lib/web_page.rb', line 106 def webdriver_wait(wait) @webdriver_wait = wait end |