Citronella
webdriver extension with a page object wrapper.
Example Tests
require 'test/unit'
require "selenium-webdriver"
require 'citronella'
require_relative '../pages/contents_page'
class NavigationTest < Test::Unit::TestCase
def setup
= Selenium::WebDriver::Chrome::Options.new
driver = Selenium::WebDriver.for :chrome, options:
@web = Citronella::Web::WebPage.new(driver)
@web.page = ContentsPage
@web.driver.navigate.to('https://rubygems.org')
end
def teardown
@web.driver.quit
end
def
@web.page.home_page..click
assert_includes(@web.driver.title, 'Releases')
@web.page.release_page..click
assert_includes(@web.driver.title, 'Gem')
@web.page.gems_page..click
assert_includes(@web.driver.title, 'Sign in')
@web.page.sign_in_page..click
assert_includes(@web.driver.title, 'Sign up')
@web.page.sign_up_page..click
assert_includes(@web.driver.title, 'Guides')
@web.page.guides_page..click
assert_includes(@web.driver.title, 'Blog')
end
end
Even though this module is mainly designed for the page object model, it can also be used without it for quick prototyping or mockups, etc.
require 'test/unit'
require "selenium-webdriver"
require 'citronella'
class PackageSearchTest < Test::Unit::TestCase
def setup
= Selenium::WebDriver::Chrome::Options.new
driver = Selenium::WebDriver.for :chrome, options:
@web = Citronella::Web::WebPage.new(driver)
end
def teardown
@web.driver.quit
end
def test_search_package
@web.driver.navigate.to "https://rubygems.org/"
@web.locate(id: 'home_query').send_keys('citronella')
@web.locate(class: 'home__search__icon').click
assert(@web.locate(class: 'gems__gem__name').get_element.text, 'citronella')
end
end
Install Package
gem install citronella
Documentation
There are only two modules imported in this package:
- The first module is for the tests.
require 'test/unit'
require "selenium-webdriver"
require 'citronella'
class NavigationTest < Test::Unit::TestCase
def setup
= Selenium::WebDriver::Chrome::Options.new
driver = Selenium::WebDriver.for :chrome, options:
@web = Citronella::Web::WebPage.new(driver)
end
def teardown
@web.driver.quit
end
end
- The last module is for the page object model.
require 'citronella'
require_relative '../components/header_menu'
class HomePage
include HeaderMenu
def
ui(class: 'home__search__icon')
end
def
ui(css: 'div.nav--v > a:nth-child(3)')
end
end
Page Object Design / Strategy
see full Page object example
require "selenium-webdriver"
require 'citronella'
module HeaderMenu
def home_logo
ui(class: 'header__logo')
end
def search_input
ui(id: 'home_query')
end
def
ui(css: 'a[href="/gems"]')
end
end
class HomePage
include HeaderMenu
def
ui(class: 'home__search__icon')
end
def
ui(css: 'div.nav--v > a:nth-child(3)')
end
end
class SearchPage
include HeaderMenu
def search_lists
ui(class: 'gems__gem__name')
end
end
class ContentsPage
def home_page
HomePage
end
def search_page
SearchPage
end
end
= Selenium::WebDriver::Chrome::Options.new
driver = Selenium::WebDriver.for :chrome, options:
web = Citronella::Web::WebPage.new(driver)
web.page = ContentsPage
web.driver.navigate.to('https://rubygems.org')
web.page.home_page.search_input.send_keys('citronella', return_key=true)
puts web.page.search_page.search_list.get_element.text
Usage
citronella.WebPage
Args:
- driver / webdriver
Kwargs (optional):
- webdriver_wait
number(seconds)
, default value is10
- logger
bool
, default value istrue
Method Lists:
Method Name | Args* | Kwargs** | Note |
---|---|---|---|
driver | - | - | return selenium webdriver object |
locate | - | how: what | similar asdriver.get_element as input & return citronella.WebUi |
page | Page Object | - | setter |
page | - | - | getter |
webdriver_wait | number(sec) | - | |
ready_state | number(sec) | - | execute javascript document.readyState manually |
citronella.ui / citronella.WebUi
Kwargs:
- how: what
Method Lists:
Method Name | Args* | Kwargs** | Note |
---|---|---|---|
send_keys | text | clear bool , return_key bool |
|
click | - | - | |
get_element | - | - | |
get_elements | - | - |