Class: Citronella::Web::WebPage

Inherits:
Object
  • Object
show all
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

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

#driverWebdriver

Returns the original Selenium driver.

Returns:

  • (Webdriver)

    The web driver object.



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

Parameters:

  • args (Hash)

    The locator details.

Returns:



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

#pageCitronella::Wrapper::PageDecorator

Returns the wrapped page object model.

Returns:



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.

Parameters:

  • page (PageObject)

    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.

Parameters:

  • wait (Integer)

    The number of times to check the page’s ready state.



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.

Parameters:

  • wait (Integer)

    The new value for ‘webdriver_wait`.



106
107
108
# File 'lib/web_page.rb', line 106

def webdriver_wait(wait)
  @webdriver_wait = wait
end