Created
April 18, 2012 17:30
-
-
Save cheezy/2415279 to your computer and use it in GitHub Desktop.
Using PageObject with RSpec
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
# spec_helper.rb | |
require 'rspec' | |
require 'watir-webdriver' | |
require 'page-object' | |
require 'page-object/page_factory' | |
require 'require_all' | |
require_all 'lib/pages' | |
RSpec.configure do |config| | |
config.include PageObject::PageFactory | |
config.before(:all) do | |
@browser = Watir::Browser.new :firefox | |
end | |
config.after(:all) do | |
@browser.close | |
end | |
end | |
PageObject::PageFactory.routes = { | |
:default => [[HomePage, :select_puppy], | |
[DetailsPage, :add_to_cart], | |
[ShoppingCartPage, :continue_to_checkout], | |
[CheckoutPage, :complete_order]] | |
} | |
# Example spec agains puppy application | |
require 'spec_helper' | |
describe "Using the adoption site" do | |
context "to adopt puppies it" do | |
before(:each) do | |
visit_page HomePage | |
end | |
it "should display thank you message when adoption is completed" do | |
navigate_to(CheckoutPage).complete_order | |
@current_page.text.should include "Thank you for adopting a puppy!" | |
end | |
it "should require name during checkout" do | |
navigate_to(CheckoutPage).complete_order('name' => '') | |
@current_page.should have_error_message "Name can't be blank" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment