Skip to content

Instantly share code, notes, and snippets.

@cheezy
Created April 18, 2012 17:30
Show Gist options
  • Save cheezy/2415279 to your computer and use it in GitHub Desktop.
Save cheezy/2415279 to your computer and use it in GitHub Desktop.
Using PageObject with RSpec
# 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