Skip to content

Instantly share code, notes, and snippets.

@natritmeyer
Created May 31, 2012 18:32
Show Gist options
  • Save natritmeyer/2845288 to your computer and use it in GitHub Desktop.
Save natritmeyer/2845288 to your computer and use it in GitHub Desktop.
Page Object Management blog post material
visit LoginPage do |page|
page.login_with('foo', 'badpass')
page.text.should include "Login error"
page.text.should include "Secure your account"
end
class App
def home
HomePage.new #returns an instance of the HomePage class
end
def login_page
LoginPage.new
end
def account_page
AccountPage.new
end
def account_history_page
AccountHistoryPage.new
end
end
When /^I log in as the administrator$/ do
@app.home.expand_user_section
@app.home.sign_in.click
@app.login.username.set "admin"
@app.login.password.set "p4ssword"
@app.login.login_button.click
end
When /^I visit the (home|login|account|account history) page$/ do |page_name|
@app = App.new # <= the only place where @app is instantiated
target_page = case page_name
when 'home' then @app.home
when 'login' then @app.login
when 'account' then @app.account
when 'account history' then @app.account_history
end
visit target_page
end
@login_page = LoginPage.new # <= dirt
@login_page.login_with "bob", "p4ssword"
@account_page = AccountPage.new # <= more dirt
@account_page.username.text.should == "bob"
@account_page.view_account_history.click
@account_history_page = AccountHistoryPage.new # <= yet more dirt
@account_history_page.purchased_items.size.should == 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment