yannp-capybara 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +112 -0
- data/README.rdoc +442 -0
- data/lib/capybara/cucumber.rb +32 -0
- data/lib/capybara/driver/base.rb +56 -0
- data/lib/capybara/driver/celerity_driver.rb +154 -0
- data/lib/capybara/driver/culerity_driver.rb +26 -0
- data/lib/capybara/driver/node.rb +66 -0
- data/lib/capybara/driver/rack_test_driver.rb +279 -0
- data/lib/capybara/driver/selenium_driver.rb +157 -0
- data/lib/capybara/dsl.rb +98 -0
- data/lib/capybara/node/actions.rb +156 -0
- data/lib/capybara/node/finders.rb +155 -0
- data/lib/capybara/node/matchers.rb +97 -0
- data/lib/capybara/node.rb +209 -0
- data/lib/capybara/rails.rb +17 -0
- data/lib/capybara/server.rb +101 -0
- data/lib/capybara/session.rb +278 -0
- data/lib/capybara/spec/driver.rb +190 -0
- data/lib/capybara/spec/fixtures/capybara.jpg +0 -0
- data/lib/capybara/spec/fixtures/test_file.txt +1 -0
- data/lib/capybara/spec/public/jquery-ui.js +35 -0
- data/lib/capybara/spec/public/jquery.js +19 -0
- data/lib/capybara/spec/public/test.js +33 -0
- data/lib/capybara/spec/session/all_spec.rb +73 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +64 -0
- data/lib/capybara/spec/session/check_spec.rb +67 -0
- data/lib/capybara/spec/session/choose_spec.rb +26 -0
- data/lib/capybara/spec/session/click_button_spec.rb +243 -0
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +30 -0
- data/lib/capybara/spec/session/click_link_spec.rb +108 -0
- data/lib/capybara/spec/session/current_url_spec.rb +15 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +119 -0
- data/lib/capybara/spec/session/find_button_spec.rb +18 -0
- data/lib/capybara/spec/session/find_by_id_spec.rb +18 -0
- data/lib/capybara/spec/session/find_field_spec.rb +26 -0
- data/lib/capybara/spec/session/find_link_spec.rb +19 -0
- data/lib/capybara/spec/session/find_spec.rb +91 -0
- data/lib/capybara/spec/session/has_button_spec.rb +32 -0
- data/lib/capybara/spec/session/has_content_spec.rb +106 -0
- data/lib/capybara/spec/session/has_css_spec.rb +107 -0
- data/lib/capybara/spec/session/has_field_spec.rb +96 -0
- data/lib/capybara/spec/session/has_link_spec.rb +33 -0
- data/lib/capybara/spec/session/has_select_spec.rb +89 -0
- data/lib/capybara/spec/session/has_table_spec.rb +96 -0
- data/lib/capybara/spec/session/has_xpath_spec.rb +123 -0
- data/lib/capybara/spec/session/headers.rb +19 -0
- data/lib/capybara/spec/session/javascript.rb +232 -0
- data/lib/capybara/spec/session/response_code.rb +19 -0
- data/lib/capybara/spec/session/select_spec.rb +91 -0
- data/lib/capybara/spec/session/uncheck_spec.rb +21 -0
- data/lib/capybara/spec/session/unselect_spec.rb +54 -0
- data/lib/capybara/spec/session/within_spec.rb +153 -0
- data/lib/capybara/spec/session.rb +78 -0
- data/lib/capybara/spec/test_app.rb +94 -0
- data/lib/capybara/spec/views/buttons.erb +4 -0
- data/lib/capybara/spec/views/fieldsets.erb +29 -0
- data/lib/capybara/spec/views/form.erb +245 -0
- data/lib/capybara/spec/views/frame_one.erb +8 -0
- data/lib/capybara/spec/views/frame_two.erb +8 -0
- data/lib/capybara/spec/views/postback.erb +13 -0
- data/lib/capybara/spec/views/tables.erb +122 -0
- data/lib/capybara/spec/views/with_html.erb +43 -0
- data/lib/capybara/spec/views/with_js.erb +39 -0
- data/lib/capybara/spec/views/with_scope.erb +36 -0
- data/lib/capybara/spec/views/with_simple_html.erb +1 -0
- data/lib/capybara/spec/views/within_frames.erb +10 -0
- data/lib/capybara/util/save_and_open_page.rb +36 -0
- data/lib/capybara/util/timeout.rb +27 -0
- data/lib/capybara/version.rb +3 -0
- data/lib/capybara/xpath.rb +182 -0
- data/lib/capybara.rb +73 -0
- data/spec/capybara_spec.rb +18 -0
- data/spec/driver/celerity_driver_spec.rb +17 -0
- data/spec/driver/culerity_driver_spec.rb +13 -0
- data/spec/driver/rack_test_driver_spec.rb +19 -0
- data/spec/driver/remote_culerity_driver_spec.rb +24 -0
- data/spec/driver/remote_selenium_driver_spec.rb +19 -0
- data/spec/driver/selenium_driver_spec.rb +13 -0
- data/spec/dsl_spec.rb +140 -0
- data/spec/save_and_open_page_spec.rb +83 -0
- data/spec/server_spec.rb +53 -0
- data/spec/session/celerity_session_spec.rb +28 -0
- data/spec/session/culerity_session_spec.rb +26 -0
- data/spec/session/rack_test_session_spec.rb +34 -0
- data/spec/session/selenium_session_spec.rb +26 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/timeout_spec.rb +28 -0
- data/spec/xpath_spec.rb +173 -0
- metadata +314 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'capybara'
|
2
|
+
require 'capybara/dsl'
|
3
|
+
|
4
|
+
Capybara.app = Rack::Builder.new do
|
5
|
+
map "/" do
|
6
|
+
if Rails.version.to_f >= 3.0
|
7
|
+
run Rails.application
|
8
|
+
else # Rails 2
|
9
|
+
use Rails::Rack::Static
|
10
|
+
run ActionController::Dispatcher.new
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end.to_app
|
14
|
+
|
15
|
+
Capybara.asset_root = Rails.root.join('public')
|
16
|
+
Capybara.save_and_open_page_path = Rails.root.join('tmp/capybara')
|
17
|
+
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'rack'
|
4
|
+
require 'capybara/util/timeout'
|
5
|
+
|
6
|
+
module Capybara
|
7
|
+
class Server
|
8
|
+
class Identify
|
9
|
+
def initialize(app)
|
10
|
+
@app = app
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
if env["PATH_INFO"] == "/__identify__"
|
15
|
+
[200, {}, @app.object_id.to_s]
|
16
|
+
else
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def ports
|
24
|
+
@ports ||= {}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
attr_reader :app, :port
|
29
|
+
|
30
|
+
def initialize(app)
|
31
|
+
@app = app
|
32
|
+
end
|
33
|
+
|
34
|
+
def host
|
35
|
+
"localhost"
|
36
|
+
end
|
37
|
+
|
38
|
+
def url(path)
|
39
|
+
if path =~ /^http/
|
40
|
+
path
|
41
|
+
else
|
42
|
+
(Capybara.app_host || "http://#{host}:#{port}") + path.to_s
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def responsive?
|
47
|
+
res = Net::HTTP.start(host, @port) { |http| http.get('/__identify__') }
|
48
|
+
|
49
|
+
if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
|
50
|
+
return res.body == @app.object_id.to_s
|
51
|
+
end
|
52
|
+
rescue Errno::ECONNREFUSED, Errno::EBADF
|
53
|
+
return false
|
54
|
+
end
|
55
|
+
|
56
|
+
def handler
|
57
|
+
begin
|
58
|
+
require 'rack/handler/thin'
|
59
|
+
Rack::Handler::Thin
|
60
|
+
rescue LoadError
|
61
|
+
begin
|
62
|
+
require 'rack/handler/mongrel'
|
63
|
+
Rack::Handler::Mongrel
|
64
|
+
rescue LoadError
|
65
|
+
require 'rack/handler/webrick'
|
66
|
+
Rack::Handler::WEBrick
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def boot
|
72
|
+
if @app
|
73
|
+
@port = Capybara::Server.ports[@app.object_id]
|
74
|
+
|
75
|
+
if not @port or not responsive?
|
76
|
+
@port = find_available_port
|
77
|
+
Capybara::Server.ports[@app.object_id] = @port
|
78
|
+
|
79
|
+
Thread.new { handler.run(Identify.new(@app), :Port => @port, :AccessLog => []) }
|
80
|
+
|
81
|
+
Capybara.timeout(10) { if responsive? then true else sleep(0.5) and false end }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
rescue Timeout::Error
|
85
|
+
puts "Rack application timed out during boot"
|
86
|
+
exit
|
87
|
+
else
|
88
|
+
self
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
def find_available_port
|
94
|
+
server = TCPServer.new('127.0.0.1', 0)
|
95
|
+
server.addr[1]
|
96
|
+
ensure
|
97
|
+
server.close if server
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,278 @@
|
|
1
|
+
require 'capybara/util/timeout'
|
2
|
+
|
3
|
+
module Capybara
|
4
|
+
|
5
|
+
##
|
6
|
+
#
|
7
|
+
# The Session class represents a single user's interaction with the system. The Session can use
|
8
|
+
# any of the underlying drivers. A session can be initialized manually like this:
|
9
|
+
#
|
10
|
+
# session = Capybara::Session.new(:culerity, MyRackApp)
|
11
|
+
#
|
12
|
+
# The application given as the second argument is optional. When running Capybara against an external
|
13
|
+
# page, you might want to leave it out:
|
14
|
+
#
|
15
|
+
# session = Capybara::Session.new(:culerity)
|
16
|
+
# session.visit('http://www.google.com')
|
17
|
+
#
|
18
|
+
# Session provides a number of methods for controlling the navigation of the page, such as +visit+,
|
19
|
+
# +current_path, and so on. It also delegate a number of methods to a Capybara::Document, representing
|
20
|
+
# the current HTML document. This allows interaction:
|
21
|
+
#
|
22
|
+
# session.fill_in('q', :with => 'Capybara')
|
23
|
+
# session.click_button('Search')
|
24
|
+
# session.should have_content('Capybara')
|
25
|
+
#
|
26
|
+
# When using capybara/dsl, the Session is initialized automatically for you.
|
27
|
+
#
|
28
|
+
class Session
|
29
|
+
DSL_METHODS = [
|
30
|
+
:all, :attach_file, :body, :check, :choose, :click_link_or_button, :click_button, :click_link, :current_url, :drag, :evaluate_script,
|
31
|
+
:field_labeled, :fill_in, :find, :find_button, :find_by_id, :find_field, :find_link, :has_content?, :has_css?,
|
32
|
+
:has_no_content?, :has_no_css?, :has_no_xpath?, :has_xpath?, :locate, :save_and_open_page, :select, :source, :uncheck,
|
33
|
+
:visit, :wait_until, :within, :within_fieldset, :within_table, :within_frame, :has_link?, :has_no_link?, :has_button?,
|
34
|
+
:has_no_button?, :has_field?, :has_no_field?, :has_checked_field?, :has_unchecked_field?, :has_no_table?, :has_table?,
|
35
|
+
:unselect, :has_select?, :has_no_select?, :current_path, :scope_to, :click, :driver
|
36
|
+
]
|
37
|
+
|
38
|
+
attr_reader :mode, :app
|
39
|
+
|
40
|
+
def initialize(mode, app=nil)
|
41
|
+
@mode = mode
|
42
|
+
@app = app
|
43
|
+
end
|
44
|
+
|
45
|
+
def driver
|
46
|
+
@driver ||= begin
|
47
|
+
string = mode.to_s
|
48
|
+
string.gsub!(%r{(^.)|(_.)}) { |m| m[m.length-1,1].upcase }
|
49
|
+
Capybara::Driver.const_get(string.to_sym).new(app)
|
50
|
+
rescue NameError
|
51
|
+
raise Capybara::DriverNotFoundError, "no driver called #{mode} was found"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
#
|
57
|
+
# Reset the session, removing all cookies.
|
58
|
+
#
|
59
|
+
def cleanup!
|
60
|
+
driver.cleanup!
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
#
|
65
|
+
# Returns a hash of response headers. Not supported by all drivers (e.g. Selenium)
|
66
|
+
#
|
67
|
+
# @return [Hash{String => String}] A hash of response headers.
|
68
|
+
#
|
69
|
+
def response_headers
|
70
|
+
driver.response_headers
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
#
|
75
|
+
# Returns the current HTTP status code as an Integer. Not supported by all drivers (e.g. Selenium)
|
76
|
+
#
|
77
|
+
# @return [Integer] Current HTTP status code
|
78
|
+
#
|
79
|
+
def status_code
|
80
|
+
driver.status_code
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
#
|
85
|
+
# @return [String] A snapshot of the HTML of the current document, as it looks right now
|
86
|
+
#
|
87
|
+
def body
|
88
|
+
driver.body
|
89
|
+
end
|
90
|
+
|
91
|
+
##
|
92
|
+
#
|
93
|
+
# @return [String] HTML source of the document, before being modified by JavaScript.
|
94
|
+
#
|
95
|
+
def source
|
96
|
+
driver.source
|
97
|
+
end
|
98
|
+
|
99
|
+
##
|
100
|
+
#
|
101
|
+
# @return [String] Path of the current page, without any domain information
|
102
|
+
#
|
103
|
+
def current_path
|
104
|
+
URI.parse(current_url).path
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
#
|
109
|
+
# @return [String] Fully qualified URL of the current page
|
110
|
+
#
|
111
|
+
def current_url
|
112
|
+
driver.current_url
|
113
|
+
end
|
114
|
+
|
115
|
+
##
|
116
|
+
#
|
117
|
+
# Navigate to the given URL. The URL can either be a relative URL or an absolute URL
|
118
|
+
# The behaviour of either depends on the driver.
|
119
|
+
#
|
120
|
+
# session.visit('/foo')
|
121
|
+
# session.visit('http://google.com')
|
122
|
+
#
|
123
|
+
# For drivers which can run against an external application, such as culerity and selenium
|
124
|
+
# giving an absolute URL will navigate to that page. This allows testing applications
|
125
|
+
# running on remote servers. For these drivers, setting Capybara.app_host will make the
|
126
|
+
# remote server the default. For example:
|
127
|
+
#
|
128
|
+
# Capybara.app_host = 'http://google.com'
|
129
|
+
# session.visit('/') # visits the google homepage
|
130
|
+
#
|
131
|
+
# @param [String] url The URL to navigate to
|
132
|
+
#
|
133
|
+
def visit(url)
|
134
|
+
driver.visit(url)
|
135
|
+
end
|
136
|
+
|
137
|
+
##
|
138
|
+
#
|
139
|
+
# Execute the given block for a particular scope on the page. Within will find the first
|
140
|
+
# element matching the given selector and execute the block scoped to that element:
|
141
|
+
#
|
142
|
+
# within(:xpath, '//div[@id="delivery-address"]') do
|
143
|
+
# fill_in('Street', :with => '12 Main Street')
|
144
|
+
# end
|
145
|
+
#
|
146
|
+
# It is possible to omit the first parameter, in that case, the selector is assumed to be
|
147
|
+
# of the type set in Capybara.default_selector.
|
148
|
+
#
|
149
|
+
# within('div#delivery-address') do
|
150
|
+
# fill_in('Street', :with => '12 Main Street')
|
151
|
+
# end
|
152
|
+
#
|
153
|
+
# @param [:css, :xpath, String] kind The type of selector or the selector if the second argument is blank
|
154
|
+
# @param [String] selector The selector within which to execute the given block
|
155
|
+
#
|
156
|
+
def within(kind, selector=nil)
|
157
|
+
new_scope = find(kind, selector, :message => "scope '#{selector || kind}' not found on page")
|
158
|
+
begin
|
159
|
+
scopes.push(new_scope)
|
160
|
+
yield
|
161
|
+
ensure
|
162
|
+
scopes.pop
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
##
|
167
|
+
#
|
168
|
+
# Execute the given block within the a specific fieldset given the id or legend of that fieldset.
|
169
|
+
#
|
170
|
+
# @param [String] locator Id or legend of the fieldset
|
171
|
+
#
|
172
|
+
def within_fieldset(locator)
|
173
|
+
within :xpath, XPath.fieldset(locator) do
|
174
|
+
yield
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
##
|
179
|
+
#
|
180
|
+
# Execute the given block within the a specific table given the id or caption of that table.
|
181
|
+
#
|
182
|
+
# @param [String] locator Id or caption of the table
|
183
|
+
#
|
184
|
+
def within_table(locator)
|
185
|
+
within :xpath, XPath.table(locator) do
|
186
|
+
yield
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
##
|
191
|
+
#
|
192
|
+
# Execute the given block within the given iframe given the id of that iframe. Only works on
|
193
|
+
# some drivers (e.g. Selenium)
|
194
|
+
#
|
195
|
+
# @param [String] locator Id of the frame
|
196
|
+
#
|
197
|
+
def within_frame(frame_id)
|
198
|
+
driver.within_frame(frame_id) do
|
199
|
+
yield
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
##
|
204
|
+
#
|
205
|
+
# Retry executing the block until a truthy result is returned or the timeout time is exceeded
|
206
|
+
#
|
207
|
+
# @param [Integer] timeout The amount of seconds to retry executing the given block
|
208
|
+
#
|
209
|
+
def wait_until(timeout = Capybara.default_wait_time)
|
210
|
+
Capybara.timeout(timeout,driver) { yield }
|
211
|
+
end
|
212
|
+
|
213
|
+
##
|
214
|
+
#
|
215
|
+
# Execute the given script, not returning a result. This is useful for scripts that return
|
216
|
+
# complex objects, such as jQuery statements. +execute_script+ should always be used over
|
217
|
+
# +evaluate_script+ whenever possible.
|
218
|
+
#
|
219
|
+
# @param [String] script A string of JavaScript to execute
|
220
|
+
#
|
221
|
+
def execute_script(script)
|
222
|
+
driver.execute_script(script)
|
223
|
+
end
|
224
|
+
|
225
|
+
##
|
226
|
+
#
|
227
|
+
# Evaluate the given JavaScript and return the result. Be careful when using this with
|
228
|
+
# scripts that return complex objects, such as jQuery statements. +execute_script+ might
|
229
|
+
# be a better alternative.
|
230
|
+
#
|
231
|
+
# @param [String] script A string of JavaScript to evaluate
|
232
|
+
# @return [Object] The result of the evaluated JavaScript (may be driver specific)
|
233
|
+
#
|
234
|
+
def evaluate_script(script)
|
235
|
+
driver.evaluate_script(script)
|
236
|
+
end
|
237
|
+
|
238
|
+
##
|
239
|
+
#
|
240
|
+
# @deprecated click is deprecated, please use {Capybara::Node::Actions#click_link_or_button} instead
|
241
|
+
#
|
242
|
+
def click(locator)
|
243
|
+
warn "DEPRECATED: click is deprecated, use click_link_or_button instead"
|
244
|
+
current_node.click_link_or_button(locator)
|
245
|
+
end
|
246
|
+
|
247
|
+
##
|
248
|
+
#
|
249
|
+
# Save a snapshot of the page and open it in a browser for inspection
|
250
|
+
#
|
251
|
+
def save_and_open_page
|
252
|
+
require 'capybara/util/save_and_open_page'
|
253
|
+
Capybara.save_and_open_page(body)
|
254
|
+
end
|
255
|
+
|
256
|
+
def document
|
257
|
+
Capybara::Document.new(self, driver)
|
258
|
+
end
|
259
|
+
|
260
|
+
def method_missing(*args)
|
261
|
+
current_node.send(*args)
|
262
|
+
end
|
263
|
+
|
264
|
+
def respond_to?(method)
|
265
|
+
super || current_node.respond_to?(method)
|
266
|
+
end
|
267
|
+
|
268
|
+
private
|
269
|
+
|
270
|
+
def current_node
|
271
|
+
scopes.last
|
272
|
+
end
|
273
|
+
|
274
|
+
def scopes
|
275
|
+
@scopes ||= [document]
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'capybara/spec/test_app'
|
2
|
+
|
3
|
+
shared_examples_for 'driver' do
|
4
|
+
|
5
|
+
describe '#visit' do
|
6
|
+
it "should move to another page" do
|
7
|
+
@driver.visit('/')
|
8
|
+
@driver.body.should include('Hello world!')
|
9
|
+
@driver.visit('/foo')
|
10
|
+
@driver.body.should include('Another World')
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should show the correct URL" do
|
14
|
+
@driver.visit('/foo')
|
15
|
+
@driver.current_url.should include('/foo')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#body' do
|
20
|
+
it "should return text reponses" do
|
21
|
+
@driver.visit('/')
|
22
|
+
@driver.body.should include('Hello world!')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return the full response html" do
|
26
|
+
@driver.visit('/with_simple_html')
|
27
|
+
@driver.body.should include('Bar')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#find' do
|
32
|
+
context "with xpath selector" do
|
33
|
+
before do
|
34
|
+
@driver.visit('/with_html')
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should extract node texts" do
|
38
|
+
@driver.find('//a')[0].text.should == 'labore'
|
39
|
+
@driver.find('//a')[1].text.should == 'ullamco'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should extract node attributes" do
|
43
|
+
@driver.find('//a')[0][:href].should == '/with_simple_html'
|
44
|
+
@driver.find('//a')[0][:class].should == 'simple'
|
45
|
+
@driver.find('//a')[1][:href].should == '/foo'
|
46
|
+
@driver.find('//a')[1][:id].should == 'foo'
|
47
|
+
@driver.find('//a')[1][:rel].should be_nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should extract boolean node attributes" do
|
51
|
+
@driver.find('//input[@id="checked_field"]')[0][:checked].should be_true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should allow retrieval of the value" do
|
55
|
+
@driver.find('//textarea').first.value.should == 'banana'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should allow assignment of field value" do
|
59
|
+
@driver.find('//input').first.value.should == 'monkey'
|
60
|
+
@driver.find('//input').first.set('gorilla')
|
61
|
+
@driver.find('//input').first.value.should == 'gorilla'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should extract node tag name" do
|
65
|
+
@driver.find('//a')[0].tag_name.should == 'a'
|
66
|
+
@driver.find('//a')[1].tag_name.should == 'a'
|
67
|
+
@driver.find('//p')[1].tag_name.should == 'p'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should extract node visibility" do
|
71
|
+
@driver.find('//a')[0].should be_visible
|
72
|
+
|
73
|
+
@driver.find('//div[@id="hidden"]')[0].should_not be_visible
|
74
|
+
@driver.find('//div[@id="hidden_via_ancestor"]')[0].should_not be_visible
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
shared_examples_for "driver with javascript support" do
|
81
|
+
before { @driver.visit('/with_js') }
|
82
|
+
|
83
|
+
describe '#find' do
|
84
|
+
it "should find dynamically changed nodes" do
|
85
|
+
@driver.find('//p').first.text.should == 'I changed it'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe '#drag_to' do
|
90
|
+
it "should drag and drop an object" do
|
91
|
+
pending "drag/drop is currently broken under celerity/culerity" if @driver.is_a?(Capybara::Driver::Celerity)
|
92
|
+
draggable = @driver.find('//div[@id="drag"]').first
|
93
|
+
droppable = @driver.find('//div[@id="drop"]').first
|
94
|
+
draggable.drag_to(droppable)
|
95
|
+
@driver.find('//div[contains(., "Dropped!")]').should_not be_empty
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#evaluate_script" do
|
100
|
+
it "should return the value of the executed script" do
|
101
|
+
@driver.evaluate_script('1+1').should == 2
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
shared_examples_for "driver with header support" do
|
107
|
+
it "should make headers available through response_headers" do
|
108
|
+
@driver.visit('/with_simple_html')
|
109
|
+
@driver.response_headers['Content-Type'].should == 'text/html'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
shared_examples_for "driver with status code support" do
|
114
|
+
it "should make the status code available through status_code" do
|
115
|
+
@driver.visit('/with_simple_html')
|
116
|
+
@driver.status_code.should == 200
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
shared_examples_for "driver without status code support" do
|
121
|
+
it "should raise when trying to access the status code available through status_code" do
|
122
|
+
@driver.visit('/with_simple_html')
|
123
|
+
lambda {
|
124
|
+
@driver.status_code
|
125
|
+
}.should raise_error(Capybara::NotSupportedByDriverError)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
shared_examples_for "driver with frame support" do
|
130
|
+
describe '#within_frame' do
|
131
|
+
before(:each) do
|
132
|
+
@driver.visit('/within_frames')
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should find the div in frameOne" do
|
136
|
+
@driver.within_frame("frameOne") do
|
137
|
+
@driver.find("//*[@id='divInFrameOne']")[0].text.should eql 'This is the text of divInFrameOne'
|
138
|
+
end
|
139
|
+
end
|
140
|
+
it "should find the div in FrameTwo" do
|
141
|
+
@driver.within_frame("frameTwo") do
|
142
|
+
@driver.find("//*[@id='divInFrameTwo']")[0].text.should eql 'This is the text of divInFrameTwo'
|
143
|
+
end
|
144
|
+
end
|
145
|
+
it "should find the text div in the main window after finding text in frameOne" do
|
146
|
+
@driver.within_frame("frameOne") do
|
147
|
+
@driver.find("//*[@id='divInFrameOne']")[0].text.should eql 'This is the text of divInFrameOne'
|
148
|
+
end
|
149
|
+
@driver.find("//*[@id='divInMainWindow']")[0].text.should eql 'This is the text for divInMainWindow'
|
150
|
+
end
|
151
|
+
it "should find the text div in the main window after finding text in frameTwo" do
|
152
|
+
@driver.within_frame("frameTwo") do
|
153
|
+
@driver.find("//*[@id='divInFrameTwo']")[0].text.should eql 'This is the text of divInFrameTwo'
|
154
|
+
end
|
155
|
+
@driver.find("//*[@id='divInMainWindow']")[0].text.should eql 'This is the text for divInMainWindow'
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
shared_examples_for "driver with cookies support" do
|
161
|
+
describe "#cleanup" do
|
162
|
+
it "should set and clean cookies" do
|
163
|
+
@driver.visit('/get_cookie')
|
164
|
+
@driver.body.should_not include('test_cookie')
|
165
|
+
|
166
|
+
@driver.visit('/set_cookie')
|
167
|
+
@driver.body.should include('Cookie set to test_cookie')
|
168
|
+
|
169
|
+
@driver.visit('/get_cookie')
|
170
|
+
@driver.body.should include('test_cookie')
|
171
|
+
|
172
|
+
@driver.cleanup!
|
173
|
+
@driver.visit('/get_cookie')
|
174
|
+
@driver.body.should_not include('test_cookie')
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
shared_examples_for "driver with infinite redirect detection" do
|
180
|
+
it "should follow 5 redirects" do
|
181
|
+
@driver.visit('/redirect/5/times')
|
182
|
+
@driver.body.should include('redirection complete')
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should not follow more than 5 redirects" do
|
186
|
+
running do
|
187
|
+
@driver.visit('/redirect/6/times')
|
188
|
+
end.should raise_error(Capybara::InfiniteRedirectError)
|
189
|
+
end
|
190
|
+
end
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
ThisIsTheTestFile
|