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
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.rdoc
|
4
|
+
Rakefile
|
5
|
+
config.ru
|
6
|
+
lib/capybara.rb
|
7
|
+
lib/capybara/cucumber.rb
|
8
|
+
lib/capybara/driver/base.rb
|
9
|
+
lib/capybara/driver/celerity_driver.rb
|
10
|
+
lib/capybara/driver/culerity_driver.rb
|
11
|
+
lib/capybara/driver/rack_test_driver.rb
|
12
|
+
lib/capybara/driver/selenium_driver.rb
|
13
|
+
lib/capybara/dsl.rb
|
14
|
+
lib/capybara/node.rb
|
15
|
+
lib/capybara/rails.rb
|
16
|
+
lib/capybara/save_and_open_page.rb
|
17
|
+
lib/capybara/searchable.rb
|
18
|
+
lib/capybara/server.rb
|
19
|
+
lib/capybara/session.rb
|
20
|
+
lib/capybara/wait_until.rb
|
21
|
+
lib/capybara/xpath.rb
|
22
|
+
script/console
|
23
|
+
script/destroy
|
24
|
+
script/generate
|
25
|
+
spec/capybara_spec.rb
|
26
|
+
spec/driver/celerity_driver_spec.rb
|
27
|
+
spec/driver/culerity_driver_spec.rb
|
28
|
+
spec/driver/rack_test_driver_spec.rb
|
29
|
+
spec/driver/remote_culerity_driver_spec.rb
|
30
|
+
spec/driver/remote_selenium_driver_spec.rb
|
31
|
+
spec/driver/selenium_driver_spec.rb
|
32
|
+
spec/drivers_spec.rb
|
33
|
+
spec/dsl/all_spec.rb
|
34
|
+
spec/dsl/attach_file_spec.rb
|
35
|
+
spec/dsl/check_spec.rb
|
36
|
+
spec/dsl/choose_spec.rb
|
37
|
+
spec/dsl/click_button_spec.rb
|
38
|
+
spec/dsl/click_link_spec.rb
|
39
|
+
spec/dsl/click_spec.rb
|
40
|
+
spec/dsl/current_url_spec.rb
|
41
|
+
spec/dsl/fill_in_spec.rb
|
42
|
+
spec/dsl/find_button_spec.rb
|
43
|
+
spec/dsl/find_by_id_spec.rb
|
44
|
+
spec/dsl/find_field_spec.rb
|
45
|
+
spec/dsl/find_link_spec.rb
|
46
|
+
spec/dsl/find_spec.rb
|
47
|
+
spec/dsl/has_button_spec.rb
|
48
|
+
spec/dsl/has_content_spec.rb
|
49
|
+
spec/dsl/has_css_spec.rb
|
50
|
+
spec/dsl/has_field_spec.rb
|
51
|
+
spec/dsl/has_link_spec.rb
|
52
|
+
spec/dsl/has_xpath_spec.rb
|
53
|
+
spec/dsl/locate_spec.rb
|
54
|
+
spec/dsl/select_spec.rb
|
55
|
+
spec/dsl/uncheck_spec.rb
|
56
|
+
spec/dsl/within_spec.rb
|
57
|
+
spec/dsl_spec.rb
|
58
|
+
spec/fixtures/capybara.jpg
|
59
|
+
spec/fixtures/test_file.txt
|
60
|
+
spec/public/jquery-ui.js
|
61
|
+
spec/public/jquery.js
|
62
|
+
spec/public/test.js
|
63
|
+
spec/save_and_open_page_spec.rb
|
64
|
+
spec/searchable_spec.rb
|
65
|
+
spec/server_spec.rb
|
66
|
+
spec/session/celerity_session_spec.rb
|
67
|
+
spec/session/culerity_session_spec.rb
|
68
|
+
spec/session/rack_test_session_spec.rb
|
69
|
+
spec/session/selenium_session_spec.rb
|
70
|
+
spec/session_spec.rb
|
71
|
+
spec/session_with_headers_support_spec.rb
|
72
|
+
spec/session_with_javascript_support_spec.rb
|
73
|
+
spec/session_without_headers_support_spec.rb
|
74
|
+
spec/session_without_javascript_support_spec.rb
|
75
|
+
spec/spec_helper.rb
|
76
|
+
spec/test_app.rb
|
77
|
+
spec/views/buttons.erb
|
78
|
+
spec/views/fieldsets.erb
|
79
|
+
spec/views/form.erb
|
80
|
+
spec/views/postback.erb
|
81
|
+
spec/views/tables.erb
|
82
|
+
spec/views/with_html.erb
|
83
|
+
spec/views/with_js.erb
|
84
|
+
spec/views/with_scope.erb
|
85
|
+
spec/views/with_simple_html.erb
|
86
|
+
spec/wait_until_spec.rb
|
87
|
+
spec/xpath_spec.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,404 @@
|
|
1
|
+
= capybara
|
2
|
+
|
3
|
+
* http://github.com/jnicklas/capybara
|
4
|
+
|
5
|
+
== Description:
|
6
|
+
|
7
|
+
Capybara aims to simplify the process of integration testing Rack applications,
|
8
|
+
such as Rails, Sinatra or Merb. It is inspired by and aims to replace Webrat as
|
9
|
+
a DSL for interacting with a webapplication. It is agnostic about the driver
|
10
|
+
running your tests and currently comes bundled with rack-test, Culerity,
|
11
|
+
Celerity and Selenium support built in.
|
12
|
+
|
13
|
+
== Install:
|
14
|
+
|
15
|
+
Install as a gem:
|
16
|
+
|
17
|
+
sudo gem install capybara
|
18
|
+
|
19
|
+
On OSX you may have to install libffi, you can install it via MacPorts with:
|
20
|
+
|
21
|
+
sudo port install libffi
|
22
|
+
|
23
|
+
== Development:
|
24
|
+
|
25
|
+
* Source hosted at {GitHub}[http://github.com/jnicklas/capybara].
|
26
|
+
* Please direct questions, discussions at the {mailing list}[http://groups.google.com/group/ruby-capybara].
|
27
|
+
* Report issues on {GitHub Issues}[http://github.com/jnicklas/capybara/issues]
|
28
|
+
|
29
|
+
Pull requests are very welcome! Make sure your patches are well tested, Capybara is
|
30
|
+
a testing tool after all.
|
31
|
+
|
32
|
+
== Using Capybara with Cucumber
|
33
|
+
|
34
|
+
Capybara is built to work nicely with Cucumber. The API is very similar to
|
35
|
+
Webrat, so if you know Webrat you should feel right at home. Support for
|
36
|
+
Capybara is built into cucumber-rails 0.2. In your Rails app, just run:
|
37
|
+
|
38
|
+
script/generate cucumber --capybara
|
39
|
+
|
40
|
+
And everything should be set up and ready to go.
|
41
|
+
|
42
|
+
If you want to use Capybara with Cucumber outside Rails (for example with Merb
|
43
|
+
or Sinatra), you'll need require capybara and set the Rack app manually:
|
44
|
+
|
45
|
+
require 'capybara/cucumber'
|
46
|
+
Capybara.app = MyRackApp
|
47
|
+
|
48
|
+
Now you can use it in your steps:
|
49
|
+
|
50
|
+
When /I sign in/ do
|
51
|
+
within("//form[@id='session']") do
|
52
|
+
fill_in 'Login', :with => 'user@example.com'
|
53
|
+
fill_in 'Password', :with => 'password'
|
54
|
+
end
|
55
|
+
click_link 'Sign in'
|
56
|
+
end
|
57
|
+
|
58
|
+
== Default and current driver
|
59
|
+
|
60
|
+
You can set up a default driver for your features. For example if you'd prefer
|
61
|
+
to run Selenium, you could do:
|
62
|
+
|
63
|
+
require 'capybara/rails'
|
64
|
+
require 'capybara/cucumber'
|
65
|
+
Capybara.default_driver = :selenium
|
66
|
+
|
67
|
+
You can change the driver temporarily:
|
68
|
+
|
69
|
+
Capybara.current_driver = :culerity
|
70
|
+
Capybara.use_default_driver
|
71
|
+
|
72
|
+
You can do this in Before and After blocks to temporarily switch to a different
|
73
|
+
driver. Note that switching driver creates a new session, so you may not be able
|
74
|
+
to switch in the middle of a Scenario.
|
75
|
+
|
76
|
+
== Cucumber and Tags
|
77
|
+
|
78
|
+
Capybara sets up some {tags}[http://wiki.github.com/aslakhellesoy/cucumber/tags]
|
79
|
+
for you to use in Cucumber. Often you'll want to run only some scenarios with a
|
80
|
+
driver that supports JavaScript, Capybara makes this easy: simply tag the
|
81
|
+
scenario (or feature) with <tt>@javascript</tt>:
|
82
|
+
|
83
|
+
@javascript
|
84
|
+
Scenario: do something AJAXy
|
85
|
+
When I click the AJAX link
|
86
|
+
...
|
87
|
+
|
88
|
+
You can change which driver Capybara uses for JavaScript:
|
89
|
+
|
90
|
+
Capybara.javascript_driver = :culerity
|
91
|
+
|
92
|
+
There are also explicit <tt>@selenium</tt>, <tt>@culerity</tt> and
|
93
|
+
<tt>@rack_test</tt> tags set up for you.
|
94
|
+
|
95
|
+
== Selenium
|
96
|
+
|
97
|
+
At the moment, Capybara supports Webdriver, also called Selenium 2.0, *not*
|
98
|
+
Selenium RC. Provided Firefox is installed, everything is set up for you, and
|
99
|
+
you should be able to start using Selenium right away.
|
100
|
+
|
101
|
+
== Celerity
|
102
|
+
|
103
|
+
Celerity only runs on JRuby, so you'll need to install the celerity gem under
|
104
|
+
JRuby:
|
105
|
+
|
106
|
+
jruby -S gem install celerity
|
107
|
+
|
108
|
+
Note that some specs currently fail on celerity 0.7.5, due to a bug in recent
|
109
|
+
versions of HTMLUnit. It is recommended you use celerity 0.7.4 for the time
|
110
|
+
being.
|
111
|
+
|
112
|
+
== Culerity
|
113
|
+
|
114
|
+
Install celerity as noted above, make sure JRuby is in your path. Note that
|
115
|
+
Culerity doesn't seem to be working under Ruby 1.9 at the moment.
|
116
|
+
|
117
|
+
== The DSL
|
118
|
+
|
119
|
+
Capybara's DSL is inspired by Webrat. While backwards compatibility is retained
|
120
|
+
in a lot of cases, there are certain important differences.
|
121
|
+
|
122
|
+
Unlike in Webrat, all searches in Capybara are *case sensitive*. This is because
|
123
|
+
Capybara heavily uses XPath, which doesn't support case insensitivity.
|
124
|
+
|
125
|
+
=== Navigating
|
126
|
+
|
127
|
+
You can use the <tt>visit</tt> method to navigate to other pages:
|
128
|
+
|
129
|
+
visit('/projects')
|
130
|
+
visit(post_comments_path(post))
|
131
|
+
|
132
|
+
The visit method only takes a single parameter, the request method is *always*
|
133
|
+
GET.
|
134
|
+
|
135
|
+
=== Clicking links and buttons
|
136
|
+
|
137
|
+
You can interact with the webapp by following links and buttons. Capybara
|
138
|
+
automatically follows any redirects, and submits forms associated with buttons.
|
139
|
+
|
140
|
+
click_link('id-of-link')
|
141
|
+
click_link('Link Text')
|
142
|
+
click_button('Save')
|
143
|
+
click('Link Text') # Click either a link or a button
|
144
|
+
click('Button Value')
|
145
|
+
|
146
|
+
=== Interacting with forms
|
147
|
+
|
148
|
+
Forms are everywhere in webapps, there are a number of tools for interacting
|
149
|
+
with the various form elements:
|
150
|
+
|
151
|
+
fill_in('First Name', :with => 'John')
|
152
|
+
fill_in('Password', :with => 'Seekrit')
|
153
|
+
fill_in('Description', :with => 'Really Long Text…')
|
154
|
+
choose('An Option')
|
155
|
+
check('A Checkbox')
|
156
|
+
uncheck('A Checkbox')
|
157
|
+
attach_file('Image', '/path/to/image.jpg')
|
158
|
+
select('Option', :from => 'Select Box')
|
159
|
+
|
160
|
+
=== Scoping
|
161
|
+
|
162
|
+
Capybara makes it possible to restrict certain actions, such as interacting with
|
163
|
+
forms or clicking links and buttons, to within a specific area of the page. For
|
164
|
+
this purpose you can use the generic <tt>within</tt> method. Optionally you can
|
165
|
+
specify which kind of selector (CSS or XPath to use).
|
166
|
+
|
167
|
+
within("//li[@id='employee']") do
|
168
|
+
fill_in 'Name', :with => 'Jimmy'
|
169
|
+
end
|
170
|
+
|
171
|
+
within(:css, "li#employee") do
|
172
|
+
fill_in 'Name', :with => 'Jimmy'
|
173
|
+
end
|
174
|
+
|
175
|
+
You can choose which kind of selector Capybara uses by default, by setting
|
176
|
+
<tt>Capybara.default_selector</tt>.
|
177
|
+
|
178
|
+
There are special methods for restricting the scope to a specific fieldset,
|
179
|
+
identified by either an id or the text of the fieldet's legend tag, and to a
|
180
|
+
specific table, identified by either idea or text of the table's caption tag.
|
181
|
+
|
182
|
+
within_fieldset('Employee') do
|
183
|
+
fill_in 'Name', :with => 'Jimmy'
|
184
|
+
end
|
185
|
+
|
186
|
+
within_table('Employee') do
|
187
|
+
fill_in 'Name', :with => 'Jimmy'
|
188
|
+
end
|
189
|
+
|
190
|
+
=== Querying
|
191
|
+
|
192
|
+
Capybara has a rich set of options for querying the page for the existence of
|
193
|
+
certain elements, and working with and manipulating those elements.
|
194
|
+
|
195
|
+
page.has_xpath?('//table/tr')
|
196
|
+
page.has_css?('table tr.foo')
|
197
|
+
page.has_content?('foo')
|
198
|
+
|
199
|
+
You can use with RSpecs magic matchers:
|
200
|
+
|
201
|
+
page.should have_xpath('//table/tr')
|
202
|
+
page.should have_css('table tr.foo')
|
203
|
+
page.should have_content('foo')
|
204
|
+
page.should have_no_content('foo')
|
205
|
+
|
206
|
+
Note that <tt>page.should have_no_xpath</tt> is preferred over
|
207
|
+
<tt>page.should_not have_xpath</tt>. Read the section on asynchronous JavaScript
|
208
|
+
for an explanation.
|
209
|
+
|
210
|
+
You can also find specific elements, in order to manipulate them:
|
211
|
+
|
212
|
+
find_field('First Name').value
|
213
|
+
find_link('Hello').visible?
|
214
|
+
find_button('Send').click
|
215
|
+
|
216
|
+
find('//table/tr').click
|
217
|
+
wait_for("//*[@id='overlay'").find("//h1").click
|
218
|
+
all('a').each { |a| a[:href] }
|
219
|
+
|
220
|
+
=== Scripting
|
221
|
+
|
222
|
+
In drivers which support it, you can easily evaluate JavaScript:
|
223
|
+
|
224
|
+
result = page.evaluate_script('4 + 4');
|
225
|
+
|
226
|
+
=== Debugging
|
227
|
+
|
228
|
+
It can be useful to take a snapshot of the page as it currently is and take a
|
229
|
+
look at it:
|
230
|
+
|
231
|
+
save_and_open_page
|
232
|
+
|
233
|
+
== Asynchronous JavaScript (AJAX and friends)
|
234
|
+
|
235
|
+
When working with asynchronous JavaScript, you might come across situations
|
236
|
+
where you are attempting to interact with an element which is not yet present
|
237
|
+
on the page. Capybara automatically deals with this by waiting for elements
|
238
|
+
to appear on the page.
|
239
|
+
|
240
|
+
When issuing instructions to the DSL such as:
|
241
|
+
|
242
|
+
click_link('foo')
|
243
|
+
click_link('bar')
|
244
|
+
page.should have_content('baz')
|
245
|
+
|
246
|
+
If clicking on the *foo* link causes triggers an asynchronous process, such as
|
247
|
+
an AJAX request, which, when complete will add the *bar* link to the page,
|
248
|
+
clicking on the *bar* link would be expeced to fail, since that link doesn't
|
249
|
+
exist yet. However Capybara is smart enought to retry finding the link for a
|
250
|
+
brief period of time before giving up and throwing an error. The same is true of
|
251
|
+
the next line, which looks for the content *baz* on the page; it will retry
|
252
|
+
looking for that content for a brief time. You can adjust how long this period
|
253
|
+
is (the default is 2 seconds):
|
254
|
+
|
255
|
+
Capybara.default_wait_time = 5
|
256
|
+
|
257
|
+
Be aware that because of this behaviour, the following two statements are *not*
|
258
|
+
identical, and you should *always* use the latter!
|
259
|
+
|
260
|
+
page.should_not have_xpath('//a')
|
261
|
+
page.should have_no_xpath('//a')
|
262
|
+
|
263
|
+
The former would incorrectly wait for the content to appear, since the
|
264
|
+
asynchronous process has not yet removed the element from the page, it would
|
265
|
+
therefore fail, even though the code might be working correctly. The latter
|
266
|
+
correctly wait for the element to disappear from the page.
|
267
|
+
|
268
|
+
== Using the DSL outside cucumber
|
269
|
+
|
270
|
+
You can mix the DSL into any context, for example you could use it in RSpec
|
271
|
+
examples. Just load the dsl and include it anywhere:
|
272
|
+
|
273
|
+
require 'capybara'
|
274
|
+
require 'capybara/dsl'
|
275
|
+
|
276
|
+
include Capybara
|
277
|
+
Capybara.default_driver = :culerity
|
278
|
+
|
279
|
+
within("//form[@id='session']") do
|
280
|
+
fill_in 'Login', :with => 'user@example.com'
|
281
|
+
fill_in 'Password', :with => 'password'
|
282
|
+
end
|
283
|
+
click_link 'Sign in'
|
284
|
+
|
285
|
+
== Calling remote servers
|
286
|
+
|
287
|
+
Normally Capybara expects to be testing an in-process Rack application, but you can also use it to talk to a web server running anywhere on the internets, by setting app_host:
|
288
|
+
|
289
|
+
require 'capybara'
|
290
|
+
require 'capybara/dsl'
|
291
|
+
|
292
|
+
include Capybara
|
293
|
+
Capybara.current_driver = :selenium
|
294
|
+
Capybara.app_host = 'http://www.google.com'
|
295
|
+
|
296
|
+
visit('/')
|
297
|
+
|
298
|
+
Note that rack-test does not support running against a remote server. With drivers that support it, you can also visit any URL directly:
|
299
|
+
|
300
|
+
visit('http://www.google.com')
|
301
|
+
|
302
|
+
By default Capybara will try to boot a rack application automatically. You might want to switch off Capybara's rack server if you are running against a remote application:
|
303
|
+
|
304
|
+
Capybara.run_server = false
|
305
|
+
|
306
|
+
== Using the sessions manually
|
307
|
+
|
308
|
+
For ultimate control, you can instantiate and use a session manually.
|
309
|
+
|
310
|
+
require 'capybara'
|
311
|
+
|
312
|
+
session = Capybara::Session.new(:culerity, my_rack_app)
|
313
|
+
session.within("//form[@id='session']") do
|
314
|
+
session.fill_in 'Login', :with => 'user@example.com'
|
315
|
+
session.fill_in 'Password', :with => 'password'
|
316
|
+
end
|
317
|
+
session.click_link 'Sign in'
|
318
|
+
|
319
|
+
== XPath and CSS
|
320
|
+
|
321
|
+
Capybara does not try to guess what kind of selector you are going to give it,
|
322
|
+
if you want to use CSS with your 'within' declarations for example, you'll need
|
323
|
+
to do:
|
324
|
+
|
325
|
+
within(:css, 'ul li') { ... }
|
326
|
+
find(:css, 'ul li').text
|
327
|
+
locate(:css, 'input#name').value
|
328
|
+
|
329
|
+
Alternatively you can set the default selector to CSS, which may help if you are
|
330
|
+
moving from Webrat and used CSS a lot, or simply generally prefer CSS:
|
331
|
+
|
332
|
+
Capybara.default_selector = :css
|
333
|
+
within('ul li') { ... }
|
334
|
+
find('ul li').text
|
335
|
+
locate('input#name').value
|
336
|
+
|
337
|
+
== Gotchas:
|
338
|
+
|
339
|
+
* Domain names (including subdomains) don't work under rack-test. Since it's a
|
340
|
+
pain to set up subdomains for the other drivers anyway, you should consider an
|
341
|
+
alternate solution. You might use
|
342
|
+
{default_url_options}[https://gist.github.com/643a758320a2926bd2ed] in Rails
|
343
|
+
for example.
|
344
|
+
|
345
|
+
* Access to session, request and response from the test is not possible. Maybe
|
346
|
+
we'll do response headers at some point in the future, but the others really
|
347
|
+
shouldn't be touched in an integration test anyway.
|
348
|
+
|
349
|
+
* Access to Rails specific stuff (such as <tt>controller</tt>) is unavailable,
|
350
|
+
since we're not using Rails' integration testing.
|
351
|
+
|
352
|
+
* <tt><a href="#"></tt> Will cause problems under rack-test, please do
|
353
|
+
<tt><a href="/same/url#"></tt> instead. You can achieve this in Rails with
|
354
|
+
<tt>link_to('foo', :anchor => '')</tt>
|
355
|
+
|
356
|
+
== Contributors:
|
357
|
+
|
358
|
+
The following people have dedicated their time and effort to Capybara:
|
359
|
+
|
360
|
+
* Jonas Nicklas
|
361
|
+
* Dennis Rogenius
|
362
|
+
* Rob Holland
|
363
|
+
* Wincent Colaiuta
|
364
|
+
* Andrea Fazzi
|
365
|
+
* Aslak Hellesøy
|
366
|
+
* Andrew Brown
|
367
|
+
* Lenny Marks
|
368
|
+
* Aaron Patterson
|
369
|
+
* Dan Dofter
|
370
|
+
* Thorbjørn Hermansen
|
371
|
+
* Louis T.
|
372
|
+
* Stephan Hagemann
|
373
|
+
* Graham Ashton
|
374
|
+
* Joseph Wilk
|
375
|
+
* Matt Wynne
|
376
|
+
* Piotr Sarnacki
|
377
|
+
* Pavel Gabriel
|
378
|
+
* Bodaniel Jeanes
|
379
|
+
* Carl Porth
|
380
|
+
|
381
|
+
== License:
|
382
|
+
|
383
|
+
(The MIT License)
|
384
|
+
|
385
|
+
Copyright (c) 2009 Jonas Nicklas
|
386
|
+
|
387
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
388
|
+
a copy of this software and associated documentation files (the
|
389
|
+
'Software'), to deal in the Software without restriction, including
|
390
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
391
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
392
|
+
permit persons to whom the Software is furnished to do so, subject to
|
393
|
+
the following conditions:
|
394
|
+
|
395
|
+
The above copyright notice and this permission notice shall be
|
396
|
+
included in all copies or substantial portions of the Software.
|
397
|
+
|
398
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
399
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
400
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
401
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
402
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
403
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
404
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|