capybara-webkit 1.5.2 → 1.6.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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CONTRIBUTING.md +4 -1
- data/Gemfile.lock +1 -1
- data/NEWS.md +12 -0
- data/README.md +54 -12
- data/lib/capybara/webkit.rb +9 -4
- data/lib/capybara/webkit/browser.rb +18 -2
- data/lib/capybara/webkit/configuration.rb +98 -0
- data/lib/capybara/webkit/connection.rb +13 -1
- data/lib/capybara/webkit/driver.rb +133 -52
- data/lib/capybara/webkit/errors.rb +3 -0
- data/lib/capybara/webkit/node.rb +9 -8
- data/lib/capybara/webkit/version.rb +1 -1
- data/spec/browser_spec.rb +0 -229
- data/spec/configuration_spec.rb +16 -0
- data/spec/connection_spec.rb +15 -2
- data/spec/driver_spec.rb +343 -53
- data/spec/selenium_compatibility_spec.rb +88 -9
- data/spec/spec_helper.rb +7 -2
- data/spec/support/app_runner.rb +13 -3
- data/src/Authenticate.cpp +4 -0
- data/src/Headers.cpp +4 -1
- data/src/Server.cpp +7 -0
- data/src/WebPage.cpp +11 -9
- data/src/WebPage.h +1 -1
- data/src/WebPageManager.cpp +0 -3
- data/src/capybara.js +20 -3
- metadata +5 -3
- data/lib/capybara/webkit/socket_debugger.rb +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb1c802882892f9e70e1b42d5b2f16bd01fbe99f
|
4
|
+
data.tar.gz: 8d803700aa341d54a6cb4a5e3016ab8afb0dbcf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb8a7c5f7b5e29063d2fa241f38510797d26aefd9e3f112715b1d1c42028d169f954e869e445c8f8a4ee652e969e7972b67663774f579992c16346355383100f
|
7
|
+
data.tar.gz: 72b58214cdb532805b2ff63b7f8ff64342dc61a1faca858ee878f5ba5932839143785aef111ec00fa1ebb960fc8053ade23c4681a18c6f59e182c178d17a5e53
|
data/.travis.yml
CHANGED
data/CONTRIBUTING.md
CHANGED
data/Gemfile.lock
CHANGED
data/NEWS.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
New for 1.6.0:
|
2
|
+
|
3
|
+
* New, easier, global configuration API.
|
4
|
+
* Add `page.driver.allow_unknown_urls` to silent all unknown host warnings.
|
5
|
+
* Add warning for users on Qt 4.
|
6
|
+
* Fix bug when parsing response headers with values containing colons.
|
7
|
+
* Allow multiple, different basic authorizations in a single session.
|
8
|
+
* Caches behave more like Selenium
|
9
|
+
* Select tag events behave more like Selenium
|
10
|
+
* Deprecated `driver.browser`
|
11
|
+
* Provide better behavior and information when the driver crashes
|
12
|
+
|
1
13
|
New for 1.5.2:
|
2
14
|
|
3
15
|
* Fixes bug where aborted Ajax requests caused a crash during reset.
|
data/README.md
CHANGED
@@ -82,6 +82,60 @@ If you're using capybara-webkit with Sinatra, don't forget to set
|
|
82
82
|
Capybara.app = MySinatraApp.new
|
83
83
|
```
|
84
84
|
|
85
|
+
Configuration
|
86
|
+
-------------
|
87
|
+
|
88
|
+
You can configure global options using `Capybara::Webkit.configure`:
|
89
|
+
|
90
|
+
``` ruby
|
91
|
+
Capybara::Webkit.configure do |config|
|
92
|
+
# Enable debug mode. Prints a log of everything the driver is doing.
|
93
|
+
config.debug = true
|
94
|
+
|
95
|
+
# By default, requests to outside domains (anything besides localhost) will
|
96
|
+
# result in a warning. Several methods allow you to change this behavior.
|
97
|
+
|
98
|
+
# Silently return an empty 200 response for any requests to unknown URLs.
|
99
|
+
config.block_unknown_urls
|
100
|
+
|
101
|
+
# Allow pages to make requests to any URL without issuing a warning.
|
102
|
+
config.allow_unknown_urls
|
103
|
+
|
104
|
+
# Allow a specifc domain without issuing a warning.
|
105
|
+
config.allow_url("example.com")
|
106
|
+
|
107
|
+
# Allow a specifc URL and path without issuing a warning.
|
108
|
+
config.allow_url("example.com/some/path")
|
109
|
+
|
110
|
+
# Wildcards are allowed in URL expressions.
|
111
|
+
config.allow_url("*.example.com")
|
112
|
+
|
113
|
+
# Silently return an empty 200 response for any requests to the given URL.
|
114
|
+
config.block_url("example.com")
|
115
|
+
|
116
|
+
# Timeout if requests take longer than 5 seconds
|
117
|
+
config.timeout = 5
|
118
|
+
|
119
|
+
# Don't raise errors when SSL certificates can't be validated
|
120
|
+
config.ignore_ssl_errors
|
121
|
+
|
122
|
+
# Don't load images
|
123
|
+
config.skip_image_loading
|
124
|
+
|
125
|
+
# Use a proxy
|
126
|
+
config.use_proxy(
|
127
|
+
host: "example.com",
|
128
|
+
port: 1234,
|
129
|
+
user: "proxy",
|
130
|
+
pass: "secret"
|
131
|
+
)
|
132
|
+
end
|
133
|
+
```
|
134
|
+
|
135
|
+
These options will take effect for all future sessions and only need to be set
|
136
|
+
once. It's recommended that you configure these in your `spec_helper.rb` or
|
137
|
+
`test_helper.rb` rather than a `before` or `setup` block.
|
138
|
+
|
85
139
|
Offline Application Cache
|
86
140
|
-------------------------
|
87
141
|
|
@@ -127,18 +181,6 @@ page.driver.cookies["alpha"]
|
|
127
181
|
page.driver.header 'Referer', 'https://www.thoughtbot.com'
|
128
182
|
```
|
129
183
|
|
130
|
-
**block_unknown_urls**: By default, capybara-webkit will warn when a request is made to a URL other than 127.0.0.1 or localhost. This option will block such unknown URLs instead.
|
131
|
-
|
132
|
-
```ruby
|
133
|
-
page.driver.block_unknown_urls
|
134
|
-
```
|
135
|
-
|
136
|
-
**allow_url**: Allow requests to a URL. This will silence unknown URL warnings, or permit requests to a URL when `block_unknown_urls` is used. Allowed URLs are reset on `Driver#reset!`.
|
137
|
-
|
138
|
-
```ruby
|
139
|
-
page.driver.allow_url 'example.com/*.js'
|
140
|
-
```
|
141
|
-
|
142
184
|
Contributing
|
143
185
|
------------
|
144
186
|
|
data/lib/capybara/webkit.rb
CHANGED
@@ -2,17 +2,22 @@ require "capybara"
|
|
2
2
|
|
3
3
|
module Capybara
|
4
4
|
module Webkit
|
5
|
+
def self.configure(&block)
|
6
|
+
Capybara::Webkit::Configuration.modify(&block)
|
7
|
+
end
|
5
8
|
end
|
6
9
|
end
|
7
10
|
|
8
11
|
require "capybara/webkit/driver"
|
12
|
+
require "capybara/webkit/configuration"
|
9
13
|
|
10
14
|
Capybara.register_driver :webkit do |app|
|
11
|
-
Capybara::Webkit::Driver.new(app)
|
15
|
+
Capybara::Webkit::Driver.new(app, Capybara::Webkit::Configuration.to_hash)
|
12
16
|
end
|
13
17
|
|
14
18
|
Capybara.register_driver :webkit_debug do |app|
|
15
|
-
|
16
|
-
|
17
|
-
|
19
|
+
Capybara::Webkit::Driver.new(
|
20
|
+
app,
|
21
|
+
Capybara::Webkit::Configuration.to_hash.merge(debug: true)
|
22
|
+
)
|
18
23
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require "json"
|
2
|
+
require "capybara/webkit/errors"
|
2
3
|
|
3
4
|
module Capybara::Webkit
|
4
5
|
class Browser
|
@@ -71,7 +72,7 @@ module Capybara::Webkit
|
|
71
72
|
end
|
72
73
|
|
73
74
|
def response_headers
|
74
|
-
|
75
|
+
JSON.parse(command("Headers"))
|
75
76
|
end
|
76
77
|
|
77
78
|
def current_url
|
@@ -209,6 +210,17 @@ module Capybara::Webkit
|
|
209
210
|
end
|
210
211
|
check
|
211
212
|
read_response
|
213
|
+
rescue SystemCallError => exception
|
214
|
+
@connection.restart
|
215
|
+
raise(Capybara::Webkit::CrashError, <<-MESSAGE.strip)
|
216
|
+
The webkit_server process crashed!
|
217
|
+
|
218
|
+
#{exception.message}
|
219
|
+
|
220
|
+
This is a bug in capybara-webkit. For help with this crash, please visit:
|
221
|
+
|
222
|
+
https://github.com/thoughtbot/capybara-webkit/wiki/Reporting-Crashes
|
223
|
+
MESSAGE
|
212
224
|
end
|
213
225
|
|
214
226
|
def evaluate_script(script)
|
@@ -277,6 +289,10 @@ module Capybara::Webkit
|
|
277
289
|
command("SetUnknownUrlMode", "block")
|
278
290
|
end
|
279
291
|
|
292
|
+
def allow_unknown_urls
|
293
|
+
allow_url("*")
|
294
|
+
end
|
295
|
+
|
280
296
|
private
|
281
297
|
|
282
298
|
def check
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Capybara
|
2
|
+
module Webkit
|
3
|
+
class Configuration
|
4
|
+
class << self
|
5
|
+
private
|
6
|
+
|
7
|
+
def instance
|
8
|
+
@instance ||= new
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.to_hash
|
13
|
+
instance.freeze.to_hash
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.modify
|
17
|
+
if instance.frozen?
|
18
|
+
raise "All configuration must take place before the driver starts"
|
19
|
+
else
|
20
|
+
yield instance
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_accessor :allowed_urls
|
25
|
+
attr_writer :block_unknown_urls
|
26
|
+
attr_accessor :blocked_urls
|
27
|
+
attr_accessor :debug
|
28
|
+
attr_writer :ignore_ssl_errors
|
29
|
+
attr_accessor :proxy
|
30
|
+
attr_accessor :timeout
|
31
|
+
attr_writer :skip_image_loading
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
@allowed_urls = []
|
35
|
+
@blocked_urls = []
|
36
|
+
@block_unknown_urls = false
|
37
|
+
@debug = false
|
38
|
+
@ignore_ssl_errors = false
|
39
|
+
@proxy = nil
|
40
|
+
@skip_image_loading = false
|
41
|
+
@timeout = -1
|
42
|
+
end
|
43
|
+
|
44
|
+
def allow_url(url)
|
45
|
+
@allowed_urls << url
|
46
|
+
end
|
47
|
+
|
48
|
+
def block_url(url)
|
49
|
+
@blocked_urls << url
|
50
|
+
end
|
51
|
+
|
52
|
+
def block_unknown_urls
|
53
|
+
@block_unknown_urls = true
|
54
|
+
end
|
55
|
+
|
56
|
+
def block_unknown_urls?
|
57
|
+
@block_unknown_urls
|
58
|
+
end
|
59
|
+
|
60
|
+
def allow_unknown_urls
|
61
|
+
allow_url("*")
|
62
|
+
end
|
63
|
+
|
64
|
+
def ignore_ssl_errors
|
65
|
+
@ignore_ssl_errors = true
|
66
|
+
end
|
67
|
+
|
68
|
+
def ignore_ssl_errors?
|
69
|
+
@ignore_ssl_errors
|
70
|
+
end
|
71
|
+
|
72
|
+
def skip_image_loading
|
73
|
+
@skip_image_loading = true
|
74
|
+
end
|
75
|
+
|
76
|
+
def skip_image_loading?
|
77
|
+
@skip_image_loading
|
78
|
+
end
|
79
|
+
|
80
|
+
def use_proxy(proxy)
|
81
|
+
@proxy = proxy
|
82
|
+
end
|
83
|
+
|
84
|
+
def to_hash
|
85
|
+
{
|
86
|
+
allowed_urls: allowed_urls,
|
87
|
+
block_unknown_urls: block_unknown_urls?,
|
88
|
+
blocked_urls: blocked_urls,
|
89
|
+
debug: debug,
|
90
|
+
ignore_ssl_errors: ignore_ssl_errors?,
|
91
|
+
proxy: proxy,
|
92
|
+
skip_image_loading: skip_image_loading?,
|
93
|
+
timeout: timeout
|
94
|
+
}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -12,7 +12,13 @@ module Capybara::Webkit
|
|
12
12
|
|
13
13
|
def initialize(options = {})
|
14
14
|
@socket = nil
|
15
|
-
|
15
|
+
if options.has_key?(:socket_class)
|
16
|
+
warn '[DEPRECATION] The Capybara::Webkit::Connection `socket_class` ' \
|
17
|
+
'option is deprecated without replacement.'
|
18
|
+
@socket_class = options[:socket_class]
|
19
|
+
else
|
20
|
+
@socket_class = TCPSocket
|
21
|
+
end
|
16
22
|
if options.has_key?(:stderr)
|
17
23
|
@output_target = options[:stderr]
|
18
24
|
elsif options.has_key?(:stdout)
|
@@ -55,6 +61,12 @@ module Capybara::Webkit
|
|
55
61
|
response
|
56
62
|
end
|
57
63
|
|
64
|
+
def restart
|
65
|
+
@socket = nil
|
66
|
+
start_server
|
67
|
+
connect
|
68
|
+
end
|
69
|
+
|
58
70
|
private
|
59
71
|
|
60
72
|
def start_server
|
@@ -3,109 +3,120 @@ require "capybara/webkit/version"
|
|
3
3
|
require "capybara/webkit/node"
|
4
4
|
require "capybara/webkit/connection"
|
5
5
|
require "capybara/webkit/browser"
|
6
|
-
require "capybara/webkit/socket_debugger"
|
7
6
|
require "capybara/webkit/cookie_jar"
|
8
7
|
require "capybara/webkit/errors"
|
9
8
|
|
10
9
|
module Capybara::Webkit
|
11
10
|
class Driver < Capybara::Driver::Base
|
12
|
-
attr_reader :browser
|
13
|
-
|
14
11
|
def initialize(app, options={})
|
15
12
|
@app = app
|
16
13
|
@options = options
|
17
14
|
@browser = options[:browser] || Browser.new(Connection.new(options))
|
15
|
+
apply_options
|
18
16
|
end
|
19
17
|
|
20
18
|
def enable_logging
|
21
|
-
|
19
|
+
deprecate_and_replace_with_config "enable_logging", "debug = true"
|
20
|
+
@browser.enable_logging
|
22
21
|
end
|
23
22
|
|
24
23
|
def allow_url(url)
|
25
|
-
|
24
|
+
deprecate_and_replace_with_config "allow_url", "allow_url(#{url.inspect})"
|
25
|
+
@browser.allow_url(url)
|
26
26
|
end
|
27
27
|
|
28
28
|
def block_url(url)
|
29
|
-
|
29
|
+
deprecate_and_replace_with_config "block_url", "block_url(#{url.inspect})"
|
30
|
+
@browser.block_url(url)
|
30
31
|
end
|
31
32
|
|
32
33
|
def block_unknown_urls
|
33
|
-
|
34
|
+
deprecate_and_replace_with_config "block_unknown_urls"
|
35
|
+
@browser.block_unknown_urls
|
36
|
+
end
|
37
|
+
|
38
|
+
def allow_unknown_urls
|
39
|
+
deprecate_and_replace_with_config "allow_unknown_urls"
|
40
|
+
@browser.allow_url("*")
|
34
41
|
end
|
35
42
|
|
36
43
|
def current_url
|
37
|
-
browser.current_url
|
44
|
+
@browser.current_url
|
38
45
|
end
|
39
46
|
|
40
47
|
def visit(path)
|
41
|
-
browser.visit(path)
|
48
|
+
@browser.visit(path)
|
42
49
|
end
|
43
50
|
|
44
51
|
def find_xpath(xpath)
|
45
|
-
browser.
|
52
|
+
@browser.
|
53
|
+
find_xpath(xpath).
|
54
|
+
map { |native| Node.new(self, native, @browser) }
|
46
55
|
end
|
47
56
|
|
48
57
|
alias_method :find, :find_xpath
|
49
58
|
|
50
59
|
def find_css(selector)
|
51
|
-
browser.
|
60
|
+
@browser.
|
61
|
+
find_css(selector).
|
62
|
+
map { |native| Node.new(self, native, @browser) }
|
52
63
|
end
|
53
64
|
|
54
65
|
def html
|
55
|
-
browser.body
|
66
|
+
@browser.body
|
56
67
|
end
|
57
68
|
|
58
69
|
def header(key, value)
|
59
|
-
browser.header(key, value)
|
70
|
+
@browser.header(key, value)
|
60
71
|
end
|
61
72
|
|
62
73
|
def title
|
63
|
-
browser.title
|
74
|
+
@browser.title
|
64
75
|
end
|
65
76
|
|
66
77
|
def execute_script(script)
|
67
|
-
value = browser.execute_script script
|
78
|
+
value = @browser.execute_script script
|
68
79
|
value.empty? ? nil : value
|
69
80
|
end
|
70
81
|
|
71
82
|
def evaluate_script(script)
|
72
|
-
browser.evaluate_script script
|
83
|
+
@browser.evaluate_script script
|
73
84
|
end
|
74
85
|
|
75
86
|
def console_messages
|
76
|
-
browser.console_messages
|
87
|
+
@browser.console_messages
|
77
88
|
end
|
78
89
|
|
79
90
|
def error_messages
|
80
|
-
browser.error_messages
|
91
|
+
@browser.error_messages
|
81
92
|
end
|
82
93
|
|
83
94
|
def alert_messages
|
84
95
|
warn '[DEPRECATION] Capybara::Webkit::Driver#alert_messages ' \
|
85
96
|
'is deprecated. Please use Capybara::Session#accept_alert instead.'
|
86
|
-
browser.alert_messages
|
97
|
+
@browser.alert_messages
|
87
98
|
end
|
88
99
|
|
89
100
|
def confirm_messages
|
90
101
|
warn '[DEPRECATION] Capybara::Webkit::Driver#confirm_messages ' \
|
91
102
|
'is deprecated. Please use Capybara::Session#accept_confirm ' \
|
92
103
|
'or Capybara::Session#dismiss_confirm instead.'
|
93
|
-
browser.confirm_messages
|
104
|
+
@browser.confirm_messages
|
94
105
|
end
|
95
106
|
|
96
107
|
def prompt_messages
|
97
108
|
warn '[DEPRECATION] Capybara::Webkit::Driver#prompt_messages ' \
|
98
109
|
'is deprecated. Please use Capybara::Session#accept_prompt ' \
|
99
110
|
'or Capybara::Session#dismiss_prompt instead.'
|
100
|
-
browser.prompt_messages
|
111
|
+
@browser.prompt_messages
|
101
112
|
end
|
102
113
|
|
103
114
|
def response_headers
|
104
|
-
browser.response_headers
|
115
|
+
@browser.response_headers
|
105
116
|
end
|
106
117
|
|
107
118
|
def status_code
|
108
|
-
browser.status_code
|
119
|
+
@browser.status_code
|
109
120
|
end
|
110
121
|
|
111
122
|
def resize_window(width, height)
|
@@ -115,19 +126,19 @@ module Capybara::Webkit
|
|
115
126
|
end
|
116
127
|
|
117
128
|
def resize_window_to(handle, width, height)
|
118
|
-
browser.window_resize(handle, width, height)
|
129
|
+
@browser.window_resize(handle, width, height)
|
119
130
|
end
|
120
131
|
|
121
132
|
def window_size(handle)
|
122
|
-
browser.window_size(handle)
|
133
|
+
@browser.window_size(handle)
|
123
134
|
end
|
124
135
|
|
125
136
|
def within_frame(selector)
|
126
|
-
browser.frame_focus(selector)
|
137
|
+
@browser.frame_focus(selector)
|
127
138
|
begin
|
128
139
|
yield
|
129
140
|
ensure
|
130
|
-
browser.frame_focus
|
141
|
+
@browser.frame_focus
|
131
142
|
end
|
132
143
|
end
|
133
144
|
|
@@ -137,74 +148,74 @@ module Capybara::Webkit
|
|
137
148
|
begin
|
138
149
|
yield
|
139
150
|
ensure
|
140
|
-
browser.window_focus(current_window)
|
151
|
+
@browser.window_focus(current_window)
|
141
152
|
end
|
142
153
|
end
|
143
154
|
|
144
155
|
def switch_to_window(selector)
|
145
|
-
browser.window_focus(selector)
|
156
|
+
@browser.window_focus(selector)
|
146
157
|
end
|
147
158
|
|
148
159
|
def window_handles
|
149
|
-
browser.get_window_handles
|
160
|
+
@browser.get_window_handles
|
150
161
|
end
|
151
162
|
|
152
163
|
def current_window_handle
|
153
|
-
browser.get_window_handle
|
164
|
+
@browser.get_window_handle
|
154
165
|
end
|
155
166
|
|
156
167
|
def open_new_window
|
157
|
-
browser.window_open
|
168
|
+
@browser.window_open
|
158
169
|
end
|
159
170
|
|
160
171
|
def close_window(selector)
|
161
|
-
browser.window_close(selector)
|
172
|
+
@browser.window_close(selector)
|
162
173
|
end
|
163
174
|
|
164
175
|
def maximize_window(selector)
|
165
|
-
browser.window_maximize(selector)
|
176
|
+
@browser.window_maximize(selector)
|
166
177
|
end
|
167
178
|
|
168
179
|
def accept_js_confirms!
|
169
180
|
warn '[DEPRECATION] Capybara::Webkit::Driver#accept_js_confirms! ' \
|
170
181
|
'is deprecated. Please use Capybara::Session#accept_confirm instead.'
|
171
|
-
browser.accept_js_confirms
|
182
|
+
@browser.accept_js_confirms
|
172
183
|
end
|
173
184
|
|
174
185
|
def dismiss_js_confirms!
|
175
186
|
warn '[DEPRECATION] Capybara::Webkit::Driver#dismiss_js_confirms! ' \
|
176
187
|
'is deprecated. Please use Capybara::Session#dismiss_confirm instead.'
|
177
|
-
browser.reject_js_confirms
|
188
|
+
@browser.reject_js_confirms
|
178
189
|
end
|
179
190
|
|
180
191
|
def accept_js_prompts!
|
181
192
|
warn '[DEPRECATION] Capybara::Webkit::Driver#accept_js_prompts! ' \
|
182
193
|
'is deprecated. Please use Capybara::Session#accept_prompt instead.'
|
183
|
-
browser.accept_js_prompts
|
194
|
+
@browser.accept_js_prompts
|
184
195
|
end
|
185
196
|
|
186
197
|
def dismiss_js_prompts!
|
187
198
|
warn '[DEPRECATION] Capybara::Webkit::Driver#dismiss_js_prompts! ' \
|
188
199
|
'is deprecated. Please use Capybara::Session#dismiss_prompt instead.'
|
189
|
-
browser.reject_js_prompts
|
200
|
+
@browser.reject_js_prompts
|
190
201
|
end
|
191
202
|
|
192
203
|
def js_prompt_input=(value)
|
193
204
|
warn '[DEPRECATION] Capybara::Webkit::Driver#js_prompt_input= ' \
|
194
205
|
'is deprecated. Please use Capybara::Session#accept_prompt instead.'
|
195
206
|
if value.nil?
|
196
|
-
browser.clear_prompt_text
|
207
|
+
@browser.clear_prompt_text
|
197
208
|
else
|
198
|
-
browser.set_prompt_text_to(value)
|
209
|
+
@browser.set_prompt_text_to(value)
|
199
210
|
end
|
200
211
|
end
|
201
212
|
|
202
213
|
def go_back
|
203
|
-
browser.go_back
|
214
|
+
@browser.go_back
|
204
215
|
end
|
205
216
|
|
206
217
|
def go_forward
|
207
|
-
browser.go_forward
|
218
|
+
@browser.go_forward
|
208
219
|
end
|
209
220
|
|
210
221
|
def accept_modal(type, options={})
|
@@ -212,11 +223,11 @@ module Capybara::Webkit
|
|
212
223
|
|
213
224
|
case type
|
214
225
|
when :confirm
|
215
|
-
id = browser.accept_confirm(options)
|
226
|
+
id = @browser.accept_confirm(options)
|
216
227
|
when :prompt
|
217
|
-
id = browser.accept_prompt(options)
|
228
|
+
id = @browser.accept_prompt(options)
|
218
229
|
else
|
219
|
-
id = browser.accept_alert(options)
|
230
|
+
id = @browser.accept_alert(options)
|
220
231
|
end
|
221
232
|
|
222
233
|
yield
|
@@ -229,9 +240,9 @@ module Capybara::Webkit
|
|
229
240
|
|
230
241
|
case type
|
231
242
|
when :confirm
|
232
|
-
id = browser.reject_confirm(options)
|
243
|
+
id = @browser.reject_confirm(options)
|
233
244
|
else
|
234
|
-
id = browser.reject_prompt(options)
|
245
|
+
id = @browser.reject_prompt(options)
|
235
246
|
end
|
236
247
|
|
237
248
|
yield
|
@@ -248,7 +259,8 @@ module Capybara::Webkit
|
|
248
259
|
end
|
249
260
|
|
250
261
|
def reset!
|
251
|
-
browser.reset!
|
262
|
+
@browser.reset!
|
263
|
+
apply_options
|
252
264
|
end
|
253
265
|
|
254
266
|
def has_shortcircuit_timeout?
|
@@ -259,11 +271,19 @@ module Capybara::Webkit
|
|
259
271
|
options[:width] ||= 1000
|
260
272
|
options[:height] ||= 10
|
261
273
|
|
262
|
-
browser.render path, options[:width], options[:height]
|
274
|
+
@browser.render path, options[:width], options[:height]
|
263
275
|
end
|
264
276
|
|
265
277
|
def cookies
|
266
|
-
@cookie_jar ||= CookieJar.new(browser)
|
278
|
+
@cookie_jar ||= CookieJar.new(@browser)
|
279
|
+
end
|
280
|
+
|
281
|
+
def set_cookie(cookie)
|
282
|
+
@browser.set_cookie(cookie)
|
283
|
+
end
|
284
|
+
|
285
|
+
def clear_cookies
|
286
|
+
@browser.clear_cookies
|
267
287
|
end
|
268
288
|
|
269
289
|
def invalid_element_errors
|
@@ -278,10 +298,32 @@ module Capybara::Webkit
|
|
278
298
|
[
|
279
299
|
"Capybara: #{Capybara::VERSION}",
|
280
300
|
"capybara-webkit: #{Capybara::Driver::Webkit::VERSION}",
|
281
|
-
browser.version
|
301
|
+
@browser.version
|
282
302
|
].join("\n")
|
283
303
|
end
|
284
304
|
|
305
|
+
def authenticate(username, password)
|
306
|
+
@browser.authenticate(username, password)
|
307
|
+
end
|
308
|
+
|
309
|
+
def timeout
|
310
|
+
deprecate_and_replace_with_config "timeout"
|
311
|
+
@browser.timeout
|
312
|
+
end
|
313
|
+
|
314
|
+
def timeout=(timeout)
|
315
|
+
deprecate_and_replace_with_config(
|
316
|
+
"timeout=",
|
317
|
+
"timeout = #{timeout.inspect}"
|
318
|
+
)
|
319
|
+
@browser.timeout = timeout
|
320
|
+
end
|
321
|
+
|
322
|
+
def browser
|
323
|
+
warn "[DEPRECATION] Capybara::Webkit::Driver#browser is deprecated."
|
324
|
+
@browser
|
325
|
+
end
|
326
|
+
|
285
327
|
private
|
286
328
|
|
287
329
|
def modal_action_options_for_browser(options)
|
@@ -294,7 +336,7 @@ module Capybara::Webkit
|
|
294
336
|
|
295
337
|
def find_modal(type, id, options)
|
296
338
|
Timeout::timeout(options[:wait] || Capybara.default_wait_time) do
|
297
|
-
browser.find_modal(id)
|
339
|
+
@browser.find_modal(id)
|
298
340
|
end
|
299
341
|
rescue ModalNotFound
|
300
342
|
raise Capybara::ModalNotFound,
|
@@ -303,5 +345,44 @@ module Capybara::Webkit
|
|
303
345
|
raise Capybara::ModalNotFound,
|
304
346
|
"Timed out waiting for modal dialog#{" with #{options[:original_text]}" if options[:original_text]}"
|
305
347
|
end
|
348
|
+
|
349
|
+
def apply_options
|
350
|
+
if @options[:debug]
|
351
|
+
@browser.enable_logging
|
352
|
+
end
|
353
|
+
|
354
|
+
if @options[:block_unknown_urls]
|
355
|
+
@browser.block_unknown_urls
|
356
|
+
end
|
357
|
+
|
358
|
+
if @options[:ignore_ssl_errors]
|
359
|
+
@browser.ignore_ssl_errors
|
360
|
+
end
|
361
|
+
|
362
|
+
if @options[:skip_image_loading]
|
363
|
+
@browser.set_skip_image_loading(true)
|
364
|
+
end
|
365
|
+
|
366
|
+
if @options[:proxy]
|
367
|
+
@browser.set_proxy(@options[:proxy])
|
368
|
+
end
|
369
|
+
|
370
|
+
if @options[:timeout]
|
371
|
+
@browser.timeout = @options[:timeout]
|
372
|
+
end
|
373
|
+
|
374
|
+
Array(@options[:allowed_urls]).each { |url| @browser.allow_url(url) }
|
375
|
+
Array(@options[:blocked_urls]).each { |url| @browser.block_url(url) }
|
376
|
+
end
|
377
|
+
|
378
|
+
def deprecate_and_replace_with_config(deprecated_method, config_syntax = deprecated_method)
|
379
|
+
warn "[DEPRECATION] #{deprecated_method} is deprecated. " \
|
380
|
+
"Please use Capybara::Webkit.configure instead:\n\n" \
|
381
|
+
" Capybara::Webkit.configure do |config|\n" \
|
382
|
+
" config.#{config_syntax}\n" \
|
383
|
+
" end\n\n" \
|
384
|
+
"This option is global and can be configured once" \
|
385
|
+
" (not in a `before` or `setup` block)."
|
386
|
+
end
|
306
387
|
end
|
307
388
|
end
|