playwright-ruby-client 1.28.1 → 1.29.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -20,6 +20,7 @@ module Playwright
|
|
20
20
|
# ```
|
21
21
|
class BrowserContext < PlaywrightApi
|
22
22
|
|
23
|
+
#
|
23
24
|
# API testing helper associated with this context. Requests made with this API will use context cookies.
|
24
25
|
def request # property
|
25
26
|
wrap_impl(@impl.request)
|
@@ -29,9 +30,12 @@ module Playwright
|
|
29
30
|
wrap_impl(@impl.tracing)
|
30
31
|
end
|
31
32
|
|
33
|
+
#
|
32
34
|
# Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be
|
33
35
|
# obtained via [`method: BrowserContext.cookies`].
|
34
36
|
#
|
37
|
+
# **Usage**
|
38
|
+
#
|
35
39
|
# ```python sync
|
36
40
|
# browser_context.add_cookies([cookie_object1, cookie_object2])
|
37
41
|
# ```
|
@@ -39,14 +43,16 @@ module Playwright
|
|
39
43
|
wrap_impl(@impl.add_cookies(unwrap_impl(cookies)))
|
40
44
|
end
|
41
45
|
|
46
|
+
#
|
42
47
|
# Adds a script which would be evaluated in one of the following scenarios:
|
43
48
|
# - Whenever a page is created in the browser context or is navigated.
|
44
|
-
# - Whenever a child frame is attached or navigated in any page in the browser context. In this case, the script is
|
45
|
-
# evaluated in the context of the newly attached frame.
|
49
|
+
# - 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.
|
46
50
|
#
|
47
51
|
# The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
|
48
52
|
# the JavaScript environment, e.g. to seed `Math.random`.
|
49
53
|
#
|
54
|
+
# **Usage**
|
55
|
+
#
|
50
56
|
# An example of overriding `Math.random` before the page loads:
|
51
57
|
#
|
52
58
|
# ```python sync
|
@@ -54,31 +60,37 @@ module Playwright
|
|
54
60
|
# browser_context.add_init_script(path="preload.js")
|
55
61
|
# ```
|
56
62
|
#
|
57
|
-
#
|
63
|
+
# **NOTE**: The order of evaluation of multiple scripts installed via [`method: BrowserContext.addInitScript`] and
|
58
64
|
# [`method: Page.addInitScript`] is not defined.
|
59
65
|
def add_init_script(path: nil, script: nil)
|
60
66
|
wrap_impl(@impl.add_init_script(path: unwrap_impl(path), script: unwrap_impl(script)))
|
61
67
|
end
|
62
68
|
|
63
|
-
#
|
69
|
+
#
|
70
|
+
# **NOTE**: Background pages are only supported on Chromium-based browsers.
|
64
71
|
#
|
65
72
|
# All existing background pages in the context.
|
66
73
|
def background_pages
|
67
74
|
wrap_impl(@impl.background_pages)
|
68
75
|
end
|
69
76
|
|
77
|
+
#
|
70
78
|
# Returns the browser instance of the context. If it was launched as a persistent context null gets returned.
|
71
79
|
def browser
|
72
80
|
wrap_impl(@impl.browser)
|
73
81
|
end
|
74
82
|
|
83
|
+
#
|
75
84
|
# Clears context cookies.
|
76
85
|
def clear_cookies
|
77
86
|
wrap_impl(@impl.clear_cookies)
|
78
87
|
end
|
79
88
|
|
89
|
+
#
|
80
90
|
# Clears all permission overrides for the browser context.
|
81
91
|
#
|
92
|
+
# **Usage**
|
93
|
+
#
|
82
94
|
# ```python sync
|
83
95
|
# context = browser.new_context()
|
84
96
|
# context.grant_permissions(["clipboard-read"])
|
@@ -89,28 +101,33 @@ module Playwright
|
|
89
101
|
wrap_impl(@impl.clear_permissions)
|
90
102
|
end
|
91
103
|
|
104
|
+
#
|
92
105
|
# Closes the browser context. All the pages that belong to the browser context will be closed.
|
93
106
|
#
|
94
|
-
#
|
107
|
+
# **NOTE**: The default browser context cannot be closed.
|
95
108
|
def close
|
96
109
|
wrap_impl(@impl.close)
|
97
110
|
end
|
98
111
|
|
112
|
+
#
|
99
113
|
# If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
|
100
114
|
# are returned.
|
101
115
|
def cookies(urls: nil)
|
102
116
|
wrap_impl(@impl.cookies(urls: unwrap_impl(urls)))
|
103
117
|
end
|
104
118
|
|
105
|
-
# The method adds a function called `name` on the `window` object of every frame in every page in the context. When
|
106
|
-
# called, the function executes `callback` and returns a [Promise] which resolves to the return value of `callback`. If
|
107
|
-
# the `callback` returns a [Promise], it will be awaited.
|
108
119
|
#
|
109
|
-
# The
|
110
|
-
#
|
120
|
+
# The method adds a function called `name` on the `window` object of every frame in every page in the context.
|
121
|
+
# When called, the function executes `callback` and returns a [Promise] which resolves to the return value of
|
122
|
+
# `callback`. If the `callback` returns a [Promise], it will be awaited.
|
123
|
+
#
|
124
|
+
# The first argument of the `callback` function contains information about the caller: `{ browserContext:
|
125
|
+
# BrowserContext, page: Page, frame: Frame }`.
|
111
126
|
#
|
112
127
|
# See [`method: Page.exposeBinding`] for page-only version.
|
113
128
|
#
|
129
|
+
# **Usage**
|
130
|
+
#
|
114
131
|
# An example of exposing page URL to all frames in all pages in the context:
|
115
132
|
#
|
116
133
|
# ```python sync
|
@@ -156,13 +173,17 @@ module Playwright
|
|
156
173
|
wrap_impl(@impl.expose_binding(unwrap_impl(name), unwrap_impl(callback), handle: unwrap_impl(handle)))
|
157
174
|
end
|
158
175
|
|
159
|
-
#
|
160
|
-
#
|
176
|
+
#
|
177
|
+
# The method adds a function called `name` on the `window` object of every frame in every page in the context.
|
178
|
+
# When called, the function executes `callback` and returns a [Promise] which resolves to the return value of
|
179
|
+
# `callback`.
|
161
180
|
#
|
162
181
|
# If the `callback` returns a [Promise], it will be awaited.
|
163
182
|
#
|
164
183
|
# See [`method: Page.exposeFunction`] for page-only version.
|
165
184
|
#
|
185
|
+
# **Usage**
|
186
|
+
#
|
166
187
|
# An example of adding a `sha256` function to all pages in the context:
|
167
188
|
#
|
168
189
|
# ```python sync
|
@@ -199,35 +220,40 @@ module Playwright
|
|
199
220
|
wrap_impl(@impl.expose_function(unwrap_impl(name), unwrap_impl(callback)))
|
200
221
|
end
|
201
222
|
|
223
|
+
#
|
202
224
|
# Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if
|
203
225
|
# specified.
|
204
226
|
def grant_permissions(permissions, origin: nil)
|
205
227
|
wrap_impl(@impl.grant_permissions(unwrap_impl(permissions), origin: unwrap_impl(origin)))
|
206
228
|
end
|
207
229
|
|
208
|
-
#
|
230
|
+
#
|
231
|
+
# **NOTE**: CDP sessions are only supported on Chromium-based browsers.
|
209
232
|
#
|
210
233
|
# Returns the newly created session.
|
211
234
|
def new_cdp_session(page)
|
212
235
|
wrap_impl(@impl.new_cdp_session(unwrap_impl(page)))
|
213
236
|
end
|
214
237
|
|
238
|
+
#
|
215
239
|
# Creates a new page in the browser context.
|
216
240
|
def new_page(&block)
|
217
241
|
wrap_impl(@impl.new_page(&wrap_block_call(block)))
|
218
242
|
end
|
219
243
|
|
244
|
+
#
|
220
245
|
# Returns all open pages in the context.
|
221
246
|
def pages
|
222
247
|
wrap_impl(@impl.pages)
|
223
248
|
end
|
224
249
|
|
250
|
+
#
|
225
251
|
# Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
|
226
252
|
# is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
227
253
|
#
|
228
|
-
#
|
229
|
-
#
|
230
|
-
#
|
254
|
+
# **NOTE**: [`method: BrowserContext.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'`.
|
255
|
+
#
|
256
|
+
# **Usage**
|
231
257
|
#
|
232
258
|
# An example of a naive handler that aborts all image requests:
|
233
259
|
#
|
@@ -251,8 +277,7 @@ module Playwright
|
|
251
277
|
# browser.close()
|
252
278
|
# ```
|
253
279
|
#
|
254
|
-
# It is possible to examine the request to decide the route action. For example, mocking all requests that contain some
|
255
|
-
# post data, and leaving all other requests as is:
|
280
|
+
# 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:
|
256
281
|
#
|
257
282
|
# ```python sync
|
258
283
|
# def handle_route(route):
|
@@ -268,28 +293,28 @@ module Playwright
|
|
268
293
|
#
|
269
294
|
# To remove a route with its handler you can use [`method: BrowserContext.unroute`].
|
270
295
|
#
|
271
|
-
#
|
296
|
+
# **NOTE**: Enabling routing disables http cache.
|
272
297
|
def route(url, handler, times: nil)
|
273
298
|
wrap_impl(@impl.route(unwrap_impl(url), unwrap_impl(handler), times: unwrap_impl(times)))
|
274
299
|
end
|
275
300
|
|
276
|
-
# If specified the network requests that are made in the context will be served from the HAR file. Read more about
|
277
|
-
# [Replaying from HAR](../network.md#replaying-from-har).
|
278
301
|
#
|
279
|
-
#
|
280
|
-
#
|
281
|
-
# request interception by setting `Browser.newContext.serviceWorkers` to `'block'`.
|
302
|
+
# If specified the network requests that are made in the context will be served from the HAR file. Read more about [Replaying from HAR](../network.md#replaying-from-har).
|
303
|
+
#
|
304
|
+
# 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'`.
|
282
305
|
def route_from_har(har, notFound: nil, update: nil, url: nil)
|
283
306
|
wrap_impl(@impl.route_from_har(unwrap_impl(har), notFound: unwrap_impl(notFound), update: unwrap_impl(update), url: unwrap_impl(url)))
|
284
307
|
end
|
285
308
|
|
286
|
-
#
|
309
|
+
#
|
310
|
+
# **NOTE**: Service workers are only supported on Chromium-based browsers.
|
287
311
|
#
|
288
312
|
# All existing service workers in the context.
|
289
313
|
def service_workers
|
290
314
|
wrap_impl(@impl.service_workers)
|
291
315
|
end
|
292
316
|
|
317
|
+
#
|
293
318
|
# This setting will change the default maximum navigation time for the following methods and related shortcuts:
|
294
319
|
# - [`method: Page.goBack`]
|
295
320
|
# - [`method: Page.goForward`]
|
@@ -298,40 +323,45 @@ module Playwright
|
|
298
323
|
# - [`method: Page.setContent`]
|
299
324
|
# - [`method: Page.waitForNavigation`]
|
300
325
|
#
|
301
|
-
#
|
326
|
+
# **NOTE**: [`method: Page.setDefaultNavigationTimeout`] and [`method: Page.setDefaultTimeout`] take priority over
|
302
327
|
# [`method: BrowserContext.setDefaultNavigationTimeout`].
|
303
328
|
def set_default_navigation_timeout(timeout)
|
304
329
|
wrap_impl(@impl.set_default_navigation_timeout(unwrap_impl(timeout)))
|
305
330
|
end
|
306
331
|
alias_method :default_navigation_timeout=, :set_default_navigation_timeout
|
307
332
|
|
333
|
+
#
|
308
334
|
# This setting will change the default maximum time for all the methods accepting `timeout` option.
|
309
335
|
#
|
310
|
-
#
|
336
|
+
# **NOTE**: [`method: Page.setDefaultNavigationTimeout`], [`method: Page.setDefaultTimeout`] and
|
311
337
|
# [`method: BrowserContext.setDefaultNavigationTimeout`] take priority over [`method: BrowserContext.setDefaultTimeout`].
|
312
338
|
def set_default_timeout(timeout)
|
313
339
|
wrap_impl(@impl.set_default_timeout(unwrap_impl(timeout)))
|
314
340
|
end
|
315
341
|
alias_method :default_timeout=, :set_default_timeout
|
316
342
|
|
343
|
+
#
|
317
344
|
# The extra HTTP headers will be sent with every request initiated by any page in the context. These headers are merged
|
318
345
|
# with page-specific extra HTTP headers set with [`method: Page.setExtraHTTPHeaders`]. If page overrides a particular
|
319
346
|
# header, page-specific header value will be used instead of the browser context header value.
|
320
347
|
#
|
321
|
-
#
|
348
|
+
# **NOTE**: [`method: BrowserContext.setExtraHTTPHeaders`] does not guarantee the order of headers in the outgoing requests.
|
322
349
|
def set_extra_http_headers(headers)
|
323
350
|
wrap_impl(@impl.set_extra_http_headers(unwrap_impl(headers)))
|
324
351
|
end
|
325
352
|
alias_method :extra_http_headers=, :set_extra_http_headers
|
326
353
|
|
354
|
+
#
|
327
355
|
# Sets the context's geolocation. Passing `null` or `undefined` emulates position unavailable.
|
328
356
|
#
|
357
|
+
# **Usage**
|
358
|
+
#
|
329
359
|
# ```python sync
|
330
360
|
# browser_context.set_geolocation({"latitude": 59.95, "longitude": 30.31667})
|
331
361
|
# ```
|
332
362
|
#
|
333
|
-
#
|
334
|
-
#
|
363
|
+
# **NOTE**: Consider using [`method: BrowserContext.grantPermissions`] to grant permissions for the browser context pages to read
|
364
|
+
# its geolocation.
|
335
365
|
def set_geolocation(geolocation)
|
336
366
|
wrap_impl(@impl.set_geolocation(unwrap_impl(geolocation)))
|
337
367
|
end
|
@@ -342,20 +372,25 @@ module Playwright
|
|
342
372
|
end
|
343
373
|
alias_method :offline=, :set_offline
|
344
374
|
|
375
|
+
#
|
345
376
|
# Returns storage state for this browser context, contains current cookies and local storage snapshot.
|
346
377
|
def storage_state(path: nil)
|
347
378
|
wrap_impl(@impl.storage_state(path: unwrap_impl(path)))
|
348
379
|
end
|
349
380
|
|
350
|
-
#
|
351
|
-
#
|
381
|
+
#
|
382
|
+
# Removes a route created with [`method: BrowserContext.route`]. When `handler` is not specified, removes all
|
383
|
+
# routes for the `url`.
|
352
384
|
def unroute(url, handler: nil)
|
353
385
|
wrap_impl(@impl.unroute(unwrap_impl(url), handler: unwrap_impl(handler)))
|
354
386
|
end
|
355
387
|
|
388
|
+
#
|
356
389
|
# Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
|
357
390
|
# value. Will throw an error if the context closes before the event is fired. Returns the event data value.
|
358
391
|
#
|
392
|
+
# **Usage**
|
393
|
+
#
|
359
394
|
# ```python sync
|
360
395
|
# with context.expect_event("page") as event_info:
|
361
396
|
# page.get_by_role("button").click()
|
@@ -365,18 +400,20 @@ module Playwright
|
|
365
400
|
wrap_impl(@impl.expect_event(unwrap_impl(event), predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
|
366
401
|
end
|
367
402
|
|
368
|
-
#
|
369
|
-
#
|
370
|
-
# the
|
403
|
+
#
|
404
|
+
# Performs action and waits for a new `Page` to be created in the context. If predicate is provided, it passes
|
405
|
+
# `Page` value into the `predicate` function and waits for `predicate(event)` to return a truthy value.
|
406
|
+
# Will throw an error if the context closes before new `Page` is created.
|
371
407
|
def expect_page(predicate: nil, timeout: nil)
|
372
408
|
wrap_impl(@impl.expect_page(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout)))
|
373
409
|
end
|
374
410
|
|
375
|
-
# > NOTE: In most cases, you should use [`method: BrowserContext.waitForEvent`].
|
376
411
|
#
|
377
|
-
#
|
378
|
-
#
|
379
|
-
# `event` is
|
412
|
+
# **NOTE**: In most cases, you should use [`method: BrowserContext.waitForEvent`].
|
413
|
+
#
|
414
|
+
# Waits for given `event` to fire. If predicate is provided, it passes
|
415
|
+
# event's value into the `predicate` function and waits for `predicate(event)` to return a truthy value.
|
416
|
+
# Will throw an error if the browser context is closed before the `event` is fired.
|
380
417
|
def wait_for_event(event, predicate: nil, timeout: nil)
|
381
418
|
raise NotImplementedError.new('wait_for_event is not implemented yet.')
|
382
419
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module Playwright
|
2
|
+
#
|
2
3
|
# BrowserType provides methods to launch a specific browser instance or connect to an existing one. The following is a
|
3
4
|
# typical example of using Playwright to drive automation:
|
4
5
|
#
|
@@ -18,18 +19,20 @@ module Playwright
|
|
18
19
|
# ```
|
19
20
|
class BrowserType < PlaywrightApi
|
20
21
|
|
21
|
-
#
|
22
|
-
# `BrowserType.launchServer` in Node.js, the major and minor version needs to match the client version (1.2.3 → is
|
23
|
-
# compatible with 1.2.x).
|
22
|
+
#
|
23
|
+
# This method attaches Playwright to an existing browser instance. When connecting to another browser launched via `BrowserType.launchServer` in Node.js, the major and minor version needs to match the client version (1.2.3 → is compatible with 1.2.x).
|
24
24
|
def connect(wsEndpoint, headers: nil, slowMo: nil, timeout: nil)
|
25
25
|
raise NotImplementedError.new('connect is not implemented yet.')
|
26
26
|
end
|
27
27
|
|
28
|
+
#
|
28
29
|
# This method attaches Playwright to an existing browser instance using the Chrome DevTools Protocol.
|
29
30
|
#
|
30
31
|
# The default browser context is accessible via [`method: Browser.contexts`].
|
31
32
|
#
|
32
|
-
#
|
33
|
+
# **NOTE**: Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.
|
34
|
+
#
|
35
|
+
# **Usage**
|
33
36
|
#
|
34
37
|
# ```python sync
|
35
38
|
# browser = playwright.chromium.connect_over_cdp("http://localhost:9222")
|
@@ -45,13 +48,17 @@ module Playwright
|
|
45
48
|
wrap_impl(@impl.connect_over_cdp(unwrap_impl(endpointURL), headers: unwrap_impl(headers), slowMo: unwrap_impl(slowMo), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
|
46
49
|
end
|
47
50
|
|
51
|
+
#
|
48
52
|
# A path where Playwright expects to find a bundled browser executable.
|
49
53
|
def executable_path
|
50
54
|
wrap_impl(@impl.executable_path)
|
51
55
|
end
|
52
56
|
|
57
|
+
#
|
53
58
|
# Returns the browser instance.
|
54
59
|
#
|
60
|
+
# **Usage**
|
61
|
+
#
|
55
62
|
# You can use `ignoreDefaultArgs` to filter out `--mute-audio` from default arguments:
|
56
63
|
#
|
57
64
|
# ```python sync
|
@@ -60,18 +67,19 @@ module Playwright
|
|
60
67
|
# )
|
61
68
|
# ```
|
62
69
|
#
|
63
|
-
# > **Chromium-only** Playwright can also be used to control the Google Chrome or Microsoft Edge browsers, but it works
|
64
|
-
#
|
65
|
-
#
|
70
|
+
# > **Chromium-only** Playwright can also be used to control the Google Chrome or Microsoft Edge browsers, but it works best with the version of
|
71
|
+
# Chromium it is bundled with. There is no guarantee it will work with any other version. Use `executablePath`
|
72
|
+
# option with extreme caution.
|
73
|
+
#
|
66
74
|
# >
|
75
|
+
#
|
67
76
|
# > If Google Chrome (rather than Chromium) is preferred, a
|
68
77
|
# [Chrome Canary](https://www.google.com/chrome/browser/canary.html) or
|
69
78
|
# [Dev Channel](https://www.chromium.org/getting-involved/dev-channel) build is suggested.
|
79
|
+
#
|
70
80
|
# >
|
71
|
-
#
|
72
|
-
# video playback. See
|
73
|
-
# [this article](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for other
|
74
|
-
# differences between Chromium and Chrome.
|
81
|
+
#
|
82
|
+
# > 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.
|
75
83
|
# [This article](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md)
|
76
84
|
# describes some differences for Linux users.
|
77
85
|
def launch(
|
@@ -96,10 +104,11 @@ module Playwright
|
|
96
104
|
wrap_impl(@impl.launch(args: unwrap_impl(args), channel: unwrap_impl(channel), chromiumSandbox: unwrap_impl(chromiumSandbox), devtools: unwrap_impl(devtools), downloadsPath: unwrap_impl(downloadsPath), env: unwrap_impl(env), executablePath: unwrap_impl(executablePath), firefoxUserPrefs: unwrap_impl(firefoxUserPrefs), handleSIGHUP: unwrap_impl(handleSIGHUP), handleSIGINT: unwrap_impl(handleSIGINT), handleSIGTERM: unwrap_impl(handleSIGTERM), headless: unwrap_impl(headless), ignoreDefaultArgs: unwrap_impl(ignoreDefaultArgs), proxy: unwrap_impl(proxy), slowMo: unwrap_impl(slowMo), timeout: unwrap_impl(timeout), tracesDir: unwrap_impl(tracesDir), &wrap_block_call(block)))
|
97
105
|
end
|
98
106
|
|
107
|
+
#
|
99
108
|
# Returns the persistent browser context instance.
|
100
109
|
#
|
101
|
-
# Launches browser that uses persistent storage located at `userDataDir` and returns the only context. Closing
|
102
|
-
# context will automatically close the browser.
|
110
|
+
# Launches browser that uses persistent storage located at `userDataDir` and returns the only context. Closing
|
111
|
+
# this context will automatically close the browser.
|
103
112
|
def launch_persistent_context(
|
104
113
|
userDataDir,
|
105
114
|
acceptDownloads: nil,
|
@@ -153,6 +162,7 @@ module Playwright
|
|
153
162
|
wrap_impl(@impl.launch_persistent_context(unwrap_impl(userDataDir), acceptDownloads: unwrap_impl(acceptDownloads), args: unwrap_impl(args), baseURL: unwrap_impl(baseURL), bypassCSP: unwrap_impl(bypassCSP), channel: unwrap_impl(channel), chromiumSandbox: unwrap_impl(chromiumSandbox), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), devtools: unwrap_impl(devtools), downloadsPath: unwrap_impl(downloadsPath), env: unwrap_impl(env), executablePath: unwrap_impl(executablePath), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), forcedColors: unwrap_impl(forcedColors), geolocation: unwrap_impl(geolocation), handleSIGHUP: unwrap_impl(handleSIGHUP), handleSIGINT: unwrap_impl(handleSIGINT), handleSIGTERM: unwrap_impl(handleSIGTERM), hasTouch: unwrap_impl(hasTouch), headless: unwrap_impl(headless), httpCredentials: unwrap_impl(httpCredentials), ignoreDefaultArgs: unwrap_impl(ignoreDefaultArgs), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_content: unwrap_impl(record_har_content), record_har_mode: unwrap_impl(record_har_mode), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_har_url_filter: unwrap_impl(record_har_url_filter), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), serviceWorkers: unwrap_impl(serviceWorkers), slowMo: unwrap_impl(slowMo), strictSelectors: unwrap_impl(strictSelectors), timeout: unwrap_impl(timeout), timezoneId: unwrap_impl(timezoneId), tracesDir: unwrap_impl(tracesDir), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
|
154
163
|
end
|
155
164
|
|
165
|
+
#
|
156
166
|
# Returns browser name. For example: `'chromium'`, `'webkit'` or `'firefox'`.
|
157
167
|
def name
|
158
168
|
wrap_impl(@impl.name)
|
@@ -6,10 +6,8 @@ module Playwright
|
|
6
6
|
# - protocol events can be subscribed to with `session.on` method.
|
7
7
|
#
|
8
8
|
# Useful links:
|
9
|
-
# - Documentation on DevTools Protocol can be found here:
|
10
|
-
#
|
11
|
-
# - Getting Started with DevTools Protocol:
|
12
|
-
# https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md
|
9
|
+
# - Documentation on DevTools Protocol can be found here: [DevTools Protocol Viewer](https://chromedevtools.github.io/devtools-protocol/).
|
10
|
+
# - Getting Started with DevTools Protocol: https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md
|
13
11
|
#
|
14
12
|
# ```python sync
|
15
13
|
# client = page.context.new_cdp_session(page)
|
@@ -23,6 +21,7 @@ module Playwright
|
|
23
21
|
# ```
|
24
22
|
class CDPSession < PlaywrightApi
|
25
23
|
|
24
|
+
#
|
26
25
|
# Detaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be used to
|
27
26
|
# send messages.
|
28
27
|
def detach
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Playwright
|
2
|
-
#
|
3
|
-
#
|
2
|
+
#
|
3
|
+
# `ConsoleMessage` objects are dispatched by page via the [`event: Page.console`] event.
|
4
|
+
# For each console messages logged in the page there will be corresponding event in the Playwright
|
5
|
+
# context.
|
4
6
|
#
|
5
7
|
# ```python sync
|
6
8
|
# # Listen for all console logs
|
@@ -21,6 +23,7 @@ module Playwright
|
|
21
23
|
# ```
|
22
24
|
class ConsoleMessage < PlaywrightApi
|
23
25
|
|
26
|
+
#
|
24
27
|
# List of arguments passed to a `console` function call. See also [`event: Page.console`].
|
25
28
|
def args
|
26
29
|
wrap_impl(@impl.args)
|
@@ -30,11 +33,13 @@ module Playwright
|
|
30
33
|
wrap_impl(@impl.location)
|
31
34
|
end
|
32
35
|
|
36
|
+
#
|
33
37
|
# The text of the console message.
|
34
38
|
def text
|
35
39
|
wrap_impl(@impl.text)
|
36
40
|
end
|
37
41
|
|
42
|
+
#
|
38
43
|
# One of the following values: `'log'`, `'debug'`, `'info'`, `'error'`, `'warning'`, `'dir'`, `'dirxml'`, `'table'`,
|
39
44
|
# `'trace'`, `'clear'`, `'startGroup'`, `'startGroupCollapsed'`, `'endGroup'`, `'assert'`, `'profile'`, `'profileEnd'`,
|
40
45
|
# `'count'`, `'timeEnd'`.
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module Playwright
|
2
|
+
#
|
2
3
|
# `Dialog` objects are dispatched by page via the [`event: Page.dialog`] event.
|
3
4
|
#
|
4
5
|
# An example of using `Dialog` class:
|
@@ -22,32 +23,35 @@ module Playwright
|
|
22
23
|
# run(playwright)
|
23
24
|
# ```
|
24
25
|
#
|
25
|
-
#
|
26
|
-
# present, it **must** either [`method: Dialog.accept`] or [`method: Dialog.dismiss`] the dialog - otherwise the page will
|
27
|
-
# [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and
|
28
|
-
# actions like click will never finish.
|
26
|
+
# **NOTE**: Dialogs are dismissed automatically, unless there is a [`event: Page.dialog`] listener.
|
27
|
+
# When listener is present, it **must** either [`method: Dialog.accept`] or [`method: 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.
|
29
28
|
class Dialog < PlaywrightApi
|
30
29
|
|
30
|
+
#
|
31
31
|
# Returns when the dialog has been accepted.
|
32
32
|
def accept(promptText: nil)
|
33
33
|
wrap_impl(@impl.accept(promptText: unwrap_impl(promptText)))
|
34
34
|
end
|
35
35
|
|
36
|
+
#
|
36
37
|
# If dialog is prompt, returns default prompt value. Otherwise, returns empty string.
|
37
38
|
def default_value
|
38
39
|
wrap_impl(@impl.default_value)
|
39
40
|
end
|
40
41
|
|
42
|
+
#
|
41
43
|
# Returns when the dialog has been dismissed.
|
42
44
|
def dismiss
|
43
45
|
wrap_impl(@impl.dismiss)
|
44
46
|
end
|
45
47
|
|
48
|
+
#
|
46
49
|
# A message displayed in the dialog.
|
47
50
|
def message
|
48
51
|
wrap_impl(@impl.message)
|
49
52
|
end
|
50
53
|
|
54
|
+
#
|
51
55
|
# Returns dialog's type, can be one of `alert`, `beforeunload`, `confirm` or `prompt`.
|
52
56
|
def type
|
53
57
|
wrap_impl(@impl.type)
|
@@ -1,7 +1,9 @@
|
|
1
1
|
module Playwright
|
2
|
+
#
|
2
3
|
# `Download` objects are dispatched by page via the [`event: Page.download`] event.
|
3
4
|
#
|
4
|
-
# All the downloaded files belonging to the browser context are deleted when the
|
5
|
+
# All the downloaded files belonging to the browser context are deleted when the
|
6
|
+
# browser context is closed.
|
5
7
|
#
|
6
8
|
# Download event is emitted once the download starts. Download path becomes available once download completes:
|
7
9
|
#
|
@@ -14,42 +16,49 @@ module Playwright
|
|
14
16
|
# ```
|
15
17
|
class Download < PlaywrightApi
|
16
18
|
|
17
|
-
#
|
18
|
-
#
|
19
|
+
#
|
20
|
+
# Cancels a download. Will not fail if the download is already finished or canceled.
|
21
|
+
# Upon successful cancellations, `download.failure()` would resolve to `'canceled'`.
|
19
22
|
def cancel
|
20
23
|
wrap_impl(@impl.cancel)
|
21
24
|
end
|
22
25
|
|
26
|
+
#
|
23
27
|
# Deletes the downloaded file. Will wait for the download to finish if necessary.
|
24
28
|
def delete
|
25
29
|
wrap_impl(@impl.delete)
|
26
30
|
end
|
27
31
|
|
32
|
+
#
|
28
33
|
# Returns download error if any. Will wait for the download to finish if necessary.
|
29
34
|
def failure
|
30
35
|
wrap_impl(@impl.failure)
|
31
36
|
end
|
32
37
|
|
38
|
+
#
|
33
39
|
# Get the page that the download belongs to.
|
34
40
|
def page
|
35
41
|
wrap_impl(@impl.page)
|
36
42
|
end
|
37
43
|
|
38
|
-
# Returns path to the downloaded file in case of successful download. The method will wait for the download to finish if
|
39
|
-
# necessary. The method throws when connected remotely.
|
40
44
|
#
|
41
|
-
#
|
42
|
-
#
|
45
|
+
# Returns path to the downloaded file in case of successful download. The method will
|
46
|
+
# wait for the download to finish if necessary. The method throws when connected remotely.
|
47
|
+
#
|
48
|
+
# Note that the download's file name is a random GUID, use [`method: Download.suggestedFilename`]
|
49
|
+
# to get suggested file name.
|
43
50
|
def path
|
44
51
|
wrap_impl(@impl.path)
|
45
52
|
end
|
46
53
|
|
47
|
-
#
|
48
|
-
#
|
54
|
+
#
|
55
|
+
# Copy the download to a user-specified path. It is safe to call this method while the download
|
56
|
+
# is still in progress. Will wait for the download to finish if necessary.
|
49
57
|
def save_as(path)
|
50
58
|
wrap_impl(@impl.save_as(unwrap_impl(path)))
|
51
59
|
end
|
52
60
|
|
61
|
+
#
|
53
62
|
# Returns suggested filename for this download. It is typically computed by the browser from the
|
54
63
|
# [`Content-Disposition`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition) response header
|
55
64
|
# or the `download` attribute. See the spec on [whatwg](https://html.spec.whatwg.org/#downloading-resources). Different
|
@@ -58,6 +67,7 @@ module Playwright
|
|
58
67
|
wrap_impl(@impl.suggested_filename)
|
59
68
|
end
|
60
69
|
|
70
|
+
#
|
61
71
|
# Returns downloaded url.
|
62
72
|
def url
|
63
73
|
wrap_impl(@impl.url)
|