Last active
December 15, 2015 08:38
-
-
Save robpark/5231874 to your computer and use it in GitHub Desktop.
Notes for a code read at the Boston Software Craftsmanship meeting on 4/1/2013.
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
Page Objects | |
"Within your web app's UI there are areas that your tests interact with. | |
A Page Object simply models these as objects within the test code. | |
This reduces the amount of duplicated code and means that if the UI changes, | |
the fix need only be applied in one place." | |
Page-object gem is used with Cucumber (ruby) either testing via watir or selenium | |
--- usage snippet --- | |
class CreateAnimal | |
include PageObject | |
page_url "#{@@base_url}/animal/new" | |
select_list(:genus, :id => 'genus_selector') | |
button(:submit, :value => 'Submit') | |
text_field(:name, :id => 'name') | |
text_field(:birth_date, :id => 'birthday') | |
label(:message, :id => 'success_message') | |
def add genus, name | |
self.genus = genus | |
self.name = name | |
self.birth_date = '3/1/2011' | |
end | |
def find_name | |
#get the name out of self.message | |
end | |
end | |
Given /^I have a "([^"]*)" named "([^"]*)"$/ do |genus, name| | |
visit_page(CreateAnimal) { |page| page.add genus, name } | |
end | |
Given /^his birthday is "([^"]*)"$/ do |birthday| | |
on_page(CreateAnimal) { |page| page.birth_date = birthday } | |
end | |
When /^he's added$/ do | |
on_page(CreateAnimal) { |page| page.submit } | |
end | |
Then /^"([^"]*)" is successfully saved$/ do |name| | |
on_page(CreateAnimal) { |page| page.find_name.should == name } | |
end | |
It is test-driven from the outside in using Cucumber and RSpec. | |
Look into elements (features, specs, elements) | |
< I wish the element-based features were in an elements folder > | |
Platforms are platform-specific [watir || selenium] modules for various elements. | |
They get mixed-in (essentially multiple inheritance) during page-object element initialization. | |
TODO: look into root classes | |
* ele is shorthand for element; eles is elements | |
* 80 char line lengths would be better | |
* Any opinions on monkey patching String for is_integer? (and no test?) | |
--- resources --- | |
Wiki: | |
https://github.com/cheezy/page-object/wiki | |
Google group: | |
https://groups.google.com/forum/?fromgroups#!forum/page-object | |
Page Object pattern: | |
https://code.google.com/p/selenium/wiki/PageObjects |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment