capybara 2.6.2 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +40 -15
- data/README.md +45 -38
- data/lib/capybara.rb +86 -10
- data/lib/capybara/cucumber.rb +1 -0
- data/lib/capybara/driver/base.rb +5 -2
- data/lib/capybara/driver/node.rb +1 -0
- data/lib/capybara/dsl.rb +1 -0
- data/lib/capybara/helpers.rb +3 -2
- data/lib/capybara/node/actions.rb +6 -0
- data/lib/capybara/node/base.rb +1 -0
- data/lib/capybara/node/document.rb +1 -0
- data/lib/capybara/node/document_matchers.rb +1 -0
- data/lib/capybara/node/element.rb +1 -0
- data/lib/capybara/node/finders.rb +3 -2
- data/lib/capybara/node/matchers.rb +72 -2
- data/lib/capybara/node/simple.rb +6 -3
- data/lib/capybara/queries/base_query.rb +1 -0
- data/lib/capybara/queries/current_path_query.rb +1 -0
- data/lib/capybara/queries/match_query.rb +21 -0
- data/lib/capybara/queries/selector_query.rb +138 -0
- data/lib/capybara/queries/text_query.rb +1 -0
- data/lib/capybara/queries/title_query.rb +1 -0
- data/lib/capybara/query.rb +3 -131
- data/lib/capybara/rack_test/browser.rb +1 -0
- data/lib/capybara/rack_test/css_handlers.rb +1 -0
- data/lib/capybara/rack_test/driver.rb +6 -4
- data/lib/capybara/rack_test/form.rb +1 -0
- data/lib/capybara/rack_test/node.rb +1 -0
- data/lib/capybara/rails.rb +2 -1
- data/lib/capybara/result.rb +1 -0
- data/lib/capybara/rspec.rb +1 -0
- data/lib/capybara/rspec/features.rb +1 -0
- data/lib/capybara/rspec/matchers.rb +54 -3
- data/lib/capybara/selector.rb +175 -75
- data/lib/capybara/selector/filter.rb +48 -0
- data/lib/capybara/selenium/driver.rb +24 -7
- data/lib/capybara/selenium/node.rb +1 -0
- data/lib/capybara/server.rb +38 -6
- data/lib/capybara/session.rb +30 -14
- data/lib/capybara/session/matchers.rb +2 -1
- data/lib/capybara/spec/public/test.js +6 -0
- data/lib/capybara/spec/session/accept_alert_spec.rb +2 -1
- data/lib/capybara/spec/session/accept_confirm_spec.rb +2 -1
- data/lib/capybara/spec/session/accept_prompt_spec.rb +2 -1
- data/lib/capybara/spec/session/all_spec.rb +1 -0
- data/lib/capybara/spec/session/assert_current_path.rb +1 -0
- data/lib/capybara/spec/session/assert_selector.rb +1 -0
- data/lib/capybara/spec/session/assert_text.rb +1 -0
- data/lib/capybara/spec/session/assert_title.rb +1 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +1 -0
- data/lib/capybara/spec/session/body_spec.rb +1 -0
- data/lib/capybara/spec/session/check_spec.rb +1 -0
- data/lib/capybara/spec/session/choose_spec.rb +1 -0
- data/lib/capybara/spec/session/click_button_spec.rb +1 -0
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +1 -0
- data/lib/capybara/spec/session/click_link_spec.rb +1 -0
- data/lib/capybara/spec/session/current_scope_spec.rb +2 -1
- data/lib/capybara/spec/session/current_url_spec.rb +1 -0
- data/lib/capybara/spec/session/dismiss_confirm_spec.rb +2 -1
- data/lib/capybara/spec/session/dismiss_prompt_spec.rb +2 -1
- data/lib/capybara/spec/session/element/assert_match_selector.rb +31 -0
- data/lib/capybara/spec/session/element/match_css_spec.rb +17 -0
- data/lib/capybara/spec/session/element/match_xpath_spec.rb +23 -0
- data/lib/capybara/spec/session/element/matches_selector_spec.rb +63 -0
- data/lib/capybara/spec/session/evaluate_script_spec.rb +1 -0
- data/lib/capybara/spec/session/execute_script_spec.rb +1 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +1 -0
- data/lib/capybara/spec/session/find_button_spec.rb +1 -0
- data/lib/capybara/spec/session/find_by_id_spec.rb +1 -0
- data/lib/capybara/spec/session/find_field_spec.rb +1 -0
- data/lib/capybara/spec/session/find_link_spec.rb +1 -0
- data/lib/capybara/spec/session/find_spec.rb +1 -0
- data/lib/capybara/spec/session/first_spec.rb +1 -0
- data/lib/capybara/spec/session/go_back_spec.rb +1 -0
- data/lib/capybara/spec/session/go_forward_spec.rb +1 -0
- data/lib/capybara/spec/session/has_button_spec.rb +1 -0
- data/lib/capybara/spec/session/has_css_spec.rb +1 -0
- data/lib/capybara/spec/session/has_current_path_spec.rb +1 -0
- data/lib/capybara/spec/session/has_field_spec.rb +13 -0
- data/lib/capybara/spec/session/has_link_spec.rb +1 -0
- data/lib/capybara/spec/session/has_select_spec.rb +19 -0
- data/lib/capybara/spec/session/has_selector_spec.rb +6 -0
- data/lib/capybara/spec/session/has_table_spec.rb +1 -0
- data/lib/capybara/spec/session/has_text_spec.rb +1 -0
- data/lib/capybara/spec/session/has_title_spec.rb +1 -0
- data/lib/capybara/spec/session/has_xpath_spec.rb +1 -0
- data/lib/capybara/spec/session/headers.rb +1 -0
- data/lib/capybara/spec/session/html_spec.rb +1 -0
- data/lib/capybara/spec/session/node_spec.rb +29 -0
- data/lib/capybara/spec/session/reset_session_spec.rb +35 -1
- data/lib/capybara/spec/session/response_code.rb +1 -0
- data/lib/capybara/spec/session/save_and_open_page_spec.rb +1 -0
- data/lib/capybara/spec/session/save_and_open_screenshot_spec.rb +3 -2
- data/lib/capybara/spec/session/save_page_spec.rb +34 -2
- data/lib/capybara/spec/session/save_screenshot_spec.rb +31 -1
- data/lib/capybara/spec/session/screenshot_spec.rb +3 -1
- data/lib/capybara/spec/session/select_spec.rb +1 -0
- data/lib/capybara/spec/session/selectors_spec.rb +35 -0
- data/lib/capybara/spec/session/text_spec.rb +1 -0
- data/lib/capybara/spec/session/title_spec.rb +2 -1
- data/lib/capybara/spec/session/uncheck_spec.rb +1 -0
- data/lib/capybara/spec/session/unselect_spec.rb +1 -0
- data/lib/capybara/spec/session/visit_spec.rb +1 -0
- data/lib/capybara/spec/session/window/become_closed_spec.rb +1 -0
- data/lib/capybara/spec/session/window/current_window_spec.rb +1 -0
- data/lib/capybara/spec/session/window/open_new_window_spec.rb +1 -0
- data/lib/capybara/spec/session/window/switch_to_window_spec.rb +1 -0
- data/lib/capybara/spec/session/window/window_opened_by_spec.rb +1 -0
- data/lib/capybara/spec/session/window/window_spec.rb +1 -8
- data/lib/capybara/spec/session/window/windows_spec.rb +1 -0
- data/lib/capybara/spec/session/window/within_window_spec.rb +2 -3
- data/lib/capybara/spec/session/within_frame_spec.rb +1 -0
- data/lib/capybara/spec/session/within_spec.rb +1 -0
- data/lib/capybara/spec/spec_helper.rb +2 -0
- data/lib/capybara/spec/test_app.rb +1 -0
- data/lib/capybara/spec/views/buttons.erb +1 -0
- data/lib/capybara/spec/views/fieldsets.erb +2 -1
- data/lib/capybara/spec/views/form.erb +24 -0
- data/lib/capybara/spec/views/frame_child.erb +2 -1
- data/lib/capybara/spec/views/frame_one.erb +2 -1
- data/lib/capybara/spec/views/frame_parent.erb +2 -1
- data/lib/capybara/spec/views/frame_two.erb +2 -1
- data/lib/capybara/spec/views/header_links.erb +1 -0
- data/lib/capybara/spec/views/host_links.erb +1 -0
- data/lib/capybara/spec/views/path.erb +1 -0
- data/lib/capybara/spec/views/popup_one.erb +1 -0
- data/lib/capybara/spec/views/popup_two.erb +1 -0
- data/lib/capybara/spec/views/postback.erb +2 -1
- data/lib/capybara/spec/views/tables.erb +1 -0
- data/lib/capybara/spec/views/with_base_tag.erb +1 -0
- data/lib/capybara/spec/views/with_count.erb +2 -1
- data/lib/capybara/spec/views/with_hover.erb +2 -1
- data/lib/capybara/spec/views/with_html.erb +3 -0
- data/lib/capybara/spec/views/with_html_entities.erb +1 -0
- data/lib/capybara/spec/views/with_js.erb +5 -0
- data/lib/capybara/spec/views/with_scope.erb +1 -0
- data/lib/capybara/spec/views/with_simple_html.erb +2 -1
- data/lib/capybara/spec/views/with_slow_unload.erb +17 -0
- data/lib/capybara/spec/views/with_title.erb +2 -1
- data/lib/capybara/spec/views/with_unload_alert.erb +12 -0
- data/lib/capybara/spec/views/with_windows.erb +1 -0
- data/lib/capybara/spec/views/within_frames.erb +2 -1
- data/lib/capybara/version.rb +2 -1
- data/lib/capybara/window.rb +1 -0
- data/spec/basic_node_spec.rb +1 -0
- data/spec/capybara_spec.rb +28 -1
- data/spec/dsl_spec.rb +1 -0
- data/spec/fixtures/selenium_driver_rspec_failure.rb +1 -0
- data/spec/fixtures/selenium_driver_rspec_success.rb +1 -0
- data/spec/rack_test_spec.rb +1 -0
- data/spec/result_spec.rb +1 -0
- data/spec/rspec/features_spec.rb +1 -0
- data/spec/rspec/matchers_spec.rb +1 -0
- data/spec/rspec/scenarios_spec.rb +1 -0
- data/spec/rspec/views_spec.rb +1 -0
- data/spec/rspec_spec.rb +1 -0
- data/spec/selector_spec.rb +55 -1
- data/spec/selenium_spec.rb +6 -2
- data/spec/selenium_spec_chrome.rb +1 -0
- data/spec/server_spec.rb +101 -13
- data/spec/spec_helper.rb +1 -0
- metadata +16 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13e267dd4eab833671b7653e9cec855306653102
|
4
|
+
data.tar.gz: 80707daeb161eac1ac1cabff4edef7c06823b707
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03a372cfdbdd251f39577df0b83bd8286af62cc4d02bdedd49d91594fb3c2de88babacf628366f49c3a8d10470203bccfe371e461f3789f8c7dae0be94d6eda2
|
7
|
+
data.tar.gz: 77db21ebef969917a1a8836d5d95e6a725f1fe6dc235fe0e795eeca25fd46b209f77487ddb5e38a523c80f7772ea6d17627ddabda78081e335e002847f8da53e
|
data/History.md
CHANGED
@@ -1,3 +1,28 @@
|
|
1
|
+
# Version 2.7.0
|
2
|
+
Release date: unreleased
|
3
|
+
|
4
|
+
### Fixed
|
5
|
+
* Element#visible?/checked?/disabled?/selected? Now return boolean
|
6
|
+
as expected when using the rack_test driver [Thomas Walpole]
|
7
|
+
* The rack_test driver now considers \<input type="hidden"> elements as non-visible [Thomas Walpole]
|
8
|
+
* A nil locator passed to the built-in html type selectors now behaves consistently, and finds elements of the expected types [Thomas Walpole]
|
9
|
+
* Capybara::Server now searches for available ports on the same interface it binds to [Aaron Stone]
|
10
|
+
* Selenium Driver handles system modals that appear when page is unloading [Thomas Walpole]
|
11
|
+
* Warning output if unused parameters are passed to a selector query [Thomas Walpole]
|
12
|
+
|
13
|
+
### Added
|
14
|
+
* Capybara now waits for requests to Capybaras server to complete while restting the session [John Hawthorn, Thomas Walpole]
|
15
|
+
* Capybara.reuse_server option to allow disabling of sharing server instance between sessions [Thomas Walpole]
|
16
|
+
* :multiple filter added to relevant selectors [Thomas Walpole]
|
17
|
+
* Provided server registrations for :webrick and :puma. Capybara.server = :puma for testing with Rails 5 [Thomas Walpole]
|
18
|
+
* Deprecate passing a block to Capybara::server user Capybara::register_server instead [Thomas Walpole]
|
19
|
+
* :option selector supports :selected and :disabled filters [Thomas Walpole]
|
20
|
+
* Element#matches_selector? and associated matchers (match_selector, match_css, etc) for comparing an element to a selector [Thomas Walpole]
|
21
|
+
* Deprecated Driver#browser_initialized? - Driver#reset! is required to be synchronous [Jonas Nicklas, Thomas Walpole]
|
22
|
+
* Deprecated Capybara.save_and_open_page_path in favor of Capybara.save_path with slightly different behavior when using relative paths with
|
23
|
+
save_page/save_screenshot [Thomas Walpole]
|
24
|
+
* :label selector [Thomas Walpole]
|
25
|
+
|
1
26
|
#Version 2.6.2
|
2
27
|
Relase date: 2016-01-27
|
3
28
|
|
@@ -14,44 +39,44 @@ Release date: 2016-01-27
|
|
14
39
|
Relase date: 2016-01-17
|
15
40
|
|
16
41
|
### Fixed
|
17
|
-
* Fixed path escaping issue with current_path matchers [
|
42
|
+
* Fixed path escaping issue with current_path matchers [Thomas Walpole, Luke Rollans] (Issue #1611)
|
18
43
|
* Fixed circular require [David Rodríguez]
|
19
44
|
* Capybara::RackTest::Form no longer overrides Object#method [David Rodriguez]
|
20
45
|
* options and with_options filter for :select selector have more intuitive visibility behavior [Nathan]
|
21
|
-
* Test for nested modal API method support [
|
46
|
+
* Test for nested modal API method support [Thomas Walpole]
|
22
47
|
|
23
48
|
|
24
49
|
### Added
|
25
|
-
* Capybara.modify_selector [
|
50
|
+
* Capybara.modify_selector [Thomas Walpole]
|
26
51
|
* xfeature and ffeature aliases added when using RSpec [Filip Bartuzi]
|
27
|
-
* Selenium driver supports a :clear option to #set to handle different strategies for clearing a field [
|
28
|
-
* Support the use of rack 2.0 with the rack_test driver [Travis Grathwell,
|
29
|
-
* Disabled option for default selectors now supports true, false, or :all [Jillian Rosile,
|
30
|
-
* Modal API methods now default wait time to Capybara.default_max_wait_time [
|
52
|
+
* Selenium driver supports a :clear option to #set to handle different strategies for clearing a field [Thomas Walpole]
|
53
|
+
* Support the use of rack 2.0 with the rack_test driver [Travis Grathwell, Thomas Walpole]
|
54
|
+
* Disabled option for default selectors now supports true, false, or :all [Jillian Rosile, Thomas Walpole]
|
55
|
+
* Modal API methods now default wait time to Capybara.default_max_wait_time [Thomas Walpole]
|
31
56
|
|
32
57
|
# Version 2.5.0
|
33
58
|
Release date: 2015-08-25
|
34
59
|
|
35
60
|
### Fixed
|
36
|
-
* Error message now raised correctly when invalid options passed to 'have_text'/'have_content' [
|
37
|
-
* Rack-test driver correctly gets document title when elements on the page have nested title elements (SVG) [
|
61
|
+
* Error message now raised correctly when invalid options passed to 'have_text'/'have_content' [Thomas Walpole]
|
62
|
+
* Rack-test driver correctly gets document title when elements on the page have nested title elements (SVG) [Thomas Walpole]
|
38
63
|
* 'save_page' no longer errors when using Capybara.asset_host if the page has no \<head> element [Travis Grathwell]
|
39
64
|
* rack-test driver will ignore clicks on links with href starting with '#' or 'javascript:'
|
40
65
|
|
41
66
|
### Added
|
42
|
-
* has_current_path? and associated asserts/matchers added [
|
67
|
+
* has_current_path? and associated asserts/matchers added [Thomas Walpole]
|
43
68
|
* Implement Node#path in selenium driver [Soutaro Matsumoto]
|
44
|
-
* 'using_session' is now nestable [
|
45
|
-
* 'switch_to_window' will now use waiting behavior for a matching window to appear [
|
69
|
+
* 'using_session' is now nestable [Thomas Walpole]
|
70
|
+
* 'switch_to_window' will now use waiting behavior for a matching window to appear [Thomas Walpole]
|
46
71
|
* Warning when attempting to select a disabled option
|
47
72
|
* Capybara matchers are now available in RSpec view specs by default [Joshua Clayton]
|
48
73
|
* 'have_link' and 'click_link' now accept Regexp for href matching [Yaniv Savir]
|
49
74
|
* 'find_all' as an alias of 'all' due to collision with RSpec
|
50
75
|
* Capybara.wait_on_first_by_default setting (default is false)
|
51
76
|
If set to true 'first' will use Capybaras waiting behavior to wait for at least one element to appear by default
|
52
|
-
* Capybara waiting behavior uses the monotonic clock if supported to ease restrictions on freezing time in tests [Dmitry Maksyoma,
|
53
|
-
* Capybara.server_errors setting that allows to configure what type of errors will be raised from the server thread [
|
54
|
-
* Node#send_keys to allow for sending keypresses directly to elements [
|
77
|
+
* Capybara waiting behavior uses the monotonic clock if supported to ease restrictions on freezing time in tests [Dmitry Maksyoma, Thomas Walpole]
|
78
|
+
* Capybara.server_errors setting that allows to configure what type of errors will be raised from the server thread [Thomas Walpole]
|
79
|
+
* Node#send_keys to allow for sending keypresses directly to elements [Thomas Walpole]
|
55
80
|
* 'formmethod' attribute support in RackTest driver [Emilia Andrzejewska]
|
56
81
|
* Clear field using backspaces in Selenium driver by using `:fill_options => { :clear => :backspace }` [Joe Lencioni]
|
57
82
|
|
data/README.md
CHANGED
@@ -51,7 +51,7 @@ GitHub): http://groups.google.com/group/ruby-capybara
|
|
51
51
|
- [Gotchas:](#gotchas)
|
52
52
|
- [Development](#development)
|
53
53
|
|
54
|
-
## Key benefits
|
54
|
+
## <a name="key-benefits"></a>Key benefits
|
55
55
|
|
56
56
|
- **No setup** necessary for Rails and Rack application. Works out of the box.
|
57
57
|
- **Intuitive API** which mimics the language an actual user would use.
|
@@ -60,7 +60,7 @@ GitHub): http://groups.google.com/group/ruby-capybara
|
|
60
60
|
- **Powerful synchronization** features mean you never have to manually wait
|
61
61
|
for asynchronous processes to complete.
|
62
62
|
|
63
|
-
## Setup
|
63
|
+
## <a name="setup"></a>Setup
|
64
64
|
|
65
65
|
Capybara requires Ruby 1.9.3 or later. To install, add this line to your
|
66
66
|
`Gemfile` and run `bundle install`:
|
@@ -89,7 +89,7 @@ Capybara.app = MyRackApp
|
|
89
89
|
If you need to test JavaScript, or if your app interacts with (or is located at)
|
90
90
|
a remote URL, you'll need to [use a different driver](#drivers).
|
91
91
|
|
92
|
-
## Using Capybara with Cucumber
|
92
|
+
## <a name="using-capybara-with-cucumber"></a>Using Capybara with Cucumber
|
93
93
|
|
94
94
|
The `cucumber-rails` gem comes with Capybara support built-in. If you
|
95
95
|
are not using Rails, manually load the `capybara/cucumber` module:
|
@@ -124,7 +124,7 @@ Scenario: do something Ajaxy
|
|
124
124
|
There are also explicit `@selenium` and `@rack_test`
|
125
125
|
tags set up for you.
|
126
126
|
|
127
|
-
## Using Capybara with RSpec
|
127
|
+
## <a name="using-capybara-with-rspec"></a>Using Capybara with RSpec
|
128
128
|
|
129
129
|
Load RSpec 2.x support by adding the following line (typically to your
|
130
130
|
`spec_helper.rb` file):
|
@@ -135,7 +135,7 @@ require 'capybara/rspec'
|
|
135
135
|
|
136
136
|
If you are using Rails, put your Capybara specs in `spec/features` (only works
|
137
137
|
if [you have it configured in
|
138
|
-
|
138
|
+
RSpec](https://www.relishapp.com/rspec/rspec-rails/docs/upgrade#file-type-inference-disabled))
|
139
139
|
and if you have your Capybara specs in a different directory, then tag the
|
140
140
|
example groups with `:type => :feature`.
|
141
141
|
|
@@ -223,7 +223,7 @@ RSpec.describe "todos/show.html.erb", type: :view do
|
|
223
223
|
end
|
224
224
|
```
|
225
225
|
|
226
|
-
## Using Capybara with Test::Unit
|
226
|
+
## <a name="using-capybara-with-testunit"></a>Using Capybara with Test::Unit
|
227
227
|
|
228
228
|
* If you are using Rails, add the following code in your `test_helper.rb`
|
229
229
|
file to make Capybara available in all test cases deriving from
|
@@ -233,6 +233,13 @@ end
|
|
233
233
|
class ActionDispatch::IntegrationTest
|
234
234
|
# Make the Capybara DSL available in all integration tests
|
235
235
|
include Capybara::DSL
|
236
|
+
|
237
|
+
# Reset sessions and driver between tests
|
238
|
+
# Use super wherever this method is redefined in your individual test classes
|
239
|
+
def teardown
|
240
|
+
Capybara.reset_sessions!
|
241
|
+
Capybara.use_default_driver
|
242
|
+
end
|
236
243
|
end
|
237
244
|
```
|
238
245
|
|
@@ -267,7 +274,7 @@ class BlogTest < ActionDispatch::IntegrationTest
|
|
267
274
|
end
|
268
275
|
```
|
269
276
|
|
270
|
-
## Using Capybara with MiniTest::Spec
|
277
|
+
## <a name="using-capybara-with-minitestspec"></a>Using Capybara with MiniTest::Spec
|
271
278
|
|
272
279
|
Set up your base class as with Test::Unit. (On Rails, the right base class
|
273
280
|
could be something other than ActionDispatch::IntegrationTest.)
|
@@ -280,11 +287,11 @@ expectations for Capybara. For example:
|
|
280
287
|
page.must_have_content('Important!')
|
281
288
|
```
|
282
289
|
|
283
|
-
## Drivers
|
290
|
+
## <a name="drivers"></a>Drivers
|
284
291
|
|
285
292
|
Capybara uses the same DSL to drive a variety of browser and headless drivers.
|
286
293
|
|
287
|
-
### Selecting the Driver
|
294
|
+
### <a name="selecting-the-driver"></a>Selecting the Driver
|
288
295
|
|
289
296
|
By default, Capybara uses the `:rack_test` driver, which is fast but limited: it
|
290
297
|
does not support JavaScript, nor is it able to access HTTP resources outside of
|
@@ -315,7 +322,7 @@ Capybara.use_default_driver # switch back to default driver
|
|
315
322
|
**Note**: switching the driver creates a new session, so you may not be able to
|
316
323
|
switch in the middle of a test.
|
317
324
|
|
318
|
-
### RackTest
|
325
|
+
### <a name="racktest"></a>RackTest
|
319
326
|
|
320
327
|
RackTest is Capybara's default driver. It is written in pure Ruby and does not
|
321
328
|
have any support for executing JavaScript. Since the RackTest driver interacts
|
@@ -340,7 +347,7 @@ end
|
|
340
347
|
|
341
348
|
See the section on adding and configuring drivers.
|
342
349
|
|
343
|
-
### Selenium
|
350
|
+
### <a name="selenium"></a>Selenium
|
344
351
|
|
345
352
|
At the moment, Capybara supports [Selenium 2.0
|
346
353
|
(Webdriver)](http://seleniumhq.org/docs/01_introducing_selenium.html#selenium-2-aka-selenium-webdriver),
|
@@ -353,7 +360,7 @@ able to start using Selenium right away.
|
|
353
360
|
same transaction as your tests, causing data not to be shared between your test
|
354
361
|
and test server, see "Transactions and database setup" below.
|
355
362
|
|
356
|
-
### Capybara-webkit
|
363
|
+
### <a name="capybara-webkit"></a>Capybara-webkit
|
357
364
|
|
358
365
|
The [capybara-webkit driver](https://github.com/thoughtbot/capybara-webkit) is for true headless
|
359
366
|
testing. It uses QtWebKit to start a rendering engine process. It can execute JavaScript as well.
|
@@ -371,7 +378,7 @@ And you can use it by:
|
|
371
378
|
Capybara.javascript_driver = :webkit
|
372
379
|
```
|
373
380
|
|
374
|
-
### Poltergeist
|
381
|
+
### <a name="poltergeist"></a>Poltergeist
|
375
382
|
|
376
383
|
[Poltergeist](https://github.com/teampoltergeist/poltergeist) is another
|
377
384
|
headless driver which integrates Capybara with
|
@@ -379,7 +386,7 @@ headless driver which integrates Capybara with
|
|
379
386
|
require Xvfb to run on your CI server. It will also detect and report
|
380
387
|
any Javascript errors that happen within the page.
|
381
388
|
|
382
|
-
## The DSL
|
389
|
+
## <a name="the-dsl"></a>The DSL
|
383
390
|
|
384
391
|
*A complete reference is available at
|
385
392
|
[rubydoc.info](http://rubydoc.info/github/jnicklas/capybara/master)*.
|
@@ -390,7 +397,7 @@ any Javascript errors that happen within the page.
|
|
390
397
|
**Note**: All searches in Capybara are *case sensitive*. This is because
|
391
398
|
Capybara heavily uses XPath, which doesn't support case insensitivity.
|
392
399
|
|
393
|
-
### Navigating
|
400
|
+
### <a name="navigating"></a>Navigating
|
394
401
|
|
395
402
|
You can use the
|
396
403
|
<tt>[visit](http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Session#visit-instance_method)</tt>
|
@@ -416,7 +423,7 @@ expect(page).to have_current_path(post_comments_path(post))
|
|
416
423
|
safer since it uses Capybara's [waiting behaviour](#asynchronous-javascript-ajax-and-friends)
|
417
424
|
to ensure that preceding actions (such as a `click_link`) have completed.
|
418
425
|
|
419
|
-
### Clicking links and buttons
|
426
|
+
### <a name="clicking-links-and-buttons"></a>Clicking links and buttons
|
420
427
|
|
421
428
|
*Full reference: [Capybara::Node::Actions](http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions)*
|
422
429
|
|
@@ -431,7 +438,7 @@ click_on('Link Text') # clicks on either links or buttons
|
|
431
438
|
click_on('Button Value')
|
432
439
|
```
|
433
440
|
|
434
|
-
### Interacting with forms
|
441
|
+
### <a name="interacting-with-forms"></a>Interacting with forms
|
435
442
|
|
436
443
|
*Full reference: [Capybara::Node::Actions](http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions)*
|
437
444
|
|
@@ -448,7 +455,7 @@ attach_file('Image', '/path/to/image.jpg')
|
|
448
455
|
select('Option', :from => 'Select Box')
|
449
456
|
```
|
450
457
|
|
451
|
-
### Querying
|
458
|
+
### <a name="querying"></a>Querying
|
452
459
|
|
453
460
|
*Full reference: [Capybara::Node::Matchers](http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Matchers)*
|
454
461
|
|
@@ -478,7 +485,7 @@ expect(page).to have_css('table tr.foo')
|
|
478
485
|
expect(page).to have_content('foo')
|
479
486
|
```
|
480
487
|
|
481
|
-
### Finding
|
488
|
+
### <a name="finding"></a>Finding
|
482
489
|
|
483
490
|
_Full reference: [Capybara::Node::Finders](http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Finders)_
|
484
491
|
|
@@ -505,7 +512,7 @@ find('#navigation').click_link('Home')
|
|
505
512
|
expect(find('#navigation')).to have_button('Sign out')
|
506
513
|
```
|
507
514
|
|
508
|
-
### Scoping
|
515
|
+
### <a name="scoping"></a>Scoping
|
509
516
|
|
510
517
|
Capybara makes it possible to restrict certain actions, such as interacting with
|
511
518
|
forms or clicking links and buttons, to within a specific area of the page. For
|
@@ -537,7 +544,7 @@ within_table('Employee') do
|
|
537
544
|
end
|
538
545
|
```
|
539
546
|
|
540
|
-
### Working with windows
|
547
|
+
### <a name="working-with-windows"></a>Working with windows
|
541
548
|
|
542
549
|
Capybara provides some methods to ease finding and switching windows:
|
543
550
|
|
@@ -552,7 +559,7 @@ within_window facebook_window do
|
|
552
559
|
end
|
553
560
|
```
|
554
561
|
|
555
|
-
### Scripting
|
562
|
+
### <a name="scripting"></a>Scripting
|
556
563
|
|
557
564
|
In drivers which support it, you can easily execute JavaScript:
|
558
565
|
|
@@ -567,7 +574,7 @@ that this may break with more complicated expressions:
|
|
567
574
|
result = page.evaluate_script('4 + 4');
|
568
575
|
```
|
569
576
|
|
570
|
-
### Modals
|
577
|
+
### <a name="modals"></a>Modals
|
571
578
|
|
572
579
|
In drivers which support it, you can accept, dismiss and respond to alerts, confirms and prompts.
|
573
580
|
|
@@ -605,7 +612,7 @@ end
|
|
605
612
|
expect(message).to eq('Who is the chief architect of Linux?')
|
606
613
|
```
|
607
614
|
|
608
|
-
### Debugging
|
615
|
+
### <a name="debugging"></a>Debugging
|
609
616
|
|
610
617
|
It can be useful to take a snapshot of the page as it currently is and take a
|
611
618
|
look at it:
|
@@ -636,12 +643,12 @@ Or have it save and automatically open:
|
|
636
643
|
save_and_open_screenshot
|
637
644
|
```
|
638
645
|
|
639
|
-
## Matching
|
646
|
+
## <a name="matching"></a>Matching
|
640
647
|
|
641
648
|
It is possible to customize how Capybara finds elements. At your disposal
|
642
649
|
are two options, `Capybara.exact` and `Capybara.match`.
|
643
650
|
|
644
|
-
### Exactness
|
651
|
+
### <a name="exactness"></a>Exactness
|
645
652
|
|
646
653
|
`Capybara.exact` and the `exact` option work together with the `is` expression
|
647
654
|
inside the XPath gem. When `exact` is true, all `is` expressions match exactly,
|
@@ -658,7 +665,7 @@ click_link("Password") # does not match "Password confirmation"
|
|
658
665
|
click_link("Password", exact: false) # can be overridden
|
659
666
|
```
|
660
667
|
|
661
|
-
### Strategy
|
668
|
+
### <a name="strategy"></a>Strategy
|
662
669
|
|
663
670
|
Using `Capybara.match` and the equivalent `match` option, you can control how
|
664
671
|
Capybara behaves when multiple elements all match a query. There are currently
|
@@ -679,7 +686,7 @@ The default for `Capybara.match` is `:smart`. To emulate the behaviour in
|
|
679
686
|
Capybara 2.0.x, set `Capybara.match` to `:one`. To emulate the behaviour in
|
680
687
|
Capybara 1.x, set `Capybara.match` to `:prefer_exact`.
|
681
688
|
|
682
|
-
## Transactions and database setup
|
689
|
+
## <a name="transactions-and-database-setup"></a>Transactions and database setup
|
683
690
|
|
684
691
|
Some Capybara drivers need to run against an actual HTTP server. Capybara takes
|
685
692
|
care of this and starts one for you in the same process as your test, but on
|
@@ -695,7 +702,7 @@ Cucumber handles this by using truncation instead of transactions, i.e. they
|
|
695
702
|
empty out the entire database after each test. You can get the same behaviour
|
696
703
|
by using a gem such as [database_cleaner](https://github.com/DatabaseCleaner/database_cleaner).
|
697
704
|
|
698
|
-
## Asynchronous JavaScript (Ajax and friends)
|
705
|
+
## <a name="asynchronous-javascript-ajax-and-friends"></a>Asynchronous JavaScript (Ajax and friends)
|
699
706
|
|
700
707
|
When working with asynchronous JavaScript, you might come across situations
|
701
708
|
where you are attempting to interact with an element which is not yet present
|
@@ -735,7 +742,7 @@ The former would immediately fail because the content has not yet been removed.
|
|
735
742
|
Only the latter would wait for the asynchronous process to remove the content
|
736
743
|
from the page.
|
737
744
|
|
738
|
-
Capybara's
|
745
|
+
Capybara's RSpec matchers, however, are smart enough to handle either form.
|
739
746
|
The two following statements are functionally equivalent:
|
740
747
|
|
741
748
|
```ruby
|
@@ -757,7 +764,7 @@ the text of the `h1` to "Something", and this happened, this test would
|
|
757
764
|
pass. If you do not want this behaviour, you can set
|
758
765
|
`Capybara.automatic_reload` to `false`.
|
759
766
|
|
760
|
-
## Using the DSL elsewhere
|
767
|
+
## <a name="using-the-dsl-elsewhere"></a>Using the DSL elsewhere
|
761
768
|
|
762
769
|
You can mix the DSL into any context by including <tt>Capybara::DSL</tt>:
|
763
770
|
|
@@ -782,7 +789,7 @@ end
|
|
782
789
|
|
783
790
|
This enables its use in unsupported testing frameworks, and for general-purpose scripting.
|
784
791
|
|
785
|
-
## Calling remote servers
|
792
|
+
## <a name="calling-remote-servers"></a>Calling remote servers
|
786
793
|
|
787
794
|
Normally Capybara expects to be testing an in-process Rack application, but you
|
788
795
|
can also use it to talk to a web server running anywhere on the internet, by
|
@@ -811,7 +818,7 @@ remote application:
|
|
811
818
|
Capybara.run_server = false
|
812
819
|
```
|
813
820
|
|
814
|
-
## Using the sessions manually
|
821
|
+
## <a name="using-the-sessions-manually"></a>Using the sessions manually
|
815
822
|
|
816
823
|
For ultimate control, you can instantiate and use a
|
817
824
|
[Session](http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Session)
|
@@ -828,7 +835,7 @@ end
|
|
828
835
|
session.click_button 'Sign in'
|
829
836
|
```
|
830
837
|
|
831
|
-
## XPath, CSS and selectors
|
838
|
+
## <a name="xpath-css-and-selectors"></a>XPath, CSS and selectors
|
832
839
|
|
833
840
|
Capybara does not try to guess what kind of selector you are going to give it,
|
834
841
|
and will always use CSS by default. If you want to use XPath, you'll need to
|
@@ -874,7 +881,7 @@ find(:row, 3)
|
|
874
881
|
find(:flash_type, :notice)
|
875
882
|
```
|
876
883
|
|
877
|
-
## Beware the XPath // trap
|
884
|
+
## <a name="beware-the-xpath--trap"></a>Beware the XPath // trap
|
878
885
|
|
879
886
|
In XPath the expression // means something very specific, and it might not be what
|
880
887
|
you think. Contrary to common belief, // means "anywhere in the document" not "anywhere
|
@@ -902,7 +909,7 @@ within(:xpath, '//body') do
|
|
902
909
|
end
|
903
910
|
```
|
904
911
|
|
905
|
-
## Configuring and adding drivers
|
912
|
+
## <a name="configuring-and-adding-drivers"></a>Configuring and adding drivers
|
906
913
|
|
907
914
|
Capybara makes it convenient to switch between different drivers. It also exposes
|
908
915
|
an API to tweak those drivers with whatever settings you want, or to add your own
|
@@ -934,7 +941,7 @@ Gems can use this API to add their own drivers to Capybara.
|
|
934
941
|
The [Selenium wiki](https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings) has
|
935
942
|
additional info about how the underlying driver can be configured.
|
936
943
|
|
937
|
-
## Gotchas:
|
944
|
+
## <a name="gotchas"></a>Gotchas:
|
938
945
|
|
939
946
|
* Access to session and request is not possible from the test, Access to
|
940
947
|
response is limited. Some drivers allow access to response headers and HTTP
|
@@ -962,7 +969,7 @@ additional info about how the underlying driver can be configured.
|
|
962
969
|
are testing for specific server errors and using multiple sessions make sure to test for the
|
963
970
|
errors using the initial session (usually :default)
|
964
971
|
|
965
|
-
## Development
|
972
|
+
## <a name="development"></a>Development
|
966
973
|
|
967
974
|
To set up a development environment, simply do:
|
968
975
|
|
data/lib/capybara.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'timeout'
|
2
3
|
require 'nokogiri'
|
3
4
|
require 'xpath'
|
@@ -22,8 +23,10 @@ module Capybara
|
|
22
23
|
attr_accessor :asset_host, :app_host, :run_server, :default_host, :always_include_port
|
23
24
|
attr_accessor :server_port, :exact, :match, :exact_options, :visible_text_only
|
24
25
|
attr_accessor :default_selector, :default_max_wait_time, :ignore_hidden_elements
|
25
|
-
attr_accessor :
|
26
|
+
attr_accessor :save_path, :wait_on_first_by_default, :automatic_reload
|
27
|
+
attr_accessor :reuse_server, :raise_server_errors, :server_errors
|
26
28
|
attr_writer :default_driver, :current_driver, :javascript_driver, :session_name, :server_host
|
29
|
+
attr_reader :save_and_open_page_path
|
27
30
|
attr_accessor :app
|
28
31
|
|
29
32
|
##
|
@@ -47,8 +50,9 @@ module Capybara
|
|
47
50
|
# [default_max_wait_time = Numeric] The maximum number of seconds to wait for asynchronous processes to finish (Default: 2)
|
48
51
|
# [ignore_hidden_elements = Boolean] Whether to ignore hidden elements on the page (Default: true)
|
49
52
|
# [automatic_reload = Boolean] Whether to automatically reload elements as Capybara is waiting (Default: true)
|
50
|
-
# [
|
53
|
+
# [save_path = String] Where to put pages saved through save_(page|screenshot), save_and_open_(page|screenshot) (Default: Dir.pwd)
|
51
54
|
# [wait_on_first_by_default = Boolean] Whether Node#first defaults to Capybara waiting behavior for at least 1 element to match (Default: false)
|
55
|
+
# [reuse_server = Boolean] Reuse the server thread between multiple sessions using the same app object (Default: true)
|
52
56
|
# === DSL Options
|
53
57
|
#
|
54
58
|
# when using capybara/dsl, the following options are also available:
|
@@ -77,6 +81,26 @@ module Capybara
|
|
77
81
|
drivers[name] = block
|
78
82
|
end
|
79
83
|
|
84
|
+
##
|
85
|
+
#
|
86
|
+
# Register a new server for Capybara.
|
87
|
+
#
|
88
|
+
# Capybara.register_server :webrick do |app, port, host|
|
89
|
+
# require 'rack/handler/webrick'
|
90
|
+
# Rack::Handler::WEBrick.run(app, ...)
|
91
|
+
# end
|
92
|
+
#
|
93
|
+
# @param [Symbol] name The name of the new driver
|
94
|
+
# @yield [app, port, host] This block takes a rack app and a port and returns a rack server listening on that port
|
95
|
+
# @yieldparam [<Rack>] app The rack application that this server will contain.
|
96
|
+
# @yieldparam port The port number the server should listen on
|
97
|
+
# @yieldparam host The host/ip to bind to
|
98
|
+
# @yieldreturn [Capybara::Driver::Base] A Capybara driver instance
|
99
|
+
#
|
100
|
+
def register_server(name, &block)
|
101
|
+
servers[name.to_sym] = block
|
102
|
+
end
|
103
|
+
|
80
104
|
##
|
81
105
|
#
|
82
106
|
# Add a new selector to Capybara. Selectors can be used by various methods in Capybara
|
@@ -111,11 +135,11 @@ module Capybara
|
|
111
135
|
|
112
136
|
##
|
113
137
|
#
|
114
|
-
# Modify a selector previously
|
138
|
+
# Modify a selector previously created by {Capybara.add_selector}.
|
115
139
|
# For example modifying the :button selector to also find divs styled
|
116
140
|
# to look like buttons might look like this
|
117
141
|
#
|
118
|
-
# Capybara.
|
142
|
+
# Capybara.modify_selector(:button) do
|
119
143
|
# xpath { |locator| XPath::HTML.button(locator).or(XPath::css('div.btn')[XPath::string.n.is(locator)]) }
|
120
144
|
# end
|
121
145
|
#
|
@@ -130,27 +154,49 @@ module Capybara
|
|
130
154
|
@drivers ||= {}
|
131
155
|
end
|
132
156
|
|
157
|
+
def servers
|
158
|
+
@servers ||= {}
|
159
|
+
end
|
160
|
+
|
133
161
|
##
|
134
162
|
#
|
135
163
|
# Register a proc that Capybara will call to run the Rack application.
|
136
164
|
#
|
137
|
-
# Capybara.server do |app, port|
|
165
|
+
# Capybara.server do |app, port, host|
|
138
166
|
# require 'rack/handler/mongrel'
|
139
167
|
# Rack::Handler::Mongrel.run(app, :Port => port)
|
140
168
|
# end
|
141
169
|
#
|
142
170
|
# By default, Capybara will try to run webrick.
|
143
171
|
#
|
144
|
-
# @yield [app, port]
|
172
|
+
# @yield [app, port, host] This block receives a rack app, port, and host/ip and should run a Rack handler
|
145
173
|
#
|
146
174
|
def server(&block)
|
147
175
|
if block_given?
|
176
|
+
warn "DEPRECATED: Passing a block to Capybara::server is deprecated, please use Capybara::register_server instead"
|
148
177
|
@server = block
|
149
178
|
else
|
150
179
|
@server
|
151
180
|
end
|
152
181
|
end
|
153
182
|
|
183
|
+
##
|
184
|
+
#
|
185
|
+
# Set the server to use.
|
186
|
+
#
|
187
|
+
# Capybara.server = :webrick
|
188
|
+
#
|
189
|
+
# @param [Symbol] name Name of the server type to use
|
190
|
+
# @see register_server
|
191
|
+
#
|
192
|
+
def server=(name)
|
193
|
+
@server = if name.respond_to? :call
|
194
|
+
name
|
195
|
+
else
|
196
|
+
servers[name.to_sym]
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
154
200
|
##
|
155
201
|
#
|
156
202
|
# Wraps the given string, which should contain an HTML document or fragment
|
@@ -197,8 +243,7 @@ module Capybara
|
|
197
243
|
# @param [Fixnum] port The port to run the application on
|
198
244
|
#
|
199
245
|
def run_default_server(app, port)
|
200
|
-
|
201
|
-
Rack::Handler::WEBrick.run(app, :Host => server_host, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
|
246
|
+
servers[:webrick].call(app, port, server_host)
|
202
247
|
end
|
203
248
|
|
204
249
|
##
|
@@ -335,11 +380,22 @@ module Capybara
|
|
335
380
|
self.default_max_wait_time = t
|
336
381
|
end
|
337
382
|
|
383
|
+
def save_and_open_page_path=(path)
|
384
|
+
warn "DEPRECATED: #save_and_open_page_path is deprecated, please use #save_path instead. \n"\
|
385
|
+
"Note: Behavior is slightly different with relative paths - see documentation" unless path.nil?
|
386
|
+
@save_and_open_page_path = path
|
387
|
+
end
|
388
|
+
|
338
389
|
def included(base)
|
339
390
|
base.send(:include, Capybara::DSL)
|
340
391
|
warn "`include Capybara` is deprecated. Please use `include Capybara::DSL` instead."
|
341
392
|
end
|
342
393
|
|
394
|
+
def reuse_server=(bool)
|
395
|
+
warn "Capybara.reuse_server == false is a BETA feature and may change in a future version" unless bool
|
396
|
+
@reuse_server = bool
|
397
|
+
end
|
398
|
+
|
343
399
|
def deprecate(method, alternate_method, once=false)
|
344
400
|
@deprecation_notified ||= {}
|
345
401
|
warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead" unless once and @deprecation_notified[method]
|
@@ -370,10 +426,12 @@ module Capybara
|
|
370
426
|
require 'capybara/version'
|
371
427
|
|
372
428
|
require 'capybara/queries/base_query'
|
373
|
-
require 'capybara/
|
429
|
+
require 'capybara/queries/selector_query'
|
374
430
|
require 'capybara/queries/text_query'
|
375
431
|
require 'capybara/queries/title_query'
|
376
432
|
require 'capybara/queries/current_path_query'
|
433
|
+
require 'capybara/queries/match_query'
|
434
|
+
require 'capybara/query'
|
377
435
|
|
378
436
|
require 'capybara/node/finders'
|
379
437
|
require 'capybara/node/matchers'
|
@@ -397,10 +455,26 @@ module Capybara
|
|
397
455
|
require 'capybara/selenium/driver'
|
398
456
|
end
|
399
457
|
|
458
|
+
Capybara.register_server :default do |app, port, host|
|
459
|
+
Capybara.run_default_server(app, port)
|
460
|
+
end
|
461
|
+
|
462
|
+
Capybara.register_server :webrick do |app, port, host|
|
463
|
+
require 'rack/handler/webrick'
|
464
|
+
Rack::Handler::WEBrick.run(app, :Host => host, :Port => port, :AccessLog => [], :Logger => WEBrick::Log::new(nil, 0))
|
465
|
+
end
|
466
|
+
|
467
|
+
Capybara.register_server :puma do |app, port, host|
|
468
|
+
require 'puma'
|
469
|
+
Puma::Server.new(app).tap do |s|
|
470
|
+
s.add_tcp_listener host, port
|
471
|
+
end.run.join
|
472
|
+
end
|
473
|
+
|
400
474
|
Capybara.configure do |config|
|
401
475
|
config.always_include_port = false
|
402
476
|
config.run_server = true
|
403
|
-
config.server
|
477
|
+
config.server = :default
|
404
478
|
config.default_selector = :css
|
405
479
|
config.default_max_wait_time = 2
|
406
480
|
config.ignore_hidden_elements = true
|
@@ -412,6 +486,7 @@ Capybara.configure do |config|
|
|
412
486
|
config.server_errors = [StandardError]
|
413
487
|
config.visible_text_only = false
|
414
488
|
config.wait_on_first_by_default = false
|
489
|
+
config.reuse_server = true
|
415
490
|
end
|
416
491
|
|
417
492
|
Capybara.register_driver :rack_test do |app|
|
@@ -421,3 +496,4 @@ end
|
|
421
496
|
Capybara.register_driver :selenium do |app|
|
422
497
|
Capybara::Selenium::Driver.new(app)
|
423
498
|
end
|
499
|
+
|