capybara 1.1.4 → 2.0.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/{History.txt → History.md} +138 -0
- data/License.txt +22 -0
- data/README.md +850 -0
- data/lib/capybara/cucumber.rb +2 -5
- data/lib/capybara/driver/base.rb +6 -6
- data/lib/capybara/driver/node.rb +3 -2
- data/lib/capybara/dsl.rb +13 -124
- data/lib/capybara/helpers.rb +33 -0
- data/lib/capybara/node/actions.rb +16 -30
- data/lib/capybara/node/base.rb +56 -13
- data/lib/capybara/node/element.rb +18 -30
- data/lib/capybara/node/finders.rb +28 -90
- data/lib/capybara/node/matchers.rb +121 -73
- data/lib/capybara/node/simple.rb +13 -11
- data/lib/capybara/query.rb +78 -0
- data/lib/capybara/rack_test/browser.rb +27 -39
- data/lib/capybara/rack_test/driver.rb +13 -3
- data/lib/capybara/rack_test/node.rb +31 -2
- data/lib/capybara/result.rb +72 -0
- data/lib/capybara/rspec/features.rb +4 -1
- data/lib/capybara/rspec/matchers.rb +33 -63
- data/lib/capybara/rspec.rb +7 -4
- data/lib/capybara/selector.rb +97 -34
- data/lib/capybara/selenium/driver.rb +15 -62
- data/lib/capybara/selenium/node.rb +14 -21
- data/lib/capybara/server.rb +32 -27
- data/lib/capybara/session.rb +90 -50
- data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
- data/lib/capybara/spec/public/jquery-ui.js +791 -0
- data/lib/capybara/spec/public/jquery.js +9046 -0
- data/lib/capybara/spec/public/test.js +3 -0
- data/lib/capybara/spec/session/all_spec.rb +61 -59
- data/lib/capybara/spec/session/assert_selector.rb +123 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +72 -55
- data/lib/capybara/spec/session/body_spec.rb +21 -0
- data/lib/capybara/spec/session/check_spec.rb +68 -48
- data/lib/capybara/spec/session/choose_spec.rb +32 -18
- data/lib/capybara/spec/session/click_button_spec.rb +263 -232
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -29
- data/lib/capybara/spec/session/click_link_spec.rb +96 -96
- data/lib/capybara/spec/session/current_url_spec.rb +88 -10
- data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
- data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +119 -103
- data/lib/capybara/spec/session/find_button_spec.rb +16 -14
- data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
- data/lib/capybara/spec/session/find_field_spec.rb +23 -21
- data/lib/capybara/spec/session/find_link_spec.rb +15 -14
- data/lib/capybara/spec/session/find_spec.rb +93 -115
- data/lib/capybara/spec/session/first_spec.rb +51 -85
- data/lib/capybara/spec/session/has_button_spec.rb +22 -24
- data/lib/capybara/spec/session/has_css_spec.rb +190 -205
- data/lib/capybara/spec/session/has_field_spec.rb +170 -144
- data/lib/capybara/spec/session/has_link_spec.rb +26 -29
- data/lib/capybara/spec/session/has_select_spec.rb +161 -109
- data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
- data/lib/capybara/spec/session/has_table_spec.rb +22 -88
- data/lib/capybara/spec/session/has_text_spec.rb +195 -0
- data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
- data/lib/capybara/spec/session/headers.rb +4 -17
- data/lib/capybara/spec/session/html_spec.rb +15 -0
- data/lib/capybara/spec/session/node_spec.rb +205 -0
- data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
- data/lib/capybara/spec/session/response_code.rb +4 -17
- data/lib/capybara/spec/session/save_page_spec.rb +46 -0
- data/lib/capybara/spec/session/screenshot.rb +13 -0
- data/lib/capybara/spec/session/select_spec.rb +99 -88
- data/lib/capybara/spec/session/source_spec.rb +12 -0
- data/lib/capybara/spec/session/text_spec.rb +15 -12
- data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
- data/lib/capybara/spec/session/unselect_spec.rb +69 -58
- data/lib/capybara/spec/session/visit_spec.rb +74 -0
- data/lib/capybara/spec/session/within_frame_spec.rb +31 -0
- data/lib/capybara/spec/session/within_spec.rb +118 -131
- data/lib/capybara/spec/session/within_window_spec.rb +38 -0
- data/lib/capybara/spec/spec_helper.rb +84 -0
- data/lib/capybara/spec/test_app.rb +32 -6
- data/lib/capybara/spec/views/form.erb +12 -10
- data/lib/capybara/spec/views/host_links.erb +2 -2
- data/lib/capybara/spec/views/tables.erb +6 -66
- data/lib/capybara/spec/views/with_html.erb +9 -4
- data/lib/capybara/spec/views/with_js.erb +11 -7
- data/lib/capybara/version.rb +1 -1
- data/lib/capybara.rb +125 -6
- data/spec/basic_node_spec.rb +17 -5
- data/spec/capybara_spec.rb +9 -0
- data/spec/dsl_spec.rb +31 -17
- data/spec/rack_test_spec.rb +157 -0
- data/spec/result_spec.rb +51 -0
- data/spec/rspec/features_spec.rb +19 -2
- data/spec/rspec/matchers_spec.rb +170 -89
- data/spec/rspec_spec.rb +1 -3
- data/spec/selenium_spec.rb +53 -0
- data/spec/server_spec.rb +37 -25
- data/spec/spec_helper.rb +1 -30
- metadata +39 -31
- data/README.rdoc +0 -722
- data/lib/capybara/spec/driver.rb +0 -301
- data/lib/capybara/spec/session/current_host_spec.rb +0 -68
- data/lib/capybara/spec/session/has_content_spec.rb +0 -106
- data/lib/capybara/spec/session/javascript.rb +0 -306
- data/lib/capybara/spec/session.rb +0 -154
- data/lib/capybara/util/save_and_open_page.rb +0 -44
- data/lib/capybara/util/timeout.rb +0 -27
- data/spec/driver/rack_test_driver_spec.rb +0 -89
- data/spec/driver/selenium_driver_spec.rb +0 -37
- data/spec/save_and_open_page_spec.rb +0 -155
- data/spec/session/rack_test_session_spec.rb +0 -55
- data/spec/session/selenium_session_spec.rb +0 -26
- data/spec/string_spec.rb +0 -77
- data/spec/timeout_spec.rb +0 -28
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<form action="/form" method="post">
|
|
2
2
|
<table id="agent_table">
|
|
3
3
|
<caption>Agent</caption>
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
<tr>
|
|
6
6
|
<td>
|
|
7
7
|
<label for="form_agent_name">Name</label>
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<input type="text" name="form[agent_name]" value="James" id="form_agent_name"/>
|
|
11
11
|
</td>
|
|
12
12
|
</tr>
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
<tr>
|
|
15
15
|
<td colspan="2">
|
|
16
16
|
<input type="submit" value="Create"/>
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
<form action="/form" method="post">
|
|
23
23
|
<table id="girl_table">
|
|
24
24
|
<caption>Girl</caption>
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
<tr>
|
|
27
27
|
<td>
|
|
28
28
|
<label for="form_girl_name">Name</label>
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
<input type="text" name="form[girl_name]" value="Vesper" id="form_girl_name"/>
|
|
32
32
|
</td>
|
|
33
33
|
</tr>
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
<tr>
|
|
36
36
|
<td colspan="2">
|
|
37
37
|
<input type="submit" value="Create"/>
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
<form action="/form" method="post">
|
|
44
44
|
<table id="villain_table">
|
|
45
45
|
<caption>Villain</caption>
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
<tr>
|
|
48
48
|
<td>
|
|
49
49
|
<label for="form_villain_name">Name</label>
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
<input type="text" name="form[villain_name]" value="Ernst" id="form_villain_name"/>
|
|
53
53
|
</td>
|
|
54
54
|
</tr>
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
<tr>
|
|
57
57
|
<td colspan="2">
|
|
58
58
|
<input type="submit" value="Create"/>
|
|
@@ -60,63 +60,3 @@
|
|
|
60
60
|
</tr>
|
|
61
61
|
</table>
|
|
62
62
|
</form>
|
|
63
|
-
|
|
64
|
-
<table>
|
|
65
|
-
<caption>Ransom</caption>
|
|
66
|
-
|
|
67
|
-
<thead>
|
|
68
|
-
<tr>
|
|
69
|
-
<th>Year</th>
|
|
70
|
-
<th>Governmental</th>
|
|
71
|
-
<th>Private</th>
|
|
72
|
-
</tr>
|
|
73
|
-
</thead>
|
|
74
|
-
|
|
75
|
-
<tbody>
|
|
76
|
-
<tr>
|
|
77
|
-
<th scope="row">2007</th>
|
|
78
|
-
<td>$300</td>
|
|
79
|
-
<td>$100</td>
|
|
80
|
-
</tr>
|
|
81
|
-
<tr>
|
|
82
|
-
<th scope="row">2008</th>
|
|
83
|
-
<td>$123</td>
|
|
84
|
-
<td>$897</td>
|
|
85
|
-
</tr>
|
|
86
|
-
<tr>
|
|
87
|
-
<th scope="row">2009</th>
|
|
88
|
-
<td>$543</td>
|
|
89
|
-
<td>$99</td>
|
|
90
|
-
</tr>
|
|
91
|
-
</tbody>
|
|
92
|
-
</table>
|
|
93
|
-
|
|
94
|
-
<table>
|
|
95
|
-
<caption>Deaths</caption>
|
|
96
|
-
|
|
97
|
-
<thead>
|
|
98
|
-
<tr>
|
|
99
|
-
<th>Year</th>
|
|
100
|
-
<th>Sharks with lasers</th>
|
|
101
|
-
<th>Flaming volcano</th>
|
|
102
|
-
</tr>
|
|
103
|
-
</thead>
|
|
104
|
-
|
|
105
|
-
<tbody>
|
|
106
|
-
<tr>
|
|
107
|
-
<th scope="row">2007</th>
|
|
108
|
-
<td>66</td>
|
|
109
|
-
<td>7</td>
|
|
110
|
-
</tr>
|
|
111
|
-
<tr>
|
|
112
|
-
<th scope="row">2008</th>
|
|
113
|
-
<td>123</td>
|
|
114
|
-
<td>12</td>
|
|
115
|
-
</tr>
|
|
116
|
-
<tr>
|
|
117
|
-
<th scope="row">2009</th>
|
|
118
|
-
<td>913</td>
|
|
119
|
-
<td>13</td>
|
|
120
|
-
</tr>
|
|
121
|
-
</tbody>
|
|
122
|
-
</table>
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
|
|
22
22
|
dolore eu fugiat <a href="/redirect" id="red">Redirect</a> pariatur. Excepteur sint occaecat cupidatat non proident,
|
|
23
23
|
sunt in culpa qui officia
|
|
24
|
-
text with
|
|
24
|
+
text with
|
|
25
25
|
whitespace
|
|
26
26
|
id est laborum.
|
|
27
27
|
</p>
|
|
@@ -37,14 +37,15 @@ banana</textarea>
|
|
|
37
37
|
<a title="twas a fine link" href="/redirect">A link came first</a>
|
|
38
38
|
<a title="a fine link" href="/with_simple_html">A link</a>
|
|
39
39
|
<a title="a fine link with data method" data-method="delete" href="/delete">A link with data-method</a>
|
|
40
|
+
<a title="a fine link with capitalized data method" data-method="DELETE" href="/delete">A link with capitalized data-method</a>
|
|
40
41
|
<a>No Href</a>
|
|
41
42
|
<a href="">Blank Href</a>
|
|
42
43
|
<a href="#">Blank Anchor</a>
|
|
43
|
-
<a href="#anchor">Anchor</a>
|
|
44
|
+
<a href="#anchor">Normal Anchor</a>
|
|
44
45
|
<a href="/with_simple_html#anchor">Anchor on different page</a>
|
|
45
46
|
<a href="/with_html#anchor">Anchor on same page</a>
|
|
46
47
|
<a href="with_html">Relative</a>
|
|
47
|
-
<
|
|
48
|
+
<a href="//<%= request.host_with_port %>/foo">Protocol</a>
|
|
48
49
|
<input type="text" checked="checked" id="checked_field">
|
|
49
50
|
<a href="/redirect"><img width="20" height="20" alt="very fine image" /></a>
|
|
50
51
|
<a href="/with_simple_html"><img width="20" height="20" alt="fine image" /></a>
|
|
@@ -57,7 +58,7 @@ banana</textarea>
|
|
|
57
58
|
|
|
58
59
|
<div id="hidden" style="display: none;">
|
|
59
60
|
<div id="hidden_via_ancestor">Inside element with hidden ancestor</div>
|
|
60
|
-
<a href="/with_simple_html" title="
|
|
61
|
+
<a href="/with_simple_html" title="hidden link" class="simple">hidden link</a>
|
|
61
62
|
</div>
|
|
62
63
|
|
|
63
64
|
<div style="display: none;">
|
|
@@ -72,6 +73,10 @@ banana</textarea>
|
|
|
72
73
|
<a id="visible" class="visibility">visible link</a>
|
|
73
74
|
</div>
|
|
74
75
|
|
|
76
|
+
<div>
|
|
77
|
+
Number 42
|
|
78
|
+
</div>
|
|
79
|
+
|
|
75
80
|
<ul>
|
|
76
81
|
<li id="john_monkey">Monkey John</li>
|
|
77
82
|
<li id="paul_monkey">Monkey Paul</li>
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
<head>
|
|
3
3
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
|
|
4
4
|
<title>with_js</title>
|
|
5
|
-
<script src="
|
|
6
|
-
<script src="
|
|
5
|
+
<script src="/jquery.js" type="text/javascript" charset="utf-8"></script>
|
|
6
|
+
<script src="/jquery-ui.js" type="text/javascript" charset="utf-8"></script>
|
|
7
7
|
<script src="/test.js" type="text/javascript" charset="utf-8"></script>
|
|
8
8
|
</head>
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
<body id="with_js">
|
|
11
11
|
<h1>FooBar</h1>
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
<p id="change">This is text</p>
|
|
14
14
|
<div id="drag">
|
|
15
15
|
<p>This is a draggable element.</p>
|
|
@@ -17,20 +17,24 @@
|
|
|
17
17
|
<div id="drop">
|
|
18
18
|
<p>It should be dropped here.</p>
|
|
19
19
|
</div>
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
<p><a href="#" id="clickable">Click me</a></p>
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
<p>
|
|
24
24
|
<select id="waiter">
|
|
25
25
|
<option>Foo</option>
|
|
26
26
|
<option>My Waiting Option</option>
|
|
27
27
|
</select>
|
|
28
28
|
</p>
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
<p>
|
|
31
31
|
<input type="text" name="with_focus_event" value="" id="with_focus_event"/>
|
|
32
32
|
</p>
|
|
33
33
|
|
|
34
|
+
<p>
|
|
35
|
+
<input type="text" name="with_change_event" value="default value" id="with_change_event"/>
|
|
36
|
+
</p>
|
|
37
|
+
|
|
34
38
|
<p>
|
|
35
39
|
<input type="checkbox" id="checkbox_with_event"/>
|
|
36
40
|
</p>
|
data/lib/capybara/version.rb
CHANGED
data/lib/capybara.rb
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
require 'timeout'
|
|
2
2
|
require 'nokogiri'
|
|
3
3
|
require 'xpath'
|
|
4
|
+
|
|
4
5
|
module Capybara
|
|
5
6
|
class CapybaraError < StandardError; end
|
|
6
7
|
class DriverNotFoundError < CapybaraError; end
|
|
7
8
|
class FrozenInTime < CapybaraError; end
|
|
8
9
|
class ElementNotFound < CapybaraError; end
|
|
10
|
+
class Ambiguous < ElementNotFound; end
|
|
9
11
|
class ExpectationNotMet < ElementNotFound; end
|
|
10
12
|
class FileNotFound < CapybaraError; end
|
|
11
13
|
class UnselectNotAllowed < CapybaraError; end
|
|
@@ -15,10 +17,12 @@ module Capybara
|
|
|
15
17
|
class InfiniteRedirectError < TimeoutError; end
|
|
16
18
|
|
|
17
19
|
class << self
|
|
18
|
-
attr_accessor :asset_root, :app_host, :run_server, :default_host
|
|
19
|
-
attr_accessor :
|
|
20
|
-
attr_accessor :default_selector, :default_wait_time, :ignore_hidden_elements
|
|
20
|
+
attr_accessor :asset_root, :app_host, :run_server, :default_host, :always_include_port
|
|
21
|
+
attr_accessor :server_host, :server_port
|
|
22
|
+
attr_accessor :default_selector, :default_wait_time, :ignore_hidden_elements
|
|
21
23
|
attr_accessor :save_and_open_page_path, :automatic_reload
|
|
24
|
+
attr_writer :default_driver, :current_driver, :javascript_driver, :session_name
|
|
25
|
+
attr_accessor :app
|
|
22
26
|
|
|
23
27
|
##
|
|
24
28
|
#
|
|
@@ -33,11 +37,11 @@ module Capybara
|
|
|
33
37
|
#
|
|
34
38
|
# [asset_root = String] Where static assets are located, used by save_and_open_page
|
|
35
39
|
# [app_host = String] The default host to use when giving a relative URL to visit
|
|
40
|
+
# [always_include_port = Boolean] Whether the Rack server's port should automatically be inserted into every visited URL (Default: false)
|
|
36
41
|
# [run_server = Boolean] Whether to start a Rack server for the given Rack app (Default: true)
|
|
37
42
|
# [default_selector = :css/:xpath] Methods which take a selector use the given type by default (Default: CSS)
|
|
38
43
|
# [default_wait_time = Integer] The number of seconds to wait for asynchronous processes to finish (Default: 2)
|
|
39
44
|
# [ignore_hidden_elements = Boolean] Whether to ignore hidden elements on the page (Default: false)
|
|
40
|
-
# [prefer_visible_elements = Boolean] Whether to prefer visible elements over hidden elements (Default: true)
|
|
41
45
|
# [automatic_reload = Boolean] Whether to automatically reload elements as Capybara is waiting (Default: true)
|
|
42
46
|
# [save_and_open_page_path = String] Where to put pages saved through save_and_open_page (Default: Dir.pwd)
|
|
43
47
|
#
|
|
@@ -181,14 +185,130 @@ module Capybara
|
|
|
181
185
|
end
|
|
182
186
|
end
|
|
183
187
|
|
|
188
|
+
##
|
|
189
|
+
#
|
|
190
|
+
# @return [Symbol] The name of the driver to use by default
|
|
191
|
+
#
|
|
192
|
+
def default_driver
|
|
193
|
+
@default_driver || :rack_test
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
##
|
|
197
|
+
#
|
|
198
|
+
# @return [Symbol] The name of the driver currently in use
|
|
199
|
+
#
|
|
200
|
+
def current_driver
|
|
201
|
+
@current_driver || default_driver
|
|
202
|
+
end
|
|
203
|
+
alias_method :mode, :current_driver
|
|
204
|
+
|
|
205
|
+
##
|
|
206
|
+
#
|
|
207
|
+
# @return [Symbol] The name of the driver used when JavaScript is needed
|
|
208
|
+
#
|
|
209
|
+
def javascript_driver
|
|
210
|
+
@javascript_driver || :selenium
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
##
|
|
214
|
+
#
|
|
215
|
+
# Use the default driver as the current driver
|
|
216
|
+
#
|
|
217
|
+
def use_default_driver
|
|
218
|
+
@current_driver = nil
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
##
|
|
222
|
+
#
|
|
223
|
+
# Yield a block using a specific driver
|
|
224
|
+
#
|
|
225
|
+
def using_driver(driver)
|
|
226
|
+
previous_driver = Capybara.current_driver
|
|
227
|
+
Capybara.current_driver = driver
|
|
228
|
+
yield
|
|
229
|
+
ensure
|
|
230
|
+
@current_driver = previous_driver
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
##
|
|
234
|
+
#
|
|
235
|
+
# Yield a block using a specific wait time
|
|
236
|
+
#
|
|
237
|
+
def using_wait_time(seconds)
|
|
238
|
+
previous_wait_time = Capybara.default_wait_time
|
|
239
|
+
Capybara.default_wait_time = seconds
|
|
240
|
+
yield
|
|
241
|
+
ensure
|
|
242
|
+
Capybara.default_wait_time = previous_wait_time
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
##
|
|
246
|
+
#
|
|
247
|
+
# The current Capybara::Session based on what is set as Capybara.app and Capybara.current_driver
|
|
248
|
+
#
|
|
249
|
+
# @return [Capybara::Session] The currently used session
|
|
250
|
+
#
|
|
251
|
+
def current_session
|
|
252
|
+
session_pool["#{current_driver}:#{session_name}:#{app.object_id}"] ||= Capybara::Session.new(current_driver, app)
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
##
|
|
256
|
+
#
|
|
257
|
+
# Reset sessions, cleaning out the pool of sessions. This will remove any session information such
|
|
258
|
+
# as cookies.
|
|
259
|
+
#
|
|
260
|
+
def reset_sessions!
|
|
261
|
+
session_pool.each { |mode, session| session.reset! }
|
|
262
|
+
end
|
|
263
|
+
alias_method :reset!, :reset_sessions!
|
|
264
|
+
|
|
265
|
+
##
|
|
266
|
+
#
|
|
267
|
+
# The current session name.
|
|
268
|
+
#
|
|
269
|
+
# @return [Symbol] The name of the currently used session.
|
|
270
|
+
#
|
|
271
|
+
def session_name
|
|
272
|
+
@session_name ||= :default
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
##
|
|
276
|
+
#
|
|
277
|
+
# Yield a block using a specific session name.
|
|
278
|
+
#
|
|
279
|
+
def using_session(name)
|
|
280
|
+
self.session_name = name
|
|
281
|
+
yield
|
|
282
|
+
ensure
|
|
283
|
+
self.session_name = :default
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def included(base)
|
|
287
|
+
base.send(:include, Capybara::DSL)
|
|
288
|
+
warn "`include Capybara` is deprecated. Please use `include Capybara::DSL` instead."
|
|
289
|
+
end
|
|
290
|
+
|
|
184
291
|
def deprecate(method, alternate_method)
|
|
185
292
|
warn "DEPRECATED: ##{method} is deprecated, please use ##{alternate_method} instead"
|
|
186
293
|
end
|
|
294
|
+
|
|
295
|
+
private
|
|
296
|
+
|
|
297
|
+
def session_pool
|
|
298
|
+
@session_pool ||= {}
|
|
299
|
+
end
|
|
187
300
|
end
|
|
188
301
|
|
|
302
|
+
self.default_driver = nil
|
|
303
|
+
self.current_driver = nil
|
|
304
|
+
|
|
305
|
+
autoload :DSL, 'capybara/dsl'
|
|
189
306
|
autoload :Server, 'capybara/server'
|
|
190
307
|
autoload :Session, 'capybara/session'
|
|
191
308
|
autoload :Selector, 'capybara/selector'
|
|
309
|
+
autoload :Query, 'capybara/query'
|
|
310
|
+
autoload :Result, 'capybara/result'
|
|
311
|
+
autoload :Helpers, 'capybara/helpers'
|
|
192
312
|
autoload :VERSION, 'capybara/version'
|
|
193
313
|
|
|
194
314
|
module Node
|
|
@@ -232,13 +352,12 @@ module Capybara
|
|
|
232
352
|
end
|
|
233
353
|
|
|
234
354
|
Capybara.configure do |config|
|
|
355
|
+
config.always_include_port = false
|
|
235
356
|
config.run_server = true
|
|
236
357
|
config.server {|app, port| Capybara.run_default_server(app, port)}
|
|
237
|
-
config.server_boot_timeout = 10
|
|
238
358
|
config.default_selector = :css
|
|
239
359
|
config.default_wait_time = 2
|
|
240
360
|
config.ignore_hidden_elements = false
|
|
241
|
-
config.prefer_visible_elements = true
|
|
242
361
|
config.default_host = "http://www.example.com"
|
|
243
362
|
config.automatic_reload = true
|
|
244
363
|
end
|
data/spec/basic_node_spec.rb
CHANGED
|
@@ -6,7 +6,7 @@ describe Capybara do
|
|
|
6
6
|
Capybara.string <<-STRING
|
|
7
7
|
<div id="page">
|
|
8
8
|
<div id="content">
|
|
9
|
-
<h1 data="fantastic">
|
|
9
|
+
<h1 data="fantastic">Totally awesome</h1>
|
|
10
10
|
<p>Yes it is</p>
|
|
11
11
|
</div>
|
|
12
12
|
|
|
@@ -19,6 +19,10 @@ describe Capybara do
|
|
|
19
19
|
<option selected="selected">Capybara</option>
|
|
20
20
|
</select>
|
|
21
21
|
</div>
|
|
22
|
+
|
|
23
|
+
<section>
|
|
24
|
+
<div class="subsection"></div>
|
|
25
|
+
</div>
|
|
22
26
|
</div>
|
|
23
27
|
STRING
|
|
24
28
|
end
|
|
@@ -32,14 +36,22 @@ describe Capybara do
|
|
|
32
36
|
Capybara.add_selector :lifeform do
|
|
33
37
|
xpath { |name| "//option[contains(.,'#{name}')]" }
|
|
34
38
|
end
|
|
35
|
-
string.should have_selector(:page)
|
|
36
|
-
string.should_not have_selector(:'does-not-exist')
|
|
39
|
+
string.should have_selector(:id, "page")
|
|
40
|
+
string.should_not have_selector(:id, 'does-not-exist')
|
|
37
41
|
string.should have_selector(:lifeform, "Monkey")
|
|
38
42
|
string.should_not have_selector(:lifeform, "Gorilla")
|
|
39
43
|
end
|
|
40
44
|
|
|
45
|
+
it 'allows custom matcher using css' do
|
|
46
|
+
Capybara.add_selector :section do
|
|
47
|
+
css { |css_class| "section .#{css_class}" }
|
|
48
|
+
end
|
|
49
|
+
string.should have_selector(:section, 'subsection')
|
|
50
|
+
string.should_not have_selector(:section, 'section_8')
|
|
51
|
+
end
|
|
52
|
+
|
|
41
53
|
it "allows using matchers with text option" do
|
|
42
|
-
string.should have_css('h1', :text => '
|
|
54
|
+
string.should have_css('h1', :text => 'Totally awesome')
|
|
43
55
|
string.should_not have_css('h1', :text => 'Not so awesome')
|
|
44
56
|
end
|
|
45
57
|
|
|
@@ -49,7 +61,7 @@ describe Capybara do
|
|
|
49
61
|
end
|
|
50
62
|
|
|
51
63
|
it "allows finding elements and extracting text from them" do
|
|
52
|
-
string.find('//h1').text.should == '
|
|
64
|
+
string.find('//h1').text.should == 'Totally awesome'
|
|
53
65
|
end
|
|
54
66
|
|
|
55
67
|
it "allows finding elements and extracting attributes from them" do
|
data/spec/capybara_spec.rb
CHANGED
|
@@ -42,5 +42,14 @@ describe Capybara do
|
|
|
42
42
|
Capybara.server.should == server
|
|
43
43
|
end
|
|
44
44
|
end
|
|
45
|
+
end
|
|
45
46
|
|
|
47
|
+
describe Capybara::Session do
|
|
48
|
+
context 'with non-existant driver' do
|
|
49
|
+
it "should raise an error" do
|
|
50
|
+
expect {
|
|
51
|
+
Capybara::Session.new(:quox, TestApp).driver
|
|
52
|
+
}.to raise_error(Capybara::DriverNotFoundError)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
46
55
|
end
|
data/spec/dsl_spec.rb
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
|
|
3
2
|
require 'capybara/dsl'
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
class TestClass
|
|
5
|
+
include Capybara::DSL
|
|
6
|
+
end
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
Capybara::SpecHelper.run_specs TestClass.new, "DSL", :skip => [
|
|
9
|
+
:js,
|
|
10
|
+
:screenshot,
|
|
11
|
+
:frames,
|
|
12
|
+
:windows
|
|
13
|
+
]
|
|
10
14
|
|
|
15
|
+
describe Capybara::DSL do
|
|
11
16
|
after do
|
|
12
17
|
Capybara.session_name = nil
|
|
13
18
|
Capybara.default_driver = nil
|
|
14
19
|
Capybara.javascript_driver = nil
|
|
15
20
|
Capybara.use_default_driver
|
|
21
|
+
Capybara.app = TestApp
|
|
16
22
|
end
|
|
17
23
|
|
|
18
24
|
describe '#default_driver' do
|
|
@@ -69,12 +75,20 @@ describe Capybara::DSL do
|
|
|
69
75
|
driver.should == :selenium
|
|
70
76
|
end
|
|
71
77
|
|
|
72
|
-
it 'should
|
|
78
|
+
it 'should return the driver to default if it has not been changed' do
|
|
79
|
+
Capybara.using_driver(:selenium) do
|
|
80
|
+
Capybara.current_driver.should == :selenium
|
|
81
|
+
end
|
|
82
|
+
Capybara.current_driver.should == Capybara.default_driver
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it 'should reset the driver even if an exception occurs' do
|
|
86
|
+
driver_before_block = Capybara.current_driver
|
|
73
87
|
begin
|
|
74
88
|
Capybara.using_driver(:selenium) { raise "ohnoes!" }
|
|
75
89
|
rescue Exception
|
|
76
90
|
end
|
|
77
|
-
Capybara.current_driver.should ==
|
|
91
|
+
Capybara.current_driver.should == driver_before_block
|
|
78
92
|
end
|
|
79
93
|
|
|
80
94
|
it 'should return the driver to what it was previously' do
|
|
@@ -96,13 +110,21 @@ describe Capybara::DSL do
|
|
|
96
110
|
end
|
|
97
111
|
|
|
98
112
|
describe '#using_wait_time' do
|
|
113
|
+
before do
|
|
114
|
+
@previous_wait_time = Capybara.default_wait_time
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
after do
|
|
118
|
+
Capybara.default_wait_time = @previous_wait_time
|
|
119
|
+
end
|
|
120
|
+
|
|
99
121
|
it "should switch the wait time and switch it back" do
|
|
100
122
|
in_block = nil
|
|
101
123
|
Capybara.using_wait_time 6 do
|
|
102
124
|
in_block = Capybara.default_wait_time
|
|
103
125
|
end
|
|
104
126
|
in_block.should == 6
|
|
105
|
-
Capybara.default_wait_time.should ==
|
|
127
|
+
Capybara.default_wait_time.should == @previous_wait_time
|
|
106
128
|
end
|
|
107
129
|
|
|
108
130
|
it "should ensure wait time is reset" do
|
|
@@ -111,11 +133,7 @@ describe Capybara::DSL do
|
|
|
111
133
|
raise "hell"
|
|
112
134
|
end
|
|
113
135
|
end.to raise_error
|
|
114
|
-
Capybara.default_wait_time.should ==
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
after do
|
|
118
|
-
Capybara.default_wait_time = 0
|
|
136
|
+
Capybara.default_wait_time.should == @previous_wait_time
|
|
119
137
|
end
|
|
120
138
|
end
|
|
121
139
|
|
|
@@ -209,9 +227,6 @@ describe Capybara::DSL do
|
|
|
209
227
|
@session = Class.new { include Capybara::DSL }.new
|
|
210
228
|
end
|
|
211
229
|
|
|
212
|
-
it_should_behave_like "session"
|
|
213
|
-
it_should_behave_like "session without javascript support"
|
|
214
|
-
|
|
215
230
|
it "should be possible to include it in another class" do
|
|
216
231
|
klass = Class.new do
|
|
217
232
|
include Capybara::DSL
|
|
@@ -250,5 +265,4 @@ describe Capybara::DSL do
|
|
|
250
265
|
foo.using_wait_time(6)
|
|
251
266
|
end
|
|
252
267
|
end
|
|
253
|
-
|
|
254
268
|
end
|