bjeanes-capybara 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +87 -0
- data/README.rdoc +404 -0
- data/Rakefile +29 -0
- data/config.ru +6 -0
- data/lib/capybara.rb +53 -0
- data/lib/capybara/cucumber.rb +32 -0
- data/lib/capybara/driver/base.rb +37 -0
- data/lib/capybara/driver/celerity_driver.rb +135 -0
- data/lib/capybara/driver/culerity_driver.rb +25 -0
- data/lib/capybara/driver/rack_test_driver.rb +244 -0
- data/lib/capybara/driver/selenium_driver.rb +137 -0
- data/lib/capybara/dsl.rb +60 -0
- data/lib/capybara/node.rb +69 -0
- data/lib/capybara/rails.rb +11 -0
- data/lib/capybara/save_and_open_page.rb +33 -0
- data/lib/capybara/searchable.rb +53 -0
- data/lib/capybara/server.rb +111 -0
- data/lib/capybara/session.rb +274 -0
- data/lib/capybara/wait_until.rb +23 -0
- data/lib/capybara/xpath.rb +176 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/capybara_spec.rb +18 -0
- data/spec/driver/celerity_driver_spec.rb +17 -0
- data/spec/driver/culerity_driver_spec.rb +13 -0
- data/spec/driver/rack_test_driver_spec.rb +12 -0
- data/spec/driver/remote_culerity_driver_spec.rb +26 -0
- data/spec/driver/remote_selenium_driver_spec.rb +18 -0
- data/spec/driver/selenium_driver_spec.rb +12 -0
- data/spec/drivers_spec.rb +139 -0
- data/spec/dsl/all_spec.rb +69 -0
- data/spec/dsl/attach_file_spec.rb +64 -0
- data/spec/dsl/check_spec.rb +39 -0
- data/spec/dsl/choose_spec.rb +26 -0
- data/spec/dsl/click_button_spec.rb +218 -0
- data/spec/dsl/click_link_spec.rb +108 -0
- data/spec/dsl/click_spec.rb +24 -0
- data/spec/dsl/current_url_spec.rb +8 -0
- data/spec/dsl/fill_in_spec.rb +91 -0
- data/spec/dsl/find_button_spec.rb +16 -0
- data/spec/dsl/find_by_id_spec.rb +16 -0
- data/spec/dsl/find_field_spec.rb +22 -0
- data/spec/dsl/find_link_spec.rb +17 -0
- data/spec/dsl/find_spec.rb +57 -0
- data/spec/dsl/has_button_spec.rb +32 -0
- data/spec/dsl/has_content_spec.rb +101 -0
- data/spec/dsl/has_css_spec.rb +107 -0
- data/spec/dsl/has_field_spec.rb +96 -0
- data/spec/dsl/has_link_spec.rb +33 -0
- data/spec/dsl/has_xpath_spec.rb +123 -0
- data/spec/dsl/locate_spec.rb +59 -0
- data/spec/dsl/select_spec.rb +71 -0
- data/spec/dsl/uncheck_spec.rb +21 -0
- data/spec/dsl/within_spec.rb +153 -0
- data/spec/dsl_spec.rb +140 -0
- data/spec/fixtures/capybara.jpg +0 -0
- data/spec/fixtures/test_file.txt +1 -0
- data/spec/public/jquery-ui.js +35 -0
- data/spec/public/jquery.js +19 -0
- data/spec/public/test.js +30 -0
- data/spec/save_and_open_page_spec.rb +43 -0
- data/spec/searchable_spec.rb +61 -0
- data/spec/server_spec.rb +47 -0
- data/spec/session/celerity_session_spec.rb +27 -0
- data/spec/session/culerity_session_spec.rb +25 -0
- data/spec/session/rack_test_session_spec.rb +25 -0
- data/spec/session/selenium_session_spec.rb +25 -0
- data/spec/session_spec.rb +77 -0
- data/spec/session_with_headers_support_spec.rb +13 -0
- data/spec/session_with_javascript_support_spec.rb +182 -0
- data/spec/session_without_headers_support_spec.rb +15 -0
- data/spec/session_without_javascript_support_spec.rb +15 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/test_app.rb +71 -0
- data/spec/views/buttons.erb +4 -0
- data/spec/views/fieldsets.erb +29 -0
- data/spec/views/form.erb +226 -0
- data/spec/views/postback.erb +13 -0
- data/spec/views/tables.erb +122 -0
- data/spec/views/with_html.erb +38 -0
- data/spec/views/with_js.erb +34 -0
- data/spec/views/with_scope.erb +36 -0
- data/spec/views/with_simple_html.erb +1 -0
- data/spec/wait_until_spec.rb +28 -0
- data/spec/xpath_spec.rb +271 -0
- metadata +239 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path('../spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe Capybara::Session do
|
4
|
+
context 'with selenium driver' do
|
5
|
+
before do
|
6
|
+
@session = Capybara::Session.new(:selenium, TestApp)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#driver' do
|
10
|
+
it "should be a selenium driver" do
|
11
|
+
@session.driver.should be_an_instance_of(Capybara::Driver::Selenium)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#mode' do
|
16
|
+
it "should remember the mode" do
|
17
|
+
@session.mode.should == :selenium
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_behave_like "session"
|
22
|
+
it_should_behave_like "session with javascript support"
|
23
|
+
it_should_behave_like "session without headers support"
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
shared_examples_for "session" do
|
5
|
+
def extract_results(session)
|
6
|
+
YAML.load Nokogiri::HTML(session.body).xpath("//pre[@id='results']").first.text
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#app' do
|
10
|
+
it "should remember the application" do
|
11
|
+
@session.app.should == TestApp
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#visit' do
|
16
|
+
it "should fetch a response from the driver" do
|
17
|
+
@session.visit('/')
|
18
|
+
@session.body.should include('Hello world!')
|
19
|
+
@session.visit('/foo')
|
20
|
+
@session.body.should include('Another World')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#body' do
|
25
|
+
it "should return the unmodified page body" do
|
26
|
+
@session.visit('/')
|
27
|
+
@session.body.should include('Hello world!')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#source' do
|
32
|
+
it "should return the unmodified page source" do
|
33
|
+
@session.visit('/')
|
34
|
+
@session.source.should include('Hello world!')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it_should_behave_like "all"
|
39
|
+
it_should_behave_like "attach_file"
|
40
|
+
it_should_behave_like "check"
|
41
|
+
it_should_behave_like "choose"
|
42
|
+
it_should_behave_like "click"
|
43
|
+
it_should_behave_like "click_button"
|
44
|
+
it_should_behave_like "click_link"
|
45
|
+
it_should_behave_like "fill_in"
|
46
|
+
it_should_behave_like "find_button"
|
47
|
+
it_should_behave_like "find_field"
|
48
|
+
it_should_behave_like "find_link"
|
49
|
+
it_should_behave_like "find_by_id"
|
50
|
+
it_should_behave_like "find"
|
51
|
+
it_should_behave_like "has_content"
|
52
|
+
it_should_behave_like "has_css"
|
53
|
+
it_should_behave_like "has_css"
|
54
|
+
it_should_behave_like "has_xpath"
|
55
|
+
it_should_behave_like "has_link"
|
56
|
+
it_should_behave_like "has_button"
|
57
|
+
it_should_behave_like "has_field"
|
58
|
+
it_should_behave_like "has_select"
|
59
|
+
it_should_behave_like "has_table"
|
60
|
+
it_should_behave_like "select"
|
61
|
+
it_should_behave_like "uncheck"
|
62
|
+
it_should_behave_like "unselect"
|
63
|
+
it_should_behave_like "locate"
|
64
|
+
it_should_behave_like "within"
|
65
|
+
it_should_behave_like "current_url"
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
describe Capybara::Session do
|
70
|
+
context 'with non-existant driver' do
|
71
|
+
it "should raise an error" do
|
72
|
+
running {
|
73
|
+
Capybara::Session.new(:quox, TestApp).driver
|
74
|
+
}.should raise_error(Capybara::DriverNotFoundError)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
|
4
|
+
shared_examples_for "session with headers support" do
|
5
|
+
|
6
|
+
describe '#response_headers' do
|
7
|
+
it "should return response headers" do
|
8
|
+
@session.visit('/with_simple_html')
|
9
|
+
@session.response_headers['Content-Type'].should == 'text/html'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
shared_examples_for "session with javascript support" do
|
6
|
+
before do
|
7
|
+
Capybara.default_wait_time = 1
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
Capybara.default_wait_time = 0
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#find' do
|
15
|
+
it "should allow triggering of custom JS events" do
|
16
|
+
pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
|
17
|
+
@session.visit('/with_js')
|
18
|
+
@session.find(:css, '#with_focus_event').trigger(:focus)
|
19
|
+
@session.should have_css('#focus_event_triggered')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#body' do
|
24
|
+
it "should return the current state of the page" do
|
25
|
+
@session.visit('/with_js')
|
26
|
+
@session.body.should include('I changed it')
|
27
|
+
@session.body.should_not include('This is text')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#source' do
|
32
|
+
it "should return the original, unmodified source of the page" do
|
33
|
+
pending "cannot figure out how to do this with selenium" if @session.mode == :selenium
|
34
|
+
@session.visit('/with_js')
|
35
|
+
@session.source.should include('This is text')
|
36
|
+
@session.source.should_not include('I changed it')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#evaluate_script" do
|
41
|
+
it "should return the evaluated script" do
|
42
|
+
@session.visit('/with_js')
|
43
|
+
@session.evaluate_script("1+3").should == 4
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#locate' do
|
48
|
+
it "should wait for asynchronous load" do
|
49
|
+
@session.visit('/with_js')
|
50
|
+
@session.click_link('Click me')
|
51
|
+
@session.locate("//a[contains(.,'Has been clicked')]")[:href].should == '#'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#wait_until' do
|
56
|
+
before do
|
57
|
+
@default_timeout = Capybara.default_wait_time
|
58
|
+
end
|
59
|
+
|
60
|
+
after do
|
61
|
+
Capybara.default_wait_time = @default_wait_time
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should wait for block to return true" do
|
65
|
+
@session.visit('/with_js')
|
66
|
+
@session.select('My Waiting Option', :from => 'waiter')
|
67
|
+
@session.evaluate_script('activeRequests == 1').should be_true
|
68
|
+
@session.wait_until do
|
69
|
+
@session.evaluate_script('activeRequests == 0')
|
70
|
+
end
|
71
|
+
@session.evaluate_script('activeRequests == 0').should be_true
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should raise Capybara::TimeoutError if block doesn't return true within timeout" do
|
75
|
+
@session.visit('/with_html')
|
76
|
+
Proc.new do
|
77
|
+
@session.wait_until(0.1) do
|
78
|
+
@session.find('//div[@id="nosuchthing"]')
|
79
|
+
end
|
80
|
+
end.should raise_error(::Capybara::TimeoutError)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should accept custom timeout in seconds" do
|
84
|
+
start = Time.now
|
85
|
+
Capybara.default_wait_time = 5
|
86
|
+
begin
|
87
|
+
@session.wait_until(0.1) { false }
|
88
|
+
rescue Capybara::TimeoutError; end
|
89
|
+
(Time.now - start).should be_close(0.1, 0.1)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should default to Capybara.default_wait_time before timeout" do
|
93
|
+
start = Time.now
|
94
|
+
Capybara.default_wait_time = 0.2
|
95
|
+
begin
|
96
|
+
@session.wait_until { false }
|
97
|
+
rescue Capybara::TimeoutError; end
|
98
|
+
(Time.now - start).should be_close(0.2, 0.1)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#click' do
|
103
|
+
it "should wait for asynchronous load" do
|
104
|
+
@session.visit('/with_js')
|
105
|
+
@session.click_link('Click me')
|
106
|
+
@session.click('Has been clicked')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#click_link' do
|
111
|
+
it "should wait for asynchronous load" do
|
112
|
+
@session.visit('/with_js')
|
113
|
+
@session.click_link('Click me')
|
114
|
+
@session.click_link('Has been clicked')
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe '#click_button' do
|
119
|
+
it "should wait for asynchronous load" do
|
120
|
+
@session.visit('/with_js')
|
121
|
+
@session.click_link('Click me')
|
122
|
+
@session.click_button('New Here')
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe '#fill_in' do
|
127
|
+
it "should wait for asynchronous load" do
|
128
|
+
@session.visit('/with_js')
|
129
|
+
@session.click_link('Click me')
|
130
|
+
@session.fill_in('new_field', :with => 'Testing...')
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#has_xpath?' do
|
135
|
+
it "should wait for content to appear" do
|
136
|
+
@session.visit('/with_js')
|
137
|
+
@session.click_link('Click me')
|
138
|
+
@session.should have_xpath("//input[@type='submit' and @value='New Here']")
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe '#has_no_xpath?' do
|
143
|
+
it "should wait for content to disappear" do
|
144
|
+
@session.visit('/with_js')
|
145
|
+
@session.click_link('Click me')
|
146
|
+
@session.should have_no_xpath("//p[@id='change']")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe '#has_css?' do
|
151
|
+
it "should wait for content to appear" do
|
152
|
+
@session.visit('/with_js')
|
153
|
+
@session.click_link('Click me')
|
154
|
+
@session.should have_css("input[type='submit'][value='New Here']")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe '#has_no_xpath?' do
|
159
|
+
it "should wait for content to disappear" do
|
160
|
+
@session.visit('/with_js')
|
161
|
+
@session.click_link('Click me')
|
162
|
+
@session.should have_no_css("p#change")
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe '#has_content?' do
|
167
|
+
it "should wait for content to appear" do
|
168
|
+
@session.visit('/with_js')
|
169
|
+
@session.click_link('Click me')
|
170
|
+
@session.should have_content("Has been clicked")
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe '#has_no_content?' do
|
175
|
+
it "should wait for content to disappear" do
|
176
|
+
@session.visit('/with_js')
|
177
|
+
@session.click_link('Click me')
|
178
|
+
@session.should have_no_content("I changed it")
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
shared_examples_for "session without headers support" do
|
6
|
+
describe "#evaluate_script" do
|
7
|
+
before{ @session.visit('/with_simple_html') }
|
8
|
+
it "should raise an error" do
|
9
|
+
running {
|
10
|
+
@session.response_headers
|
11
|
+
}.should raise_error(Capybara::NotSupportedByDriverError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('spec_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
shared_examples_for "session without javascript support" do
|
6
|
+
describe "#evaluate_script" do
|
7
|
+
before{ @session.visit('/with_js') }
|
8
|
+
it "should raise an error" do
|
9
|
+
running {
|
10
|
+
@session.evaluate_script("1+5")
|
11
|
+
}.should raise_error(Capybara::NotSupportedByDriverError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
$:.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
|
2
|
+
$:.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'spec'
|
6
|
+
require 'spec/autorun'
|
7
|
+
require 'capybara'
|
8
|
+
require 'test_app'
|
9
|
+
require 'drivers_spec'
|
10
|
+
require 'session_spec'
|
11
|
+
Dir[File.dirname(__FILE__)+'/dsl/*'].each { |group|
|
12
|
+
require group
|
13
|
+
}
|
14
|
+
require 'session_with_javascript_support_spec'
|
15
|
+
require 'session_without_javascript_support_spec'
|
16
|
+
require 'session_with_headers_support_spec'
|
17
|
+
require 'session_without_headers_support_spec'
|
18
|
+
|
19
|
+
alias :running :lambda
|
20
|
+
|
21
|
+
Capybara.default_wait_time = 0 # less timeout so tests run faster
|
22
|
+
|
23
|
+
Spec::Runner.configure do |config|
|
24
|
+
config.after do
|
25
|
+
Capybara.default_selector = :xpath
|
26
|
+
end
|
27
|
+
end
|
data/spec/test_app.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'rack'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
class TestApp < Sinatra::Base
|
6
|
+
set :root, File.dirname(__FILE__)
|
7
|
+
set :static, true
|
8
|
+
|
9
|
+
get '/' do
|
10
|
+
'Hello world!'
|
11
|
+
end
|
12
|
+
|
13
|
+
get '/foo' do
|
14
|
+
'Another World'
|
15
|
+
end
|
16
|
+
|
17
|
+
get '/redirect' do
|
18
|
+
redirect '/redirect_again'
|
19
|
+
end
|
20
|
+
|
21
|
+
get '/redirect_again' do
|
22
|
+
redirect '/landed'
|
23
|
+
end
|
24
|
+
|
25
|
+
get '/landed' do
|
26
|
+
"You landed"
|
27
|
+
end
|
28
|
+
|
29
|
+
get '/with-quotes' do
|
30
|
+
%q{"No," he said, "you can't do that."}
|
31
|
+
end
|
32
|
+
|
33
|
+
get '/form/get' do
|
34
|
+
'<pre id="results">' + params[:form].to_yaml + '</pre>'
|
35
|
+
end
|
36
|
+
|
37
|
+
get '/favicon.ico' do
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
post '/redirect' do
|
42
|
+
redirect '/redirect_again'
|
43
|
+
end
|
44
|
+
|
45
|
+
get '/redirect_back' do
|
46
|
+
redirect back
|
47
|
+
end
|
48
|
+
|
49
|
+
get '/:view' do |view|
|
50
|
+
erb view.to_sym
|
51
|
+
end
|
52
|
+
|
53
|
+
post '/form' do
|
54
|
+
'<pre id="results">' + params[:form].to_yaml + '</pre>'
|
55
|
+
end
|
56
|
+
|
57
|
+
post '/upload' do
|
58
|
+
begin
|
59
|
+
buffer = []
|
60
|
+
buffer << "Content-type: #{params[:form][:document][:type]}"
|
61
|
+
buffer << "File content: #{params[:form][:document][:tempfile].read}"
|
62
|
+
buffer.join(' | ')
|
63
|
+
rescue
|
64
|
+
'No file uploaded'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
if __FILE__ == $0
|
70
|
+
Rack::Handler::Mongrel.run TestApp, :Port => 8070
|
71
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<form action="/form" method="post">
|
2
|
+
<fieldset id="agent_fieldset">
|
3
|
+
<legend>Agent</legend>
|
4
|
+
|
5
|
+
<p>
|
6
|
+
<label for="form_agent_name">Name</label>
|
7
|
+
<input type="text" name="form[agent_name]" value="James" id="form_agent_name"/>
|
8
|
+
</p>
|
9
|
+
|
10
|
+
<p>
|
11
|
+
<input type="submit" value="Create"/>
|
12
|
+
</p>
|
13
|
+
</fieldset>
|
14
|
+
</form>
|
15
|
+
|
16
|
+
<form action="/form" method="post">
|
17
|
+
<fieldset id="villain_fieldset">
|
18
|
+
<legend>Villain</legend>
|
19
|
+
|
20
|
+
<p>
|
21
|
+
<label for="form_villain_name">Name</label>
|
22
|
+
<input type="text" name="form[villain_name]" value="Ernst" id="form_villain_name"/>
|
23
|
+
</p>
|
24
|
+
|
25
|
+
<p>
|
26
|
+
<input type="submit" value="Create"/>
|
27
|
+
</p>
|
28
|
+
</fieldset>
|
29
|
+
</form>
|