yannp-capybara 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/History.txt +112 -0
  2. data/README.rdoc +442 -0
  3. data/lib/capybara/cucumber.rb +32 -0
  4. data/lib/capybara/driver/base.rb +56 -0
  5. data/lib/capybara/driver/celerity_driver.rb +154 -0
  6. data/lib/capybara/driver/culerity_driver.rb +26 -0
  7. data/lib/capybara/driver/node.rb +66 -0
  8. data/lib/capybara/driver/rack_test_driver.rb +279 -0
  9. data/lib/capybara/driver/selenium_driver.rb +157 -0
  10. data/lib/capybara/dsl.rb +98 -0
  11. data/lib/capybara/node/actions.rb +156 -0
  12. data/lib/capybara/node/finders.rb +155 -0
  13. data/lib/capybara/node/matchers.rb +97 -0
  14. data/lib/capybara/node.rb +209 -0
  15. data/lib/capybara/rails.rb +17 -0
  16. data/lib/capybara/server.rb +101 -0
  17. data/lib/capybara/session.rb +278 -0
  18. data/lib/capybara/spec/driver.rb +190 -0
  19. data/lib/capybara/spec/fixtures/capybara.jpg +0 -0
  20. data/lib/capybara/spec/fixtures/test_file.txt +1 -0
  21. data/lib/capybara/spec/public/jquery-ui.js +35 -0
  22. data/lib/capybara/spec/public/jquery.js +19 -0
  23. data/lib/capybara/spec/public/test.js +33 -0
  24. data/lib/capybara/spec/session/all_spec.rb +73 -0
  25. data/lib/capybara/spec/session/attach_file_spec.rb +64 -0
  26. data/lib/capybara/spec/session/check_spec.rb +67 -0
  27. data/lib/capybara/spec/session/choose_spec.rb +26 -0
  28. data/lib/capybara/spec/session/click_button_spec.rb +243 -0
  29. data/lib/capybara/spec/session/click_link_or_button_spec.rb +30 -0
  30. data/lib/capybara/spec/session/click_link_spec.rb +108 -0
  31. data/lib/capybara/spec/session/current_url_spec.rb +15 -0
  32. data/lib/capybara/spec/session/fill_in_spec.rb +119 -0
  33. data/lib/capybara/spec/session/find_button_spec.rb +18 -0
  34. data/lib/capybara/spec/session/find_by_id_spec.rb +18 -0
  35. data/lib/capybara/spec/session/find_field_spec.rb +26 -0
  36. data/lib/capybara/spec/session/find_link_spec.rb +19 -0
  37. data/lib/capybara/spec/session/find_spec.rb +91 -0
  38. data/lib/capybara/spec/session/has_button_spec.rb +32 -0
  39. data/lib/capybara/spec/session/has_content_spec.rb +106 -0
  40. data/lib/capybara/spec/session/has_css_spec.rb +107 -0
  41. data/lib/capybara/spec/session/has_field_spec.rb +96 -0
  42. data/lib/capybara/spec/session/has_link_spec.rb +33 -0
  43. data/lib/capybara/spec/session/has_select_spec.rb +89 -0
  44. data/lib/capybara/spec/session/has_table_spec.rb +96 -0
  45. data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
  46. data/lib/capybara/spec/session/headers.rb +19 -0
  47. data/lib/capybara/spec/session/javascript.rb +232 -0
  48. data/lib/capybara/spec/session/response_code.rb +19 -0
  49. data/lib/capybara/spec/session/select_spec.rb +91 -0
  50. data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
  51. data/lib/capybara/spec/session/unselect_spec.rb +54 -0
  52. data/lib/capybara/spec/session/within_spec.rb +153 -0
  53. data/lib/capybara/spec/session.rb +78 -0
  54. data/lib/capybara/spec/test_app.rb +94 -0
  55. data/lib/capybara/spec/views/buttons.erb +4 -0
  56. data/lib/capybara/spec/views/fieldsets.erb +29 -0
  57. data/lib/capybara/spec/views/form.erb +245 -0
  58. data/lib/capybara/spec/views/frame_one.erb +8 -0
  59. data/lib/capybara/spec/views/frame_two.erb +8 -0
  60. data/lib/capybara/spec/views/postback.erb +13 -0
  61. data/lib/capybara/spec/views/tables.erb +122 -0
  62. data/lib/capybara/spec/views/with_html.erb +43 -0
  63. data/lib/capybara/spec/views/with_js.erb +39 -0
  64. data/lib/capybara/spec/views/with_scope.erb +36 -0
  65. data/lib/capybara/spec/views/with_simple_html.erb +1 -0
  66. data/lib/capybara/spec/views/within_frames.erb +10 -0
  67. data/lib/capybara/util/save_and_open_page.rb +36 -0
  68. data/lib/capybara/util/timeout.rb +27 -0
  69. data/lib/capybara/version.rb +3 -0
  70. data/lib/capybara/xpath.rb +182 -0
  71. data/lib/capybara.rb +73 -0
  72. data/spec/capybara_spec.rb +18 -0
  73. data/spec/driver/celerity_driver_spec.rb +17 -0
  74. data/spec/driver/culerity_driver_spec.rb +13 -0
  75. data/spec/driver/rack_test_driver_spec.rb +19 -0
  76. data/spec/driver/remote_culerity_driver_spec.rb +24 -0
  77. data/spec/driver/remote_selenium_driver_spec.rb +19 -0
  78. data/spec/driver/selenium_driver_spec.rb +13 -0
  79. data/spec/dsl_spec.rb +140 -0
  80. data/spec/save_and_open_page_spec.rb +83 -0
  81. data/spec/server_spec.rb +53 -0
  82. data/spec/session/celerity_session_spec.rb +28 -0
  83. data/spec/session/culerity_session_spec.rb +26 -0
  84. data/spec/session/rack_test_session_spec.rb +34 -0
  85. data/spec/session/selenium_session_spec.rb +26 -0
  86. data/spec/spec_helper.rb +23 -0
  87. data/spec/timeout_spec.rb +28 -0
  88. data/spec/xpath_spec.rb +173 -0
  89. metadata +314 -0
data/History.txt ADDED
@@ -0,0 +1,112 @@
1
+ # Version 0.3.9
2
+
3
+ Release data: 2010-07-03
4
+
5
+ ### yannp's fork
6
+
7
+ * exposing the driver method to add flexibility
8
+
9
+ ### Added
10
+
11
+ * status_code which returns the HTTP status code of the last response (no Selenium!)
12
+ * Capybara.save_and_open_page to store tempfiles
13
+ * RackTest and Culerity drivers now clean up after themselves properly
14
+
15
+ ### Fixed
16
+
17
+ * When no rack app is set and the app is called, a more descriptive error is raised
18
+ * select now works with optgroups
19
+ * Don't submit image buttons unless they were clicked under rack-test
20
+ * Support custom field types under Selenium
21
+ * Support input fields without a type, treat them as though they were text fields
22
+ * Redirect now throws an error after 5 redirects, as per RFC
23
+ * Selenium now properly raises an error when Node#trigger is called
24
+ * Node#value now returns the correct value for textareas under rack-test
25
+
26
+ # Version 0.3.8
27
+
28
+ Release date: 2010-05-12
29
+
30
+ ### Added
31
+
32
+ * Within_frame method to execute a block of code within a particular iframe (Selenium only!)
33
+
34
+ ### Fixed
35
+
36
+ * Single quotes are properly escaped with `select` under rack-test and Selenium.
37
+ * The :text option for searches now escapes regexp special characters when a string is given.
38
+ * Selenium now correctly checks already checked checkboxes (same with uncheck)
39
+ * Timing issue which caused Selenium to hang under certain circumstances.
40
+ * Selenium now resolves attributes even if they are given as a Symbol
41
+
42
+ # Version 0.3.7
43
+
44
+ Release date: 2010-04-09
45
+
46
+ This is a drop in compatible maintainance release. It's mostly
47
+ important for driver authors.
48
+
49
+ ### Added
50
+
51
+ * RackTest scans for data-method which rails3 uses to change the request method
52
+
53
+ ### Fixed
54
+
55
+ * Don't hang when starting server on Windoze
56
+
57
+ ### Changed
58
+
59
+ * The driver and session specs are now located inside lib! Driver authors can simply require them.
60
+
61
+ # Version 0.3.6
62
+
63
+ Release date: 2010-03-22
64
+
65
+ This is a maintainance release with minor bug fixes, should be
66
+ drop in compatible.
67
+
68
+ ### Added
69
+
70
+ * It's now possible to load in external drivers
71
+
72
+ ### Fixed
73
+
74
+ * has_content? ignores whitespace
75
+ * Trigger events when choosing radios and checking checkboxes under Selenium
76
+ * Make Capybara.app totally optional when running without server
77
+ * Changed fallback host so it matches the one set up by Rails' integration tests
78
+
79
+ # Version 0.3.5
80
+
81
+ Release date: 2010-02-26
82
+
83
+ This is a mostly backwards compatible release, it does break
84
+ the API in some minor places, which should hopefully not affect
85
+ too many users, please read the release notes carefully!
86
+
87
+ ### Breaking
88
+
89
+ * Relative searching in a node (e.g. find('//p').all('//a')) will now follow XPath standard
90
+ this means that if you want to find descendant nodes only, you'll need to prefix a dot!
91
+ * `visit` now accepts fully qualified URLs for drivers that support it.
92
+ * Capybara will always try to run a rack server, unless you set Capybara.run_sever = false
93
+
94
+ ### Changed
95
+
96
+ * thin is preferred over mongrel and webrick, since it is Ruby 1.9 compatible
97
+ * click_button and click will find <input type="button">, clicking them does nothing in RackTest
98
+
99
+ ### Added
100
+
101
+ * Much improved error messages in a multitude of places
102
+ * More semantic page querying with has_link?, has_button?, etc...
103
+ * Option to ignore hidden elements when querying and interacting with the page
104
+ * Support for multiple selects
105
+
106
+ ### Fixed
107
+
108
+ * find_by_id is no longer broken
109
+ * clicking links where the image's alt attribute contains the text is now possible
110
+ * within_fieldset and within_table work when the default selector is CSS
111
+ * boolean attributes work the same across drivers (return true/false)
112
+
data/README.rdoc ADDED
@@ -0,0 +1,442 @@
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. env.js support is available as the
12
+ {capybara-envjs gem}[http://github.com/smparkes/capybara-envjs].
13
+
14
+ Online documentation is availbable
15
+ {at rdoc.info}[http://rdoc.info/projects/jnicklas/capybara].
16
+
17
+ == Install:
18
+
19
+ Install as a gem:
20
+
21
+ sudo gem install capybara
22
+
23
+ On OSX you may have to install libffi, you can install it via MacPorts with:
24
+
25
+ sudo port install libffi
26
+
27
+ == Development:
28
+
29
+ * Source hosted at {GitHub}[http://github.com/jnicklas/capybara].
30
+ * Please direct questions, discussions at the {mailing list}[http://groups.google.com/group/ruby-capybara].
31
+ * Report issues on {GitHub Issues}[http://github.com/jnicklas/capybara/issues]
32
+
33
+ Pull requests are very welcome! Make sure your patches are well tested, Capybara is
34
+ a testing tool after all. Please create a topic branch for every separate change
35
+ you make.
36
+
37
+ Capybara uses bundler in development. To set up a development environment, simply do:
38
+
39
+ gem install bundler --pre
40
+ bundle install
41
+
42
+ == Using Capybara with Cucumber
43
+
44
+ Capybara is built to work nicely with Cucumber. The API is very similar to
45
+ Webrat, so if you know Webrat you should feel right at home. Support for
46
+ Capybara is built into cucumber-rails 0.2. In your Rails app, just run:
47
+
48
+ script/generate cucumber --capybara
49
+
50
+ And everything should be set up and ready to go.
51
+
52
+ If you want to use Capybara with Cucumber outside Rails (for example with Merb
53
+ or Sinatra), you'll need to require Capybara and set the Rack app manually:
54
+
55
+ require 'capybara/cucumber'
56
+ Capybara.app = MyRackApp
57
+
58
+ Now you can use it in your steps:
59
+
60
+ When /I sign in/ do
61
+ within("#session") do
62
+ fill_in 'Login', :with => 'user@example.com'
63
+ fill_in 'Password', :with => 'password'
64
+ end
65
+ click_link 'Sign in'
66
+ end
67
+
68
+ == Default and current driver
69
+
70
+ You can set up a default driver for your features. For example if you'd prefer
71
+ to run Selenium, you could do:
72
+
73
+ require 'capybara/rails'
74
+ require 'capybara/cucumber'
75
+ Capybara.default_driver = :selenium
76
+
77
+ You can change the driver temporarily:
78
+
79
+ Capybara.current_driver = :culerity
80
+ Capybara.use_default_driver
81
+
82
+ You can do this in Before and After blocks to temporarily switch to a different
83
+ driver. Note that switching driver creates a new session, so you may not be able
84
+ to switch in the middle of a Scenario.
85
+
86
+ == Cucumber and Tags
87
+
88
+ Capybara sets up some {tags}[http://wiki.github.com/aslakhellesoy/cucumber/tags]
89
+ for you to use in Cucumber. Often you'll want to run only some scenarios with a
90
+ driver that supports JavaScript, Capybara makes this easy: simply tag the
91
+ scenario (or feature) with <tt>@javascript</tt>:
92
+
93
+ @javascript
94
+ Scenario: do something AJAXy
95
+ When I click the AJAX link
96
+ ...
97
+
98
+ You can change which driver Capybara uses for JavaScript:
99
+
100
+ Capybara.javascript_driver = :culerity
101
+
102
+ There are also explicit <tt>@selenium</tt>, <tt>@culerity</tt> and
103
+ <tt>@rack_test</tt> tags set up for you.
104
+
105
+ == Selenium
106
+
107
+ At the moment, Capybara supports Webdriver, also called Selenium 2.0, *not*
108
+ Selenium RC. Provided Firefox is installed, everything is set up for you, and
109
+ you should be able to start using Selenium right away.
110
+
111
+ If desired, you can change Selenium browser to :chrome or :ie:
112
+
113
+ require "selenium-webdriver"
114
+ Selenium::WebDriver.for :chrome
115
+
116
+ == Celerity
117
+
118
+ Celerity only runs on JRuby, so you'll need to install the celerity gem under
119
+ JRuby:
120
+
121
+ jruby -S gem install celerity
122
+
123
+ Note that some specs currently fail on celerity 0.7.5, due to a bug in recent
124
+ versions of HTMLUnit. It is recommended you use celerity 0.7.4 for the time
125
+ being.
126
+
127
+ == Culerity
128
+
129
+ Install celerity as noted above, make sure JRuby is in your path. Note that
130
+ Culerity doesn't seem to be working under Ruby 1.9 at the moment.
131
+
132
+ == env.js
133
+
134
+ The {capybara-envjs driver}[http://github.com/smparkes/capybara-envjs]
135
+ uses the envjs gem ({GitHub}[http://github.com/smparkes/env-js],
136
+ {rubygems.org}[http://rubygems.org/gems/envjs]) to interpret
137
+ JavaScript outside the browser. The driver is installed by installing the capybara-envjs gem:
138
+
139
+ gem install capybara-envjs
140
+
141
+ More info about the driver and env.js are available through the links above. The envjs gem only supports
142
+ Ruby 1.8.7 at this time.
143
+
144
+ == The DSL
145
+
146
+ Capybara's DSL is inspired by Webrat. While backwards compatibility is retained
147
+ in a lot of cases, there are certain important differences.
148
+
149
+ Unlike in Webrat, all searches in Capybara are *case sensitive*. This is because
150
+ Capybara heavily uses XPath, which doesn't support case insensitivity.
151
+
152
+ === Navigating
153
+
154
+ You can use the <tt>visit</tt> method to navigate to other pages:
155
+
156
+ visit('/projects')
157
+ visit(post_comments_path(post))
158
+
159
+ The visit method only takes a single parameter, the request method is *always*
160
+ GET.
161
+
162
+ You can get the current path of the browsing session for test assertions:
163
+
164
+ current_path.should == post_comments_path(post)
165
+
166
+ === Clicking links and buttons
167
+
168
+ You can interact with the webapp by following links and buttons. Capybara
169
+ automatically follows any redirects, and submits forms associated with buttons.
170
+
171
+ click_link('id-of-link')
172
+ click_link('Link Text')
173
+ click_button('Save')
174
+ click_link_or_button('Link Text')
175
+ click_link_or_button('Button Value')
176
+
177
+ === Interacting with forms
178
+
179
+ Forms are everywhere in webapps, there are a number of tools for interacting
180
+ with the various form elements:
181
+
182
+ fill_in('First Name', :with => 'John')
183
+ fill_in('Password', :with => 'Seekrit')
184
+ fill_in('Description', :with => 'Really Long Text…')
185
+ choose('A Radio Button')
186
+ check('A Checkbox')
187
+ uncheck('A Checkbox')
188
+ attach_file('Image', '/path/to/image.jpg')
189
+ select('Option', :from => 'Select Box')
190
+
191
+ === Querying
192
+
193
+ Capybara has a rich set of options for querying the page for the existence of
194
+ certain elements, and working with and manipulating those elements.
195
+
196
+ page.has_xpath?('//table/tr')
197
+ page.has_css?('table tr.foo')
198
+ page.has_content?('foo')
199
+
200
+ You can these use with RSpec's magic matchers:
201
+
202
+ page.should have_xpath('//table/tr')
203
+ page.should have_css('table tr.foo')
204
+ page.should have_content('foo')
205
+ page.should have_no_content('foo')
206
+
207
+ Note that <tt>page.should have_no_xpath</tt> is preferred over
208
+ <tt>page.should_not have_xpath</tt>. Read the section on asynchronous JavaScript
209
+ for an explanation.
210
+
211
+ === Finding
212
+
213
+ You can also find specific elements, in order to manipulate them:
214
+
215
+ find_field('First Name').value
216
+ find_link('Hello').visible?
217
+ find_button('Send').click
218
+
219
+ find(:xpath, "//table/tr").click
220
+ find("#overlay").find("h1").click
221
+ all('a').each { |a| a[:href] }
222
+
223
+ Note that <tt>find</tt> will wait for an element to appear on the page, as explained in the
224
+ AJAX section. If the element does not appear it will raise an error.
225
+
226
+ These elements all have all the Capybara DSL methods available, so you can restrict them
227
+ to specific parts of the page:
228
+
229
+ find('#navigation').click_link('Home')
230
+ find('#navigation').should have_button('Sign out')
231
+
232
+ === Scoping
233
+
234
+ Capybara makes it possible to restrict certain actions, such as interacting with
235
+ forms or clicking links and buttons, to within a specific area of the page. For
236
+ this purpose you can use the generic <tt>within</tt> method. Optionally you can
237
+ specify which kind of selector (CSS or XPath to use).
238
+
239
+ within("//li[@id='employee']") do
240
+ fill_in 'Name', :with => 'Jimmy'
241
+ end
242
+
243
+ within(:css, "li#employee") do
244
+ fill_in 'Name', :with => 'Jimmy'
245
+ end
246
+
247
+ You can choose which kind of selector Capybara uses by default, by setting
248
+ <tt>Capybara.default_selector</tt>.
249
+
250
+ There are special methods for restricting the scope to a specific fieldset,
251
+ identified by either an id or the text of the fieldet's legend tag, and to a
252
+ specific table, identified by either id or text of the table's caption tag.
253
+
254
+ within_fieldset('Employee') do
255
+ fill_in 'Name', :with => 'Jimmy'
256
+ end
257
+
258
+ within_table('Employee') do
259
+ fill_in 'Name', :with => 'Jimmy'
260
+ end
261
+
262
+ === Scripting
263
+
264
+ In drivers which support it, you can easily execute JavaScript:
265
+
266
+ page.execute_script("$('body').empty()")
267
+
268
+ For simple expressions, you can return the result of the script. Note
269
+ that this may break with more complicated expressions:
270
+
271
+ result = page.evaluate_script('4 + 4');
272
+
273
+ === Debugging
274
+
275
+ It can be useful to take a snapshot of the page as it currently is and take a
276
+ look at it:
277
+
278
+ save_and_open_page
279
+
280
+ == Asynchronous JavaScript (AJAX and friends)
281
+
282
+ When working with asynchronous JavaScript, you might come across situations
283
+ where you are attempting to interact with an element which is not yet present
284
+ on the page. Capybara automatically deals with this by waiting for elements
285
+ to appear on the page.
286
+
287
+ When issuing instructions to the DSL such as:
288
+
289
+ click_link('foo')
290
+ click_link('bar')
291
+ page.should have_content('baz')
292
+
293
+ If clicking on the *foo* link causes triggers an asynchronous process, such as
294
+ an AJAX request, which, when complete will add the *bar* link to the page,
295
+ clicking on the *bar* link would be expeced to fail, since that link doesn't
296
+ exist yet. However Capybara is smart enought to retry finding the link for a
297
+ brief period of time before giving up and throwing an error. The same is true of
298
+ the next line, which looks for the content *baz* on the page; it will retry
299
+ looking for that content for a brief time. You can adjust how long this period
300
+ is (the default is 2 seconds):
301
+
302
+ Capybara.default_wait_time = 5
303
+
304
+ Be aware that because of this behaviour, the following two statements are *not*
305
+ equivalent, and you should *always* use the latter!
306
+
307
+ page.should_not have_xpath('//a')
308
+ page.should have_no_xpath('//a')
309
+
310
+ The former would incorrectly wait for the content to appear, since the
311
+ asynchronous process has not yet removed the element from the page, it would
312
+ therefore fail, even though the code might be working correctly. The latter
313
+ correctly waits for the element to disappear from the page.
314
+
315
+ == Using the DSL outside cucumber
316
+
317
+ You can mix the DSL into any context, for example you could use it in RSpec
318
+ examples. Just load the DSL and include it anywhere:
319
+
320
+ require 'capybara'
321
+ require 'capybara/dsl'
322
+
323
+ Capybara.default_driver = :culerity
324
+
325
+ module MyModule
326
+ include Capybara
327
+
328
+ def login!
329
+ within("//form[@id='session']") do
330
+ fill_in 'Login', :with => 'user@example.com'
331
+ fill_in 'Password', :with => 'password'
332
+ end
333
+ click_link 'Sign in'
334
+ end
335
+ end
336
+
337
+ == Calling remote servers
338
+
339
+ 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:
340
+
341
+ Capybara.current_driver = :selenium
342
+ Capybara.app_host = 'http://www.google.com'
343
+ ...
344
+ visit('/')
345
+
346
+ Note that rack-test does not support running against a remote server. With drivers that support it, you can also visit any URL directly:
347
+
348
+ visit('http://www.google.com')
349
+
350
+ 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:
351
+
352
+ Capybara.run_server = false
353
+
354
+ == Using the sessions manually
355
+
356
+ For ultimate control, you can instantiate and use a session manually.
357
+
358
+ require 'capybara'
359
+
360
+ session = Capybara::Session.new(:culerity, my_rack_app)
361
+ session.within("//form[@id='session']") do
362
+ session.fill_in 'Login', :with => 'user@example.com'
363
+ session.fill_in 'Password', :with => 'password'
364
+ end
365
+ session.click_link 'Sign in'
366
+
367
+ == XPath and CSS
368
+
369
+ Capybara does not try to guess what kind of selector you are going to give it,
370
+ if you want to use XPath with your 'within' declarations for example, you'll need
371
+ to do:
372
+
373
+ within(:xpath, '//ul/li') { ... }
374
+ find(:xpath, '//ul/li').text
375
+ find(:xpath, '//li[contains(.//a[@href = "#"]/text(), "foo")]').value
376
+
377
+ Alternatively you can set the default selector to XPath:
378
+
379
+ Capybara.default_selector = :xpath
380
+ find('//ul/li').text
381
+
382
+ == Beware the XPath // trap
383
+
384
+ In XPath the expression // means something very specific, and it might not be what
385
+ you think. Contrary to common belief, // means "anywhere in the document" not "anywhere
386
+ in the current context". As an example:
387
+
388
+ page.find('//body').all('//script')
389
+
390
+ You might expect this to find all script tags in the body, but actually, it finds all
391
+ script tags in the entire document, not only those in the body! What you're looking
392
+ for is the .// expression which means "any descendant of the current node":
393
+
394
+ page.find('//body').all('.//script')
395
+
396
+ The same thing goes for within:
397
+
398
+ within('//body') do
399
+ page.find('.//script')
400
+ end
401
+
402
+ == Gotchas:
403
+
404
+ * Access to session and request is not possible from the test, Access to
405
+ response is limited. Some drivers allow access to response headers and HTTP
406
+ status code, but this kind of functionality is not provided by some drivers,
407
+ such as Selenium.
408
+
409
+ * Access to Rails specific stuff (such as <tt>controller</tt>) is unavailable,
410
+ since we're not using Rails' integration testing.
411
+
412
+ * Freezing time: It's common practice to mock out the Time so that features
413
+ that depend on the current Date work as expected. This can be problematic,
414
+ since Capybara's AJAX timing uses the system time, resulting in Capybara
415
+ never timing out and just hanging when a failure occurs. It's still possible to
416
+ use plugins which allow you to travel in time, rather than freeze time.
417
+ One such plugin is {Timecop}[http://github.com/jtrupiano/timecop].
418
+
419
+ == License:
420
+
421
+ (The MIT License)
422
+
423
+ Copyright (c) 2009 Jonas Nicklas
424
+
425
+ Permission is hereby granted, free of charge, to any person obtaining
426
+ a copy of this software and associated documentation files (the
427
+ 'Software'), to deal in the Software without restriction, including
428
+ without limitation the rights to use, copy, modify, merge, publish,
429
+ distribute, sublicense, and/or sell copies of the Software, and to
430
+ permit persons to whom the Software is furnished to do so, subject to
431
+ the following conditions:
432
+
433
+ The above copyright notice and this permission notice shall be
434
+ included in all copies or substantial portions of the Software.
435
+
436
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
437
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
438
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
439
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
440
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
441
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
442
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ require 'capybara'
2
+ require 'capybara/dsl'
3
+
4
+ World(Capybara)
5
+
6
+ After do
7
+ Capybara.reset_sessions!
8
+ end
9
+
10
+ Before('@javascript') do
11
+ Capybara.current_driver = Capybara.javascript_driver
12
+ end
13
+
14
+ Before('@selenium') do
15
+ Capybara.current_driver = :selenium
16
+ end
17
+
18
+ Before('@celerity') do
19
+ Capybara.current_driver = :celerity
20
+ end
21
+
22
+ Before('@culerity') do
23
+ Capybara.current_driver = :culerity
24
+ end
25
+
26
+ Before('@rack_test') do
27
+ Capybara.current_driver = :rack_test
28
+ end
29
+
30
+ After do
31
+ Capybara.use_default_driver
32
+ end
@@ -0,0 +1,56 @@
1
+ class Capybara::Driver::Base
2
+ def current_url
3
+ raise NotImplementedError
4
+ end
5
+
6
+ def visit(path)
7
+ raise NotImplementedError
8
+ end
9
+
10
+ def find(query)
11
+ raise NotImplementedError
12
+ end
13
+
14
+ def source
15
+ raise NotImplementedError
16
+ end
17
+
18
+ def body
19
+ raise NotImplementedError
20
+ end
21
+
22
+ def execute_script(script)
23
+ raise Capybara::NotSupportedByDriverError
24
+ end
25
+
26
+ def evaluate_script(script)
27
+ raise Capybara::NotSupportedByDriverError
28
+ end
29
+
30
+ def response_headers
31
+ raise Capybara::NotSupportedByDriverError
32
+ end
33
+
34
+ def status_code
35
+ raise Capybara::NotSupportedByDriverError
36
+ end
37
+
38
+ def within_frame(frame_id)
39
+ raise Capybara::NotSupportedByDriverError
40
+ end
41
+
42
+ def wait?
43
+ false
44
+ end
45
+
46
+ def wait_until(*args)
47
+ end
48
+
49
+ def cleanup!
50
+ end
51
+
52
+ def has_shortcircuit_timeout?
53
+ false
54
+ end
55
+
56
+ end