2009-11-04 22:00:05 +00:00
|
|
|
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
|
|
|
|
2009-11-07 19:44:45 +00:00
|
|
|
shared_examples_for "session" do
|
|
|
|
describe '#app' do
|
|
|
|
it "should remember the application" do
|
|
|
|
@session.app.should == TestApp
|
2009-11-04 22:17:17 +00:00
|
|
|
end
|
2009-11-07 19:44:45 +00:00
|
|
|
end
|
2009-11-07 17:56:04 +00:00
|
|
|
|
2009-11-07 19:44:45 +00:00
|
|
|
describe '#visit' do
|
|
|
|
it "should fetch a response from the driver" do
|
|
|
|
@session.visit('/')
|
|
|
|
@session.body.should == 'Hello world!'
|
|
|
|
@session.visit('/foo')
|
|
|
|
@session.body.should == 'Another World'
|
2009-11-04 23:42:13 +00:00
|
|
|
end
|
2009-11-04 22:00:05 +00:00
|
|
|
end
|
|
|
|
|
2009-11-07 19:44:45 +00:00
|
|
|
describe '#click_link' do
|
2009-11-04 22:17:17 +00:00
|
|
|
before do
|
2009-11-07 19:44:45 +00:00
|
|
|
@session.visit('/with_html')
|
2009-11-04 22:00:05 +00:00
|
|
|
end
|
2009-11-07 19:44:45 +00:00
|
|
|
|
|
|
|
context "with id given" do
|
|
|
|
it "should take user to the linked page" do
|
|
|
|
@session.click_link('foo')
|
|
|
|
@session.body.should == 'Another World'
|
2009-11-04 22:17:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-11-07 19:44:45 +00:00
|
|
|
context "with text given" do
|
|
|
|
it "should take user to the linked page" do
|
|
|
|
@session.click_link('labore')
|
|
|
|
@session.body.should == '<h1>Bar</h1>'
|
2009-11-04 22:17:17 +00:00
|
|
|
end
|
2009-11-04 22:00:05 +00:00
|
|
|
end
|
2009-11-07 19:44:45 +00:00
|
|
|
|
|
|
|
context "with title given" do
|
|
|
|
it "should take user to the linked page" do
|
|
|
|
@session.click_link('awesome title')
|
|
|
|
@session.body.should == '<h1>Bar</h1>'
|
2009-11-04 22:17:17 +00:00
|
|
|
end
|
2009-11-04 22:00:05 +00:00
|
|
|
end
|
2009-11-07 19:44:45 +00:00
|
|
|
|
|
|
|
context "with a locator that doesn't exist" do
|
|
|
|
it "should raise an error" do
|
|
|
|
running do
|
|
|
|
@session.click_link('does not exist')
|
|
|
|
end.should raise_error(Webcat::ElementNotFound)
|
2009-11-04 22:17:17 +00:00
|
|
|
end
|
|
|
|
end
|
2009-11-04 22:00:05 +00:00
|
|
|
end
|
2009-11-08 00:13:16 +00:00
|
|
|
|
|
|
|
describe '#click_button' do
|
|
|
|
before do
|
|
|
|
@session.visit('/form')
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with value given" do
|
2009-11-09 22:10:15 +00:00
|
|
|
before do
|
2009-11-08 00:13:16 +00:00
|
|
|
@session.click_button('awesome')
|
2009-11-09 22:10:15 +00:00
|
|
|
@results = YAML.load(@session.body)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should serialize and submit text fields" do
|
2009-11-09 22:38:19 +00:00
|
|
|
@results['first_name'].should == 'John'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not serialize fields from other forms" do
|
|
|
|
@results['middle_name'].should be_nil
|
2009-11-09 22:10:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should submit the button that was clicked, but not other buttons" do
|
|
|
|
@results['awesome'].should == 'awesome'
|
|
|
|
@results['crappy'].should be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should serialize radio buttons" do
|
|
|
|
@results['gender'].should == 'female'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should serialize check boxes" do
|
|
|
|
@results['pets'].should include('dog', 'hamster')
|
|
|
|
@results['pets'].should_not include('cat')
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should serialize text areas" do
|
|
|
|
@results['description'].should == 'Descriptive text goes here'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should serialize select tag with values" do
|
|
|
|
@results['locale'].should == 'en'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should serialize select tag without values" do
|
|
|
|
@results['region'].should == 'Norway'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should serialize first option for select tag with no selection" do
|
|
|
|
@results['city'].should == 'London'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should not serialize a select tag without options" do
|
|
|
|
@results['tendency'].should be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with multipart form" do
|
|
|
|
it "should attach the file"
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with normal form" do
|
|
|
|
it "should serialize the file path"
|
2009-11-08 00:13:16 +00:00
|
|
|
end
|
|
|
|
end
|
2009-11-08 00:29:03 +00:00
|
|
|
|
|
|
|
context "with id given" do
|
|
|
|
it "should submit the associated form" do
|
|
|
|
@session.click_button('awe123')
|
|
|
|
results = YAML.load(@session.body)
|
2009-11-09 22:38:19 +00:00
|
|
|
results['first_name'].should == 'John'
|
2009-11-08 00:29:03 +00:00
|
|
|
end
|
|
|
|
end
|
2009-11-08 00:13:16 +00:00
|
|
|
end
|
2009-11-09 22:51:39 +00:00
|
|
|
|
|
|
|
describe "#fill_in" do
|
2009-11-10 21:48:31 +00:00
|
|
|
before do
|
2009-11-09 22:51:39 +00:00
|
|
|
@session.visit('/form')
|
2009-11-10 21:48:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should fill in a field by id" do
|
2009-11-09 22:51:39 +00:00
|
|
|
@session.fill_in('form_first_name', :with => 'Harry')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
YAML.load(@session.body)['first_name'].should == 'Harry'
|
|
|
|
end
|
2009-11-09 23:06:51 +00:00
|
|
|
|
|
|
|
it "should fill in a field by label" do
|
|
|
|
@session.fill_in('First Name', :with => 'Harry')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
YAML.load(@session.body)['first_name'].should == 'Harry'
|
|
|
|
end
|
2009-11-10 21:48:31 +00:00
|
|
|
|
|
|
|
it "should fill in a textarea by id" do
|
|
|
|
@session.fill_in('form_description', :with => 'Texty text')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
YAML.load(@session.body)['description'].should == 'Texty text'
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should fill in a textarea by label" do
|
|
|
|
@session.fill_in('Description', :with => 'Texty text')
|
|
|
|
@session.click_button('awesome')
|
|
|
|
YAML.load(@session.body)['description'].should == 'Texty text'
|
|
|
|
end
|
2009-11-09 22:51:39 +00:00
|
|
|
end
|
2009-11-07 19:44:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe Webcat::Session do
|
|
|
|
context 'with non-existant driver' do
|
2009-11-04 22:17:17 +00:00
|
|
|
it "should raise an error" do
|
|
|
|
running {
|
|
|
|
Webcat::Session.new(:quox, TestApp).driver
|
|
|
|
}.should raise_error(Webcat::DriverNotFoundError)
|
2009-11-04 22:00:05 +00:00
|
|
|
end
|
|
|
|
end
|
2009-11-07 14:36:58 +00:00
|
|
|
end
|