Last active
January 4, 2016 02:19
-
-
Save bbbco/8554007 to your computer and use it in GitHub Desktop.
A simple example gist of a theoretical SWD Page Object gem based on using dot notation object oriented hierarchy for mapping and accessing elements on a page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TablesPage < Selenium::Pages::Page | |
// Define url to visit and matchers | |
url "/tables" | |
url_matcher /tables/ | |
// Creates a new Element object that is required (i.e. expects to be visible at page load) | |
required_element :header, :css => "h3" | |
// Can also define multiple elements. Not specifying requirement only means it is expected to be present | |
elements :example_subheaders, :css => "h4" | |
// You can define sections to allow you to create a hierarchy | |
required_sections :tables, :css => "table.tablesorter-default" do |t| | |
t.elements :header_columns, :css => "thead > tr > th" | |
t.sections :rows, :css => "tbody > tr" do |r| | |
r.elements :cells, :css => "td" | |
end | |
end | |
// Optional elements can be defined as elements that might appear on the page later on | |
// optional_element :not_here_now, :css => "div" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'selenium-webdriver' | |
// Placeholder SWD Page Object Gem | |
require 'selenium-pages' | |
require 'tables_po' | |
class TestCase < Test::Unit | |
def setup | |
@driver = Selenium::WebDriver.for :firefox | |
@browser = Selenium::Pages::Browser.new(@driver, "http://the-internet.herokuapp.com") | |
end | |
def test_sort_by_last_name | |
// Instantiate Page Object | |
@page = @browser.visit(TablesPage) | |
// Valid Page Checks | |
assert @page.everything_ready? | |
// The code immediately above would be the equivalent of calling: | |
assert_matches @page.url_matcher, @browser.url | |
assert @page.header.displayed? // "h3" element visible | |
assert @page.example_subheaders // "h4" elements present | |
assert @page.tables.displayed? // "table" elements visible | |
// Ensure valid text data | |
assert_matches "Data Tables", @page.header.text | |
// Sort on last name in the first table | |
table = @page.tables.first // First displayed table | |
assert_matches "Last Name", table.header_columns[0].text | |
table.header_columns[0].click | |
// Check to ensure table is sorted | |
assert_matches "Conway", table.rows.first.cells.first.text | |
assert_matches "Smith", table.rows.last.cells.first.text | |
end | |
def teardown | |
@driver.quit | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment