playwright-ruby-client 0.5.9 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/documentation/README.md +33 -0
  4. data/documentation/babel.config.js +3 -0
  5. data/documentation/docs/api/accessibility.md +7 -0
  6. data/documentation/docs/api/browser.md +187 -0
  7. data/documentation/docs/api/browser_context.md +397 -0
  8. data/documentation/docs/api/browser_type.md +105 -0
  9. data/documentation/docs/api/cdp_session.md +7 -0
  10. data/documentation/docs/api/console_message.md +41 -0
  11. data/documentation/docs/api/dialog.md +71 -0
  12. data/documentation/docs/api/element_handle.md +618 -0
  13. data/documentation/docs/api/experimental/_category_.yml +3 -0
  14. data/documentation/docs/api/experimental/android.md +25 -0
  15. data/documentation/docs/api/experimental/android_device.md +92 -0
  16. data/documentation/docs/api/experimental/android_input.md +38 -0
  17. data/documentation/docs/api/experimental/android_socket.md +7 -0
  18. data/documentation/docs/api/experimental/android_web_view.md +7 -0
  19. data/documentation/docs/api/file_chooser.md +50 -0
  20. data/documentation/docs/api/frame.md +866 -0
  21. data/documentation/docs/api/js_handle.md +113 -0
  22. data/documentation/docs/api/keyboard.md +157 -0
  23. data/documentation/docs/api/mouse.md +69 -0
  24. data/documentation/docs/api/page.md +1402 -0
  25. data/documentation/docs/api/playwright.md +63 -0
  26. data/documentation/docs/api/request.md +188 -0
  27. data/documentation/docs/api/response.md +97 -0
  28. data/documentation/docs/api/route.md +80 -0
  29. data/documentation/docs/api/selectors.md +23 -0
  30. data/documentation/docs/api/touchscreen.md +8 -0
  31. data/documentation/docs/api/tracing.md +54 -0
  32. data/documentation/docs/api/web_socket.md +7 -0
  33. data/documentation/docs/api/worker.md +24 -0
  34. data/documentation/docs/article/api_coverage.mdx +11 -0
  35. data/documentation/docs/article/getting_started.md +152 -0
  36. data/documentation/docs/article/guides/_category_.yml +3 -0
  37. data/documentation/docs/article/guides/download_playwright_driver.md +49 -0
  38. data/documentation/docs/article/guides/launch_browser.md +119 -0
  39. data/documentation/docs/article/guides/rails_integration.md +162 -0
  40. data/{docs → documentation/docs/include}/api_coverage.md +12 -1
  41. data/documentation/docusaurus.config.js +107 -0
  42. data/documentation/package.json +39 -0
  43. data/documentation/sidebars.js +15 -0
  44. data/documentation/src/components/HomepageFeatures.js +61 -0
  45. data/documentation/src/components/HomepageFeatures.module.css +13 -0
  46. data/documentation/src/css/custom.css +44 -0
  47. data/documentation/src/pages/index.js +50 -0
  48. data/documentation/src/pages/index.module.css +41 -0
  49. data/documentation/src/pages/markdown-page.md +7 -0
  50. data/documentation/static/.nojekyll +0 -0
  51. data/documentation/static/img/playwright-logo.svg +9 -0
  52. data/documentation/static/img/undraw_dropdown_menu.svg +1 -0
  53. data/documentation/static/img/undraw_web_development.svg +1 -0
  54. data/documentation/static/img/undraw_windows.svg +1 -0
  55. data/documentation/yarn.lock +8805 -0
  56. data/lib/playwright/channel_owners/binding_call.rb +33 -0
  57. data/lib/playwright/channel_owners/browser.rb +11 -2
  58. data/lib/playwright/channel_owners/browser_context.rb +58 -6
  59. data/lib/playwright/channel_owners/browser_type.rb +8 -1
  60. data/lib/playwright/channel_owners/element_handle.rb +17 -16
  61. data/lib/playwright/channel_owners/frame.rb +24 -34
  62. data/lib/playwright/channel_owners/js_handle.rb +2 -10
  63. data/lib/playwright/channel_owners/page.rb +37 -52
  64. data/lib/playwright/channel_owners/worker.rb +4 -0
  65. data/lib/playwright/download.rb +3 -2
  66. data/lib/playwright/events.rb +4 -0
  67. data/lib/playwright/input_files.rb +0 -8
  68. data/lib/playwright/javascript.rb +0 -10
  69. data/lib/playwright/javascript/expression.rb +2 -7
  70. data/lib/playwright/playwright_api.rb +16 -1
  71. data/lib/playwright/tracing_impl.rb +31 -0
  72. data/lib/playwright/version.rb +2 -1
  73. data/lib/playwright_api/accessibility.rb +7 -88
  74. data/lib/playwright_api/android.rb +2 -59
  75. data/lib/playwright_api/android_device.rb +6 -5
  76. data/lib/playwright_api/browser.rb +13 -122
  77. data/lib/playwright_api/browser_context.rb +66 -433
  78. data/lib/playwright_api/browser_type.rb +28 -78
  79. data/lib/playwright_api/cdp_session.rb +2 -25
  80. data/lib/playwright_api/console_message.rb +2 -0
  81. data/lib/playwright_api/dialog.rb +5 -63
  82. data/lib/playwright_api/element_handle.rb +96 -294
  83. data/lib/playwright_api/file_chooser.rb +0 -21
  84. data/lib/playwright_api/frame.rb +98 -564
  85. data/lib/playwright_api/js_handle.rb +10 -67
  86. data/lib/playwright_api/keyboard.rb +22 -166
  87. data/lib/playwright_api/mouse.rb +1 -45
  88. data/lib/playwright_api/page.rb +223 -1224
  89. data/lib/playwright_api/playwright.rb +8 -93
  90. data/lib/playwright_api/request.rb +9 -87
  91. data/lib/playwright_api/response.rb +1 -1
  92. data/lib/playwright_api/route.rb +3 -80
  93. data/lib/playwright_api/selectors.rb +0 -66
  94. data/lib/playwright_api/tracing.rb +39 -0
  95. data/lib/playwright_api/web_socket.rb +1 -1
  96. data/lib/playwright_api/worker.rb +28 -42
  97. data/playwright.gemspec +2 -2
  98. metadata +60 -20
  99. data/lib/playwright/javascript/function.rb +0 -67
@@ -1,66 +1,15 @@
1
1
  module Playwright
2
2
  # - extends: [EventEmitter]
3
- #
3
+ #
4
4
  # Page provides methods to interact with a single tab in a `Browser`, or an
5
5
  # [extension background page](https://developer.chrome.com/extensions/background_pages) in Chromium. One `Browser`
6
6
  # instance might have multiple `Page` instances.
7
- #
7
+ #
8
8
  # This example creates a page, navigates it to a URL, and then saves a screenshot:
9
- #
10
9
  #
11
- # ```js
12
- # const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
13
- #
14
- # (async () => {
15
- # const browser = await webkit.launch();
16
- # const context = await browser.newContext();
17
- # const page = await context.newPage();
18
- # await page.goto('https://example.com');
19
- # await page.screenshot({path: 'screenshot.png'});
20
- # await browser.close();
21
- # })();
22
- # ```
23
- #
24
- # ```java
25
- # import com.microsoft.playwright.*;
26
- #
27
- # public class Example {
28
- # public static void main(String[] args) {
29
- # try (Playwright playwright = Playwright.create()) {
30
- # BrowserType webkit = playwright.webkit();
31
- # Browser browser = webkit.launch();
32
- # BrowserContext context = browser.newContext();
33
- # Page page = context.newPage();
34
- # page.navigate("https://example.com");
35
- # page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("screenshot.png")));
36
- # browser.close();
37
- # }
38
- # }
39
- # }
40
- # ```
41
- #
42
- # ```python async
43
- # import asyncio
44
- # from playwright.async_api import async_playwright
45
- #
46
- # async def run(playwright):
47
- # webkit = playwright.webkit
48
- # browser = await webkit.launch()
49
- # context = await browser.new_context()
50
- # page = await context.new_page()
51
- # await page.goto("https://example.com")
52
- # await page.screenshot(path="screenshot.png")
53
- # await browser.close()
54
- #
55
- # async def main():
56
- # async with async_playwright() as playwright:
57
- # await run(playwright)
58
- # asyncio.run(main())
59
- # ```
60
- #
61
10
  # ```python sync
62
11
  # from playwright.sync_api import sync_playwright
63
- #
12
+ #
64
13
  # def run(playwright):
65
14
  # webkit = playwright.webkit
66
15
  # browser = webkit.launch()
@@ -69,51 +18,23 @@ module Playwright
69
18
  # page.goto("https://example.com")
70
19
  # page.screenshot(path="screenshot.png")
71
20
  # browser.close()
72
- #
21
+ #
73
22
  # with sync_playwright() as playwright:
74
23
  # run(playwright)
75
24
  # ```
76
- #
25
+ #
77
26
  # The Page class emits various events (described below) which can be handled using any of Node's native
78
27
  # [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter) methods, such as `on`, `once` or
79
28
  # `removeListener`.
80
- #
29
+ #
81
30
  # This example logs a message for a single page `load` event:
82
- #
83
31
  #
84
- # ```js
85
- # page.once('load', () => console.log('Page loaded!'));
86
- # ```
87
- #
88
- # ```java
89
- # page.onLoad(p -> System.out.println("Page loaded!"));
90
- # ```
91
- #
92
32
  # ```py
93
33
  # page.once("load", lambda: print("page loaded!"))
94
34
  # ```
95
- #
35
+ #
96
36
  # To unsubscribe from events use the `removeListener` method:
97
- #
98
37
  #
99
- # ```js
100
- # function logRequest(interceptedRequest) {
101
- # console.log('A request was made:', interceptedRequest.url());
102
- # }
103
- # page.on('request', logRequest);
104
- # // Sometime later...
105
- # page.removeListener('request', logRequest);
106
- # ```
107
- #
108
- # ```java
109
- # Consumer<Request> logRequest = interceptedRequest -> {
110
- # System.out.println("A request was made: " + interceptedRequest.url());
111
- # };
112
- # page.onRequest(logRequest);
113
- # // Sometime later...
114
- # page.offRequest(logRequest);
115
- # ```
116
- #
117
38
  # ```py
118
39
  # def log_request(intercepted_request):
119
40
  # print("a request was made:", intercepted_request.url)
@@ -143,39 +64,17 @@ module Playwright
143
64
  # - Whenever the page is navigated.
144
65
  # - Whenever the child frame is attached or navigated. In this case, the script is evaluated in the context of the newly
145
66
  # attached frame.
146
- #
67
+ #
147
68
  # The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend
148
69
  # the JavaScript environment, e.g. to seed `Math.random`.
149
- #
150
- # An example of overriding `Math.random` before the page loads:
151
- #
152
70
  #
153
- # ```js browser
154
- # // preload.js
155
- # Math.random = () => 42;
156
- # ```
157
- #
71
+ # An example of overriding `Math.random` before the page loads:
158
72
  #
159
- # ```js
160
- # // In your playwright script, assuming the preload.js file is in same directory
161
- # await page.addInitScript({ path: './preload.js' });
162
- # ```
163
- #
164
- # ```java
165
- # // In your playwright script, assuming the preload.js file is in same directory
166
- # page.addInitScript(Paths.get("./preload.js"));
167
- # ```
168
- #
169
- # ```python async
170
- # # in your playwright script, assuming the preload.js file is in same directory
171
- # await page.add_init_script(path="./preload.js")
172
- # ```
173
- #
174
73
  # ```python sync
175
74
  # # in your playwright script, assuming the preload.js file is in same directory
176
75
  # page.add_init_script(path="./preload.js")
177
76
  # ```
178
- #
77
+ #
179
78
  # > NOTE: The order of evaluation of multiple scripts installed via [`method: BrowserContext.addInitScript`] and
180
79
  # [`method: Page.addInitScript`] is not defined.
181
80
  def add_init_script(path: nil, script: nil)
@@ -184,7 +83,7 @@ module Playwright
184
83
 
185
84
  # Adds a `<script>` tag into the page with the desired url or content. Returns the added tag when the script's onload
186
85
  # fires or when the script content was injected into frame.
187
- #
86
+ #
188
87
  # Shortcut for main frame's [`method: Frame.addScriptTag`].
189
88
  def add_script_tag(content: nil, path: nil, type: nil, url: nil)
190
89
  wrap_impl(@impl.add_script_tag(content: unwrap_impl(content), path: unwrap_impl(path), type: unwrap_impl(type), url: unwrap_impl(url)))
@@ -192,7 +91,7 @@ module Playwright
192
91
 
193
92
  # Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the
194
93
  # content. Returns the added tag when the stylesheet's onload fires or when the CSS content was injected into frame.
195
- #
94
+ #
196
95
  # Shortcut for main frame's [`method: Frame.addStyleTag`].
197
96
  def add_style_tag(content: nil, path: nil, url: nil)
198
97
  wrap_impl(@impl.add_style_tag(content: unwrap_impl(content), path: unwrap_impl(path), url: unwrap_impl(url)))
@@ -213,18 +112,19 @@ module Playwright
213
112
  # 1. Use [`property: Page.mouse`] to click in the center of the element.
214
113
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
215
114
  # 1. Ensure that the element is now checked. If not, this method throws.
216
- #
115
+ #
217
116
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
218
117
  # zero timeout disables this.
219
- #
118
+ #
220
119
  # Shortcut for main frame's [`method: Frame.check`].
221
120
  def check(
222
121
  selector,
223
122
  force: nil,
224
123
  noWaitAfter: nil,
225
124
  position: nil,
226
- timeout: nil)
227
- wrap_impl(@impl.check(unwrap_impl(selector), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout)))
125
+ timeout: nil,
126
+ trial: nil)
127
+ wrap_impl(@impl.check(unwrap_impl(selector), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
228
128
  end
229
129
 
230
130
  # This method clicks an element matching `selector` by performing the following steps:
@@ -234,10 +134,10 @@ module Playwright
234
134
  # 1. Scroll the element into view if needed.
235
135
  # 1. Use [`property: Page.mouse`] to click in the center of the element, or the specified `position`.
236
136
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
237
- #
137
+ #
238
138
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
239
139
  # zero timeout disables this.
240
- #
140
+ #
241
141
  # Shortcut for main frame's [`method: Frame.click`].
242
142
  def click(
243
143
  selector,
@@ -248,15 +148,16 @@ module Playwright
248
148
  modifiers: nil,
249
149
  noWaitAfter: nil,
250
150
  position: nil,
251
- timeout: nil)
252
- wrap_impl(@impl.click(unwrap_impl(selector), button: unwrap_impl(button), clickCount: unwrap_impl(clickCount), delay: unwrap_impl(delay), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout)))
151
+ timeout: nil,
152
+ trial: nil)
153
+ wrap_impl(@impl.click(unwrap_impl(selector), button: unwrap_impl(button), clickCount: unwrap_impl(clickCount), delay: unwrap_impl(delay), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
253
154
  end
254
155
 
255
156
  # If `runBeforeUnload` is `false`, does not run any unload handlers and waits for the page to be closed. If
256
157
  # `runBeforeUnload` is `true` the method will run unload handlers, but will **not** wait for the page to close.
257
- #
158
+ #
258
159
  # By default, `page.close()` **does not** run `beforeunload` handlers.
259
- #
160
+ #
260
161
  # > NOTE: if `runBeforeUnload` is passed as true, a `beforeunload` dialog might be summoned and should be handled manually
261
162
  # via [`event: Page.dialog`] event.
262
163
  def close(runBeforeUnload: nil)
@@ -281,12 +182,12 @@ module Playwright
281
182
  # 1. Use [`property: Page.mouse`] to double click in the center of the element, or the specified `position`.
282
183
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the
283
184
  # first click of the `dblclick()` triggers a navigation event, this method will throw.
284
- #
185
+ #
285
186
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
286
187
  # zero timeout disables this.
287
- #
188
+ #
288
189
  # > NOTE: `page.dblclick()` dispatches two `click` events and a single `dblclick` event.
289
- #
190
+ #
290
191
  # Shortcut for main frame's [`method: Frame.dblclick`].
291
192
  def dblclick(
292
193
  selector,
@@ -296,34 +197,22 @@ module Playwright
296
197
  modifiers: nil,
297
198
  noWaitAfter: nil,
298
199
  position: nil,
299
- timeout: nil)
300
- wrap_impl(@impl.dblclick(unwrap_impl(selector), button: unwrap_impl(button), delay: unwrap_impl(delay), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout)))
200
+ timeout: nil,
201
+ trial: nil)
202
+ wrap_impl(@impl.dblclick(unwrap_impl(selector), button: unwrap_impl(button), delay: unwrap_impl(delay), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
301
203
  end
302
204
 
303
205
  # The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element,
304
206
  # `click` is dispatched. This is equivalent to calling
305
207
  # [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
306
- #
307
208
  #
308
- # ```js
309
- # await page.dispatchEvent('button#submit', 'click');
310
- # ```
311
- #
312
- # ```java
313
- # page.dispatchEvent("button#submit", "click");
314
- # ```
315
- #
316
- # ```python async
317
- # await page.dispatch_event("button#submit", "click")
318
- # ```
319
- #
320
209
  # ```python sync
321
210
  # page.dispatch_event("button#submit", "click")
322
211
  # ```
323
- #
212
+ #
324
213
  # Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties
325
214
  # and dispatches it on the element. Events are `composed`, `cancelable` and bubble by default.
326
- #
215
+ #
327
216
  # Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial properties:
328
217
  # - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
329
218
  # - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
@@ -332,30 +221,9 @@ module Playwright
332
221
  # - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
333
222
  # - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
334
223
  # - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
335
- #
224
+ #
336
225
  # You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
337
- #
338
226
  #
339
- # ```js
340
- # // Note you can only create DataTransfer in Chromium and Firefox
341
- # const dataTransfer = await page.evaluateHandle(() => new DataTransfer());
342
- # await page.dispatchEvent('#source', 'dragstart', { dataTransfer });
343
- # ```
344
- #
345
- # ```java
346
- # // Note you can only create DataTransfer in Chromium and Firefox
347
- # JSHandle dataTransfer = page.evaluateHandle("() => new DataTransfer()");
348
- # Map<String, Object> arg = new HashMap<>();
349
- # arg.put("dataTransfer", dataTransfer);
350
- # page.dispatchEvent("#source", "dragstart", arg);
351
- # ```
352
- #
353
- # ```python async
354
- # # note you can only create data_transfer in chromium and firefox
355
- # data_transfer = await page.evaluate_handle("new DataTransfer()")
356
- # await page.dispatch_event("#source", "dragstart", { "dataTransfer": data_transfer })
357
- # ```
358
- #
359
227
  # ```python sync
360
228
  # # note you can only create data_transfer in chromium and firefox
361
229
  # data_transfer = page.evaluate_handle("new DataTransfer()")
@@ -365,114 +233,28 @@ module Playwright
365
233
  wrap_impl(@impl.dispatch_event(unwrap_impl(selector), unwrap_impl(type), eventInit: unwrap_impl(eventInit), timeout: unwrap_impl(timeout)))
366
234
  end
367
235
 
236
+ # This method changes the `CSS media type` through the `media` argument, and/or the `'prefers-colors-scheme'` media
237
+ # feature, using the `colorScheme` argument.
368
238
  #
369
- # ```js
370
- # await page.evaluate(() => matchMedia('screen').matches);
371
- # // → true
372
- # await page.evaluate(() => matchMedia('print').matches);
373
- # // → false
374
- #
375
- # await page.emulateMedia({ media: 'print' });
376
- # await page.evaluate(() => matchMedia('screen').matches);
377
- # // → false
378
- # await page.evaluate(() => matchMedia('print').matches);
379
- # // → true
380
- #
381
- # await page.emulateMedia({});
382
- # await page.evaluate(() => matchMedia('screen').matches);
383
- # // → true
384
- # await page.evaluate(() => matchMedia('print').matches);
385
- # // → false
386
- # ```
387
- #
388
- # ```java
389
- # page.evaluate("() => matchMedia('screen').matches");
390
- # // → true
391
- # page.evaluate("() => matchMedia('print').matches");
392
- # // → false
393
- #
394
- # page.emulateMedia(new Page.EmulateMediaOptions().setMedia(Media.PRINT));
395
- # page.evaluate("() => matchMedia('screen').matches");
396
- # // → false
397
- # page.evaluate("() => matchMedia('print').matches");
398
- # // → true
399
- #
400
- # page.emulateMedia(new Page.EmulateMediaOptions());
401
- # page.evaluate("() => matchMedia('screen').matches");
402
- # // → true
403
- # page.evaluate("() => matchMedia('print').matches");
404
- # // → false
405
- # ```
406
- #
407
- # ```python async
408
- # await page.evaluate("matchMedia('screen').matches")
409
- # # → True
410
- # await page.evaluate("matchMedia('print').matches")
411
- # # → False
412
- #
413
- # await page.emulate_media(media="print")
414
- # await page.evaluate("matchMedia('screen').matches")
415
- # # → False
416
- # await page.evaluate("matchMedia('print').matches")
417
- # # → True
418
- #
419
- # await page.emulate_media()
420
- # await page.evaluate("matchMedia('screen').matches")
421
- # # → True
422
- # await page.evaluate("matchMedia('print').matches")
423
- # # → False
424
- # ```
425
- #
426
239
  # ```python sync
427
240
  # page.evaluate("matchMedia('screen').matches")
428
241
  # # → True
429
242
  # page.evaluate("matchMedia('print').matches")
430
243
  # # → False
431
- #
244
+ #
432
245
  # page.emulate_media(media="print")
433
246
  # page.evaluate("matchMedia('screen').matches")
434
247
  # # → False
435
248
  # page.evaluate("matchMedia('print').matches")
436
249
  # # → True
437
- #
250
+ #
438
251
  # page.emulate_media()
439
252
  # page.evaluate("matchMedia('screen').matches")
440
253
  # # → True
441
254
  # page.evaluate("matchMedia('print').matches")
442
255
  # # → False
443
256
  # ```
444
- #
445
- #
446
- # ```js
447
- # await page.emulateMedia({ colorScheme: 'dark' });
448
- # await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches);
449
- # // → true
450
- # await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches);
451
- # // → false
452
- # await page.evaluate(() => matchMedia('(prefers-color-scheme: no-preference)').matches);
453
- # // → false
454
- # ```
455
- #
456
- # ```java
457
- # page.emulateMedia(new Page.EmulateMediaOptions().setColorScheme(ColorScheme.DARK));
458
- # page.evaluate("() => matchMedia('(prefers-color-scheme: dark)').matches");
459
- # // → true
460
- # page.evaluate("() => matchMedia('(prefers-color-scheme: light)').matches");
461
- # // → false
462
- # page.evaluate("() => matchMedia('(prefers-color-scheme: no-preference)').matches");
463
- # // → false
464
- # ```
465
- #
466
- # ```python async
467
- # await page.emulate_media(color_scheme="dark")
468
- # await page.evaluate("matchMedia('(prefers-color-scheme: dark)').matches")
469
- # # → True
470
- # await page.evaluate("matchMedia('(prefers-color-scheme: light)').matches")
471
- # # → False
472
- # await page.evaluate("matchMedia('(prefers-color-scheme: no-preference)').matches")
473
- # # → False
474
- # ```
475
- #
257
+ #
476
258
  # ```python sync
477
259
  # page.emulate_media(color_scheme="dark")
478
260
  # page.evaluate("matchMedia('(prefers-color-scheme: dark)').matches")
@@ -481,43 +263,24 @@ module Playwright
481
263
  # # → False
482
264
  # page.evaluate("matchMedia('(prefers-color-scheme: no-preference)').matches")
483
265
  # ```
484
- def emulate_media(colorScheme: nil, media: nil)
485
- wrap_impl(@impl.emulate_media(colorScheme: unwrap_impl(colorScheme), media: unwrap_impl(media)))
266
+ def emulate_media(colorScheme: nil, media: nil, reducedMotion: nil)
267
+ wrap_impl(@impl.emulate_media(colorScheme: unwrap_impl(colorScheme), media: unwrap_impl(media), reducedMotion: unwrap_impl(reducedMotion)))
486
268
  end
487
269
 
488
270
  # The method finds an element matching the specified selector within the page and passes it as a first argument to
489
271
  # `expression`. If no elements match the selector, the method throws an error. Returns the value of `expression`.
490
- #
272
+ #
491
273
  # If `expression` returns a [Promise], then [`method: Page.evalOnSelector`] would wait for the promise to resolve and
492
274
  # return its value.
493
- #
275
+ #
494
276
  # Examples:
495
- #
496
277
  #
497
- # ```js
498
- # const searchValue = await page.$eval('#search', el => el.value);
499
- # const preloadHref = await page.$eval('link[rel=preload]', el => el.href);
500
- # const html = await page.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello');
501
- # ```
502
- #
503
- # ```java
504
- # String searchValue = (String) page.evalOnSelector("#search", "el => el.value");
505
- # String preloadHref = (String) page.evalOnSelector("link[rel=preload]", "el => el.href");
506
- # String html = (String) page.evalOnSelector(".main-container", "(e, suffix) => e.outerHTML + suffix", "hello");
507
- # ```
508
- #
509
- # ```python async
510
- # search_value = await page.eval_on_selector("#search", "el => el.value")
511
- # preload_href = await page.eval_on_selector("link[rel=preload]", "el => el.href")
512
- # html = await page.eval_on_selector(".main-container", "(e, suffix) => e.outer_html + suffix", "hello")
513
- # ```
514
- #
515
278
  # ```python sync
516
279
  # search_value = page.eval_on_selector("#search", "el => el.value")
517
280
  # preload_href = page.eval_on_selector("link[rel=preload]", "el => el.href")
518
281
  # html = page.eval_on_selector(".main-container", "(e, suffix) => e.outer_html + suffix", "hello")
519
282
  # ```
520
- #
283
+ #
521
284
  # Shortcut for main frame's [`method: Frame.evalOnSelector`].
522
285
  def eval_on_selector(selector, expression, arg: nil)
523
286
  wrap_impl(@impl.eval_on_selector(unwrap_impl(selector), unwrap_impl(expression), arg: unwrap_impl(arg)))
@@ -525,25 +288,12 @@ module Playwright
525
288
 
526
289
  # The method finds all elements matching the specified selector within the page and passes an array of matched elements as
527
290
  # a first argument to `expression`. Returns the result of `expression` invocation.
528
- #
291
+ #
529
292
  # If `expression` returns a [Promise], then [`method: Page.evalOnSelectorAll`] would wait for the promise to resolve and
530
293
  # return its value.
531
- #
294
+ #
532
295
  # Examples:
533
- #
534
296
  #
535
- # ```js
536
- # const divCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);
537
- # ```
538
- #
539
- # ```java
540
- # boolean divCounts = (boolean) page.evalOnSelectorAll("div", "(divs, min) => divs.length >= min", 10);
541
- # ```
542
- #
543
- # ```python async
544
- # div_counts = await page.eval_on_selector_all("div", "(divs, min) => divs.length >= min", 10)
545
- # ```
546
- #
547
297
  # ```python sync
548
298
  # div_counts = page.eval_on_selector_all("div", "(divs, min) => divs.length >= min", 10)
549
299
  # ```
@@ -552,170 +302,63 @@ module Playwright
552
302
  end
553
303
 
554
304
  # Returns the value of the `expression` invocation.
555
- #
305
+ #
556
306
  # If the function passed to the [`method: Page.evaluate`] returns a [Promise], then [`method: Page.evaluate`] would wait
557
307
  # for the promise to resolve and return its value.
558
- #
308
+ #
559
309
  # If the function passed to the [`method: Page.evaluate`] returns a non-[Serializable] value, then
560
310
  # [`method: Page.evaluate`] resolves to `undefined`. Playwright also supports transferring some additional values that are
561
311
  # not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`.
562
- #
312
+ #
563
313
  # Passing argument to `expression`:
564
- #
565
314
  #
566
- # ```js
567
- # const result = await page.evaluate(([x, y]) => {
568
- # return Promise.resolve(x * y);
569
- # }, [7, 8]);
570
- # console.log(result); // prints "56"
571
- # ```
572
- #
573
- # ```java
574
- # Object result = page.evaluate("([x, y]) => {\n" +
575
- # " return Promise.resolve(x * y);\n" +
576
- # "}", Arrays.asList(7, 8));
577
- # System.out.println(result); // prints "56"
578
- # ```
579
- #
580
- # ```python async
581
- # result = await page.evaluate("([x, y]) => Promise.resolve(x * y)", [7, 8])
582
- # print(result) # prints "56"
583
- # ```
584
- #
585
315
  # ```python sync
586
316
  # result = page.evaluate("([x, y]) => Promise.resolve(x * y)", [7, 8])
587
317
  # print(result) # prints "56"
588
318
  # ```
589
- #
319
+ #
590
320
  # A string can also be passed in instead of a function:
591
- #
592
321
  #
593
- # ```js
594
- # console.log(await page.evaluate('1 + 2')); // prints "3"
595
- # const x = 10;
596
- # console.log(await page.evaluate(`1 + ${x}`)); // prints "11"
597
- # ```
598
- #
599
- # ```java
600
- # System.out.println(page.evaluate("1 + 2")); // prints "3"
601
- # ```
602
- #
603
- # ```python async
604
- # print(await page.evaluate("1 + 2")) # prints "3"
605
- # x = 10
606
- # print(await page.evaluate(f"1 + {x}")) # prints "11"
607
- # ```
608
- #
609
322
  # ```python sync
610
323
  # print(page.evaluate("1 + 2")) # prints "3"
611
324
  # x = 10
612
325
  # print(page.evaluate(f"1 + {x}")) # prints "11"
613
326
  # ```
614
- #
327
+ #
615
328
  # `ElementHandle` instances can be passed as an argument to the [`method: Page.evaluate`]:
616
- #
617
329
  #
618
- # ```js
619
- # const bodyHandle = await page.$('body');
620
- # const html = await page.evaluate(([body, suffix]) => body.innerHTML + suffix, [bodyHandle, 'hello']);
621
- # await bodyHandle.dispose();
622
- # ```
623
- #
624
- # ```java
625
- # ElementHandle bodyHandle = page.querySelector("body");
626
- # String html = (String) page.evaluate("([body, suffix]) => body.innerHTML + suffix", Arrays.asList(bodyHandle, "hello"));
627
- # bodyHandle.dispose();
628
- # ```
629
- #
630
- # ```python async
631
- # body_handle = await page.query_selector("body")
632
- # html = await page.evaluate("([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
633
- # await body_handle.dispose()
634
- # ```
635
- #
636
330
  # ```python sync
637
331
  # body_handle = page.query_selector("body")
638
332
  # html = page.evaluate("([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
639
333
  # body_handle.dispose()
640
334
  # ```
641
- #
335
+ #
642
336
  # Shortcut for main frame's [`method: Frame.evaluate`].
643
337
  def evaluate(expression, arg: nil)
644
338
  wrap_impl(@impl.evaluate(unwrap_impl(expression), arg: unwrap_impl(arg)))
645
339
  end
646
340
 
647
341
  # Returns the value of the `expression` invocation as a `JSHandle`.
648
- #
342
+ #
649
343
  # The only difference between [`method: Page.evaluate`] and [`method: Page.evaluateHandle`] is that
650
344
  # [`method: Page.evaluateHandle`] returns `JSHandle`.
651
- #
345
+ #
652
346
  # If the function passed to the [`method: Page.evaluateHandle`] returns a [Promise], then [`method: Page.evaluateHandle`]
653
347
  # would wait for the promise to resolve and return its value.
654
- #
655
348
  #
656
- # ```js
657
- # const aWindowHandle = await page.evaluateHandle(() => Promise.resolve(window));
658
- # aWindowHandle; // Handle for the window object.
659
- # ```
660
- #
661
- # ```java
662
- # // Handle for the window object.
663
- # JSHandle aWindowHandle = page.evaluateHandle("() => Promise.resolve(window)");
664
- # ```
665
- #
666
- # ```python async
667
- # a_window_handle = await page.evaluate_handle("Promise.resolve(window)")
668
- # a_window_handle # handle for the window object.
669
- # ```
670
- #
671
349
  # ```python sync
672
350
  # a_window_handle = page.evaluate_handle("Promise.resolve(window)")
673
351
  # a_window_handle # handle for the window object.
674
352
  # ```
675
- #
353
+ #
676
354
  # A string can also be passed in instead of a function:
677
- #
678
355
  #
679
- # ```js
680
- # const aHandle = await page.evaluateHandle('document'); // Handle for the 'document'
681
- # ```
682
- #
683
- # ```java
684
- # JSHandle aHandle = page.evaluateHandle("document"); // Handle for the "document".
685
- # ```
686
- #
687
- # ```python async
688
- # a_handle = await page.evaluate_handle("document") # handle for the "document"
689
- # ```
690
- #
691
356
  # ```python sync
692
357
  # a_handle = page.evaluate_handle("document") # handle for the "document"
693
358
  # ```
694
- #
359
+ #
695
360
  # `JSHandle` instances can be passed as an argument to the [`method: Page.evaluateHandle`]:
696
- #
697
361
  #
698
- # ```js
699
- # const aHandle = await page.evaluateHandle(() => document.body);
700
- # const resultHandle = await page.evaluateHandle(body => body.innerHTML, aHandle);
701
- # console.log(await resultHandle.jsonValue());
702
- # await resultHandle.dispose();
703
- # ```
704
- #
705
- # ```java
706
- # JSHandle aHandle = page.evaluateHandle("() => document.body");
707
- # JSHandle resultHandle = page.evaluateHandle("([body, suffix]) => body.innerHTML + suffix", Arrays.asList(aHandle, "hello"));
708
- # System.out.println(resultHandle.jsonValue());
709
- # resultHandle.dispose();
710
- # ```
711
- #
712
- # ```python async
713
- # a_handle = await page.evaluate_handle("document.body")
714
- # result_handle = await page.evaluate_handle("body => body.innerHTML", a_handle)
715
- # print(await result_handle.json_value())
716
- # await result_handle.dispose()
717
- # ```
718
- #
719
362
  # ```python sync
720
363
  # a_handle = page.evaluate_handle("document.body")
721
364
  # result_handle = page.evaluate_handle("body => body.innerHTML", a_handle)
@@ -729,92 +372,19 @@ module Playwright
729
372
  # The method adds a function called `name` on the `window` object of every frame in this page. When called, the function
730
373
  # executes `callback` and returns a [Promise] which resolves to the return value of `callback`. If the `callback` returns
731
374
  # a [Promise], it will be awaited.
732
- #
375
+ #
733
376
  # The first argument of the `callback` function contains information about the caller: `{ browserContext: BrowserContext,
734
377
  # page: Page, frame: Frame }`.
735
- #
378
+ #
736
379
  # See [`method: BrowserContext.exposeBinding`] for the context-wide version.
737
- #
380
+ #
738
381
  # > NOTE: Functions installed via [`method: Page.exposeBinding`] survive navigations.
739
- #
382
+ #
740
383
  # An example of exposing page URL to all frames in a page:
741
- #
742
- #
743
- # ```js
744
- # const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
745
- #
746
- # (async () => {
747
- # const browser = await webkit.launch({ headless: false });
748
- # const context = await browser.newContext();
749
- # const page = await context.newPage();
750
- # await page.exposeBinding('pageURL', ({ page }) => page.url());
751
- # await page.setContent(`
752
- # <script>
753
- # async function onClick() {
754
- # document.querySelector('div').textContent = await window.pageURL();
755
- # }
756
- # </script>
757
- # <button onclick="onClick()">Click me</button>
758
- # <div></div>
759
- # `);
760
- # await page.click('button');
761
- # })();
762
- # ```
763
- #
764
- # ```java
765
- # import com.microsoft.playwright.*;
766
- #
767
- # public class Example {
768
- # public static void main(String[] args) {
769
- # try (Playwright playwright = Playwright.create()) {
770
- # BrowserType webkit = playwright.webkit();
771
- # Browser browser = webkit.launch({ headless: false });
772
- # BrowserContext context = browser.newContext();
773
- # Page page = context.newPage();
774
- # page.exposeBinding("pageURL", (source, args) -> source.page().url());
775
- # page.setContent("<script>\n" +
776
- # " async function onClick() {\n" +
777
- # " document.querySelector('div').textContent = await window.pageURL();\n" +
778
- # " }\n" +
779
- # "</script>\n" +
780
- # "<button onclick=\"onClick()\">Click me</button>\n" +
781
- # "<div></div>");
782
- # page.click("button");
783
- # }
784
- # }
785
- # }
786
- # ```
787
- #
788
- # ```python async
789
- # import asyncio
790
- # from playwright.async_api import async_playwright
791
- #
792
- # async def run(playwright):
793
- # webkit = playwright.webkit
794
- # browser = await webkit.launch(headless=false)
795
- # context = await browser.new_context()
796
- # page = await context.new_page()
797
- # await page.expose_binding("pageURL", lambda source: source["page"].url)
798
- # await page.set_content("""
799
- # <script>
800
- # async function onClick() {
801
- # document.querySelector('div').textContent = await window.pageURL();
802
- # }
803
- # </script>
804
- # <button onclick="onClick()">Click me</button>
805
- # <div></div>
806
- # """)
807
- # await page.click("button")
808
- #
809
- # async def main():
810
- # async with async_playwright() as playwright:
811
- # await run(playwright)
812
- # asyncio.run(main())
813
- # ```
814
- #
384
+ #
815
385
  # ```python sync
816
386
  # from playwright.sync_api import sync_playwright
817
- #
387
+ #
818
388
  # def run(playwright):
819
389
  # webkit = playwright.webkit
820
390
  # browser = webkit.launch(headless=false)
@@ -831,59 +401,17 @@ module Playwright
831
401
  # <div></div>
832
402
  # """)
833
403
  # page.click("button")
834
- #
404
+ #
835
405
  # with sync_playwright() as playwright:
836
406
  # run(playwright)
837
407
  # ```
838
- #
408
+ #
839
409
  # An example of passing an element handle:
840
- #
841
410
  #
842
- # ```js
843
- # await page.exposeBinding('clicked', async (source, element) => {
844
- # console.log(await element.textContent());
845
- # }, { handle: true });
846
- # await page.setContent(`
847
- # <script>
848
- # document.addEventListener('click', event => window.clicked(event.target));
849
- # </script>
850
- # <div>Click me</div>
851
- # <div>Or click me</div>
852
- # `);
853
- # ```
854
- #
855
- # ```java
856
- # page.exposeBinding("clicked", (source, args) -> {
857
- # ElementHandle element = (ElementHandle) args[0];
858
- # System.out.println(element.textContent());
859
- # return null;
860
- # }, new Page.ExposeBindingOptions().setHandle(true));
861
- # page.setContent("" +
862
- # "<script>\n" +
863
- # " document.addEventListener('click', event => window.clicked(event.target));\n" +
864
- # "</script>\n" +
865
- # "<div>Click me</div>\n" +
866
- # "<div>Or click me</div>\n");
867
- # ```
868
- #
869
- # ```python async
870
- # async def print(source, element):
871
- # print(await element.text_content())
872
- #
873
- # await page.expose_binding("clicked", print, handle=true)
874
- # await page.set_content("""
875
- # <script>
876
- # document.addEventListener('click', event => window.clicked(event.target));
877
- # </script>
878
- # <div>Click me</div>
879
- # <div>Or click me</div>
880
- # """)
881
- # ```
882
- #
883
411
  # ```python sync
884
412
  # def print(source, element):
885
413
  # print(element.text_content())
886
- #
414
+ #
887
415
  # page.expose_binding("clicked", print, handle=true)
888
416
  # page.set_content("""
889
417
  # <script>
@@ -899,134 +427,41 @@ module Playwright
899
427
 
900
428
  # The method adds a function called `name` on the `window` object of every frame in the page. When called, the function
901
429
  # executes `callback` and returns a [Promise] which resolves to the return value of `callback`.
902
- #
430
+ #
903
431
  # If the `callback` returns a [Promise], it will be awaited.
904
- #
432
+ #
905
433
  # See [`method: BrowserContext.exposeFunction`] for context-wide exposed function.
906
- #
434
+ #
907
435
  # > NOTE: Functions installed via [`method: Page.exposeFunction`] survive navigations.
908
- #
909
- # An example of adding an `sha1` function to the page:
910
- #
911
- #
912
- # ```js
913
- # const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
914
- # const crypto = require('crypto');
915
- #
916
- # (async () => {
917
- # const browser = await webkit.launch({ headless: false });
918
- # const page = await browser.newPage();
919
- # await page.exposeFunction('sha1', text => crypto.createHash('sha1').update(text).digest('hex'));
920
- # await page.setContent(`
921
- # <script>
922
- # async function onClick() {
923
- # document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');
924
- # }
925
- # </script>
926
- # <button onclick="onClick()">Click me</button>
927
- # <div></div>
928
- # `);
929
- # await page.click('button');
930
- # })();
931
- # ```
932
- #
933
- # ```java
934
- # import com.microsoft.playwright.*;
935
- #
936
- # import java.nio.charset.StandardCharsets;
937
- # import java.security.MessageDigest;
938
- # import java.security.NoSuchAlgorithmException;
939
- # import java.util.Base64;
940
- #
941
- # public class Example {
942
- # public static void main(String[] args) {
943
- # try (Playwright playwright = Playwright.create()) {
944
- # BrowserType webkit = playwright.webkit();
945
- # Browser browser = webkit.launch({ headless: false });
946
- # Page page = browser.newPage();
947
- # page.exposeFunction("sha1", args -> {
948
- # String text = (String) args[0];
949
- # MessageDigest crypto;
950
- # try {
951
- # crypto = MessageDigest.getInstance("SHA-1");
952
- # } catch (NoSuchAlgorithmException e) {
953
- # return null;
954
- # }
955
- # byte[] token = crypto.digest(text.getBytes(StandardCharsets.UTF_8));
956
- # return Base64.getEncoder().encodeToString(token);
957
- # });
958
- # page.setContent("<script>\n" +
959
- # " async function onClick() {\n" +
960
- # " document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');\n" +
961
- # " }\n" +
962
- # "</script>\n" +
963
- # "<button onclick=\"onClick()\">Click me</button>\n" +
964
- # "<div></div>\n");
965
- # page.click("button");
966
- # }
967
- # }
968
- # }
969
- # ```
970
- #
971
- # ```python async
972
- # import asyncio
973
- # import hashlib
974
- # from playwright.async_api import async_playwright
975
- #
976
- # async def sha1(text):
977
- # m = hashlib.sha1()
978
- # m.update(bytes(text, "utf8"))
979
- # return m.hexdigest()
980
- #
981
- #
982
- # async def run(playwright):
983
- # webkit = playwright.webkit
984
- # browser = await webkit.launch(headless=False)
985
- # page = await browser.new_page()
986
- # await page.expose_function("sha1", sha1)
987
- # await page.set_content("""
988
- # <script>
989
- # async function onClick() {
990
- # document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');
991
- # }
992
- # </script>
993
- # <button onclick="onClick()">Click me</button>
994
- # <div></div>
995
- # """)
996
- # await page.click("button")
997
- #
998
- # async def main():
999
- # async with async_playwright() as playwright:
1000
- # await run(playwright)
1001
- # asyncio.run(main())
1002
- # ```
1003
- #
436
+ #
437
+ # An example of adding a `sha256` function to the page:
438
+ #
1004
439
  # ```python sync
1005
440
  # import hashlib
1006
441
  # from playwright.sync_api import sync_playwright
1007
- #
1008
- # def sha1(text):
1009
- # m = hashlib.sha1()
442
+ #
443
+ # def sha256(text):
444
+ # m = hashlib.sha256()
1010
445
  # m.update(bytes(text, "utf8"))
1011
446
  # return m.hexdigest()
1012
- #
1013
- #
447
+ #
448
+ #
1014
449
  # def run(playwright):
1015
450
  # webkit = playwright.webkit
1016
451
  # browser = webkit.launch(headless=False)
1017
452
  # page = browser.new_page()
1018
- # page.expose_function("sha1", sha1)
453
+ # page.expose_function("sha256", sha256)
1019
454
  # page.set_content("""
1020
455
  # <script>
1021
456
  # async function onClick() {
1022
- # document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');
457
+ # document.querySelector('div').textContent = await window.sha256('PLAYWRIGHT');
1023
458
  # }
1024
459
  # </script>
1025
460
  # <button onclick="onClick()">Click me</button>
1026
461
  # <div></div>
1027
462
  # """)
1028
463
  # page.click("button")
1029
- #
464
+ #
1030
465
  # with sync_playwright() as playwright:
1031
466
  # run(playwright)
1032
467
  # ```
@@ -1035,50 +470,35 @@ module Playwright
1035
470
  end
1036
471
 
1037
472
  # This method waits for an element matching `selector`, waits for [actionability](./actionability.md) checks, focuses the
1038
- # element, fills it and triggers an `input` event after filling. If the element is inside the `<label>` element that has
1039
- # associated [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), that control will be
1040
- # filled instead. If the element to be filled is not an `<input>`, `<textarea>` or `[contenteditable]` element, this
1041
- # method throws an error. Note that you can pass an empty string to clear the input field.
1042
- #
473
+ # element, fills it and triggers an `input` event after filling. Note that you can pass an empty string to clear the input
474
+ # field.
475
+ #
476
+ # If the target element is not an `<input>`, `<textarea>` or `[contenteditable]` element, this method throws an error.
477
+ # However, if the element is inside the `<label>` element that has an associated
478
+ # [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be filled
479
+ # instead.
480
+ #
1043
481
  # To send fine-grained keyboard events, use [`method: Page.type`].
1044
- #
1045
- # Shortcut for main frame's [`method: Frame.fill`]
482
+ #
483
+ # Shortcut for main frame's [`method: Frame.fill`].
1046
484
  def fill(selector, value, noWaitAfter: nil, timeout: nil)
1047
485
  wrap_impl(@impl.fill(unwrap_impl(selector), unwrap_impl(value), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
1048
486
  end
1049
487
 
1050
488
  # This method fetches an element with `selector` and focuses it. If there's no element matching `selector`, the method
1051
489
  # waits until a matching element appears in the DOM.
1052
- #
490
+ #
1053
491
  # Shortcut for main frame's [`method: Frame.focus`].
1054
492
  def focus(selector, timeout: nil)
1055
493
  wrap_impl(@impl.focus(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
1056
494
  end
1057
495
 
1058
496
  # Returns frame matching the specified criteria. Either `name` or `url` must be specified.
1059
- #
1060
497
  #
1061
- # ```js
1062
- # const frame = page.frame('frame-name');
1063
- # ```
1064
- #
1065
- # ```java
1066
- # Frame frame = page.frame("frame-name");
1067
- # ```
1068
- #
1069
498
  # ```py
1070
499
  # frame = page.frame(name="frame-name")
1071
500
  # ```
1072
- #
1073
501
  #
1074
- # ```js
1075
- # const frame = page.frame({ url: /.*domain.*/ });
1076
- # ```
1077
- #
1078
- # ```java
1079
- # Frame frame = page.frameByUrl(Pattern.compile(".*domain.*");
1080
- # ```
1081
- #
1082
502
  # ```py
1083
503
  # frame = page.frame(url=r".*domain.*")
1084
504
  # ```
@@ -1098,7 +518,7 @@ module Playwright
1098
518
 
1099
519
  # Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
1100
520
  # last redirect. If can not go back, returns `null`.
1101
- #
521
+ #
1102
522
  # Navigate to the previous page in history.
1103
523
  def go_back(timeout: nil, waitUntil: nil)
1104
524
  wrap_impl(@impl.go_back(timeout: unwrap_impl(timeout), waitUntil: unwrap_impl(waitUntil)))
@@ -1106,7 +526,7 @@ module Playwright
1106
526
 
1107
527
  # Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
1108
528
  # last redirect. If can not go forward, returns `null`.
1109
- #
529
+ #
1110
530
  # Navigate to the next page in history.
1111
531
  def go_forward(timeout: nil, waitUntil: nil)
1112
532
  wrap_impl(@impl.go_forward(timeout: unwrap_impl(timeout), waitUntil: unwrap_impl(waitUntil)))
@@ -1114,23 +534,23 @@ module Playwright
1114
534
 
1115
535
  # Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
1116
536
  # last redirect.
1117
- #
537
+ #
1118
538
  # `page.goto` will throw an error if:
1119
539
  # - there's an SSL error (e.g. in case of self-signed certificates).
1120
540
  # - target URL is invalid.
1121
541
  # - the `timeout` is exceeded during navigation.
1122
542
  # - the remote server does not respond or is unreachable.
1123
543
  # - the main resource failed to load.
1124
- #
544
+ #
1125
545
  # `page.goto` will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not
1126
546
  # Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling
1127
547
  # [`method: Response.status`].
1128
- #
548
+ #
1129
549
  # > NOTE: `page.goto` either throws an error or returns a main resource response. The only exceptions are navigation to
1130
550
  # `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`.
1131
551
  # > NOTE: Headless mode doesn't support navigation to a PDF document. See the
1132
552
  # [upstream issue](https://bugs.chromium.org/p/chromium/issues/detail?id=761295).
1133
- #
553
+ #
1134
554
  # Shortcut for main frame's [`method: Frame.goto`]
1135
555
  def goto(url, referer: nil, timeout: nil, waitUntil: nil)
1136
556
  wrap_impl(@impl.goto(unwrap_impl(url), referer: unwrap_impl(referer), timeout: unwrap_impl(timeout), waitUntil: unwrap_impl(waitUntil)))
@@ -1143,18 +563,19 @@ module Playwright
1143
563
  # 1. Scroll the element into view if needed.
1144
564
  # 1. Use [`property: Page.mouse`] to hover over the center of the element, or the specified `position`.
1145
565
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
1146
- #
566
+ #
1147
567
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
1148
568
  # zero timeout disables this.
1149
- #
569
+ #
1150
570
  # Shortcut for main frame's [`method: Frame.hover`].
1151
571
  def hover(
1152
572
  selector,
1153
573
  force: nil,
1154
574
  modifiers: nil,
1155
575
  position: nil,
1156
- timeout: nil)
1157
- wrap_impl(@impl.hover(unwrap_impl(selector), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), position: unwrap_impl(position), timeout: unwrap_impl(timeout)))
576
+ timeout: nil,
577
+ trial: nil)
578
+ wrap_impl(@impl.hover(unwrap_impl(selector), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
1158
579
  end
1159
580
 
1160
581
  # Returns `element.innerHTML`.
@@ -1216,10 +637,10 @@ module Playwright
1216
637
 
1217
638
  # Pauses script execution. Playwright will stop executing the script and wait for the user to either press 'Resume' button
1218
639
  # in the page overlay or to call `playwright.resume()` in the DevTools console.
1219
- #
640
+ #
1220
641
  # User can inspect selectors or perform manual steps while paused. Resume will continue running the original script from
1221
642
  # the place it was paused.
1222
- #
643
+ #
1223
644
  # > NOTE: This method requires Playwright to be started in a headed mode, with a falsy `headless` value in the
1224
645
  # [`method: BrowserType.launch`].
1225
646
  def pause
@@ -1227,54 +648,35 @@ module Playwright
1227
648
  end
1228
649
 
1229
650
  # Returns the PDF buffer.
1230
- #
651
+ #
1231
652
  # > NOTE: Generating a pdf is currently only supported in Chromium headless.
1232
- #
653
+ #
1233
654
  # `page.pdf()` generates a pdf of the page with `print` css media. To generate a pdf with `screen` media, call
1234
655
  # [`method: Page.emulateMedia`] before calling `page.pdf()`:
1235
- #
656
+ #
1236
657
  # > NOTE: By default, `page.pdf()` generates a pdf with modified colors for printing. Use the
1237
658
  # [`-webkit-print-color-adjust`](https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-print-color-adjust) property to
1238
659
  # force rendering of exact colors.
1239
- #
1240
660
  #
1241
- # ```js
1242
- # // Generates a PDF with 'screen' media type.
1243
- # await page.emulateMedia({media: 'screen'});
1244
- # await page.pdf({path: 'page.pdf'});
1245
- # ```
1246
- #
1247
- # ```java
1248
- # // Generates a PDF with "screen" media type.
1249
- # page.emulateMedia(new Page.EmulateMediaOptions().setMedia(Media.SCREEN));
1250
- # page.pdf(new Page.PdfOptions().setPath(Paths.get("page.pdf")));
1251
- # ```
1252
- #
1253
- # ```python async
1254
- # # generates a pdf with "screen" media type.
1255
- # await page.emulate_media(media="screen")
1256
- # await page.pdf(path="page.pdf")
1257
- # ```
1258
- #
1259
661
  # ```python sync
1260
662
  # # generates a pdf with "screen" media type.
1261
663
  # page.emulate_media(media="screen")
1262
664
  # page.pdf(path="page.pdf")
1263
665
  # ```
1264
- #
666
+ #
1265
667
  # The `width`, `height`, and `margin` options accept values labeled with units. Unlabeled values are treated as pixels.
1266
- #
668
+ #
1267
669
  # A few examples:
1268
670
  # - `page.pdf({width: 100})` - prints with width set to 100 pixels
1269
671
  # - `page.pdf({width: '100px'})` - prints with width set to 100 pixels
1270
672
  # - `page.pdf({width: '10cm'})` - prints with width set to 10 centimeters.
1271
- #
673
+ #
1272
674
  # All possible units are:
1273
675
  # - `px` - pixel
1274
676
  # - `in` - inch
1275
677
  # - `cm` - centimeter
1276
678
  # - `mm` - millimeter
1277
- #
679
+ #
1278
680
  # The `format` options are:
1279
681
  # - `Letter`: 8.5in x 11in
1280
682
  # - `Legal`: 8.5in x 14in
@@ -1287,7 +689,7 @@ module Playwright
1287
689
  # - `A4`: 8.27in x 11.7in
1288
690
  # - `A5`: 5.83in x 8.27in
1289
691
  # - `A6`: 4.13in x 5.83in
1290
- #
692
+ #
1291
693
  # > NOTE: `headerTemplate` and `footerTemplate` markup have the following limitations: > 1. Script tags inside templates
1292
694
  # are not evaluated. > 2. Page styles are not visible inside templates.
1293
695
  def pdf(
@@ -1308,60 +710,24 @@ module Playwright
1308
710
  end
1309
711
 
1310
712
  # Focuses the element, and then uses [`method: Keyboard.down`] and [`method: Keyboard.up`].
1311
- #
713
+ #
1312
714
  # `key` can specify the intended [keyboardEvent.key](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)
1313
715
  # value or a single character to generate the text for. A superset of the `key` values can be found
1314
716
  # [here](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values). Examples of the keys are:
1315
- #
717
+ #
1316
718
  # `F1` - `F12`, `Digit0`- `Digit9`, `KeyA`- `KeyZ`, `Backquote`, `Minus`, `Equal`, `Backslash`, `Backspace`, `Tab`,
1317
719
  # `Delete`, `Escape`, `ArrowDown`, `End`, `Enter`, `Home`, `Insert`, `PageDown`, `PageUp`, `ArrowRight`, `ArrowUp`, etc.
1318
- #
720
+ #
1319
721
  # Following modification shortcuts are also supported: `Shift`, `Control`, `Alt`, `Meta`, `ShiftLeft`.
1320
- #
722
+ #
1321
723
  # Holding down `Shift` will type the text that corresponds to the `key` in the upper case.
1322
- #
724
+ #
1323
725
  # If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
1324
726
  # texts.
1325
- #
727
+ #
1326
728
  # Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
1327
729
  # modifier, modifier is pressed and being held while the subsequent key is being pressed.
1328
- #
1329
- #
1330
- # ```js
1331
- # const page = await browser.newPage();
1332
- # await page.goto('https://keycode.info');
1333
- # await page.press('body', 'A');
1334
- # await page.screenshot({ path: 'A.png' });
1335
- # await page.press('body', 'ArrowLeft');
1336
- # await page.screenshot({ path: 'ArrowLeft.png' });
1337
- # await page.press('body', 'Shift+O');
1338
- # await page.screenshot({ path: 'O.png' });
1339
- # await browser.close();
1340
- # ```
1341
- #
1342
- # ```java
1343
- # Page page = browser.newPage();
1344
- # page.navigate("https://keycode.info");
1345
- # page.press("body", "A");
1346
- # page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("A.png")));
1347
- # page.press("body", "ArrowLeft");
1348
- # page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("ArrowLeft.png" )));
1349
- # page.press("body", "Shift+O");
1350
- # page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("O.png" )));
1351
- # ```
1352
- #
1353
- # ```python async
1354
- # page = await browser.new_page()
1355
- # await page.goto("https://keycode.info")
1356
- # await page.press("body", "A")
1357
- # await page.screenshot(path="a.png")
1358
- # await page.press("body", "ArrowLeft")
1359
- # await page.screenshot(path="arrow_left.png")
1360
- # await page.press("body", "Shift+O")
1361
- # await page.screenshot(path="o.png")
1362
- # await browser.close()
1363
- # ```
1364
- #
730
+ #
1365
731
  # ```python sync
1366
732
  # page = browser.new_page()
1367
733
  # page.goto("https://keycode.info")
@@ -1383,8 +749,8 @@ module Playwright
1383
749
  end
1384
750
 
1385
751
  # The method finds an element matching the specified selector within the page. If no elements match the selector, the
1386
- # return value resolves to `null`.
1387
- #
752
+ # return value resolves to `null`. To wait for an element on the page, use [`method: Page.waitForSelector`].
753
+ #
1388
754
  # Shortcut for main frame's [`method: Frame.querySelector`].
1389
755
  def query_selector(selector)
1390
756
  wrap_impl(@impl.query_selector(unwrap_impl(selector)))
@@ -1392,7 +758,7 @@ module Playwright
1392
758
 
1393
759
  # The method finds all elements matching the specified selector within the page. If no elements match the selector, the
1394
760
  # return value resolves to `[]`.
1395
- #
761
+ #
1396
762
  # Shortcut for main frame's [`method: Frame.querySelectorAll`].
1397
763
  def query_selector_all(selector)
1398
764
  wrap_impl(@impl.query_selector_all(unwrap_impl(selector)))
@@ -1405,78 +771,46 @@ module Playwright
1405
771
  end
1406
772
 
1407
773
  # Routing provides the capability to modify network requests that are made by a page.
1408
- #
774
+ #
1409
775
  # Once routing is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
1410
- #
776
+ #
1411
777
  # > NOTE: The handler will only be called for the first url if the response is a redirect.
1412
- #
778
+ #
1413
779
  # An example of a naive handler that aborts all image requests:
1414
- #
1415
780
  #
1416
- # ```js
1417
- # const page = await browser.newPage();
1418
- # await page.route('**/*.{png,jpg,jpeg}', route => route.abort());
1419
- # await page.goto('https://example.com');
1420
- # await browser.close();
1421
- # ```
1422
- #
1423
- # ```java
1424
- # Page page = browser.newPage();
1425
- # page.route("**/*.{png,jpg,jpeg}", route -> route.abort());
1426
- # page.navigate("https://example.com");
1427
- # browser.close();
1428
- # ```
1429
- #
1430
- # ```python async
1431
- # page = await browser.new_page()
1432
- # await page.route("**/*.{png,jpg,jpeg}", lambda route: route.abort())
1433
- # await page.goto("https://example.com")
1434
- # await browser.close()
1435
- # ```
1436
- #
1437
781
  # ```python sync
1438
782
  # page = browser.new_page()
1439
783
  # page.route("**/*.{png,jpg,jpeg}", lambda route: route.abort())
1440
784
  # page.goto("https://example.com")
1441
785
  # browser.close()
1442
786
  # ```
1443
- #
787
+ #
1444
788
  # or the same snippet using a regex pattern instead:
1445
- #
1446
789
  #
1447
- # ```js
1448
- # const page = await browser.newPage();
1449
- # await page.route(/(\.png$)|(\.jpg$)/, route => route.abort());
1450
- # await page.goto('https://example.com');
1451
- # await browser.close();
1452
- # ```
1453
- #
1454
- # ```java
1455
- # Page page = browser.newPage();
1456
- # page.route(Pattern.compile("(\\.png$)|(\\.jpg$)"),route -> route.abort());
1457
- # page.navigate("https://example.com");
1458
- # browser.close();
1459
- # ```
1460
- #
1461
- # ```python async
1462
- # page = await browser.new_page()
1463
- # await page.route(re.compile(r"(\.png$)|(\.jpg$)"), lambda route: route.abort())
1464
- # await page.goto("https://example.com")
1465
- # await browser.close()
1466
- # ```
1467
- #
1468
790
  # ```python sync
1469
791
  # page = browser.new_page()
1470
792
  # page.route(re.compile(r"(\.png$)|(\.jpg$)"), lambda route: route.abort())
1471
793
  # page.goto("https://example.com")
1472
794
  # browser.close()
1473
795
  # ```
1474
- #
796
+ #
797
+ # It is possible to examine the request to decide the route action. For example, mocking all requests that contain some
798
+ # post data, and leaving all other requests as is:
799
+ #
800
+ # ```python sync
801
+ # def handle_route(route):
802
+ # if ("my-string" in route.request.post_data)
803
+ # route.fulfill(body="mocked-data")
804
+ # else
805
+ # route.continue_()
806
+ # page.route("/api/**", handle_route)
807
+ # ```
808
+ #
1475
809
  # Page routes take precedence over browser context routes (set up with [`method: BrowserContext.route`]) when request
1476
810
  # matches both handlers.
1477
- #
811
+ #
1478
812
  # To remove a route with its handler you can use [`method: Page.unroute`].
1479
- #
813
+ #
1480
814
  # > NOTE: Enabling routing disables http cache.
1481
815
  def route(url, handler)
1482
816
  wrap_impl(@impl.route(unwrap_impl(url), unwrap_impl(handler)))
@@ -1494,44 +828,17 @@ module Playwright
1494
828
  wrap_impl(@impl.screenshot(clip: unwrap_impl(clip), fullPage: unwrap_impl(fullPage), omitBackground: unwrap_impl(omitBackground), path: unwrap_impl(path), quality: unwrap_impl(quality), timeout: unwrap_impl(timeout), type: unwrap_impl(type)))
1495
829
  end
1496
830
 
831
+ # This method waits for an element matching `selector`, waits for [actionability](./actionability.md) checks, waits until
832
+ # all specified options are present in the `<select>` element and selects these options.
833
+ #
834
+ # If the target element is not a `<select>` element, this method throws an error. However, if the element is inside the
835
+ # `<label>` element that has an associated
836
+ # [control](https://developer.mozilla.org/en-US/docs/Web/API/HTMLLabelElement/control), the control will be used instead.
837
+ #
1497
838
  # Returns the array of option values that have been successfully selected.
1498
- #
1499
- # Triggers a `change` and `input` event once all the provided options have been selected. If there's no `<select>` element
1500
- # matching `selector`, the method throws an error.
1501
- #
1502
- # Will wait until all specified options are present in the `<select>` element.
1503
- #
1504
- #
1505
- # ```js
1506
- # // single selection matching the value
1507
- # page.selectOption('select#colors', 'blue');
1508
- #
1509
- # // single selection matching the label
1510
- # page.selectOption('select#colors', { label: 'Blue' });
1511
- #
1512
- # // multiple selection
1513
- # page.selectOption('select#colors', ['red', 'green', 'blue']);
1514
- #
1515
- # ```
1516
- #
1517
- # ```java
1518
- # // single selection matching the value
1519
- # page.selectOption("select#colors", "blue");
1520
- # // single selection matching both the value and the label
1521
- # page.selectOption("select#colors", new SelectOption().setLabel("Blue"));
1522
- # // multiple selection
1523
- # page.selectOption("select#colors", new String[] {"red", "green", "blue"});
1524
- # ```
1525
- #
1526
- # ```python async
1527
- # # single selection matching the value
1528
- # await page.select_option("select#colors", "blue")
1529
- # # single selection matching the label
1530
- # await page.select_option("select#colors", label="blue")
1531
- # # multiple selection
1532
- # await page.select_option("select#colors", value=["red", "green", "blue"])
1533
- # ```
1534
- #
839
+ #
840
+ # Triggers a `change` and `input` event once all the provided options have been selected.
841
+ #
1535
842
  # ```python sync
1536
843
  # # single selection matching the value
1537
844
  # page.select_option("select#colors", "blue")
@@ -1540,8 +847,8 @@ module Playwright
1540
847
  # # multiple selection
1541
848
  # page.select_option("select#colors", value=["red", "green", "blue"])
1542
849
  # ```
1543
- #
1544
- # Shortcut for main frame's [`method: Frame.selectOption`]
850
+ #
851
+ # Shortcut for main frame's [`method: Frame.selectOption`].
1545
852
  def select_option(
1546
853
  selector,
1547
854
  element: nil,
@@ -1566,7 +873,7 @@ module Playwright
1566
873
  # - [`method: Page.setContent`]
1567
874
  # - [`method: Page.waitForNavigation`]
1568
875
  # - [`method: Page.waitForURL`]
1569
- #
876
+ #
1570
877
  # > NOTE: [`method: Page.setDefaultNavigationTimeout`] takes priority over [`method: Page.setDefaultTimeout`],
1571
878
  # [`method: BrowserContext.setDefaultTimeout`] and [`method: BrowserContext.setDefaultNavigationTimeout`].
1572
879
  def set_default_navigation_timeout(timeout)
@@ -1575,7 +882,7 @@ module Playwright
1575
882
  alias_method :default_navigation_timeout=, :set_default_navigation_timeout
1576
883
 
1577
884
  # This setting will change the default maximum time for all the methods accepting `timeout` option.
1578
- #
885
+ #
1579
886
  # > NOTE: [`method: Page.setDefaultNavigationTimeout`] takes priority over [`method: Page.setDefaultTimeout`].
1580
887
  def set_default_timeout(timeout)
1581
888
  wrap_impl(@impl.set_default_timeout(unwrap_impl(timeout)))
@@ -1583,7 +890,7 @@ module Playwright
1583
890
  alias_method :default_timeout=, :set_default_timeout
1584
891
 
1585
892
  # The extra HTTP headers will be sent with every request the page initiates.
1586
- #
893
+ #
1587
894
  # > NOTE: [`method: Page.setExtraHTTPHeaders`] does not guarantee the order of headers in the outgoing requests.
1588
895
  def set_extra_http_headers(headers)
1589
896
  wrap_impl(@impl.set_extra_http_headers(unwrap_impl(headers)))
@@ -1592,7 +899,7 @@ module Playwright
1592
899
 
1593
900
  # This method expects `selector` to point to an
1594
901
  # [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
1595
- #
902
+ #
1596
903
  # Sets the value of the file input to these file paths or files. If some of the `filePaths` are relative paths, then they
1597
904
  # are resolved relative to the the current working directory. For empty array, clears the selected files.
1598
905
  def set_input_files(selector, files, noWaitAfter: nil, timeout: nil)
@@ -1601,32 +908,10 @@ module Playwright
1601
908
 
1602
909
  # In the case of multiple pages in a single browser, each page can have its own viewport size. However,
1603
910
  # [`method: Browser.newContext`] allows to set viewport size (and more) for all pages in the context at once.
1604
- #
911
+ #
1605
912
  # `page.setViewportSize` will resize the page. A lot of websites don't expect phones to change size, so you should set the
1606
913
  # viewport size before navigating to the page.
1607
- #
1608
- #
1609
- # ```js
1610
- # const page = await browser.newPage();
1611
- # await page.setViewportSize({
1612
- # width: 640,
1613
- # height: 480,
1614
- # });
1615
- # await page.goto('https://example.com');
1616
- # ```
1617
- #
1618
- # ```java
1619
- # Page page = browser.newPage();
1620
- # page.setViewportSize(640, 480);
1621
- # page.navigate("https://example.com");
1622
- # ```
1623
- #
1624
- # ```python async
1625
- # page = await browser.new_page()
1626
- # await page.set_viewport_size({"width": 640, "height": 480})
1627
- # await page.goto("https://example.com")
1628
- # ```
1629
- #
914
+ #
1630
915
  # ```python sync
1631
916
  # page = browser.new_page()
1632
917
  # page.set_viewport_size({"width": 640, "height": 480})
@@ -1644,12 +929,12 @@ module Playwright
1644
929
  # 1. Scroll the element into view if needed.
1645
930
  # 1. Use [`property: Page.touchscreen`] to tap the center of the element, or the specified `position`.
1646
931
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
1647
- #
932
+ #
1648
933
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
1649
934
  # zero timeout disables this.
1650
- #
935
+ #
1651
936
  # > NOTE: [`method: Page.tap`] requires that the `hasTouch` option of the browser context be set to true.
1652
- #
937
+ #
1653
938
  # Shortcut for main frame's [`method: Frame.tap`].
1654
939
  def tap_point(
1655
940
  selector,
@@ -1657,8 +942,9 @@ module Playwright
1657
942
  modifiers: nil,
1658
943
  noWaitAfter: nil,
1659
944
  position: nil,
1660
- timeout: nil)
1661
- wrap_impl(@impl.tap_point(unwrap_impl(selector), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout)))
945
+ timeout: nil,
946
+ trial: nil)
947
+ wrap_impl(@impl.tap_point(unwrap_impl(selector), force: unwrap_impl(force), modifiers: unwrap_impl(modifiers), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
1662
948
  end
1663
949
 
1664
950
  # Returns `element.textContent`.
@@ -1673,32 +959,14 @@ module Playwright
1673
959
 
1674
960
  # Sends a `keydown`, `keypress`/`input`, and `keyup` event for each character in the text. `page.type` can be used to send
1675
961
  # fine-grained keyboard events. To fill values in form fields, use [`method: Page.fill`].
1676
- #
962
+ #
1677
963
  # To press a special key, like `Control` or `ArrowDown`, use [`method: Keyboard.press`].
1678
- #
1679
964
  #
1680
- # ```js
1681
- # await page.type('#mytextarea', 'Hello'); // Types instantly
1682
- # await page.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a user
1683
- # ```
1684
- #
1685
- # ```java
1686
- # // Types instantly
1687
- # page.type("#mytextarea", "Hello");
1688
- # // Types slower, like a user
1689
- # page.type("#mytextarea", "World", new Page.TypeOptions().setDelay(100));
1690
- # ```
1691
- #
1692
- # ```python async
1693
- # await page.type("#mytextarea", "hello") # types instantly
1694
- # await page.type("#mytextarea", "world", delay=100) # types slower, like a user
1695
- # ```
1696
- #
1697
965
  # ```python sync
1698
966
  # page.type("#mytextarea", "hello") # types instantly
1699
967
  # page.type("#mytextarea", "world", delay=100) # types slower, like a user
1700
968
  # ```
1701
- #
969
+ #
1702
970
  # Shortcut for main frame's [`method: Frame.type`].
1703
971
  def type(
1704
972
  selector,
@@ -1719,18 +987,19 @@ module Playwright
1719
987
  # 1. Use [`property: Page.mouse`] to click in the center of the element.
1720
988
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
1721
989
  # 1. Ensure that the element is now unchecked. If not, this method throws.
1722
- #
990
+ #
1723
991
  # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
1724
992
  # zero timeout disables this.
1725
- #
993
+ #
1726
994
  # Shortcut for main frame's [`method: Frame.uncheck`].
1727
995
  def uncheck(
1728
996
  selector,
1729
997
  force: nil,
1730
998
  noWaitAfter: nil,
1731
999
  position: nil,
1732
- timeout: nil)
1733
- wrap_impl(@impl.uncheck(unwrap_impl(selector), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout)))
1000
+ timeout: nil,
1001
+ trial: nil)
1002
+ wrap_impl(@impl.uncheck(unwrap_impl(selector), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), position: unwrap_impl(position), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
1734
1003
  end
1735
1004
 
1736
1005
  # Removes a route created with [`method: Page.route`]. When `handler` is not specified, removes all routes for the `url`.
@@ -1754,7 +1023,7 @@ module Playwright
1754
1023
 
1755
1024
  # Performs action and waits for a `ConsoleMessage` to be logged by in the page. If predicate is provided, it passes
1756
1025
  # `ConsoleMessage` value into the `predicate` function and waits for `predicate(message)` to return a truthy value. Will
1757
- # throw an error if the page is closed before the console event is fired.
1026
+ # throw an error if the page is closed before the [`event: Page.console`] event is fired.
1758
1027
  def expect_console_message(predicate: nil, timeout: nil, &block)
1759
1028
  wrap_impl(@impl.expect_console_message(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
1760
1029
  end
@@ -1768,21 +1037,7 @@ module Playwright
1768
1037
 
1769
1038
  # Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
1770
1039
  # value. Will throw an error if the page is closed before the event is fired. Returns the event data value.
1771
- #
1772
1040
  #
1773
- # ```js
1774
- # const [frame, _] = await Promise.all([
1775
- # page.waitForEvent('framenavigated'),
1776
- # page.click('button')
1777
- # ]);
1778
- # ```
1779
- #
1780
- # ```python async
1781
- # async with page.expect_event("framenavigated") as event_info:
1782
- # await page.click("button")
1783
- # frame = await event_info.value
1784
- # ```
1785
- #
1786
1041
  # ```python sync
1787
1042
  # with page.expect_event("framenavigated") as event_info:
1788
1043
  # page.click("button")
@@ -1800,61 +1055,12 @@ module Playwright
1800
1055
  end
1801
1056
 
1802
1057
  # Returns when the `expression` returns a truthy value. It resolves to a JSHandle of the truthy value.
1803
- #
1058
+ #
1804
1059
  # The [`method: Page.waitForFunction`] can be used to observe viewport size change:
1805
- #
1806
- #
1807
- # ```js
1808
- # const { webkit } = require('playwright'); // Or 'chromium' or 'firefox'.
1809
- #
1810
- # (async () => {
1811
- # const browser = await webkit.launch();
1812
- # const page = await browser.newPage();
1813
- # const watchDog = page.waitForFunction(() => window.innerWidth < 100);
1814
- # await page.setViewportSize({width: 50, height: 50});
1815
- # await watchDog;
1816
- # await browser.close();
1817
- # })();
1818
- # ```
1819
- #
1820
- # ```java
1821
- # import com.microsoft.playwright.*;
1822
- #
1823
- # public class Example {
1824
- # public static void main(String[] args) {
1825
- # try (Playwright playwright = Playwright.create()) {
1826
- # BrowserType webkit = playwright.webkit();
1827
- # Browser browser = webkit.launch();
1828
- # Page page = browser.newPage();
1829
- # page.setViewportSize(50, 50);
1830
- # page.waitForFunction("() => window.innerWidth < 100");
1831
- # browser.close();
1832
- # }
1833
- # }
1834
- # }
1835
- # ```
1836
- #
1837
- # ```python async
1838
- # import asyncio
1839
- # from playwright.async_api import async_playwright
1840
- #
1841
- # async def run(playwright):
1842
- # webkit = playwright.webkit
1843
- # browser = await webkit.launch()
1844
- # page = await browser.new_page()
1845
- # await page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);")
1846
- # await page.wait_for_function("() => window.x > 0")
1847
- # await browser.close()
1848
- #
1849
- # async def main():
1850
- # async with async_playwright() as playwright:
1851
- # await run(playwright)
1852
- # asyncio.run(main())
1853
- # ```
1854
- #
1060
+ #
1855
1061
  # ```python sync
1856
1062
  # from playwright.sync_api import sync_playwright
1857
- #
1063
+ #
1858
1064
  # def run(playwright):
1859
1065
  # webkit = playwright.webkit
1860
1066
  # browser = webkit.launch()
@@ -1862,92 +1068,33 @@ module Playwright
1862
1068
  # page.evaluate("window.x = 0; setTimeout(() => { window.x = 100 }, 1000);")
1863
1069
  # page.wait_for_function("() => window.x > 0")
1864
1070
  # browser.close()
1865
- #
1071
+ #
1866
1072
  # with sync_playwright() as playwright:
1867
1073
  # run(playwright)
1868
1074
  # ```
1869
- #
1075
+ #
1870
1076
  # To pass an argument to the predicate of [`method: Page.waitForFunction`] function:
1871
- #
1872
1077
  #
1873
- # ```js
1874
- # const selector = '.foo';
1875
- # await page.waitForFunction(selector => !!document.querySelector(selector), selector);
1876
- # ```
1877
- #
1878
- # ```java
1879
- # String selector = ".foo";
1880
- # page.waitForFunction("selector => !!document.querySelector(selector)", selector);
1881
- # ```
1882
- #
1883
- # ```python async
1884
- # selector = ".foo"
1885
- # await page.wait_for_function("selector => !!document.querySelector(selector)", selector)
1886
- # ```
1887
- #
1888
1078
  # ```python sync
1889
1079
  # selector = ".foo"
1890
1080
  # page.wait_for_function("selector => !!document.querySelector(selector)", selector)
1891
1081
  # ```
1892
- #
1082
+ #
1893
1083
  # Shortcut for main frame's [`method: Frame.waitForFunction`].
1894
1084
  def wait_for_function(expression, arg: nil, polling: nil, timeout: nil)
1895
1085
  wrap_impl(@impl.wait_for_function(unwrap_impl(expression), arg: unwrap_impl(arg), polling: unwrap_impl(polling), timeout: unwrap_impl(timeout)))
1896
1086
  end
1897
1087
 
1898
1088
  # Returns when the required load state has been reached.
1899
- #
1089
+ #
1900
1090
  # This resolves when the page reaches a required load state, `load` by default. The navigation must have been committed
1901
1091
  # when this method is called. If current document has already reached the required state, resolves immediately.
1902
- #
1903
1092
  #
1904
- # ```js
1905
- # await page.click('button'); // Click triggers navigation.
1906
- # await page.waitForLoadState(); // The promise resolves after 'load' event.
1907
- # ```
1908
- #
1909
- # ```java
1910
- # page.click("button"); // Click triggers navigation.
1911
- # page.waitForLoadState(); // The promise resolves after "load" event.
1912
- # ```
1913
- #
1914
- # ```python async
1915
- # await page.click("button") # click triggers navigation.
1916
- # await page.wait_for_load_state() # the promise resolves after "load" event.
1917
- # ```
1918
- #
1919
1093
  # ```python sync
1920
1094
  # page.click("button") # click triggers navigation.
1921
1095
  # page.wait_for_load_state() # the promise resolves after "load" event.
1922
1096
  # ```
1923
- #
1924
- #
1925
- # ```js
1926
- # const [popup] = await Promise.all([
1927
- # page.waitForEvent('popup'),
1928
- # page.click('button'), // Click triggers a popup.
1929
- # ])
1930
- # await popup.waitForLoadState('domcontentloaded'); // The promise resolves after 'domcontentloaded' event.
1931
- # console.log(await popup.title()); // Popup is ready to use.
1932
- # ```
1933
- #
1934
- # ```java
1935
- # Page popup = page.waitForPopup(() -> {
1936
- # page.click("button"); // Click triggers a popup.
1937
- # });
1938
- # popup.waitForLoadState(LoadState.DOMCONTENTLOADED);
1939
- # System.out.println(popup.title()); // Popup is ready to use.
1940
- # ```
1941
- #
1942
- # ```python async
1943
- # async with page.expect_popup() as page_info:
1944
- # await page.click("button") # click triggers a popup.
1945
- # popup = await page_info.value
1946
- # # Following resolves after "domcontentloaded" event.
1947
- # await popup.wait_for_load_state("domcontentloaded")
1948
- # print(await popup.title()) # popup is ready to use.
1949
- # ```
1950
- #
1097
+ #
1951
1098
  # ```python sync
1952
1099
  # with page.expect_popup() as page_info:
1953
1100
  # page.click("button") # click triggers a popup.
@@ -1956,7 +1103,7 @@ module Playwright
1956
1103
  # popup.wait_for_load_state("domcontentloaded")
1957
1104
  # print(popup.title()) # popup is ready to use.
1958
1105
  # ```
1959
- #
1106
+ #
1960
1107
  # Shortcut for main frame's [`method: Frame.waitForLoadState`].
1961
1108
  def wait_for_load_state(state: nil, timeout: nil)
1962
1109
  wrap_impl(@impl.wait_for_load_state(state: unwrap_impl(state), timeout: unwrap_impl(timeout)))
@@ -1965,41 +1112,20 @@ module Playwright
1965
1112
  # Waits for the main frame navigation and returns the main resource response. In case of multiple redirects, the
1966
1113
  # navigation will resolve with the response of the last redirect. In case of navigation to a different anchor or
1967
1114
  # navigation due to History API usage, the navigation will resolve with `null`.
1968
- #
1115
+ #
1969
1116
  # This resolves when the page navigates to a new URL or reloads. It is useful for when you run code which will indirectly
1970
1117
  # cause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation from a `setTimeout`.
1971
1118
  # Consider this example:
1972
- #
1973
1119
  #
1974
- # ```js
1975
- # const [response] = await Promise.all([
1976
- # page.waitForNavigation(), // The promise resolves after navigation has finished
1977
- # page.click('a.delayed-navigation'), // Clicking the link will indirectly cause a navigation
1978
- # ]);
1979
- # ```
1980
- #
1981
- # ```java
1982
- # // The method returns after navigation has finished
1983
- # Response response = page.waitForNavigation(() -> {
1984
- # page.click("a.delayed-navigation"); // Clicking the link will indirectly cause a navigation
1985
- # });
1986
- # ```
1987
- #
1988
- # ```python async
1989
- # async with page.expect_navigation():
1990
- # await page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
1991
- # # Resolves after navigation has finished
1992
- # ```
1993
- #
1994
1120
  # ```python sync
1995
1121
  # with page.expect_navigation():
1996
1122
  # page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
1997
1123
  # # Resolves after navigation has finished
1998
1124
  # ```
1999
- #
1125
+ #
2000
1126
  # > NOTE: Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is
2001
1127
  # considered a navigation.
2002
- #
1128
+ #
2003
1129
  # Shortcut for main frame's [`method: Frame.waitForNavigation`].
2004
1130
  def expect_navigation(timeout: nil, url: nil, waitUntil: nil, &block)
2005
1131
  wrap_impl(@impl.expect_navigation(timeout: unwrap_impl(timeout), url: unwrap_impl(url), waitUntil: unwrap_impl(waitUntil), &wrap_block_call(block)))
@@ -2012,162 +1138,60 @@ module Playwright
2012
1138
  wrap_impl(@impl.expect_popup(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
2013
1139
  end
2014
1140
 
2015
- # Waits for the matching request and returns it.
2016
- #
1141
+ # Waits for the matching request and returns it. See [waiting for event](./events.md#waiting-for-event) for more details
1142
+ # about events.
2017
1143
  #
2018
- # ```js
2019
- # const firstRequest = await page.waitForRequest('http://example.com/resource');
2020
- # const finalRequest = await page.waitForRequest(request => request.url() === 'http://example.com' && request.method() === 'GET');
2021
- # return firstRequest.url();
2022
- # ```
2023
- #
2024
- # ```java
2025
- # Request firstRequest = page.waitForRequest("http://example.com/resource");
2026
- # Object finalRequest = page.waitForRequest(
2027
- # request -> "http://example.com".equals(request.url()) && "GET".equals(request.method()), () -> {});
2028
- # return firstRequest.url();
2029
- # ```
2030
- #
2031
- # ```python async
2032
- # async with page.expect_request("http://example.com/resource") as first:
2033
- # await page.click('button')
2034
- # first_request = await first.value
2035
- #
2036
- # async with page.expect_request(lambda request: request.url == "http://example.com" and request.method == "get") as second:
2037
- # await page.click('img')
2038
- # second_request = await second.value
2039
- # ```
2040
- #
2041
1144
  # ```python sync
2042
1145
  # with page.expect_request("http://example.com/resource") as first:
2043
1146
  # page.click('button')
2044
1147
  # first_request = first.value
2045
- #
1148
+ #
1149
+ # # or with a lambda
2046
1150
  # with page.expect_request(lambda request: request.url == "http://example.com" and request.method == "get") as second:
2047
1151
  # page.click('img')
2048
1152
  # second_request = second.value
2049
1153
  # ```
2050
- #
2051
- #
2052
- # ```js
2053
- # await page.waitForRequest(request => request.url().searchParams.get('foo') === 'bar' && request.url().searchParams.get('foo2') === 'bar2');
2054
- # ```
2055
- def expect_request(urlOrPredicate, timeout: nil)
2056
- wrap_impl(@impl.expect_request(unwrap_impl(urlOrPredicate), timeout: unwrap_impl(timeout)))
1154
+ def expect_request(urlOrPredicate, timeout: nil, &block)
1155
+ wrap_impl(@impl.expect_request(unwrap_impl(urlOrPredicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
1156
+ end
1157
+
1158
+ # Performs action and waits for a `Request` to finish loading. If predicate is provided, it passes `Request` value into
1159
+ # the `predicate` function and waits for `predicate(request)` to return a truthy value. Will throw an error if the page is
1160
+ # closed before the [`event: Page.requestFinished`] event is fired.
1161
+ def expect_request_finished(predicate: nil, timeout: nil)
1162
+ raise NotImplementedError.new('expect_request_finished is not implemented yet.')
2057
1163
  end
2058
1164
 
2059
- # Returns the matched response.
2060
- #
1165
+ # Returns the matched response. See [waiting for event](./events.md#waiting-for-event) for more details about events.
2061
1166
  #
2062
- # ```js
2063
- # const firstResponse = await page.waitForResponse('https://example.com/resource');
2064
- # const finalResponse = await page.waitForResponse(response => response.url() === 'https://example.com' && response.status() === 200);
2065
- # return finalResponse.ok();
2066
- # ```
2067
- #
2068
- # ```java
2069
- # Response firstResponse = page.waitForResponse("https://example.com/resource", () -> {});
2070
- # Response finalResponse = page.waitForResponse(response -> "https://example.com".equals(response.url()) && response.status() == 200, () -> {});
2071
- # return finalResponse.ok();
2072
- # ```
2073
- #
2074
- # ```python async
2075
- # async with page.expect_response("https://example.com/resource") as response_info:
2076
- # await page.click("input")
2077
- # response = response_info.value
2078
- # return response.ok
2079
- #
2080
- # # or with a lambda
2081
- # async with page.expect_response(lambda response: response.url == "https://example.com" and response.status === 200) as response_info:
2082
- # await page.click("input")
2083
- # response = response_info.value
2084
- # return response.ok
2085
- # ```
2086
- #
2087
1167
  # ```python sync
2088
1168
  # with page.expect_response("https://example.com/resource") as response_info:
2089
1169
  # page.click("input")
2090
1170
  # response = response_info.value
2091
1171
  # return response.ok
2092
- #
1172
+ #
2093
1173
  # # or with a lambda
2094
1174
  # with page.expect_response(lambda response: response.url == "https://example.com" and response.status === 200) as response_info:
2095
1175
  # page.click("input")
2096
1176
  # response = response_info.value
2097
1177
  # return response.ok
2098
1178
  # ```
2099
- def expect_response(urlOrPredicate, timeout: nil)
2100
- wrap_impl(@impl.expect_response(unwrap_impl(urlOrPredicate), timeout: unwrap_impl(timeout)))
1179
+ def expect_response(urlOrPredicate, timeout: nil, &block)
1180
+ wrap_impl(@impl.expect_response(unwrap_impl(urlOrPredicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
2101
1181
  end
2102
1182
 
2103
1183
  # Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
2104
1184
  # `detached`.
2105
- #
1185
+ #
2106
1186
  # Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at
2107
1187
  # the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
2108
1188
  # selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.
2109
- #
1189
+ #
2110
1190
  # This method works across navigations:
2111
- #
2112
- #
2113
- # ```js
2114
- # const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
2115
- #
2116
- # (async () => {
2117
- # const browser = await chromium.launch();
2118
- # const page = await browser.newPage();
2119
- # for (let currentURL of ['https://google.com', 'https://bbc.com']) {
2120
- # await page.goto(currentURL);
2121
- # const element = await page.waitForSelector('img');
2122
- # console.log('Loaded image: ' + await element.getAttribute('src'));
2123
- # }
2124
- # await browser.close();
2125
- # })();
2126
- # ```
2127
- #
2128
- # ```java
2129
- # import com.microsoft.playwright.*;
2130
- #
2131
- # public class Example {
2132
- # public static void main(String[] args) {
2133
- # try (Playwright playwright = Playwright.create()) {
2134
- # BrowserType chromium = playwright.chromium();
2135
- # Browser browser = chromium.launch();
2136
- # Page page = browser.newPage();
2137
- # for (String currentURL : Arrays.asList("https://google.com", "https://bbc.com")) {
2138
- # page.navigate(currentURL);
2139
- # ElementHandle element = page.waitForSelector("img");
2140
- # System.out.println("Loaded image: " + element.getAttribute("src"));
2141
- # }
2142
- # browser.close();
2143
- # }
2144
- # }
2145
- # }
2146
- # ```
2147
- #
2148
- # ```python async
2149
- # import asyncio
2150
- # from playwright.async_api import async_playwright
2151
- #
2152
- # async def run(playwright):
2153
- # chromium = playwright.chromium
2154
- # browser = await chromium.launch()
2155
- # page = await browser.new_page()
2156
- # for current_url in ["https://google.com", "https://bbc.com"]:
2157
- # await page.goto(current_url, wait_until="domcontentloaded")
2158
- # element = await page.wait_for_selector("img")
2159
- # print("Loaded image: " + str(await element.get_attribute("src")))
2160
- # await browser.close()
2161
- #
2162
- # async def main():
2163
- # async with async_playwright() as playwright:
2164
- # await run(playwright)
2165
- # asyncio.run(main())
2166
- # ```
2167
- #
1191
+ #
2168
1192
  # ```python sync
2169
1193
  # from playwright.sync_api import sync_playwright
2170
- #
1194
+ #
2171
1195
  # def run(playwright):
2172
1196
  # chromium = playwright.chromium
2173
1197
  # browser = chromium.launch()
@@ -2177,7 +1201,7 @@ module Playwright
2177
1201
  # element = page.wait_for_selector("img")
2178
1202
  # print("Loaded image: " + str(element.get_attribute("src")))
2179
1203
  # browser.close()
2180
- #
1204
+ #
2181
1205
  # with sync_playwright() as playwright:
2182
1206
  # run(playwright)
2183
1207
  # ```
@@ -2186,64 +1210,39 @@ module Playwright
2186
1210
  end
2187
1211
 
2188
1212
  # Waits for the given `timeout` in milliseconds.
2189
- #
1213
+ #
2190
1214
  # Note that `page.waitForTimeout()` should only be used for debugging. Tests using the timer in production are going to be
2191
1215
  # flaky. Use signals such as network events, selectors becoming visible and others instead.
2192
- #
2193
1216
  #
2194
- # ```js
2195
- # // wait for 1 second
2196
- # await page.waitForTimeout(1000);
2197
- # ```
2198
- #
2199
- # ```java
2200
- # // wait for 1 second
2201
- # page.waitForTimeout(1000);
2202
- # ```
2203
- #
2204
- # ```python async
2205
- # # wait for 1 second
2206
- # await page.wait_for_timeout(1000)
2207
- # ```
2208
- #
2209
1217
  # ```python sync
2210
1218
  # # wait for 1 second
2211
1219
  # page.wait_for_timeout(1000)
2212
1220
  # ```
2213
- #
1221
+ #
2214
1222
  # Shortcut for main frame's [`method: Frame.waitForTimeout`].
2215
1223
  def wait_for_timeout(timeout)
2216
1224
  raise NotImplementedError.new('wait_for_timeout is not implemented yet.')
2217
1225
  end
2218
1226
 
2219
1227
  # Waits for the main frame to navigate to the given URL.
2220
- #
2221
1228
  #
2222
- # ```js
2223
- # await page.click('a.delayed-navigation'); // Clicking the link will indirectly cause a navigation
2224
- # await page.waitForURL('**/target.html');
2225
- # ```
2226
- #
2227
- # ```java
2228
- # page.click("a.delayed-navigation"); // Clicking the link will indirectly cause a navigation
2229
- # page.waitForURL("**/target.html");
2230
- # ```
2231
- #
2232
- # ```python async
2233
- # await page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
2234
- # await page.wait_for_url("**/target.html")
2235
- # ```
2236
- #
2237
1229
  # ```python sync
2238
1230
  # page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
2239
1231
  # page.wait_for_url("**/target.html")
2240
1232
  # ```
2241
- #
1233
+ #
2242
1234
  # Shortcut for main frame's [`method: Frame.waitForURL`].
2243
1235
  def wait_for_url(url, timeout: nil, waitUntil: nil)
2244
1236
  wrap_impl(@impl.wait_for_url(unwrap_impl(url), timeout: unwrap_impl(timeout), waitUntil: unwrap_impl(waitUntil)))
2245
1237
  end
2246
1238
 
1239
+ # Performs action and waits for a new `WebSocket`. If predicate is provided, it passes `WebSocket` value into the
1240
+ # `predicate` function and waits for `predicate(webSocket)` to return a truthy value. Will throw an error if the page is
1241
+ # closed before the WebSocket event is fired.
1242
+ def expect_websocket(predicate: nil, timeout: nil)
1243
+ raise NotImplementedError.new('expect_websocket is not implemented yet.')
1244
+ end
1245
+
2247
1246
  # Performs action and waits for a new `Worker`. If predicate is provided, it passes `Worker` value into the `predicate`
2248
1247
  # function and waits for `predicate(worker)` to return a truthy value. Will throw an error if the page is closed before
2249
1248
  # the worker event is fired.
@@ -2253,16 +1252,16 @@ module Playwright
2253
1252
 
2254
1253
  # This method returns all of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API)
2255
1254
  # associated with the page.
2256
- #
1255
+ #
2257
1256
  # > NOTE: This does not contain ServiceWorkers
2258
1257
  def workers
2259
1258
  raise NotImplementedError.new('workers is not implemented yet.')
2260
1259
  end
2261
1260
 
2262
1261
  # > NOTE: In most cases, you should use [`method: Page.waitForEvent`].
2263
- #
1262
+ #
2264
1263
  # Waits for given `event` to fire. If predicate is provided, it passes event's value into the `predicate` function and
2265
- # waits for `predicate(event)` to return a truthy value. Will throw an error if the socket is closed before the `event` is
1264
+ # waits for `predicate(event)` to return a truthy value. Will throw an error if the page is closed before the `event` is
2266
1265
  # fired.
2267
1266
  def wait_for_event(event, predicate: nil, timeout: nil)
2268
1267
  raise NotImplementedError.new('wait_for_event is not implemented yet.')
@@ -2278,11 +1277,6 @@ module Playwright
2278
1277
  wrap_impl(@impl.start_js_coverage(resetOnNavigation: unwrap_impl(resetOnNavigation), reportAnonymousScripts: unwrap_impl(reportAnonymousScripts)))
2279
1278
  end
2280
1279
 
2281
- # @nodoc
2282
- def stop_js_coverage
2283
- wrap_impl(@impl.stop_js_coverage)
2284
- end
2285
-
2286
1280
  # @nodoc
2287
1281
  def start_css_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil)
2288
1282
  wrap_impl(@impl.start_css_coverage(resetOnNavigation: unwrap_impl(resetOnNavigation), reportAnonymousScripts: unwrap_impl(reportAnonymousScripts)))
@@ -2293,6 +1287,11 @@ module Playwright
2293
1287
  wrap_impl(@impl.stop_css_coverage)
2294
1288
  end
2295
1289
 
1290
+ # @nodoc
1291
+ def stop_js_coverage
1292
+ wrap_impl(@impl.stop_js_coverage)
1293
+ end
1294
+
2296
1295
  # @nodoc
2297
1296
  def guid
2298
1297
  wrap_impl(@impl.guid)