apparition 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/capybara/apparition/browser.rb +41 -48
- data/lib/capybara/apparition/chrome_client.rb +52 -55
- data/lib/capybara/apparition/dev_tools_protocol/session.rb +2 -2
- data/lib/capybara/apparition/dev_tools_protocol/target.rb +1 -1
- data/lib/capybara/apparition/driver.rb +29 -135
- data/lib/capybara/apparition/keyboard.rb +44 -43
- data/lib/capybara/apparition/launcher.rb +35 -36
- data/lib/capybara/apparition/mouse.rb +25 -21
- data/lib/capybara/apparition/node.rb +279 -309
- data/lib/capybara/apparition/node/drag.rb +148 -0
- data/lib/capybara/apparition/page.rb +64 -30
- data/lib/capybara/apparition/response.rb +41 -0
- data/lib/capybara/apparition/version.rb +1 -1
- metadata +5 -4
- data/lib/capybara/apparition/command.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e8fee05c8a55aecbed96ec2f5f1c7d36ffdea00488281be36fe4e6ac85ab9a4
|
4
|
+
data.tar.gz: 781e519f382127f2dfd6be4bda8a0b674d185bfdc8d1072962c5136cae773a1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96e43542fe127e373cb1f5167c4023922e4a0428b11fa11c13797e1dec0f304fad8ae6422e1c887891317d064905a1a54174c4696d989ad2741a18e6c278e901
|
7
|
+
data.tar.gz: 2667120038d46b9fc874f8009c9820fc6fee86e6a02e753ffcbd16c60398928bb1f1b8ad2cdbf2640d883de94920e2d569e6e127b433866c39809cc712cb34bd
|
data/README.md
CHANGED
@@ -172,6 +172,7 @@ end
|
|
172
172
|
the browser. Useful for faking or mocking APIs.
|
173
173
|
* `:url_blacklist` (Array) - Default session url blacklist - expressed as an array of strings to match against requested URLs.
|
174
174
|
* `:url_whitelist` (Array) - Default session url whitelist - expressed as an array of strings to match against requested URLs.
|
175
|
+
* `:ignore_https_errors` (Boolean) - Ignore certificate errors when connecting to https URLs.
|
175
176
|
* `:browser_options` (Hash) - Extra command line options to pass to Chrome when starting
|
176
177
|
|
177
178
|
### URL Blacklisting & Whitelisting ###
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'capybara/apparition/errors'
|
4
|
-
require 'capybara/apparition/command'
|
5
4
|
require 'capybara/apparition/dev_tools_protocol/target_manager'
|
6
5
|
require 'capybara/apparition/page'
|
7
6
|
require 'json'
|
@@ -9,7 +8,7 @@ require 'time'
|
|
9
8
|
|
10
9
|
module Capybara::Apparition
|
11
10
|
class Browser
|
12
|
-
attr_reader :client, :logger, :paper_size
|
11
|
+
attr_reader :client, :logger, :paper_size, :zoom_factor
|
13
12
|
|
14
13
|
def initialize(client, logger = nil)
|
15
14
|
@client = client
|
@@ -18,6 +17,7 @@ module Capybara::Apparition
|
|
18
17
|
@targets = Capybara::Apparition::DevToolsProtocol::TargetManager.new
|
19
18
|
@context_id = nil
|
20
19
|
@js_errors = true
|
20
|
+
@ignore_https_errors = false
|
21
21
|
|
22
22
|
initialize_handlers
|
23
23
|
|
@@ -34,7 +34,9 @@ module Capybara::Apparition
|
|
34
34
|
|
35
35
|
self.debug = @debug if defined?(@debug)
|
36
36
|
self.js_errors = @js_errors if defined?(@js_errors)
|
37
|
+
self.zoom_factor = @zoom_factor if defined?(@zoom_factor)
|
37
38
|
self.extensions = @extensions if @extensions
|
39
|
+
current_page.clear_network_traffic
|
38
40
|
end
|
39
41
|
|
40
42
|
def visit(url)
|
@@ -130,9 +132,8 @@ module Capybara::Apparition
|
|
130
132
|
end
|
131
133
|
|
132
134
|
def close_window(handle)
|
133
|
-
@targets.delete(handle)
|
134
135
|
@current_page_handle = nil if @current_page_handle == handle
|
135
|
-
|
136
|
+
@targets.delete(handle).close
|
136
137
|
end
|
137
138
|
|
138
139
|
def within_window(locator)
|
@@ -150,9 +151,9 @@ module Capybara::Apparition
|
|
150
151
|
@context_id = command('Target.createBrowserContext')['browserContextId']
|
151
152
|
target_id = command('Target.createTarget', url: 'about:blank', browserContextId: @context_id)['targetId']
|
152
153
|
|
153
|
-
|
154
|
+
timer = Capybara::Helpers.timer(expire_in: 5)
|
154
155
|
until @targets.get(target_id)&.page&.usable?
|
155
|
-
if
|
156
|
+
if timer.expired?
|
156
157
|
puts 'Timedout waiting for reset'
|
157
158
|
# byebug
|
158
159
|
raise TimeoutError.new('reset')
|
@@ -168,26 +169,26 @@ module Capybara::Apparition
|
|
168
169
|
end
|
169
170
|
|
170
171
|
def render(path, options = {})
|
171
|
-
options
|
172
|
-
check_render_options!(options)
|
173
|
-
options[:full] = !!options[:full]
|
172
|
+
check_render_options!(options, path)
|
174
173
|
img_data = current_page.render(options)
|
175
174
|
File.open(path, 'wb') { |f| f.write(Base64.decode64(img_data)) }
|
176
175
|
end
|
177
176
|
|
178
|
-
def render_base64(
|
177
|
+
def render_base64(options = {})
|
179
178
|
check_render_options!(options)
|
180
|
-
options[:full] = !!options[:full]
|
181
179
|
current_page.render(options)
|
182
180
|
end
|
183
181
|
|
184
|
-
|
185
|
-
# TODO: implement if needed
|
186
|
-
# command 'set_zoom_factor', zoom_factor
|
187
|
-
# end
|
182
|
+
attr_writer :zoom_factor
|
188
183
|
|
189
|
-
def
|
190
|
-
@paper_size = size
|
184
|
+
def paper_size=(size)
|
185
|
+
@paper_size = if size.is_a? Hash
|
186
|
+
size
|
187
|
+
else
|
188
|
+
PAPER_SIZES.fetch(size) do
|
189
|
+
raise_errors ArgumentError, "Unknwon paper size: #{size}"
|
190
|
+
end
|
191
|
+
end
|
191
192
|
end
|
192
193
|
|
193
194
|
def resize(width, height, screen: nil)
|
@@ -223,18 +224,13 @@ module Capybara::Apparition
|
|
223
224
|
# command('set_proxy', *args)
|
224
225
|
end
|
225
226
|
|
226
|
-
def
|
227
|
-
# TODO: Implement if still needed
|
228
|
-
# command('equals', page_id, id, other_id)
|
229
|
-
end
|
230
|
-
|
231
|
-
def get_headers
|
227
|
+
def headers
|
232
228
|
current_page.extra_headers
|
233
229
|
end
|
234
230
|
|
235
|
-
def
|
231
|
+
def headers=(headers)
|
236
232
|
@targets.pages.each do |page|
|
237
|
-
page.perm_headers = headers
|
233
|
+
page.perm_headers = headers.dup
|
238
234
|
page.temp_headers = {}
|
239
235
|
page.temp_no_redirect_headers = {}
|
240
236
|
page.update_headers
|
@@ -301,7 +297,7 @@ module Capybara::Apparition
|
|
301
297
|
end
|
302
298
|
end
|
303
299
|
|
304
|
-
attr_accessor :js_errors
|
300
|
+
attr_accessor :js_errors, :ignore_https_errors
|
305
301
|
|
306
302
|
def extensions=(filenames)
|
307
303
|
@extensions = filenames
|
@@ -329,26 +325,17 @@ module Capybara::Apparition
|
|
329
325
|
end
|
330
326
|
|
331
327
|
def command(name, params = {})
|
332
|
-
|
333
|
-
log
|
334
|
-
|
335
|
-
response = client.send_cmd(name, params, async: false)
|
336
|
-
log response
|
328
|
+
result = client.send_cmd(name, params).result
|
329
|
+
log result
|
337
330
|
|
338
|
-
|
331
|
+
result || raise(Capybara::Apparition::ObsoleteNode.new(nil, nil))
|
339
332
|
rescue DeadClient
|
340
333
|
restart
|
341
334
|
raise
|
342
335
|
end
|
343
336
|
|
344
|
-
def command_for_session(session_id, name, params
|
345
|
-
|
346
|
-
log cmd.message
|
347
|
-
|
348
|
-
response = client.send_cmd_to_session(session_id, name, params, async: async)
|
349
|
-
log response
|
350
|
-
|
351
|
-
response
|
337
|
+
def command_for_session(session_id, name, params)
|
338
|
+
client.send_cmd_to_session(session_id, name, params)
|
352
339
|
rescue DeadClient
|
353
340
|
restart
|
354
341
|
raise
|
@@ -378,16 +365,10 @@ module Capybara::Apparition
|
|
378
365
|
current_page.add_modal(confirm: false)
|
379
366
|
end
|
380
367
|
|
381
|
-
#
|
382
|
-
# press "OK" with text (response) or default value
|
383
|
-
#
|
384
368
|
def accept_prompt(response)
|
385
369
|
current_page.add_modal(prompt: response)
|
386
370
|
end
|
387
371
|
|
388
|
-
#
|
389
|
-
# press "Cancel"
|
390
|
-
#
|
391
372
|
def dismiss_prompt
|
392
373
|
current_page.add_modal(prompt: false)
|
393
374
|
end
|
@@ -411,11 +392,13 @@ module Capybara::Apparition
|
|
411
392
|
end
|
412
393
|
|
413
394
|
def log(message)
|
414
|
-
logger&.puts message
|
395
|
+
logger&.puts message if ENV['DEBUG']
|
415
396
|
end
|
416
397
|
|
417
|
-
def check_render_options!(options)
|
398
|
+
def check_render_options!(options, path = nil)
|
399
|
+
options[:format] ||= File.extname(path).downcase[1..-1] if path
|
418
400
|
options[:format] = :jpeg if options[:format].to_s == 'jpg'
|
401
|
+
options[:full] = !!options[:full]
|
419
402
|
return unless options[:full] && options.key?(:selector)
|
420
403
|
|
421
404
|
warn "Ignoring :selector in #render since :full => true was given at #{caller(1..1)}"
|
@@ -528,5 +511,15 @@ module Capybara::Apparition
|
|
528
511
|
end
|
529
512
|
end
|
530
513
|
end
|
514
|
+
|
515
|
+
PAPER_SIZES = {
|
516
|
+
'A3' => { width: 11.69, height: 16.53 },
|
517
|
+
'A4' => { width: 8.27, height: 11.69 },
|
518
|
+
'A5' => { width: 5.83, height: 8.27 },
|
519
|
+
'Legal' => { width: 8.5, height: 14 },
|
520
|
+
'Letter' => { width: 8.5, height: 11 },
|
521
|
+
'Tabloid' => { width: 11, height: 17 },
|
522
|
+
'Ledger' => { width: 17, height: 11 }
|
523
|
+
}.freeze
|
531
524
|
end
|
532
525
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'capybara/apparition/errors'
|
4
4
|
require 'capybara/apparition/web_socket_client'
|
5
|
+
require 'capybara/apparition/response'
|
5
6
|
|
6
7
|
module Capybara::Apparition
|
7
8
|
class ChromeClient
|
@@ -58,68 +59,57 @@ module Capybara::Apparition
|
|
58
59
|
@session_handlers[session_id][event_name] << block
|
59
60
|
end
|
60
61
|
|
61
|
-
def send_cmd(command, params
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
@ws.send_msg(msg)
|
66
|
-
end
|
67
|
-
|
68
|
-
return nil if async
|
69
|
-
|
70
|
-
puts "waiting for session response for message #{msg_id}" if ENV['DEUG']
|
71
|
-
response = wait_for_msg_response(msg_id)
|
72
|
-
|
73
|
-
raise CDPError(response['error']) if response['error']
|
74
|
-
|
75
|
-
response['result']
|
62
|
+
def send_cmd(command, params)
|
63
|
+
time = Time.now
|
64
|
+
msg_id = send_msg(command, params)
|
65
|
+
Response.new(self, msg_id, send_time: time)
|
76
66
|
end
|
77
67
|
|
78
|
-
def send_cmd_to_session(session_id, command, params
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
puts "waiting for session response for message #{msg_id}" if ENV['DEBUG'] == 'V'
|
86
|
-
response = wait_for_msg_response(msg_id)
|
68
|
+
def send_cmd_to_session(session_id, command, params)
|
69
|
+
time = Time.now
|
70
|
+
msg_id, msg = generate_msg(command, params)
|
71
|
+
wrapper_msg_id = send_msg('Target.sendMessageToTarget', sessionId: session_id, message: msg)
|
72
|
+
Response.new(self, wrapper_msg_id, msg_id, send_time: time)
|
73
|
+
end
|
87
74
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
raise WrongWorld.new(nil, error)
|
92
|
-
else
|
93
|
-
raise CDPError.new(error)
|
94
|
-
end
|
75
|
+
def add_async_id(msg_id)
|
76
|
+
@msg_mutex.synchronize do
|
77
|
+
@async_ids.push(msg_id)
|
95
78
|
end
|
96
|
-
|
97
|
-
response['result']
|
98
79
|
end
|
99
80
|
|
100
|
-
|
101
|
-
read_until { yield }
|
102
|
-
end
|
81
|
+
private
|
103
82
|
|
104
|
-
def
|
105
|
-
|
83
|
+
def handle_error(error)
|
84
|
+
case error['code']
|
85
|
+
when -32_000
|
86
|
+
raise WrongWorld.new(nil, error)
|
87
|
+
else
|
88
|
+
raise CDPError.new(error)
|
89
|
+
end
|
106
90
|
end
|
107
91
|
|
108
|
-
|
92
|
+
def send_msg(command, params)
|
93
|
+
msg_id, msg = generate_msg(command, params)
|
94
|
+
@send_mutex.synchronize do
|
95
|
+
puts "#{Time.now.to_i}: sending msg: #{msg}" if ENV['DEBUG']
|
96
|
+
@ws.send_msg(msg)
|
97
|
+
end
|
98
|
+
msg_id
|
99
|
+
end
|
109
100
|
|
110
|
-
def generate_msg(command, params
|
101
|
+
def generate_msg(command, params)
|
111
102
|
@send_mutex.synchronize do
|
112
103
|
msg_id = generate_unique_id
|
113
|
-
@async_ids.push(msg_id) if async
|
114
104
|
[msg_id, { method: command, params: params, id: msg_id }.to_json]
|
115
105
|
end
|
116
106
|
end
|
117
107
|
|
118
108
|
def wait_for_msg_response(msg_id)
|
119
109
|
@msg_mutex.synchronize do
|
120
|
-
|
110
|
+
timer = Capybara::Helpers.timer(expire_in: @timeout)
|
121
111
|
while (response = @responses.delete(msg_id)).nil?
|
122
|
-
if @timeout &&
|
112
|
+
if @timeout && timer.expired?
|
123
113
|
puts "Timedout waiting for response for msg: #{msg_id}"
|
124
114
|
raise TimeoutError.new(msg_id)
|
125
115
|
end
|
@@ -141,6 +131,14 @@ module Capybara::Apparition
|
|
141
131
|
end
|
142
132
|
end
|
143
133
|
|
134
|
+
def listen_until
|
135
|
+
read_until { yield }
|
136
|
+
end
|
137
|
+
|
138
|
+
def listen
|
139
|
+
read_until { false }
|
140
|
+
end
|
141
|
+
|
144
142
|
def read_msg
|
145
143
|
msg = JSON.parse(@ws.read_msg)
|
146
144
|
puts "#{Time.now.to_i}: got msg: #{msg}" if ENV['DEBUG']
|
@@ -179,24 +177,15 @@ module Capybara::Apparition
|
|
179
177
|
next unless event
|
180
178
|
|
181
179
|
event_name = event['method']
|
182
|
-
puts "
|
180
|
+
puts "Popped event #{event_name}" if ENV['DEBUG'] == 'V'
|
183
181
|
|
184
182
|
if event_name == 'Target.receivedMessageFromTarget'
|
185
183
|
session_id = event.dig('params', 'sessionId')
|
186
184
|
event = JSON.parse(event.dig('params', 'message'))
|
187
|
-
|
188
|
-
if event_name
|
189
|
-
puts "calling session handler for #{event_name}" if ENV['DEBUG'] == 'V'
|
190
|
-
@session_handlers[session_id][event_name].each do |handler|
|
191
|
-
handler.call(event['params'])
|
192
|
-
end
|
193
|
-
end
|
185
|
+
process_handlers(@session_handlers[session_id], event)
|
194
186
|
end
|
195
187
|
|
196
|
-
@handlers
|
197
|
-
puts "calling handler for #{event_name}" if ENV['DEBUG'] == 'V'
|
198
|
-
handler.call(event['params'])
|
199
|
-
end
|
188
|
+
process_handlers(@handlers, event)
|
200
189
|
end
|
201
190
|
rescue CDPError => e
|
202
191
|
if e.code == -32_602
|
@@ -213,6 +202,14 @@ module Capybara::Apparition
|
|
213
202
|
retry
|
214
203
|
end
|
215
204
|
|
205
|
+
def process_handlers(handlers, event)
|
206
|
+
event_name = event['method']
|
207
|
+
handlers[event_name].each do |handler|
|
208
|
+
puts "Calling handler for #{event_name}" if ENV['DEBUG'] == 'V'
|
209
|
+
handler.call(event['params'])
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
216
213
|
def start_threads
|
217
214
|
@processor = Thread.new do
|
218
215
|
process_messages
|
@@ -14,11 +14,11 @@ module Capybara::Apparition
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def command(name, **params)
|
17
|
-
@browser.command_for_session(@session_id, name, params
|
17
|
+
@browser.command_for_session(@session_id, name, params).result
|
18
18
|
end
|
19
19
|
|
20
20
|
def async_command(name, **params)
|
21
|
-
@browser.command_for_session(@session_id, name, params
|
21
|
+
@browser.command_for_session(@session_id, name, params).discard_result
|
22
22
|
end
|
23
23
|
|
24
24
|
def on(event_name, &block)
|
@@ -29,7 +29,7 @@ module Capybara::Apparition
|
|
29
29
|
@page ||= begin
|
30
30
|
if info['type'] == 'page'
|
31
31
|
Page.create(@browser, create_session, id,
|
32
|
-
ignore_https_errors:
|
32
|
+
ignore_https_errors: @browser.ignore_https_errors,
|
33
33
|
js_errors: @browser.js_errors).inherit(info.delete('inherit'))
|
34
34
|
else
|
35
35
|
nil
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'uri'
|
4
|
+
require 'forwardable'
|
4
5
|
require 'capybara/apparition/chrome_client'
|
5
6
|
require 'capybara/apparition/launcher'
|
6
7
|
|
@@ -8,8 +9,21 @@ module Capybara::Apparition
|
|
8
9
|
class Driver < Capybara::Driver::Base
|
9
10
|
DEFAULT_TIMEOUT = 30
|
10
11
|
|
12
|
+
extend Forwardable
|
13
|
+
|
11
14
|
attr_reader :app, :options
|
12
15
|
|
16
|
+
delegate %i[restart current_url status_code body
|
17
|
+
title frame_title frame_url switch_to_frame
|
18
|
+
window_handles close_window open_new_window switch_to_window within_window
|
19
|
+
paper_size= zoom_factor=
|
20
|
+
scroll_to
|
21
|
+
network_traffic clear_network_traffic
|
22
|
+
headers headers= add_headers
|
23
|
+
cookies remove_cookie clear_cookies cookies_enabled=
|
24
|
+
clear_memory_cache
|
25
|
+
go_back go_forward refresh] => :browser
|
26
|
+
|
13
27
|
def initialize(app, options = {})
|
14
28
|
@app = app
|
15
29
|
@options = options
|
@@ -30,7 +44,8 @@ module Capybara::Apparition
|
|
30
44
|
def browser
|
31
45
|
@browser ||= begin
|
32
46
|
browser = Browser.new(client, browser_logger)
|
33
|
-
browser.js_errors
|
47
|
+
browser.js_errors = options[:js_errors] if options.key?(:js_errors)
|
48
|
+
browser.ignore_https_errors = options[:ignore_https_errors] if options.key?(:ignore_https_errors)
|
34
49
|
browser.extensions = options.fetch(:extensions, [])
|
35
50
|
browser.debug = true if options[:debug]
|
36
51
|
browser.url_blacklist = options[:url_blacklist] || []
|
@@ -52,17 +67,14 @@ module Capybara::Apparition
|
|
52
67
|
@launcher ||= Browser::Launcher.start(
|
53
68
|
headless: options[:headless] != false,
|
54
69
|
browser: browser_options
|
55
|
-
|
70
|
+
)
|
56
71
|
ws_url = @launcher.ws_url
|
57
|
-
|
58
|
-
sleep 3
|
59
|
-
client
|
72
|
+
::Capybara::Apparition::ChromeClient.client(ws_url.to_s)
|
60
73
|
end
|
61
74
|
end
|
62
75
|
|
63
76
|
def browser_options
|
64
77
|
list = options[:browser_options] || []
|
65
|
-
|
66
78
|
# TODO: configure SSL options
|
67
79
|
# PhantomJS defaults to only using SSLv3, which since POODLE (Oct 2014)
|
68
80
|
# many sites have dropped from their supported protocols (eg PayPal,
|
@@ -70,13 +82,10 @@ module Capybara::Apparition
|
|
70
82
|
# list += ["--ignore-ssl-errors=yes"] unless list.grep(/ignore-ssl-errors/).any?
|
71
83
|
# list += ["--ssl-protocol=TLSv1"] unless list.grep(/ssl-protocol/).any?
|
72
84
|
# list += ["--remote-debugger-port=#{inspector.port}", "--remote-debugger-autorun=yes"] if inspector
|
85
|
+
# Note: Need to verify what Chrome command line options are valid for this
|
73
86
|
list
|
74
87
|
end
|
75
88
|
|
76
|
-
def restart
|
77
|
-
browser.restart
|
78
|
-
end
|
79
|
-
|
80
89
|
def quit
|
81
90
|
@client&.stop
|
82
91
|
@launcher&.stop
|
@@ -89,7 +98,7 @@ module Capybara::Apparition
|
|
89
98
|
|
90
99
|
# logger should be an object that behaves like IO or nil
|
91
100
|
def browser_logger
|
92
|
-
options.fetch(:browser_logger,
|
101
|
+
options.fetch(:browser_logger, $stdout)
|
93
102
|
end
|
94
103
|
|
95
104
|
def visit(url)
|
@@ -97,35 +106,12 @@ module Capybara::Apparition
|
|
97
106
|
browser.visit(url)
|
98
107
|
end
|
99
108
|
|
100
|
-
|
101
|
-
browser.current_url
|
102
|
-
end
|
103
|
-
|
104
|
-
def status_code
|
105
|
-
browser.status_code
|
106
|
-
end
|
107
|
-
|
108
|
-
def html
|
109
|
-
browser.body
|
110
|
-
end
|
111
|
-
alias body html
|
109
|
+
alias html body
|
112
110
|
|
113
111
|
def source
|
114
112
|
browser.source.to_s
|
115
113
|
end
|
116
114
|
|
117
|
-
def title
|
118
|
-
browser.title
|
119
|
-
end
|
120
|
-
|
121
|
-
def frame_title
|
122
|
-
browser.frame_title
|
123
|
-
end
|
124
|
-
|
125
|
-
def frame_url
|
126
|
-
browser.frame_url
|
127
|
-
end
|
128
|
-
|
129
115
|
def find(method, selector)
|
130
116
|
browser.find(method, selector).map { |page_id, id| Capybara::Apparition::Node.new(self, page_id, id) }
|
131
117
|
end
|
@@ -143,13 +129,11 @@ module Capybara::Apparition
|
|
143
129
|
end
|
144
130
|
|
145
131
|
def evaluate_script(script, *args)
|
146
|
-
|
147
|
-
unwrap_script_result(result)
|
132
|
+
unwrap_script_result(browser.evaluate(script, *native_args(args)))
|
148
133
|
end
|
149
134
|
|
150
135
|
def evaluate_async_script(script, *args)
|
151
|
-
|
152
|
-
unwrap_script_result(result)
|
136
|
+
unwrap_script_result(browser.evaluate_async(script, session_wait_time, *native_args(args)))
|
153
137
|
end
|
154
138
|
|
155
139
|
def execute_script(script, *args)
|
@@ -157,43 +141,18 @@ module Capybara::Apparition
|
|
157
141
|
nil
|
158
142
|
end
|
159
143
|
|
160
|
-
def switch_to_frame(frame)
|
161
|
-
browser.switch_to_frame(frame)
|
162
|
-
end
|
163
|
-
|
164
144
|
def current_window_handle
|
165
145
|
browser.window_handle
|
166
146
|
end
|
167
147
|
|
168
|
-
def window_handles
|
169
|
-
browser.window_handles
|
170
|
-
end
|
171
|
-
|
172
|
-
def close_window(handle)
|
173
|
-
browser.close_window(handle)
|
174
|
-
end
|
175
|
-
|
176
|
-
def open_new_window
|
177
|
-
browser.open_new_window
|
178
|
-
end
|
179
|
-
|
180
|
-
def switch_to_window(handle)
|
181
|
-
browser.switch_to_window(handle)
|
182
|
-
end
|
183
|
-
|
184
|
-
def within_window(name, &block)
|
185
|
-
browser.within_window(name, &block)
|
186
|
-
end
|
187
|
-
|
188
148
|
def no_such_window_error
|
189
149
|
NoSuchWindowError
|
190
150
|
end
|
191
151
|
|
192
152
|
def reset!
|
193
153
|
browser.reset
|
194
|
-
|
195
|
-
|
196
|
-
# browser.url_whitelist = options[:url_whitelist] || []
|
154
|
+
browser.url_blacklist = options[:url_blacklist] || []
|
155
|
+
browser.url_whitelist = options[:url_whitelist] || []
|
197
156
|
@started = false
|
198
157
|
end
|
199
158
|
|
@@ -203,18 +162,9 @@ module Capybara::Apparition
|
|
203
162
|
alias render save_screenshot
|
204
163
|
|
205
164
|
def render_base64(format = :png, options = {})
|
206
|
-
browser.render_base64(format
|
207
|
-
end
|
208
|
-
|
209
|
-
def paper_size=(size = {})
|
210
|
-
browser.set_paper_size(size)
|
165
|
+
browser.render_base64(options.merge(format: format))
|
211
166
|
end
|
212
167
|
|
213
|
-
# def zoom_factor=(zoom_factor)
|
214
|
-
# TODO: Implement if still necessary
|
215
|
-
# browser.set_zoom_factor(zoom_factor)
|
216
|
-
# end
|
217
|
-
|
218
168
|
def resize(width, height)
|
219
169
|
browser.resize(width, height, screen: options[:screen_size])
|
220
170
|
end
|
@@ -244,34 +194,10 @@ module Capybara::Apparition
|
|
244
194
|
end
|
245
195
|
end
|
246
196
|
|
247
|
-
def scroll_to(left, top)
|
248
|
-
browser.scroll_to(left, top)
|
249
|
-
end
|
250
|
-
|
251
|
-
def network_traffic(type = nil)
|
252
|
-
browser.network_traffic(type)
|
253
|
-
end
|
254
|
-
|
255
|
-
def clear_network_traffic
|
256
|
-
browser.clear_network_traffic
|
257
|
-
end
|
258
|
-
|
259
197
|
def set_proxy(ip, port, type = 'http', user = nil, password = nil)
|
260
198
|
browser.set_proxy(ip, port, type, user, password)
|
261
199
|
end
|
262
200
|
|
263
|
-
def headers
|
264
|
-
browser.get_headers
|
265
|
-
end
|
266
|
-
|
267
|
-
def headers=(headers)
|
268
|
-
browser.set_headers(headers)
|
269
|
-
end
|
270
|
-
|
271
|
-
def add_headers(headers)
|
272
|
-
browser.add_headers(headers)
|
273
|
-
end
|
274
|
-
|
275
201
|
def add_header(name, value, options = {})
|
276
202
|
browser.add_header({ name => value }, { permanent: true }.merge(options))
|
277
203
|
end
|
@@ -282,10 +208,6 @@ module Capybara::Apparition
|
|
282
208
|
end
|
283
209
|
end
|
284
210
|
|
285
|
-
def cookies
|
286
|
-
browser.cookies
|
287
|
-
end
|
288
|
-
|
289
211
|
def set_cookie(name, value, options = {})
|
290
212
|
options[:name] ||= name
|
291
213
|
options[:value] ||= value
|
@@ -300,22 +222,6 @@ module Capybara::Apparition
|
|
300
222
|
browser.set_cookie(options)
|
301
223
|
end
|
302
224
|
|
303
|
-
def remove_cookie(name)
|
304
|
-
browser.remove_cookie(name)
|
305
|
-
end
|
306
|
-
|
307
|
-
def clear_cookies
|
308
|
-
browser.clear_cookies
|
309
|
-
end
|
310
|
-
|
311
|
-
def cookies_enabled=(flag)
|
312
|
-
browser.cookies_enabled = flag
|
313
|
-
end
|
314
|
-
|
315
|
-
def clear_memory_cache
|
316
|
-
browser.clear_memory_cache
|
317
|
-
end
|
318
|
-
|
319
225
|
def basic_authorize(user = nil, password = nil)
|
320
226
|
browser.set_http_auth(user, password)
|
321
227
|
# credentials = ["#{user}:#{password}"].pack('m*').strip
|
@@ -383,18 +289,6 @@ module Capybara::Apparition
|
|
383
289
|
[Capybara::Apparition::ObsoleteNode, Capybara::Apparition::MouseEventFailed]
|
384
290
|
end
|
385
291
|
|
386
|
-
def go_back
|
387
|
-
browser.go_back
|
388
|
-
end
|
389
|
-
|
390
|
-
def go_forward
|
391
|
-
browser.go_forward
|
392
|
-
end
|
393
|
-
|
394
|
-
def refresh
|
395
|
-
browser.refresh
|
396
|
-
end
|
397
|
-
|
398
292
|
def accept_modal(type, options = {})
|
399
293
|
case type
|
400
294
|
when :alert
|
@@ -437,21 +331,21 @@ module Capybara::Apparition
|
|
437
331
|
end
|
438
332
|
|
439
333
|
def find_modal(options)
|
440
|
-
start_time = Time.now
|
441
334
|
timeout_sec = options.fetch(:wait) { session_wait_time }
|
442
335
|
expect_text = options[:text]
|
443
336
|
expect_regexp = expect_text.is_a?(Regexp) ? expect_text : Regexp.escape(expect_text.to_s)
|
337
|
+
timer = Capybara::Helpers.timer(expire_in: timeout_sec)
|
444
338
|
begin
|
445
339
|
modal_text = browser.modal_message
|
446
340
|
found_text ||= modal_text
|
447
341
|
raise Capybara::ModalNotFound if modal_text.nil? || (expect_text && !modal_text.match(expect_regexp))
|
448
342
|
rescue Capybara::ModalNotFound => e
|
449
|
-
if
|
343
|
+
if timer.expired?
|
450
344
|
raise e, 'Unable to find modal dialog'\
|
451
345
|
"#{" with #{expect_text}" if expect_text}"\
|
452
346
|
"#{", did find modal with #{found_text}" if found_text}"
|
453
347
|
end
|
454
|
-
sleep(0.
|
348
|
+
sleep(0.05)
|
455
349
|
retry
|
456
350
|
end
|
457
351
|
modal_text
|