playwright-ruby-client 1.28.1 → 1.29.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/documentation/docs/api/accessibility.md +9 -14
- data/documentation/docs/api/api_request_context.md +44 -41
- data/documentation/docs/api/api_response.md +13 -3
- data/documentation/docs/api/browser.md +24 -23
- data/documentation/docs/api/browser_context.md +71 -45
- data/documentation/docs/api/browser_type.md +21 -14
- data/documentation/docs/api/cdp_session.md +3 -5
- data/documentation/docs/api/console_message.md +7 -4
- data/documentation/docs/api/dialog.md +9 -5
- data/documentation/docs/api/download.md +19 -11
- data/documentation/docs/api/element_handle.md +125 -116
- data/documentation/docs/api/experimental/android.md +4 -5
- data/documentation/docs/api/experimental/android_device.md +11 -2
- data/documentation/docs/api/experimental/android_input.md +5 -0
- data/documentation/docs/api/file_chooser.md +6 -3
- data/documentation/docs/api/frame.md +182 -171
- data/documentation/docs/api/frame_locator.md +27 -38
- data/documentation/docs/api/js_handle.md +16 -10
- data/documentation/docs/api/keyboard.md +29 -16
- data/documentation/docs/api/locator.md +189 -140
- data/documentation/docs/api/mouse.md +9 -4
- data/documentation/docs/api/page.md +304 -289
- data/documentation/docs/api/playwright.md +8 -5
- data/documentation/docs/api/request.md +34 -15
- data/documentation/docs/api/response.md +27 -10
- data/documentation/docs/api/route.md +44 -12
- data/documentation/docs/api/selectors.md +5 -3
- data/documentation/docs/api/touchscreen.md +2 -0
- data/documentation/docs/api/tracing.md +11 -11
- data/documentation/docs/api/web_socket.md +9 -4
- data/documentation/docs/api/worker.md +12 -11
- data/documentation/docs/include/api_coverage.md +2 -0
- data/lib/playwright/channel_owners/api_request_context.rb +37 -2
- data/lib/playwright/channel_owners/browser_context.rb +22 -26
- data/lib/playwright/channel_owners/page.rb +35 -25
- data/lib/playwright/channel_owners/route.rb +28 -8
- data/lib/playwright/event_emitter.rb +6 -1
- data/lib/playwright/locator_impl.rb +8 -0
- data/lib/playwright/select_option_values.rb +2 -0
- data/lib/playwright/version.rb +2 -2
- data/lib/playwright_api/accessibility.rb +9 -13
- data/lib/playwright_api/android.rb +8 -6
- data/lib/playwright_api/android_device.rb +32 -7
- data/lib/playwright_api/android_input.rb +5 -0
- data/lib/playwright_api/android_socket.rb +4 -2
- data/lib/playwright_api/android_web_view.rb +5 -2
- data/lib/playwright_api/api_request.rb +6 -3
- data/lib/playwright_api/api_request_context.rb +46 -36
- data/lib/playwright_api/api_response.rb +13 -2
- data/lib/playwright_api/browser.rb +24 -16
- data/lib/playwright_api/browser_context.rb +76 -39
- data/lib/playwright_api/browser_type.rb +23 -13
- data/lib/playwright_api/cdp_session.rb +3 -4
- data/lib/playwright_api/console_message.rb +7 -2
- data/lib/playwright_api/dialog.rb +8 -4
- data/lib/playwright_api/download.rb +19 -9
- data/lib/playwright_api/element_handle.rb +116 -93
- data/lib/playwright_api/file_chooser.rb +6 -1
- data/lib/playwright_api/frame.rb +180 -135
- data/lib/playwright_api/frame_locator.rb +29 -32
- data/lib/playwright_api/js_handle.rb +16 -6
- data/lib/playwright_api/keyboard.rb +29 -14
- data/lib/playwright_api/locator.rb +183 -112
- data/lib/playwright_api/mouse.rb +9 -2
- data/lib/playwright_api/page.rb +301 -253
- data/lib/playwright_api/playwright.rb +11 -4
- data/lib/playwright_api/request.rb +34 -7
- data/lib/playwright_api/response.rb +27 -10
- data/lib/playwright_api/route.rb +44 -11
- data/lib/playwright_api/selectors.rb +6 -1
- data/lib/playwright_api/touchscreen.rb +2 -0
- data/lib/playwright_api/tracing.rb +11 -5
- data/lib/playwright_api/web_socket.rb +9 -4
- data/lib/playwright_api/worker.rb +16 -13
- data/playwright.gemspec +1 -1
- metadata +7 -7
@@ -26,37 +26,38 @@ page.goto("https://example.com")
|
|
26
26
|
context.close
|
27
27
|
```
|
28
28
|
|
29
|
-
|
30
|
-
|
31
29
|
## add_cookies
|
32
30
|
|
33
31
|
```
|
34
32
|
def add_cookies(cookies)
|
35
33
|
```
|
36
34
|
|
35
|
+
|
37
36
|
Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be
|
38
37
|
obtained via [BrowserContext#cookies](./browser_context#cookies).
|
39
38
|
|
39
|
+
**Usage**
|
40
|
+
|
40
41
|
```ruby
|
41
42
|
browser_context.add_cookies([cookie_object1, cookie_object2])
|
42
43
|
```
|
43
44
|
|
44
|
-
|
45
|
-
|
46
45
|
## add_init_script
|
47
46
|
|
48
47
|
```
|
49
48
|
def add_init_script(path: nil, script: nil)
|
50
49
|
```
|
51
50
|
|
51
|
+
|
52
52
|
Adds a script which would be evaluated in one of the following scenarios:
|
53
53
|
- Whenever a page is created in the browser context or is navigated.
|
54
|
-
- Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script is
|
55
|
-
evaluated in the context of the newly attached frame.
|
54
|
+
- Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script is evaluated in the context of the newly attached frame.
|
56
55
|
|
57
56
|
The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
|
58
57
|
the JavaScript environment, e.g. to seed `Math.random`.
|
59
58
|
|
59
|
+
**Usage**
|
60
|
+
|
60
61
|
An example of overriding `Math.random` before the page loads:
|
61
62
|
|
62
63
|
```ruby
|
@@ -64,7 +65,7 @@ An example of overriding `Math.random` before the page loads:
|
|
64
65
|
browser_context.add_init_script(path: "preload.js")
|
65
66
|
```
|
66
67
|
|
67
|
-
|
68
|
+
**NOTE**: The order of evaluation of multiple scripts installed via [BrowserContext#add_init_script](./browser_context#add_init_script) and
|
68
69
|
[Page#add_init_script](./page#add_init_script) is not defined.
|
69
70
|
|
70
71
|
## background_pages
|
@@ -73,7 +74,8 @@ browser_context.add_init_script(path: "preload.js")
|
|
73
74
|
def background_pages
|
74
75
|
```
|
75
76
|
|
76
|
-
|
77
|
+
|
78
|
+
**NOTE**: Background pages are only supported on Chromium-based browsers.
|
77
79
|
|
78
80
|
All existing background pages in the context.
|
79
81
|
|
@@ -83,6 +85,7 @@ All existing background pages in the context.
|
|
83
85
|
def browser
|
84
86
|
```
|
85
87
|
|
88
|
+
|
86
89
|
Returns the browser instance of the context. If it was launched as a persistent context null gets returned.
|
87
90
|
|
88
91
|
## clear_cookies
|
@@ -91,6 +94,7 @@ Returns the browser instance of the context. If it was launched as a persistent
|
|
91
94
|
def clear_cookies
|
92
95
|
```
|
93
96
|
|
97
|
+
|
94
98
|
Clears context cookies.
|
95
99
|
|
96
100
|
## clear_permissions
|
@@ -99,8 +103,11 @@ Clears context cookies.
|
|
99
103
|
def clear_permissions
|
100
104
|
```
|
101
105
|
|
106
|
+
|
102
107
|
Clears all permission overrides for the browser context.
|
103
108
|
|
109
|
+
**Usage**
|
110
|
+
|
104
111
|
```ruby
|
105
112
|
context = browser.new_context
|
106
113
|
context.grant_permissions(["clipboard-read"])
|
@@ -110,17 +117,16 @@ context.grant_permissions(["clipboard-read"])
|
|
110
117
|
context.clear_permissions
|
111
118
|
```
|
112
119
|
|
113
|
-
|
114
|
-
|
115
120
|
## close
|
116
121
|
|
117
122
|
```
|
118
123
|
def close
|
119
124
|
```
|
120
125
|
|
126
|
+
|
121
127
|
Closes the browser context. All the pages that belong to the browser context will be closed.
|
122
128
|
|
123
|
-
|
129
|
+
**NOTE**: The default browser context cannot be closed.
|
124
130
|
|
125
131
|
## cookies
|
126
132
|
|
@@ -128,6 +134,7 @@ Closes the browser context. All the pages that belong to the browser context wil
|
|
128
134
|
def cookies(urls: nil)
|
129
135
|
```
|
130
136
|
|
137
|
+
|
131
138
|
If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
|
132
139
|
are returned.
|
133
140
|
|
@@ -137,14 +144,18 @@ are returned.
|
|
137
144
|
def expose_binding(name, callback, handle: nil)
|
138
145
|
```
|
139
146
|
|
140
|
-
The method adds a function called `name` on the `window` object of every frame in every page in the context. When
|
141
|
-
called, the function executes `callback` and returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) which resolves to the return value of `callback`. If
|
142
|
-
the `callback` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), it will be awaited.
|
143
147
|
|
144
|
-
The
|
148
|
+
The method adds a function called `name` on the `window` object of every frame in every page in the context.
|
149
|
+
When called, the function executes `callback` and returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) which resolves to the return value of
|
150
|
+
`callback`. If the `callback` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), it will be awaited.
|
151
|
+
|
152
|
+
The first argument of the `callback` function contains information about the caller: `{ browserContext:
|
153
|
+
BrowserContext, page: Page, frame: Frame }`.
|
145
154
|
|
146
155
|
See [Page#expose_binding](./page#expose_binding) for page-only version.
|
147
156
|
|
157
|
+
**Usage**
|
158
|
+
|
148
159
|
An example of exposing page URL to all frames in all pages in the context:
|
149
160
|
|
150
161
|
```ruby
|
@@ -187,21 +198,23 @@ HTML
|
|
187
198
|
page.locator('div').first.click
|
188
199
|
```
|
189
200
|
|
190
|
-
|
191
|
-
|
192
201
|
## expose_function
|
193
202
|
|
194
203
|
```
|
195
204
|
def expose_function(name, callback)
|
196
205
|
```
|
197
206
|
|
198
|
-
|
199
|
-
|
207
|
+
|
208
|
+
The method adds a function called `name` on the `window` object of every frame in every page in the context.
|
209
|
+
When called, the function executes `callback` and returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) which resolves to the return value of
|
210
|
+
`callback`.
|
200
211
|
|
201
212
|
If the `callback` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), it will be awaited.
|
202
213
|
|
203
214
|
See [Page#expose_function](./page#expose_function) for page-only version.
|
204
215
|
|
216
|
+
**Usage**
|
217
|
+
|
205
218
|
An example of adding a `sha256` function to all pages in the context:
|
206
219
|
|
207
220
|
```ruby
|
@@ -225,14 +238,13 @@ HTML
|
|
225
238
|
page.get_by_role("button").click
|
226
239
|
```
|
227
240
|
|
228
|
-
|
229
|
-
|
230
241
|
## grant_permissions
|
231
242
|
|
232
243
|
```
|
233
244
|
def grant_permissions(permissions, origin: nil)
|
234
245
|
```
|
235
246
|
|
247
|
+
|
236
248
|
Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if
|
237
249
|
specified.
|
238
250
|
|
@@ -242,7 +254,8 @@ specified.
|
|
242
254
|
def new_cdp_session(page)
|
243
255
|
```
|
244
256
|
|
245
|
-
|
257
|
+
|
258
|
+
**NOTE**: CDP sessions are only supported on Chromium-based browsers.
|
246
259
|
|
247
260
|
Returns the newly created session.
|
248
261
|
|
@@ -252,6 +265,7 @@ Returns the newly created session.
|
|
252
265
|
def new_page(&block)
|
253
266
|
```
|
254
267
|
|
268
|
+
|
255
269
|
Creates a new page in the browser context.
|
256
270
|
|
257
271
|
## pages
|
@@ -260,6 +274,7 @@ Creates a new page in the browser context.
|
|
260
274
|
def pages
|
261
275
|
```
|
262
276
|
|
277
|
+
|
263
278
|
Returns all open pages in the context.
|
264
279
|
|
265
280
|
## route
|
@@ -268,12 +283,13 @@ Returns all open pages in the context.
|
|
268
283
|
def route(url, handler, times: nil)
|
269
284
|
```
|
270
285
|
|
286
|
+
|
271
287
|
Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
272
288
|
is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
273
289
|
|
274
|
-
|
275
|
-
|
276
|
-
|
290
|
+
**NOTE**: [BrowserContext#route](./browser_context#route) will not intercept requests intercepted by Service Worker. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting `Browser.newContext.serviceWorkers` to `'block'`.
|
291
|
+
|
292
|
+
**Usage**
|
277
293
|
|
278
294
|
An example of a naive handler that aborts all image requests:
|
279
295
|
|
@@ -293,8 +309,7 @@ context.route(/\.(png|jpg)$/, ->(route, request) { route.abort })
|
|
293
309
|
page.goto("https://example.com")
|
294
310
|
```
|
295
311
|
|
296
|
-
It is possible to examine the request to decide the route action. For example, mocking all requests that contain some
|
297
|
-
post data, and leaving all other requests as is:
|
312
|
+
It is possible to examine the request to decide the route action. For example, mocking all requests that contain some post data, and leaving all other requests as is:
|
298
313
|
|
299
314
|
```ruby
|
300
315
|
def handle_route(route, request)
|
@@ -313,7 +328,7 @@ handlers.
|
|
313
328
|
|
314
329
|
To remove a route with its handler you can use [BrowserContext#unroute](./browser_context#unroute).
|
315
330
|
|
316
|
-
|
331
|
+
**NOTE**: Enabling routing disables http cache.
|
317
332
|
|
318
333
|
## route_from_har
|
319
334
|
|
@@ -321,12 +336,10 @@ To remove a route with its handler you can use [BrowserContext#unroute](./browse
|
|
321
336
|
def route_from_har(har, notFound: nil, update: nil, url: nil)
|
322
337
|
```
|
323
338
|
|
324
|
-
If specified the network requests that are made in the context will be served from the HAR file. Read more about
|
325
|
-
[Replaying from HAR](https://playwright.dev/python/docs/network).
|
326
339
|
|
327
|
-
|
328
|
-
|
329
|
-
request interception by setting `Browser.newContext.serviceWorkers` to `'block'`.
|
340
|
+
If specified the network requests that are made in the context will be served from the HAR file. Read more about [Replaying from HAR](https://playwright.dev/python/docs/network#replaying-from-har).
|
341
|
+
|
342
|
+
Playwright will not serve requests intercepted by Service Worker from the HAR file. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting `Browser.newContext.serviceWorkers` to `'block'`.
|
330
343
|
|
331
344
|
## service_workers
|
332
345
|
|
@@ -334,7 +347,8 @@ request interception by setting `Browser.newContext.serviceWorkers` to `'block'`
|
|
334
347
|
def service_workers
|
335
348
|
```
|
336
349
|
|
337
|
-
|
350
|
+
|
351
|
+
**NOTE**: Service workers are only supported on Chromium-based browsers.
|
338
352
|
|
339
353
|
All existing service workers in the context.
|
340
354
|
|
@@ -345,6 +359,7 @@ def set_default_navigation_timeout(timeout)
|
|
345
359
|
```
|
346
360
|
alias: `default_navigation_timeout=`
|
347
361
|
|
362
|
+
|
348
363
|
This setting will change the default maximum navigation time for the following methods and related shortcuts:
|
349
364
|
- [Page#go_back](./page#go_back)
|
350
365
|
- [Page#go_forward](./page#go_forward)
|
@@ -353,7 +368,7 @@ This setting will change the default maximum navigation time for the following m
|
|
353
368
|
- [Page#set_content](./page#set_content)
|
354
369
|
- [Page#expect_navigation](./page#expect_navigation)
|
355
370
|
|
356
|
-
|
371
|
+
**NOTE**: [Page#set_default_navigation_timeout](./page#set_default_navigation_timeout) and [Page#set_default_timeout](./page#set_default_timeout) take priority over
|
357
372
|
[BrowserContext#set_default_navigation_timeout](./browser_context#set_default_navigation_timeout).
|
358
373
|
|
359
374
|
## set_default_timeout
|
@@ -363,9 +378,10 @@ def set_default_timeout(timeout)
|
|
363
378
|
```
|
364
379
|
alias: `default_timeout=`
|
365
380
|
|
381
|
+
|
366
382
|
This setting will change the default maximum time for all the methods accepting `timeout` option.
|
367
383
|
|
368
|
-
|
384
|
+
**NOTE**: [Page#set_default_navigation_timeout](./page#set_default_navigation_timeout), [Page#set_default_timeout](./page#set_default_timeout) and
|
369
385
|
[BrowserContext#set_default_navigation_timeout](./browser_context#set_default_navigation_timeout) take priority over [BrowserContext#set_default_timeout](./browser_context#set_default_timeout).
|
370
386
|
|
371
387
|
## set_extra_http_headers
|
@@ -375,11 +391,12 @@ def set_extra_http_headers(headers)
|
|
375
391
|
```
|
376
392
|
alias: `extra_http_headers=`
|
377
393
|
|
394
|
+
|
378
395
|
The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are merged
|
379
396
|
with page-specific extra HTTP headers set with [Page#set_extra_http_headers](./page#set_extra_http_headers). If page overrides a particular
|
380
397
|
header, page-specific header value will be used instead of the browser context header value.
|
381
398
|
|
382
|
-
|
399
|
+
**NOTE**: [BrowserContext#set_extra_http_headers](./browser_context#set_extra_http_headers) does not guarantee the order of headers in the outgoing requests.
|
383
400
|
|
384
401
|
## set_geolocation
|
385
402
|
|
@@ -388,14 +405,17 @@ def set_geolocation(geolocation)
|
|
388
405
|
```
|
389
406
|
alias: `geolocation=`
|
390
407
|
|
408
|
+
|
391
409
|
Sets the context's geolocation. Passing `null` or `undefined` emulates position unavailable.
|
392
410
|
|
411
|
+
**Usage**
|
412
|
+
|
393
413
|
```ruby
|
394
414
|
browser_context.geolocation = { latitude: 59.95, longitude: 30.31667 }
|
395
415
|
```
|
396
416
|
|
397
|
-
|
398
|
-
|
417
|
+
**NOTE**: Consider using [BrowserContext#grant_permissions](./browser_context#grant_permissions) to grant permissions for the browser context pages to read
|
418
|
+
its geolocation.
|
399
419
|
|
400
420
|
## set_offline
|
401
421
|
|
@@ -412,6 +432,7 @@ alias: `offline=`
|
|
412
432
|
def storage_state(path: nil)
|
413
433
|
```
|
414
434
|
|
435
|
+
|
415
436
|
Returns storage state for this browser context, contains current cookies and local storage snapshot.
|
416
437
|
|
417
438
|
## unroute
|
@@ -420,8 +441,9 @@ Returns storage state for this browser context, contains current cookies and loc
|
|
420
441
|
def unroute(url, handler: nil)
|
421
442
|
```
|
422
443
|
|
423
|
-
|
424
|
-
|
444
|
+
|
445
|
+
Removes a route created with [BrowserContext#route](./browser_context#route). When `handler` is not specified, removes all
|
446
|
+
routes for the `url`.
|
425
447
|
|
426
448
|
## expect_event
|
427
449
|
|
@@ -429,28 +451,32 @@ the `url`.
|
|
429
451
|
def expect_event(event, predicate: nil, timeout: nil, &block)
|
430
452
|
```
|
431
453
|
|
454
|
+
|
432
455
|
Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
|
433
456
|
value. Will throw an error if the context closes before the event is fired. Returns the event data value.
|
434
457
|
|
458
|
+
**Usage**
|
459
|
+
|
435
460
|
```ruby
|
436
461
|
new_page = browser_context.expect_event('page') do
|
437
462
|
page.get_by_role("button").click
|
438
463
|
end
|
439
464
|
```
|
440
465
|
|
441
|
-
|
442
|
-
|
443
466
|
## expect_page
|
444
467
|
|
445
468
|
```
|
446
469
|
def expect_page(predicate: nil, timeout: nil)
|
447
470
|
```
|
448
471
|
|
449
|
-
|
450
|
-
|
472
|
+
|
473
|
+
Performs action and waits for a new [Page](./page) to be created in the context. If predicate is provided, it passes
|
474
|
+
[Page](./page) value into the `predicate` function and waits for `predicate(event)` to return a truthy value.
|
475
|
+
Will throw an error if the context closes before new [Page](./page) is created.
|
451
476
|
|
452
477
|
## request
|
453
478
|
|
479
|
+
|
454
480
|
API testing helper associated with this context. Requests made with this API will use context cookies.
|
455
481
|
|
456
482
|
## tracing
|
@@ -4,6 +4,7 @@ sidebar_position: 10
|
|
4
4
|
|
5
5
|
# BrowserType
|
6
6
|
|
7
|
+
|
7
8
|
BrowserType provides methods to launch a specific browser instance or connect to an existing one. The following is a
|
8
9
|
typical example of using Playwright to drive automation:
|
9
10
|
|
@@ -18,8 +19,6 @@ chromium.launch do |browser|
|
|
18
19
|
end
|
19
20
|
```
|
20
21
|
|
21
|
-
|
22
|
-
|
23
22
|
## connect_over_cdp
|
24
23
|
|
25
24
|
```
|
@@ -31,11 +30,14 @@ def connect_over_cdp(
|
|
31
30
|
&block)
|
32
31
|
```
|
33
32
|
|
33
|
+
|
34
34
|
This method attaches Playwright to an existing browser instance using the Chrome DevTools Protocol.
|
35
35
|
|
36
36
|
The default browser context is accessible via [Browser#contexts](./browser#contexts).
|
37
37
|
|
38
|
-
|
38
|
+
**NOTE**: Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.
|
39
|
+
|
40
|
+
**Usage**
|
39
41
|
|
40
42
|
```ruby
|
41
43
|
browser = playwright.chromium.connect_over_cdp("http://localhost:9222")
|
@@ -43,14 +45,13 @@ default_context = browser.contexts.first
|
|
43
45
|
page = default_context.pages.first
|
44
46
|
```
|
45
47
|
|
46
|
-
|
47
|
-
|
48
48
|
## executable_path
|
49
49
|
|
50
50
|
```
|
51
51
|
def executable_path
|
52
52
|
```
|
53
53
|
|
54
|
+
|
54
55
|
A path where Playwright expects to find a bundled browser executable.
|
55
56
|
|
56
57
|
## launch
|
@@ -77,8 +78,11 @@ def launch(
|
|
77
78
|
&block)
|
78
79
|
```
|
79
80
|
|
81
|
+
|
80
82
|
Returns the browser instance.
|
81
83
|
|
84
|
+
**Usage**
|
85
|
+
|
82
86
|
You can use `ignoreDefaultArgs` to filter out `--mute-audio` from default arguments:
|
83
87
|
|
84
88
|
```ruby
|
@@ -89,18 +93,19 @@ browser = playwright.chromium.launch( # or "firefox" or "webkit".
|
|
89
93
|
browser.close
|
90
94
|
```
|
91
95
|
|
92
|
-
> **Chromium-only** Playwright can also be used to control the Google Chrome or Microsoft Edge browsers, but it works
|
93
|
-
|
94
|
-
|
96
|
+
> **Chromium-only** Playwright can also be used to control the Google Chrome or Microsoft Edge browsers, but it works best with the version of
|
97
|
+
Chromium it is bundled with. There is no guarantee it will work with any other version. Use `executablePath`
|
98
|
+
option with extreme caution.
|
99
|
+
|
95
100
|
>
|
101
|
+
|
96
102
|
> If Google Chrome (rather than Chromium) is preferred, a
|
97
103
|
[Chrome Canary](https://www.google.com/chrome/browser/canary.html) or
|
98
104
|
[Dev Channel](https://www.chromium.org/getting-involved/dev-channel) build is suggested.
|
105
|
+
|
99
106
|
>
|
100
|
-
|
101
|
-
video playback. See
|
102
|
-
[this article](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for other
|
103
|
-
differences between Chromium and Chrome.
|
107
|
+
|
108
|
+
> Stock browsers like Google Chrome and Microsoft Edge are suitable for tests that require proprietary media codecs for video playback. See [this article](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for other differences between Chromium and Chrome.
|
104
109
|
[This article](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md)
|
105
110
|
describes some differences for Linux users.
|
106
111
|
|
@@ -159,10 +164,11 @@ def launch_persistent_context(
|
|
159
164
|
&block)
|
160
165
|
```
|
161
166
|
|
167
|
+
|
162
168
|
Returns the persistent browser context instance.
|
163
169
|
|
164
|
-
Launches browser that uses persistent storage located at `userDataDir` and returns the only context. Closing
|
165
|
-
context will automatically close the browser.
|
170
|
+
Launches browser that uses persistent storage located at `userDataDir` and returns the only context. Closing
|
171
|
+
this context will automatically close the browser.
|
166
172
|
|
167
173
|
## name
|
168
174
|
|
@@ -170,4 +176,5 @@ context will automatically close the browser.
|
|
170
176
|
def name
|
171
177
|
```
|
172
178
|
|
179
|
+
|
173
180
|
Returns browser name. For example: `'chromium'`, `'webkit'` or `'firefox'`.
|
@@ -11,10 +11,8 @@ The [CDPSession](./cdp_session) instances are used to talk raw Chrome Devtools P
|
|
11
11
|
- protocol events can be subscribed to with `session.on` method.
|
12
12
|
|
13
13
|
Useful links:
|
14
|
-
- Documentation on DevTools Protocol can be found here:
|
15
|
-
|
16
|
-
- Getting Started with DevTools Protocol:
|
17
|
-
https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md
|
14
|
+
- Documentation on DevTools Protocol can be found here: [DevTools Protocol Viewer](https://chromedevtools.github.io/devtools-protocol/).
|
15
|
+
- Getting Started with DevTools Protocol: https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md
|
18
16
|
|
19
17
|
```ruby
|
20
18
|
client = page.context.new_cdp_session(page)
|
@@ -28,13 +26,13 @@ client.send_message(
|
|
28
26
|
)
|
29
27
|
```
|
30
28
|
|
31
|
-
|
32
29
|
## detach
|
33
30
|
|
34
31
|
```
|
35
32
|
def detach
|
36
33
|
```
|
37
34
|
|
35
|
+
|
38
36
|
Detaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be used to
|
39
37
|
send messages.
|
40
38
|
|
@@ -4,8 +4,10 @@ sidebar_position: 10
|
|
4
4
|
|
5
5
|
# ConsoleMessage
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
|
8
|
+
[ConsoleMessage](./console_message) objects are dispatched by page via the [`event: Page.console`] event.
|
9
|
+
For each console messages logged in the page there will be corresponding event in the Playwright
|
10
|
+
context.
|
9
11
|
|
10
12
|
```ruby
|
11
13
|
# Listen for all console logs
|
@@ -30,14 +32,13 @@ msg.args[1].json_value # => 42
|
|
30
32
|
msg.args[2].json_value # => { 'foo' => 'bar' }
|
31
33
|
```
|
32
34
|
|
33
|
-
|
34
|
-
|
35
35
|
## args
|
36
36
|
|
37
37
|
```
|
38
38
|
def args
|
39
39
|
```
|
40
40
|
|
41
|
+
|
41
42
|
List of arguments passed to a `console` function call. See also [`event: Page.console`].
|
42
43
|
|
43
44
|
## location
|
@@ -54,6 +55,7 @@ def location
|
|
54
55
|
def text
|
55
56
|
```
|
56
57
|
|
58
|
+
|
57
59
|
The text of the console message.
|
58
60
|
|
59
61
|
## type
|
@@ -62,6 +64,7 @@ The text of the console message.
|
|
62
64
|
def type
|
63
65
|
```
|
64
66
|
|
67
|
+
|
65
68
|
One of the following values: `'log'`, `'debug'`, `'info'`, `'error'`, `'warning'`, `'dir'`, `'dirxml'`, `'table'`,
|
66
69
|
`'trace'`, `'clear'`, `'startGroup'`, `'startGroupCollapsed'`, `'endGroup'`, `'assert'`, `'profile'`, `'profileEnd'`,
|
67
70
|
`'count'`, `'timeEnd'`.
|
@@ -4,6 +4,7 @@ sidebar_position: 10
|
|
4
4
|
|
5
5
|
# Dialog
|
6
6
|
|
7
|
+
|
7
8
|
[Dialog](./dialog) objects are dispatched by page via the [`event: Page.dialog`] event.
|
8
9
|
|
9
10
|
An example of using [Dialog](./dialog) class:
|
@@ -12,7 +13,7 @@ An example of using [Dialog](./dialog) class:
|
|
12
13
|
def handle_dialog(dialog)
|
13
14
|
puts "[#{dialog.type}] #{dialog.message}"
|
14
15
|
if dialog.message =~ /foo/
|
15
|
-
dialog.
|
16
|
+
dialog.accept
|
16
17
|
else
|
17
18
|
dialog.dismiss
|
18
19
|
end
|
@@ -25,10 +26,8 @@ page.evaluate("alert('bar')") # will be dismissed
|
|
25
26
|
# => [alert] bar
|
26
27
|
```
|
27
28
|
|
28
|
-
|
29
|
-
present, it **must** either [Dialog#accept](./dialog#accept) or [Dialog#dismiss](./dialog#dismiss) the dialog - otherwise the page will
|
30
|
-
[freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and
|
31
|
-
actions like click will never finish.
|
29
|
+
**NOTE**: Dialogs are dismissed automatically, unless there is a [`event: Page.dialog`] listener.
|
30
|
+
When listener is present, it **must** either [Dialog#accept](./dialog#accept) or [Dialog#dismiss](./dialog#dismiss) the dialog - otherwise the page will [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and actions like click will never finish.
|
32
31
|
|
33
32
|
## accept
|
34
33
|
|
@@ -36,6 +35,7 @@ actions like click will never finish.
|
|
36
35
|
def accept(promptText: nil)
|
37
36
|
```
|
38
37
|
|
38
|
+
|
39
39
|
Returns when the dialog has been accepted.
|
40
40
|
|
41
41
|
## default_value
|
@@ -44,6 +44,7 @@ Returns when the dialog has been accepted.
|
|
44
44
|
def default_value
|
45
45
|
```
|
46
46
|
|
47
|
+
|
47
48
|
If dialog is prompt, returns default prompt value. Otherwise, returns empty string.
|
48
49
|
|
49
50
|
## dismiss
|
@@ -52,6 +53,7 @@ If dialog is prompt, returns default prompt value. Otherwise, returns empty stri
|
|
52
53
|
def dismiss
|
53
54
|
```
|
54
55
|
|
56
|
+
|
55
57
|
Returns when the dialog has been dismissed.
|
56
58
|
|
57
59
|
## message
|
@@ -60,6 +62,7 @@ Returns when the dialog has been dismissed.
|
|
60
62
|
def message
|
61
63
|
```
|
62
64
|
|
65
|
+
|
63
66
|
A message displayed in the dialog.
|
64
67
|
|
65
68
|
## type
|
@@ -68,4 +71,5 @@ A message displayed in the dialog.
|
|
68
71
|
def type
|
69
72
|
```
|
70
73
|
|
74
|
+
|
71
75
|
Returns dialog's type, can be one of `alert`, `beforeunload`, `confirm` or `prompt`.
|