playwright-ruby-client 0.1.0 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -8
- data/docs/api_coverage.md +123 -73
- data/lib/playwright.rb +48 -9
- data/lib/playwright/channel.rb +12 -2
- data/lib/playwright/channel_owner.rb +3 -5
- data/lib/playwright/channel_owners/android.rb +1 -1
- data/lib/playwright/channel_owners/android_device.rb +11 -11
- data/lib/playwright/channel_owners/artifact.rb +30 -0
- data/lib/playwright/channel_owners/binding_call.rb +3 -0
- data/lib/playwright/channel_owners/browser.rb +22 -1
- data/lib/playwright/channel_owners/browser_context.rb +155 -4
- data/lib/playwright/channel_owners/browser_type.rb +28 -0
- data/lib/playwright/channel_owners/dialog.rb +28 -0
- data/lib/playwright/channel_owners/element_handle.rb +18 -5
- data/lib/playwright/channel_owners/frame.rb +40 -5
- data/lib/playwright/channel_owners/js_handle.rb +3 -3
- data/lib/playwright/channel_owners/page.rb +172 -51
- data/lib/playwright/channel_owners/playwright.rb +24 -27
- data/lib/playwright/channel_owners/request.rb +27 -3
- data/lib/playwright/channel_owners/response.rb +60 -0
- data/lib/playwright/channel_owners/route.rb +78 -0
- data/lib/playwright/channel_owners/selectors.rb +19 -1
- data/lib/playwright/channel_owners/stream.rb +15 -0
- data/lib/playwright/connection.rb +11 -32
- data/lib/playwright/download.rb +27 -0
- data/lib/playwright/errors.rb +6 -0
- data/lib/playwright/events.rb +2 -5
- data/lib/playwright/keyboard_impl.rb +1 -1
- data/lib/playwright/mouse_impl.rb +41 -0
- data/lib/playwright/playwright_api.rb +3 -1
- data/lib/playwright/route_handler_entry.rb +28 -0
- data/lib/playwright/select_option_values.rb +14 -4
- data/lib/playwright/transport.rb +28 -7
- data/lib/playwright/url_matcher.rb +1 -1
- data/lib/playwright/utils.rb +11 -2
- data/lib/playwright/version.rb +1 -1
- data/lib/playwright/video.rb +51 -0
- data/lib/playwright/wait_helper.rb +2 -2
- data/lib/playwright_api/accessibility.rb +39 -1
- data/lib/playwright_api/android.rb +72 -5
- data/lib/playwright_api/android_device.rb +139 -26
- data/lib/playwright_api/android_input.rb +17 -13
- data/lib/playwright_api/android_socket.rb +16 -0
- data/lib/playwright_api/android_web_view.rb +21 -0
- data/lib/playwright_api/browser.rb +87 -19
- data/lib/playwright_api/browser_context.rb +216 -32
- data/lib/playwright_api/browser_type.rb +45 -58
- data/lib/playwright_api/dialog.rb +54 -7
- data/lib/playwright_api/element_handle.rb +113 -33
- data/lib/playwright_api/file_chooser.rb +6 -1
- data/lib/playwright_api/frame.rb +238 -43
- data/lib/playwright_api/js_handle.rb +20 -2
- data/lib/playwright_api/keyboard.rb +48 -1
- data/lib/playwright_api/mouse.rb +26 -5
- data/lib/playwright_api/page.rb +534 -63
- data/lib/playwright_api/playwright.rb +43 -47
- data/lib/playwright_api/request.rb +38 -12
- data/lib/playwright_api/response.rb +27 -10
- data/lib/playwright_api/route.rb +51 -6
- data/lib/playwright_api/selectors.rb +28 -2
- data/lib/playwright_api/touchscreen.rb +1 -1
- data/lib/playwright_api/web_socket.rb +15 -0
- data/lib/playwright_api/worker.rb +25 -1
- data/playwright.gemspec +4 -2
- metadata +42 -14
- data/lib/playwright/channel_owners/chromium_browser.rb +0 -8
- data/lib/playwright/channel_owners/chromium_browser_context.rb +0 -8
- data/lib/playwright/channel_owners/download.rb +0 -27
- data/lib/playwright/channel_owners/firefox_browser.rb +0 -8
- data/lib/playwright/channel_owners/webkit_browser.rb +0 -8
- data/lib/playwright_api/binding_call.rb +0 -27
- data/lib/playwright_api/chromium_browser_context.rb +0 -59
- data/lib/playwright_api/download.rb +0 -100
- data/lib/playwright_api/video.rb +0 -24
@@ -136,8 +136,19 @@ module Playwright
|
|
136
136
|
nil
|
137
137
|
end
|
138
138
|
|
139
|
-
def select_option(
|
140
|
-
|
139
|
+
def select_option(
|
140
|
+
element: nil,
|
141
|
+
index: nil,
|
142
|
+
value: nil,
|
143
|
+
label: nil,
|
144
|
+
noWaitAfter: nil,
|
145
|
+
timeout: nil)
|
146
|
+
base_params = SelectOptionValues.new(
|
147
|
+
element: element,
|
148
|
+
index: index,
|
149
|
+
value: value,
|
150
|
+
label: label,
|
151
|
+
).as_params
|
141
152
|
params = base_params + { noWaitAfter: noWaitAfter, timeout: timeout }.compact
|
142
153
|
@channel.send_message_to_server('selectOption', params)
|
143
154
|
|
@@ -168,7 +179,7 @@ module Playwright
|
|
168
179
|
value: value,
|
169
180
|
noWaitAfter: noWaitAfter,
|
170
181
|
timeout: timeout,
|
171
|
-
}
|
182
|
+
}.compact
|
172
183
|
@channel.send_message_to_server('fill', params)
|
173
184
|
|
174
185
|
nil
|
@@ -219,10 +230,11 @@ module Playwright
|
|
219
230
|
nil
|
220
231
|
end
|
221
232
|
|
222
|
-
def check(force: nil, noWaitAfter: nil, timeout: nil)
|
233
|
+
def check(force: nil, noWaitAfter: nil, position: nil, timeout: nil)
|
223
234
|
params = {
|
224
235
|
force: force,
|
225
236
|
noWaitAfter: noWaitAfter,
|
237
|
+
position: position,
|
226
238
|
timeout: timeout,
|
227
239
|
}.compact
|
228
240
|
@channel.send_message_to_server('check', params)
|
@@ -230,10 +242,11 @@ module Playwright
|
|
230
242
|
nil
|
231
243
|
end
|
232
244
|
|
233
|
-
def uncheck(force: nil, noWaitAfter: nil, timeout: nil)
|
245
|
+
def uncheck(force: nil, noWaitAfter: nil, position: nil, timeout: nil)
|
234
246
|
params = {
|
235
247
|
force: force,
|
236
248
|
noWaitAfter: noWaitAfter,
|
249
|
+
position: position,
|
237
250
|
timeout: timeout,
|
238
251
|
}.compact
|
239
252
|
@channel.send_message_to_server('uncheck', params)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Playwright
|
2
2
|
# @ref https://github.com/microsoft/playwright-python/blob/master/playwright/_impl/_frame.py
|
3
3
|
define_channel_owner :Frame do
|
4
|
-
def after_initialize
|
4
|
+
private def after_initialize
|
5
5
|
if @initializer['parentFrame']
|
6
6
|
@parent_frame = ChannelOwners::Frame.from(@initializer['parentFrame'])
|
7
7
|
@parent_frame.send(:append_child_frame_from_child, self)
|
@@ -98,6 +98,15 @@ module Playwright
|
|
98
98
|
request&.response
|
99
99
|
end
|
100
100
|
|
101
|
+
def wait_for_url(url, timeout: nil, waitUntil: nil)
|
102
|
+
matcher = UrlMatcher.new(url)
|
103
|
+
if matcher.match?(@url)
|
104
|
+
wait_for_load_state(state: waitUntil, timeout: timeout)
|
105
|
+
else
|
106
|
+
expect_navigation(timeout: timeout, url: url, waitUntil: waitUntil)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
101
110
|
def wait_for_load_state(state: nil, timeout: nil)
|
102
111
|
option_state = state || 'load'
|
103
112
|
option_timeout = timeout || @page.send(:timeout_settings).navigation_timeout
|
@@ -398,8 +407,20 @@ module Playwright
|
|
398
407
|
nil
|
399
408
|
end
|
400
409
|
|
401
|
-
def select_option(
|
402
|
-
|
410
|
+
def select_option(
|
411
|
+
selector,
|
412
|
+
element: nil,
|
413
|
+
index: nil,
|
414
|
+
value: nil,
|
415
|
+
label: nil,
|
416
|
+
noWaitAfter: nil,
|
417
|
+
timeout: nil)
|
418
|
+
base_params = SelectOptionValues.new(
|
419
|
+
element: element,
|
420
|
+
index: index,
|
421
|
+
value: value,
|
422
|
+
label: label,
|
423
|
+
).as_params
|
403
424
|
params = base_params + { selector: selector, noWaitAfter: noWaitAfter, timeout: timeout }.compact
|
404
425
|
@channel.send_message_to_server('selectOption', params)
|
405
426
|
|
@@ -452,11 +473,18 @@ module Playwright
|
|
452
473
|
nil
|
453
474
|
end
|
454
475
|
|
455
|
-
def check(
|
476
|
+
def check(
|
477
|
+
selector,
|
478
|
+
force: nil,
|
479
|
+
noWaitAfter: nil,
|
480
|
+
position: nil,
|
481
|
+
timeout: nil)
|
482
|
+
|
456
483
|
params = {
|
457
484
|
selector: selector,
|
458
485
|
force: force,
|
459
486
|
noWaitAfter: noWaitAfter,
|
487
|
+
position: position,
|
460
488
|
timeout: timeout,
|
461
489
|
}.compact
|
462
490
|
@channel.send_message_to_server('check', params)
|
@@ -464,11 +492,18 @@ module Playwright
|
|
464
492
|
nil
|
465
493
|
end
|
466
494
|
|
467
|
-
def uncheck(
|
495
|
+
def uncheck(
|
496
|
+
selector,
|
497
|
+
force: nil,
|
498
|
+
noWaitAfter: nil,
|
499
|
+
position: nil,
|
500
|
+
timeout: nil)
|
501
|
+
|
468
502
|
params = {
|
469
503
|
selector: selector,
|
470
504
|
force: force,
|
471
505
|
noWaitAfter: noWaitAfter,
|
506
|
+
position: position,
|
472
507
|
timeout: timeout,
|
473
508
|
}.compact
|
474
509
|
@channel.send_message_to_server('uncheck', params)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Playwright
|
2
2
|
define_channel_owner :JSHandle do
|
3
|
-
def after_initialize
|
3
|
+
private def after_initialize
|
4
4
|
@preview = @initializer['preview']
|
5
5
|
@channel.on('previewUpdated', method(:on_preview_updated))
|
6
6
|
end
|
@@ -9,8 +9,8 @@ module Playwright
|
|
9
9
|
@preview
|
10
10
|
end
|
11
11
|
|
12
|
-
private def on_preview_updated(
|
13
|
-
@preview = preview
|
12
|
+
private def on_preview_updated(params)
|
13
|
+
@preview = params['preview']
|
14
14
|
end
|
15
15
|
|
16
16
|
def evaluate(pageFunction, arg: nil)
|
@@ -6,7 +6,7 @@ module Playwright
|
|
6
6
|
include Utils::Errors::SafeCloseError
|
7
7
|
attr_writer :owned_context
|
8
8
|
|
9
|
-
def after_initialize
|
9
|
+
private def after_initialize
|
10
10
|
@browser_context = @parent
|
11
11
|
@timeout_settings = TimeoutSettings.new(@browser_context.send(:_timeout_settings))
|
12
12
|
@accessibility = Accessibility.new(@channel)
|
@@ -14,12 +14,21 @@ module Playwright
|
|
14
14
|
@mouse = MouseImpl.new(@channel)
|
15
15
|
@touchscreen = TouchscreenImpl.new(@channel)
|
16
16
|
|
17
|
-
|
17
|
+
if @initializer['viewportSize']
|
18
|
+
@viewport_size = {
|
19
|
+
width: @initializer['viewportSize']['width'],
|
20
|
+
height: @initializer['viewportSize']['height'],
|
21
|
+
}
|
22
|
+
end
|
18
23
|
@closed = false
|
24
|
+
@bindings = {}
|
25
|
+
@routes = Set.new
|
26
|
+
|
19
27
|
@main_frame = ChannelOwners::Frame.from(@initializer['mainFrame'])
|
20
28
|
@main_frame.send(:update_page_from_page, self)
|
21
29
|
@frames = Set.new
|
22
30
|
@frames << @main_frame
|
31
|
+
@opener = ChannelOwners::Page.from_nullable(@initializer['opener'])
|
23
32
|
|
24
33
|
@channel.once('close', ->(_) { on_close })
|
25
34
|
@channel.on('console', ->(params) {
|
@@ -29,9 +38,7 @@ module Playwright
|
|
29
38
|
@channel.on('crash', ->(_) { emit(Events::Page::Crash) })
|
30
39
|
@channel.on('dialog', method(:on_dialog))
|
31
40
|
@channel.on('domcontentloaded', ->(_) { emit(Events::Page::DOMContentLoaded) })
|
32
|
-
@channel.on('download',
|
33
|
-
emit(Events::Page::Download, ChannelOwners::Download.from(params['download']))
|
34
|
-
})
|
41
|
+
@channel.on('download', method(:on_download))
|
35
42
|
@channel.on('fileChooser', ->(params) {
|
36
43
|
chooser = FileChooserImpl.new(
|
37
44
|
page: self,
|
@@ -49,9 +56,6 @@ module Playwright
|
|
49
56
|
@channel.on('pageError', ->(params) {
|
50
57
|
emit(Events::Page::PageError, Error.parse(params['error']['error']))
|
51
58
|
})
|
52
|
-
@channel.on('popup', ->(params) {
|
53
|
-
emit(Events::Page::Popup, ChannelOwners::Page.from(params['page']))
|
54
|
-
})
|
55
59
|
@channel.on('request', ->(params) {
|
56
60
|
emit(Events::Page::Request, ChannelOwners::Request.from(params['request']))
|
57
61
|
})
|
@@ -74,9 +78,7 @@ module Playwright
|
|
74
78
|
@channel.on('route', ->(params) {
|
75
79
|
on_route(ChannelOwners::Route.from(params['route']), ChannelOwners::Request.from(params['request']))
|
76
80
|
})
|
77
|
-
@channel.on('video',
|
78
|
-
video.send(:update_relative_path, params['relativePath'])
|
79
|
-
})
|
81
|
+
@channel.on('video', method(:on_video))
|
80
82
|
@channel.on('webSocket', ->(params) {
|
81
83
|
emit(Events::Page::WebSocket, ChannelOwners::WebSocket.from(params['webSocket']))
|
82
84
|
})
|
@@ -96,12 +98,12 @@ module Playwright
|
|
96
98
|
private def on_request_failed(request, response_end_timing, failure_text)
|
97
99
|
request.send(:update_failure_text, failure_text)
|
98
100
|
request.send(:update_response_end_timing, response_end_timing)
|
99
|
-
emit(Events::Page::RequestFailed)
|
101
|
+
emit(Events::Page::RequestFailed, request)
|
100
102
|
end
|
101
103
|
|
102
104
|
private def on_request_finished(request, response_end_timing)
|
103
105
|
request.send(:update_response_end_timing, response_end_timing)
|
104
|
-
emit(Events::Page::RequestFinished)
|
106
|
+
emit(Events::Page::RequestFinished, request)
|
105
107
|
end
|
106
108
|
|
107
109
|
private def on_frame_attached(frame)
|
@@ -117,8 +119,15 @@ module Playwright
|
|
117
119
|
end
|
118
120
|
|
119
121
|
private def on_route(route, request)
|
120
|
-
#
|
121
|
-
|
122
|
+
# It is not desired to use PlaywrightApi.wrap directly.
|
123
|
+
# However it is a little difficult to define wrapper for `handler` parameter in generate_api.
|
124
|
+
# Just a workaround...
|
125
|
+
wrapped_route = PlaywrightApi.wrap(route)
|
126
|
+
wrapped_request = PlaywrightApi.wrap(request)
|
127
|
+
|
128
|
+
if @routes.none? { |handler_entry| handler_entry.handle(wrapped_route, wrapped_request) }
|
129
|
+
@browser_context.send(:on_route, route, request)
|
130
|
+
end
|
122
131
|
end
|
123
132
|
|
124
133
|
private def on_close
|
@@ -130,14 +139,28 @@ module Playwright
|
|
130
139
|
private def on_dialog(params)
|
131
140
|
dialog = ChannelOwners::Dialog.from(params['dialog'])
|
132
141
|
unless emit(Events::Page::Dialog, dialog)
|
133
|
-
dialog.dismiss
|
142
|
+
dialog.dismiss
|
134
143
|
end
|
135
144
|
end
|
136
145
|
|
146
|
+
private def on_download(params)
|
147
|
+
download = Download.new(
|
148
|
+
url: params['url'],
|
149
|
+
suggested_filename: params['suggestedFilename'],
|
150
|
+
artifact: ChannelOwners::Artifact.from(params['artifact']),
|
151
|
+
)
|
152
|
+
emit(Events::Page::Download, download)
|
153
|
+
end
|
154
|
+
|
155
|
+
private def on_video(params)
|
156
|
+
artifact = ChannelOwners::Artifact.from(params['artifact'])
|
157
|
+
video.send(:set_artifact, artifact)
|
158
|
+
end
|
159
|
+
|
137
160
|
# @override
|
138
161
|
def on(event, callback)
|
139
162
|
if event == Events::Page::FileChooser && listener_count(event) == 0
|
140
|
-
@channel.
|
163
|
+
@channel.async_send_message_to_server('setFileChooserInterceptedNoReply', intercepted: true)
|
141
164
|
end
|
142
165
|
super
|
143
166
|
end
|
@@ -145,7 +168,7 @@ module Playwright
|
|
145
168
|
# @override
|
146
169
|
def once(event, callback)
|
147
170
|
if event == Events::Page::FileChooser && listener_count(event) == 0
|
148
|
-
@channel.
|
171
|
+
@channel.async_send_message_to_server('setFileChooserInterceptedNoReply', intercepted: true)
|
149
172
|
end
|
150
173
|
super
|
151
174
|
end
|
@@ -154,7 +177,7 @@ module Playwright
|
|
154
177
|
def off(event, callback)
|
155
178
|
super
|
156
179
|
if event == Events::Page::FileChooser && listener_count(event) == 0
|
157
|
-
@channel.
|
180
|
+
@channel.async_send_message_to_server('setFileChooserInterceptedNoReply', intercepted: false)
|
158
181
|
end
|
159
182
|
end
|
160
183
|
|
@@ -163,18 +186,20 @@ module Playwright
|
|
163
186
|
end
|
164
187
|
|
165
188
|
def opener
|
166
|
-
|
167
|
-
|
189
|
+
if @opener&.closed?
|
190
|
+
nil
|
191
|
+
else
|
192
|
+
@opener
|
193
|
+
end
|
168
194
|
end
|
169
195
|
|
170
|
-
def
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
[frameSelector, nil]
|
176
|
-
end
|
196
|
+
private def emit_popup_event_from_browser_context
|
197
|
+
if @opener && !@opener.closed?
|
198
|
+
@opener.emit(Events::Page::Popup, self)
|
199
|
+
end
|
200
|
+
end
|
177
201
|
|
202
|
+
def frame(name: nil, url: nil)
|
178
203
|
if name
|
179
204
|
@frames.find { |f| f.name == name }
|
180
205
|
elsif url
|
@@ -318,6 +343,10 @@ module Playwright
|
|
318
343
|
@main_frame.wait_for_load_state(state: state, timeout: timeout)
|
319
344
|
end
|
320
345
|
|
346
|
+
def wait_for_url(url, timeout: nil, waitUntil: nil)
|
347
|
+
@main_frame.wait_for_url(url, timeout: timeout, waitUntil: waitUntil)
|
348
|
+
end
|
349
|
+
|
321
350
|
def go_back(timeout: nil, waitUntil: nil)
|
322
351
|
params = { timeout: timeout, waitUntil: waitUntil }.compact
|
323
352
|
resp = @channel.send_message_to_server('goBack', params)
|
@@ -351,12 +380,37 @@ module Playwright
|
|
351
380
|
nil
|
352
381
|
end
|
353
382
|
|
354
|
-
def add_init_script(
|
383
|
+
def add_init_script(path: nil, script: nil)
|
384
|
+
source =
|
385
|
+
if path
|
386
|
+
File.read(path)
|
387
|
+
elsif script
|
388
|
+
script
|
389
|
+
else
|
390
|
+
raise ArgumentError.new('Either path or script parameter must be specified')
|
391
|
+
end
|
392
|
+
|
355
393
|
@channel.send_message_to_server('addInitScript', source: script)
|
356
|
-
# FIXME: handling `arg` for function `script`
|
357
394
|
nil
|
358
395
|
end
|
359
396
|
|
397
|
+
def route(url, handler)
|
398
|
+
entry = RouteHandlerEntry.new(url, handler)
|
399
|
+
@routes << entry
|
400
|
+
if @routes.count >= 1
|
401
|
+
@channel.send_message_to_server('setNetworkInterceptionEnabled', enabled: true)
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
def unroute(url, handler: nil)
|
406
|
+
@routes.reject! do |handler_entry|
|
407
|
+
handler_entry.same_value?(url: url, handler: handler)
|
408
|
+
end
|
409
|
+
if @routes.count == 0
|
410
|
+
@channel.send_message_to_server('setNetworkInterceptionEnabled', enabled: false)
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
360
414
|
def screenshot(
|
361
415
|
path: nil,
|
362
416
|
type: nil,
|
@@ -502,8 +556,23 @@ module Playwright
|
|
502
556
|
)
|
503
557
|
end
|
504
558
|
|
505
|
-
def select_option(
|
506
|
-
|
559
|
+
def select_option(
|
560
|
+
selector,
|
561
|
+
element: nil,
|
562
|
+
index: nil,
|
563
|
+
value: nil,
|
564
|
+
label: nil,
|
565
|
+
noWaitAfter: nil,
|
566
|
+
timeout: nil)
|
567
|
+
@main_frame.select_option(
|
568
|
+
selector,
|
569
|
+
element: element,
|
570
|
+
index: index,
|
571
|
+
value: value,
|
572
|
+
label: label,
|
573
|
+
noWaitAfter: noWaitAfter,
|
574
|
+
timeout: timeout,
|
575
|
+
)
|
507
576
|
end
|
508
577
|
|
509
578
|
def set_input_files(selector, files, noWaitAfter: nil, timeout: nil)
|
@@ -530,12 +599,24 @@ module Playwright
|
|
530
599
|
@main_frame.press(selector, key, delay: delay, noWaitAfter: noWaitAfter, timeout: timeout)
|
531
600
|
end
|
532
601
|
|
533
|
-
def check(
|
534
|
-
|
602
|
+
def check(
|
603
|
+
selector,
|
604
|
+
force: nil,
|
605
|
+
noWaitAfter: nil,
|
606
|
+
position: nil,
|
607
|
+
timeout: nil)
|
608
|
+
|
609
|
+
@main_frame.check(selector, force: force, noWaitAfter: noWaitAfter, position: position, timeout: timeout)
|
535
610
|
end
|
536
611
|
|
537
|
-
def uncheck(
|
538
|
-
|
612
|
+
def uncheck(
|
613
|
+
selector,
|
614
|
+
force: nil,
|
615
|
+
noWaitAfter: nil,
|
616
|
+
position: nil,
|
617
|
+
timeout: nil)
|
618
|
+
|
619
|
+
@main_frame.uncheck(selector, force: force, noWaitAfter: noWaitAfter, position: position, timeout: timeout)
|
539
620
|
end
|
540
621
|
|
541
622
|
def wait_for_function(pageFunction, arg: nil, polling: nil, timeout: nil)
|
@@ -581,6 +662,36 @@ module Playwright
|
|
581
662
|
decoded_binary
|
582
663
|
end
|
583
664
|
|
665
|
+
def video
|
666
|
+
return nil unless @browser_context.send(:has_record_video_option?)
|
667
|
+
@video ||= Video.new(self)
|
668
|
+
end
|
669
|
+
|
670
|
+
def start_js_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil)
|
671
|
+
params = {
|
672
|
+
resetOnNavigation: resetOnNavigation,
|
673
|
+
reportAnonymousScripts: reportAnonymousScripts,
|
674
|
+
}.compact
|
675
|
+
|
676
|
+
@channel.send_message_to_server('startJSCoverage', params)
|
677
|
+
end
|
678
|
+
|
679
|
+
def stop_js_coverage
|
680
|
+
@channel.send_message_to_server('stopJSCoverage')
|
681
|
+
end
|
682
|
+
|
683
|
+
def start_css_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil)
|
684
|
+
params = {
|
685
|
+
resetOnNavigation: resetOnNavigation,
|
686
|
+
}.compact
|
687
|
+
|
688
|
+
@channel.send_message_to_server('startCSSCoverage', params)
|
689
|
+
end
|
690
|
+
|
691
|
+
def stop_css_coverage
|
692
|
+
@channel.send_message_to_server('stopCSSCoverage')
|
693
|
+
end
|
694
|
+
|
584
695
|
class CrashedError < StandardError
|
585
696
|
def initialize
|
586
697
|
super('Page crashed')
|
@@ -599,20 +710,9 @@ module Playwright
|
|
599
710
|
end
|
600
711
|
end
|
601
712
|
|
602
|
-
def expect_event(event,
|
603
|
-
predicate, timeout =
|
604
|
-
case optionsOrPredicate
|
605
|
-
when Proc
|
606
|
-
[optionsOrPredicate, nil]
|
607
|
-
when Hash
|
608
|
-
[optionsOrPredicate[:predicate], optionsOrPredicate[:timeout]]
|
609
|
-
else
|
610
|
-
[nil, nil]
|
611
|
-
end
|
612
|
-
timeout ||= @timeout_settings.timeout
|
613
|
-
|
713
|
+
def expect_event(event, predicate: nil, timeout: nil, &block)
|
614
714
|
wait_helper = WaitHelper.new
|
615
|
-
wait_helper.reject_on_timeout(timeout, "Timeout while waiting for event \"#{event}\"")
|
715
|
+
wait_helper.reject_on_timeout(timeout || @timeout_settings.timeout, "Timeout while waiting for event \"#{event}\"")
|
616
716
|
|
617
717
|
unless event == Events::Page::Crash
|
618
718
|
wait_helper.reject_on_event(self, Events::Page::Crash, CrashedError.new)
|
@@ -629,6 +729,18 @@ module Playwright
|
|
629
729
|
wait_helper.promise.value!
|
630
730
|
end
|
631
731
|
|
732
|
+
def expect_console_message(predicate: nil, timeout: nil, &block)
|
733
|
+
expect_event(Events::Page::Console, predicate: predicate, timeout: timeout, &block)
|
734
|
+
end
|
735
|
+
|
736
|
+
def expect_download(predicate: nil, timeout: nil, &block)
|
737
|
+
expect_event(Events::Page::Download, predicate: predicate, timeout: timeout, &block)
|
738
|
+
end
|
739
|
+
|
740
|
+
def expect_file_chooser(predicate: nil, timeout: nil, &block)
|
741
|
+
expect_event(Events::Page::FileChooser, predicate: predicate, timeout: timeout, &block)
|
742
|
+
end
|
743
|
+
|
632
744
|
def expect_navigation(timeout: nil, url: nil, waitUntil: nil, &block)
|
633
745
|
@main_frame.expect_navigation(
|
634
746
|
timeout: timeout,
|
@@ -637,6 +749,10 @@ module Playwright
|
|
637
749
|
&block)
|
638
750
|
end
|
639
751
|
|
752
|
+
def expect_popup(predicate: nil, timeout: nil, &block)
|
753
|
+
expect_event(Events::Page::Popup, predicate: predicate, timeout: timeout, &block)
|
754
|
+
end
|
755
|
+
|
640
756
|
def expect_request(urlOrPredicate, timeout: nil)
|
641
757
|
predicate =
|
642
758
|
case urlOrPredicate
|
@@ -649,7 +765,7 @@ module Playwright
|
|
649
765
|
-> (_) { true }
|
650
766
|
end
|
651
767
|
|
652
|
-
expect_event(Events::Page::Request,
|
768
|
+
expect_event(Events::Page::Request, predicate: predicate, timeout: timeout)
|
653
769
|
end
|
654
770
|
|
655
771
|
def expect_response(urlOrPredicate, timeout: nil)
|
@@ -664,7 +780,7 @@ module Playwright
|
|
664
780
|
-> (_) { true }
|
665
781
|
end
|
666
782
|
|
667
|
-
expect_event(Events::Page::Response,
|
783
|
+
expect_event(Events::Page::Response, predicate: predicate, timeout: timeout)
|
668
784
|
end
|
669
785
|
|
670
786
|
# called from BrowserContext#on_page with send(:update_browser_context, page), so keep private.
|
@@ -677,5 +793,10 @@ module Playwright
|
|
677
793
|
private def timeout_settings
|
678
794
|
@timeout_settings
|
679
795
|
end
|
796
|
+
|
797
|
+
# called from BrowserContext#expose_binding
|
798
|
+
private def has_bindings?(name)
|
799
|
+
@bindings.key?(name)
|
800
|
+
end
|
680
801
|
end
|
681
802
|
end
|