capybara 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest.txt +39 -0
- data/README.rdoc +181 -57
- data/Rakefile +7 -16
- data/config.ru +6 -0
- data/lib/capybara.rb +19 -9
- data/lib/capybara/cucumber.rb +4 -0
- data/lib/capybara/driver/base.rb +25 -8
- data/lib/capybara/driver/celerity_driver.rb +108 -0
- data/lib/capybara/driver/culerity_driver.rb +1 -70
- data/lib/capybara/driver/rack_test_driver.rb +57 -25
- data/lib/capybara/driver/selenium_driver.rb +28 -10
- data/lib/capybara/dsl.rb +7 -4
- data/lib/capybara/node.rb +50 -29
- data/lib/capybara/rails.rb +1 -1
- data/lib/capybara/save_and_open_page.rb +1 -1
- data/lib/capybara/searchable.rb +45 -0
- data/lib/capybara/server.rb +11 -4
- data/lib/capybara/session.rb +94 -94
- data/lib/capybara/wait_until.rb +23 -0
- data/lib/capybara/xpath.rb +55 -41
- data/spec/capybara_spec.rb +18 -0
- data/spec/driver/celerity_driver_spec.rb +17 -0
- data/spec/driver/culerity_driver_spec.rb +3 -0
- data/spec/driver/rack_test_driver_spec.rb +3 -0
- data/spec/driver/remote_culerity_driver_spec.rb +19 -0
- data/spec/driver/remote_selenium_driver_spec.rb +18 -0
- data/spec/driver/selenium_driver_spec.rb +2 -0
- data/spec/drivers_spec.rb +51 -5
- data/spec/dsl/all_spec.rb +38 -0
- data/spec/dsl/attach_file_spec.rb +66 -0
- data/spec/dsl/check_spec.rb +28 -0
- data/spec/dsl/choose_spec.rb +28 -0
- data/spec/dsl/click_button_spec.rb +183 -0
- data/spec/dsl/click_link_spec.rb +88 -0
- data/spec/dsl/click_spec.rb +26 -0
- data/spec/dsl/current_url_spec.rb +10 -0
- data/spec/dsl/fill_in_spec.rb +83 -0
- data/spec/dsl/find_button_spec.rb +18 -0
- data/spec/dsl/find_field_spec.rb +24 -0
- data/spec/dsl/find_link_spec.rb +19 -0
- data/spec/dsl/find_spec.rb +36 -0
- data/spec/dsl/has_content_spec.rb +103 -0
- data/spec/dsl/has_css_spec.rb +109 -0
- data/spec/dsl/has_xpath_spec.rb +115 -0
- data/spec/dsl/locate_spec.rb +38 -0
- data/spec/dsl/select_spec.rb +27 -0
- data/spec/dsl/uncheck_spec.rb +29 -0
- data/spec/dsl/within_spec.rb +145 -0
- data/spec/fixtures/capybara.jpg +0 -0
- data/spec/public/test.js +27 -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 +1 -0
- data/spec/session/rack_test_session_spec.rb +1 -0
- data/spec/session/selenium_session_spec.rb +1 -0
- data/spec/session_spec.rb +32 -903
- data/spec/session_with_headers_support_spec.rb +13 -0
- data/spec/session_with_javascript_support_spec.rb +165 -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 +12 -0
- data/spec/test_app.rb +9 -1
- data/spec/views/form.erb +38 -0
- data/spec/views/postback.erb +13 -0
- data/spec/views/with_html.erb +13 -0
- data/spec/views/with_js.erb +9 -24
- data/spec/views/with_simple_html.erb +1 -1
- data/spec/wait_until_spec.rb +28 -0
- data/spec/xpath_spec.rb +34 -3
- metadata +54 -5
@@ -0,0 +1,28 @@
|
|
1
|
+
module CheckSpec
|
2
|
+
shared_examples_for "check" do
|
3
|
+
|
4
|
+
describe "#check" do
|
5
|
+
before do
|
6
|
+
@session.visit('/form')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should check a checkbox by id" do
|
10
|
+
@session.check("form_pets_cat")
|
11
|
+
@session.click_button('awesome')
|
12
|
+
extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should check a checkbox by label" do
|
16
|
+
@session.check("Cat")
|
17
|
+
@session.click_button('awesome')
|
18
|
+
extract_results(@session)['pets'].should include('dog', 'cat', 'hamster')
|
19
|
+
end
|
20
|
+
|
21
|
+
context "with a locator that doesn't exist" do
|
22
|
+
it "should raise an error" do
|
23
|
+
running { @session.check('does not exist') }.should raise_error(Capybara::ElementNotFound)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ChooseSpec
|
2
|
+
shared_examples_for "choose" do
|
3
|
+
|
4
|
+
describe "#choose" do
|
5
|
+
before do
|
6
|
+
@session.visit('/form')
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should choose a radio button by id" do
|
10
|
+
@session.choose("gender_male")
|
11
|
+
@session.click_button('awesome')
|
12
|
+
extract_results(@session)['gender'].should == 'male'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should choose a radio button by label" do
|
16
|
+
@session.choose("Both")
|
17
|
+
@session.click_button('awesome')
|
18
|
+
extract_results(@session)['gender'].should == 'both'
|
19
|
+
end
|
20
|
+
|
21
|
+
context "with a locator that doesn't exist" do
|
22
|
+
it "should raise an error" do
|
23
|
+
running { @session.choose('does not exist') }.should raise_error(Capybara::ElementNotFound)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
module ClickButtonSpec
|
2
|
+
shared_examples_for "click_button" do
|
3
|
+
describe '#click_button' do
|
4
|
+
before do
|
5
|
+
@session.visit('/form')
|
6
|
+
end
|
7
|
+
|
8
|
+
context "with multiple values with the same name" do
|
9
|
+
it "should use the latest given value" do
|
10
|
+
@session.check('Terms of Use')
|
11
|
+
@session.click_button('awesome')
|
12
|
+
extract_results(@session)['terms_of_use'].should == '1'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "with value given on a submit button" do
|
17
|
+
before do
|
18
|
+
@session.click_button('awesome')
|
19
|
+
@results = extract_results(@session)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should serialize and submit text fields" do
|
23
|
+
@results['first_name'].should == 'John'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should escape fields when submitting" do
|
27
|
+
@results['phone'].should == '+1 555 7021'
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should serialize and submit password fields" do
|
31
|
+
@results['password'].should == 'seeekrit'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should serialize and submit hidden fields" do
|
35
|
+
@results['token'].should == '12345'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not serialize fields from other forms" do
|
39
|
+
@results['middle_name'].should be_nil
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should submit the button that was clicked, but not other buttons" do
|
43
|
+
@results['awesome'].should == 'awesome'
|
44
|
+
@results['crappy'].should be_nil
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should serialize radio buttons" do
|
48
|
+
@results['gender'].should == 'female'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should serialize check boxes" do
|
52
|
+
@results['pets'].should include('dog', 'hamster')
|
53
|
+
@results['pets'].should_not include('cat')
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should serialize text areas" do
|
57
|
+
@results['description'].should == 'Descriptive text goes here'
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should serialize select tag with values" do
|
61
|
+
@results['locale'].should == 'en'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should serialize select tag without values" do
|
65
|
+
@results['region'].should == 'Norway'
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should serialize first option for select tag with no selection" do
|
69
|
+
@results['city'].should == 'London'
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should not serialize a select tag without options" do
|
73
|
+
@results['tendency'].should be_nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "with id given on a submit button" do
|
78
|
+
it "should submit the associated form" do
|
79
|
+
@session.click_button('awe123')
|
80
|
+
extract_results(@session)['first_name'].should == 'John'
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should work with partial matches" do
|
84
|
+
@session.click_button('Go')
|
85
|
+
@session.body.should include('You landed')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "with value given on an image button" do
|
90
|
+
it "should submit the associated form" do
|
91
|
+
@session.click_button('okay')
|
92
|
+
extract_results(@session)['first_name'].should == 'John'
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should work with partial matches" do
|
96
|
+
@session.click_button('kay')
|
97
|
+
extract_results(@session)['first_name'].should == 'John'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "with id given on an image button" do
|
102
|
+
it "should submit the associated form" do
|
103
|
+
@session.click_button('okay556')
|
104
|
+
extract_results(@session)['first_name'].should == 'John'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "with text given on a button defined by <button> tag" do
|
109
|
+
it "should submit the associated form" do
|
110
|
+
@session.click_button('Click me')
|
111
|
+
extract_results(@session)['first_name'].should == 'John'
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should work with partial matches" do
|
115
|
+
@session.click_button('Click')
|
116
|
+
extract_results(@session)['first_name'].should == 'John'
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should prefer exact matches over partial matches" do
|
120
|
+
@session.click_button('Just an input')
|
121
|
+
extract_results(@session)['button'].should == 'button_second'
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "with id given on a button defined by <button> tag" do
|
126
|
+
it "should submit the associated form" do
|
127
|
+
@session.click_button('click_me_123')
|
128
|
+
extract_results(@session)['first_name'].should == 'John'
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "with value given on a button defined by <button> tag" do
|
133
|
+
it "should submit the associated form" do
|
134
|
+
@session.click_button('click_me')
|
135
|
+
extract_results(@session)['first_name'].should == 'John'
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should work with partial matches" do
|
139
|
+
@session.click_button('ck_me')
|
140
|
+
extract_results(@session)['first_name'].should == 'John'
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should prefer exact matches over partial matches" do
|
144
|
+
@session.click_button('Just a button')
|
145
|
+
extract_results(@session)['button'].should == 'Just a button'
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context "with a locator that doesn't exist" do
|
150
|
+
it "should raise an error" do
|
151
|
+
running do
|
152
|
+
@session.click_button('does not exist')
|
153
|
+
end.should raise_error(Capybara::ElementNotFound)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should serialize and send GET forms" do
|
158
|
+
@session.visit('/form')
|
159
|
+
@session.click_button('med')
|
160
|
+
@results = extract_results(@session)
|
161
|
+
@results['middle_name'].should == 'Darren'
|
162
|
+
@results['foo'].should be_nil
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should follow redirects" do
|
166
|
+
@session.click_button('Go FAR')
|
167
|
+
@session.body.should include('You landed')
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should post pack to the same URL when no action given" do
|
171
|
+
@session.visit('/postback')
|
172
|
+
@session.click_button('With no action')
|
173
|
+
@session.body.should include('Postback')
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should post pack to the same URL when blank action given" do
|
177
|
+
@session.visit('/postback')
|
178
|
+
@session.click_button('With blank action')
|
179
|
+
@session.body.should include('Postback')
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module ClickLinkSpec
|
2
|
+
shared_examples_for "click_link" do
|
3
|
+
describe '#click_link' do
|
4
|
+
before do
|
5
|
+
@session.visit('/with_html')
|
6
|
+
end
|
7
|
+
|
8
|
+
context "with id given" do
|
9
|
+
it "should take user to the linked page" do
|
10
|
+
@session.click_link('foo')
|
11
|
+
@session.body.should include('Another World')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with text given" do
|
16
|
+
it "should take user to the linked page" do
|
17
|
+
@session.click_link('labore')
|
18
|
+
@session.body.should include('Bar')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should accept partial matches" do
|
22
|
+
@session.click_link('abo')
|
23
|
+
@session.body.should include('Bar')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should prefer exact matches over partial matches" do
|
27
|
+
@session.click_link('A link')
|
28
|
+
@session.body.should include('Bar')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with title given" do
|
33
|
+
it "should take user to the linked page" do
|
34
|
+
@session.click_link('awesome title')
|
35
|
+
@session.body.should include('Bar')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should accept partial matches" do
|
39
|
+
@session.click_link('some tit')
|
40
|
+
@session.body.should include('Bar')
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should prefer exact matches over partial matches" do
|
44
|
+
@session.click_link('a fine link')
|
45
|
+
@session.body.should include('Bar')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "with a locator that doesn't exist" do
|
50
|
+
it "should raise an error" do
|
51
|
+
running do
|
52
|
+
@session.click_link('does not exist')
|
53
|
+
end.should raise_error(Capybara::ElementNotFound)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should follow redirects" do
|
58
|
+
@session.click_link('Redirect')
|
59
|
+
@session.body.should include('You landed')
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should do nothing on anchor links" do
|
63
|
+
@session.fill_in("test_field", :with => 'blah')
|
64
|
+
@session.click_link('Anchor')
|
65
|
+
@session.find_field("test_field").value.should == 'blah'
|
66
|
+
@session.click_link('Blank Anchor')
|
67
|
+
@session.find_field("test_field").value.should == 'blah'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should do nothing on URL+anchor links for the same page" do
|
71
|
+
@session.fill_in("test_field", :with => 'blah')
|
72
|
+
@session.click_link('Anchor on same page')
|
73
|
+
@session.find_field("test_field").value.should == 'blah'
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should follow link on URL+anchor links for a different page" do
|
77
|
+
@session.click_link('Anchor on different page')
|
78
|
+
@session.body.should include('Bar')
|
79
|
+
end
|
80
|
+
|
81
|
+
it "raise an error with links with no href" do
|
82
|
+
running do
|
83
|
+
@session.click_link('No Href')
|
84
|
+
end.should raise_error(Capybara::ElementNotFound)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ClickSpec
|
2
|
+
shared_examples_for "click" do
|
3
|
+
describe '#click' do
|
4
|
+
it "should click on a link" do
|
5
|
+
@session.visit('/with_html')
|
6
|
+
@session.click('labore')
|
7
|
+
@session.body.should include('Bar')
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should click on a button" do
|
11
|
+
@session.visit('/form')
|
12
|
+
@session.click('awe123')
|
13
|
+
extract_results(@session)['first_name'].should == 'John'
|
14
|
+
end
|
15
|
+
|
16
|
+
context "with a locator that doesn't exist" do
|
17
|
+
it "should raise an error" do
|
18
|
+
@session.visit('/with_html')
|
19
|
+
running do
|
20
|
+
@session.click('does not exist')
|
21
|
+
end.should raise_error(Capybara::ElementNotFound)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module FillInSpec
|
2
|
+
shared_examples_for "fill_in" do
|
3
|
+
describe "#fill_in" do
|
4
|
+
before do
|
5
|
+
@session.visit('/form')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should fill in a text field by id" do
|
9
|
+
@session.fill_in('form_first_name', :with => 'Harry')
|
10
|
+
@session.click_button('awesome')
|
11
|
+
extract_results(@session)['first_name'].should == 'Harry'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should fill in a text field by label" do
|
15
|
+
@session.fill_in('First Name', :with => 'Harry')
|
16
|
+
@session.click_button('awesome')
|
17
|
+
extract_results(@session)['first_name'].should == 'Harry'
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should fill in a text field by name" do
|
21
|
+
@session.fill_in('form[first_name]', :with => 'Harry')
|
22
|
+
@session.click_button('awesome')
|
23
|
+
extract_results(@session)['first_name'].should == 'Harry'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should fill in a text field by label without for" do
|
27
|
+
@session.fill_in('Street', :with => 'Avenue Q')
|
28
|
+
@session.click_button('awesome')
|
29
|
+
extract_results(@session)['street'].should == 'Avenue Q'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should favour exact label matches over partial matches" do
|
33
|
+
@session.fill_in('Name', :with => 'Harry Jones')
|
34
|
+
@session.click_button('awesome')
|
35
|
+
extract_results(@session)['name'].should == 'Harry Jones'
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should fill in a textarea by id" do
|
39
|
+
@session.fill_in('form_description', :with => 'Texty text')
|
40
|
+
@session.click_button('awesome')
|
41
|
+
extract_results(@session)['description'].should == 'Texty text'
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should fill in a textarea by label" do
|
45
|
+
@session.fill_in('Description', :with => 'Texty text')
|
46
|
+
@session.click_button('awesome')
|
47
|
+
extract_results(@session)['description'].should == 'Texty text'
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should fill in a textarea by name" do
|
51
|
+
@session.fill_in('form[description]', :with => 'Texty text')
|
52
|
+
@session.click_button('awesome')
|
53
|
+
extract_results(@session)['description'].should == 'Texty text'
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should fill in a password field by id" do
|
57
|
+
@session.fill_in('form_password', :with => 'supasikrit')
|
58
|
+
@session.click_button('awesome')
|
59
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should fill in a password field by label" do
|
63
|
+
@session.fill_in('Password', :with => 'supasikrit')
|
64
|
+
@session.click_button('awesome')
|
65
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should fill in a password field by name" do
|
69
|
+
@session.fill_in('form[password]', :with => 'supasikrit')
|
70
|
+
@session.click_button('awesome')
|
71
|
+
extract_results(@session)['password'].should == 'supasikrit'
|
72
|
+
end
|
73
|
+
|
74
|
+
context "with a locator that doesn't exist" do
|
75
|
+
it "should raise an error" do
|
76
|
+
running do
|
77
|
+
@session.fill_in('does not exist', :with => 'Blah blah')
|
78
|
+
end.should raise_error(Capybara::ElementNotFound)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|