playwright-ruby-client 0.2.0 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -5
  3. data/docs/api_coverage.md +116 -74
  4. data/lib/playwright.rb +48 -9
  5. data/lib/playwright/channel.rb +12 -2
  6. data/lib/playwright/channel_owners/artifact.rb +30 -0
  7. data/lib/playwright/channel_owners/binding_call.rb +3 -0
  8. data/lib/playwright/channel_owners/browser.rb +21 -0
  9. data/lib/playwright/channel_owners/browser_context.rb +154 -3
  10. data/lib/playwright/channel_owners/browser_type.rb +28 -0
  11. data/lib/playwright/channel_owners/dialog.rb +28 -0
  12. data/lib/playwright/channel_owners/element_handle.rb +6 -4
  13. data/lib/playwright/channel_owners/frame.rb +25 -2
  14. data/lib/playwright/channel_owners/js_handle.rb +2 -2
  15. data/lib/playwright/channel_owners/page.rb +141 -25
  16. data/lib/playwright/channel_owners/playwright.rb +24 -27
  17. data/lib/playwright/channel_owners/request.rb +26 -2
  18. data/lib/playwright/channel_owners/response.rb +60 -0
  19. data/lib/playwright/channel_owners/route.rb +78 -0
  20. data/lib/playwright/channel_owners/selectors.rb +19 -1
  21. data/lib/playwright/channel_owners/stream.rb +15 -0
  22. data/lib/playwright/connection.rb +11 -32
  23. data/lib/playwright/download.rb +27 -0
  24. data/lib/playwright/errors.rb +6 -0
  25. data/lib/playwright/events.rb +2 -5
  26. data/lib/playwright/keyboard_impl.rb +1 -1
  27. data/lib/playwright/mouse_impl.rb +41 -0
  28. data/lib/playwright/playwright_api.rb +3 -1
  29. data/lib/playwright/route_handler_entry.rb +28 -0
  30. data/lib/playwright/transport.rb +29 -7
  31. data/lib/playwright/url_matcher.rb +1 -1
  32. data/lib/playwright/utils.rb +9 -0
  33. data/lib/playwright/version.rb +1 -1
  34. data/lib/playwright/video.rb +51 -0
  35. data/lib/playwright/wait_helper.rb +2 -2
  36. data/lib/playwright_api/accessibility.rb +39 -1
  37. data/lib/playwright_api/android.rb +74 -2
  38. data/lib/playwright_api/android_device.rb +141 -23
  39. data/lib/playwright_api/android_input.rb +17 -13
  40. data/lib/playwright_api/android_socket.rb +16 -0
  41. data/lib/playwright_api/android_web_view.rb +21 -0
  42. data/lib/playwright_api/browser.rb +77 -2
  43. data/lib/playwright_api/browser_context.rb +182 -29
  44. data/lib/playwright_api/browser_type.rb +40 -9
  45. data/lib/playwright_api/dialog.rb +54 -7
  46. data/lib/playwright_api/element_handle.rb +105 -31
  47. data/lib/playwright_api/file_chooser.rb +6 -1
  48. data/lib/playwright_api/frame.rb +229 -36
  49. data/lib/playwright_api/js_handle.rb +23 -0
  50. data/lib/playwright_api/keyboard.rb +48 -1
  51. data/lib/playwright_api/mouse.rb +26 -5
  52. data/lib/playwright_api/page.rb +491 -81
  53. data/lib/playwright_api/playwright.rb +21 -4
  54. data/lib/playwright_api/request.rb +30 -2
  55. data/lib/playwright_api/response.rb +21 -11
  56. data/lib/playwright_api/route.rb +51 -5
  57. data/lib/playwright_api/selectors.rb +27 -1
  58. data/lib/playwright_api/touchscreen.rb +1 -1
  59. data/lib/playwright_api/worker.rb +25 -1
  60. data/playwright.gemspec +4 -2
  61. metadata +42 -14
  62. data/lib/playwright/channel_owners/chromium_browser.rb +0 -8
  63. data/lib/playwright/channel_owners/chromium_browser_context.rb +0 -8
  64. data/lib/playwright/channel_owners/download.rb +0 -27
  65. data/lib/playwright/channel_owners/firefox_browser.rb +0 -8
  66. data/lib/playwright/channel_owners/webkit_browser.rb +0 -8
  67. data/lib/playwright_api/binding_call.rb +0 -27
  68. data/lib/playwright_api/chromium_browser_context.rb +0 -59
  69. data/lib/playwright_api/download.rb +0 -95
  70. data/lib/playwright_api/video.rb +0 -24
@@ -8,6 +8,11 @@ module Playwright
8
8
  # // ...
9
9
  # ```
10
10
  #
11
+ # ```java
12
+ # JSHandle windowHandle = page.evaluateHandle("() => window");
13
+ # // ...
14
+ # ```
15
+ #
11
16
  # ```python async
12
17
  # window_handle = await page.evaluate_handle("window")
13
18
  # # ...
@@ -50,6 +55,11 @@ module Playwright
50
55
  # expect(await tweetHandle.evaluate(node => node.innerText)).toBe('10 retweets');
51
56
  # ```
52
57
  #
58
+ # ```java
59
+ # ElementHandle tweetHandle = page.querySelector(".tweet .retweets");
60
+ # assertEquals("10 retweets", tweetHandle.evaluate("node => node.innerText"));
61
+ # ```
62
+ #
53
63
  # ```python async
54
64
  # tweet_handle = await page.query_selector(".tweet .retweets")
55
65
  # assert await tweet_handle.evaluate("node => node.innerText") == "10 retweets"
@@ -89,6 +99,14 @@ module Playwright
89
99
  # await handle.dispose();
90
100
  # ```
91
101
  #
102
+ # ```java
103
+ # JSHandle handle = page.evaluateHandle("() => ({window, document}"););
104
+ # Map<String, JSHandle> properties = handle.getProperties();
105
+ # JSHandle windowHandle = properties.get("window");
106
+ # JSHandle documentHandle = properties.get("document");
107
+ # handle.dispose();
108
+ # ```
109
+ #
92
110
  # ```python async
93
111
  # handle = await page.evaluate_handle("{window, document}")
94
112
  # properties = await handle.get_properties()
@@ -122,6 +140,11 @@ module Playwright
122
140
  wrap_impl(@impl.json_value)
123
141
  end
124
142
 
143
+ # @nodoc
144
+ def to_s
145
+ wrap_impl(@impl.to_s)
146
+ end
147
+
125
148
  # -- inherited from EventEmitter --
126
149
  # @nodoc
127
150
  def once(event, callback)
@@ -21,6 +21,17 @@ module Playwright
21
21
  # // Result text will end up saying 'Hello!'
22
22
  # ```
23
23
  #
24
+ # ```java
25
+ # page.keyboard().type("Hello World!");
26
+ # page.keyboard().press("ArrowLeft");
27
+ # page.keyboard().down("Shift");
28
+ # for (int i = 0; i < " World".length(); i++)
29
+ # page.keyboard().press("ArrowLeft");
30
+ # page.keyboard().up("Shift");
31
+ # page.keyboard().press("Backspace");
32
+ # // Result text will end up saying "Hello!"
33
+ # ```
34
+ #
24
35
  # ```python async
25
36
  # await page.keyboard.type("Hello World!")
26
37
  # await page.keyboard.press("ArrowLeft")
@@ -52,6 +63,12 @@ module Playwright
52
63
  # await page.keyboard.press('Shift+A');
53
64
  # ```
54
65
  #
66
+ # ```java
67
+ # page.keyboard().press("Shift+KeyA");
68
+ # // or
69
+ # page.keyboard().press("Shift+A");
70
+ # ```
71
+ #
55
72
  # ```python async
56
73
  # await page.keyboard.press("Shift+KeyA")
57
74
  # # or
@@ -74,6 +91,13 @@ module Playwright
74
91
  # await page.keyboard.press('Meta+A');
75
92
  # ```
76
93
  #
94
+ # ```java
95
+ # // on Windows and Linux
96
+ # page.keyboard().press("Control+A");
97
+ # // on macOS
98
+ # page.keyboard().press("Meta+A");
99
+ # ```
100
+ #
77
101
  # ```python async
78
102
  # # on windows and linux
79
103
  # await page.keyboard.press("Control+A")
@@ -124,6 +148,10 @@ module Playwright
124
148
  # page.keyboard.insertText('嗨');
125
149
  # ```
126
150
  #
151
+ # ```java
152
+ # page.keyboard().insertText("嗨");
153
+ # ```
154
+ #
127
155
  # ```python async
128
156
  # await page.keyboard.insert_text("嗨")
129
157
  # ```
@@ -151,7 +179,7 @@ module Playwright
151
179
  # If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
152
180
  # texts.
153
181
  #
154
- # Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When speficied with the
182
+ # Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
155
183
  # modifier, modifier is pressed and being held while the subsequent key is being pressed.
156
184
  #
157
185
  #
@@ -167,6 +195,18 @@ module Playwright
167
195
  # await browser.close();
168
196
  # ```
169
197
  #
198
+ # ```java
199
+ # Page page = browser.newPage();
200
+ # page.navigate("https://keycode.info");
201
+ # page.keyboard().press("A");
202
+ # page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("A.png"));
203
+ # page.keyboard().press("ArrowLeft");
204
+ # page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("ArrowLeft.png")));
205
+ # page.keyboard().press("Shift+O");
206
+ # page.screenshot(new Page.ScreenshotOptions().setPath(Paths.get("O.png")));
207
+ # browser.close();
208
+ # ```
209
+ #
170
210
  # ```python async
171
211
  # page = await browser.new_page()
172
212
  # await page.goto("https://keycode.info")
@@ -206,6 +246,13 @@ module Playwright
206
246
  # await page.keyboard.type('World', {delay: 100}); // Types slower, like a user
207
247
  # ```
208
248
  #
249
+ # ```java
250
+ # // Types instantly
251
+ # page.keyboard().type("Hello");
252
+ # // Types slower, like a user
253
+ # page.keyboard().type("World", new Keyboard.TypeOptions().setDelay(100));
254
+ # ```
255
+ #
209
256
  # ```python async
210
257
  # await page.keyboard.type("Hello") # types instantly
211
258
  # await page.keyboard.type("World", delay=100) # types slower, like a user
@@ -15,6 +15,17 @@ module Playwright
15
15
  # await page.mouse.up();
16
16
  # ```
17
17
  #
18
+ # ```java
19
+ # // Using ‘page.mouse’ to trace a 100x100 square.
20
+ # page.mouse().move(0, 0);
21
+ # page.mouse().down();
22
+ # page.mouse().move(0, 100);
23
+ # page.mouse().move(100, 100);
24
+ # page.mouse().move(100, 0);
25
+ # page.mouse().move(0, 0);
26
+ # page.mouse().up();
27
+ # ```
28
+ #
18
29
  # ```python async
19
30
  # # using ‘page.mouse’ to trace a 100x100 square.
20
31
  # await page.mouse.move(0, 0)
@@ -36,6 +47,16 @@ module Playwright
36
47
  # page.mouse.move(0, 0)
37
48
  # page.mouse.up()
38
49
  # ```
50
+ #
51
+ # ```csharp
52
+ # await Page.Mouse.MoveAsync(0, 0);
53
+ # await Page.Mouse.DownAsync();
54
+ # await Page.Mouse.MoveAsync(0, 100);
55
+ # await Page.Mouse.MoveAsync(100, 100);
56
+ # await Page.Mouse.MoveAsync(100, 0);
57
+ # await Page.Mouse.MoveAsync(0, 0);
58
+ # await Page.Mouse.UpAsync();
59
+ # ```
39
60
  class Mouse < PlaywrightApi
40
61
 
41
62
  # Shortcut for [`method: Mouse.move`], [`method: Mouse.down`], [`method: Mouse.up`].
@@ -45,28 +66,28 @@ module Playwright
45
66
  button: nil,
46
67
  clickCount: nil,
47
68
  delay: nil)
48
- raise NotImplementedError.new('click is not implemented yet.')
69
+ wrap_impl(@impl.click(unwrap_impl(x), unwrap_impl(y), button: unwrap_impl(button), clickCount: unwrap_impl(clickCount), delay: unwrap_impl(delay)))
49
70
  end
50
71
 
51
72
  # Shortcut for [`method: Mouse.move`], [`method: Mouse.down`], [`method: Mouse.up`], [`method: Mouse.down`] and
52
73
  # [`method: Mouse.up`].
53
74
  def dblclick(x, y, button: nil, delay: nil)
54
- raise NotImplementedError.new('dblclick is not implemented yet.')
75
+ wrap_impl(@impl.dblclick(unwrap_impl(x), unwrap_impl(y), button: unwrap_impl(button), delay: unwrap_impl(delay)))
55
76
  end
56
77
 
57
78
  # Dispatches a `mousedown` event.
58
79
  def down(button: nil, clickCount: nil)
59
- raise NotImplementedError.new('down is not implemented yet.')
80
+ wrap_impl(@impl.down(button: unwrap_impl(button), clickCount: unwrap_impl(clickCount)))
60
81
  end
61
82
 
62
83
  # Dispatches a `mousemove` event.
63
84
  def move(x, y, steps: nil)
64
- raise NotImplementedError.new('move is not implemented yet.')
85
+ wrap_impl(@impl.move(unwrap_impl(x), unwrap_impl(y), steps: unwrap_impl(steps)))
65
86
  end
66
87
 
67
88
  # Dispatches a `mouseup` event.
68
89
  def up(button: nil, clickCount: nil)
69
- raise NotImplementedError.new('up is not implemented yet.')
90
+ wrap_impl(@impl.up(button: unwrap_impl(button), clickCount: unwrap_impl(clickCount)))
70
91
  end
71
92
  end
72
93
  end
@@ -21,6 +21,24 @@ module Playwright
21
21
  # })();
22
22
  # ```
23
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
+ #
24
42
  # ```python async
25
43
  # import asyncio
26
44
  # from playwright.async_api import async_playwright
@@ -67,6 +85,10 @@ module Playwright
67
85
  # page.once('load', () => console.log('Page loaded!'));
68
86
  # ```
69
87
  #
88
+ # ```java
89
+ # page.onLoad(p -> System.out.println("Page loaded!"));
90
+ # ```
91
+ #
70
92
  # ```py
71
93
  # page.once("load", lambda: print("page loaded!"))
72
94
  # ```
@@ -83,6 +105,15 @@ module Playwright
83
105
  # page.removeListener('request', logRequest);
84
106
  # ```
85
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
+ #
86
117
  # ```py
87
118
  # def log_request(intercepted_request):
88
119
  # print("a request was made:", intercepted_request.url)
@@ -130,6 +161,11 @@ module Playwright
130
161
  # await page.addInitScript({ path: './preload.js' });
131
162
  # ```
132
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
+ #
133
169
  # ```python async
134
170
  # # in your playwright script, assuming the preload.js file is in same directory
135
171
  # await page.add_init_script(path="./preload.js")
@@ -168,34 +204,39 @@ module Playwright
168
204
  end
169
205
 
170
206
  # This method checks an element matching `selector` by performing the following steps:
171
- # 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
172
- # 1. Ensure that matched element is a checkbox or a radio input. If not, this method rejects. If the element is already
207
+ # 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
208
+ # 1. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is already
173
209
  # checked, this method returns immediately.
174
210
  # 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
175
211
  # element is detached during the checks, the whole action is retried.
176
212
  # 1. Scroll the element into view if needed.
177
213
  # 1. Use [`property: Page.mouse`] to click in the center of the element.
178
214
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
179
- # 1. Ensure that the element is now checked. If not, this method rejects.
215
+ # 1. Ensure that the element is now checked. If not, this method throws.
180
216
  #
181
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
182
- # Passing zero timeout disables this.
217
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
218
+ # zero timeout disables this.
183
219
  #
184
220
  # Shortcut for main frame's [`method: Frame.check`].
185
- def check(selector, force: nil, noWaitAfter: nil, timeout: nil)
186
- wrap_impl(@impl.check(unwrap_impl(selector), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
221
+ def check(
222
+ selector,
223
+ force: nil,
224
+ noWaitAfter: nil,
225
+ 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)))
187
228
  end
188
229
 
189
230
  # This method clicks an element matching `selector` by performing the following steps:
190
- # 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
231
+ # 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
191
232
  # 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
192
233
  # element is detached during the checks, the whole action is retried.
193
234
  # 1. Scroll the element into view if needed.
194
235
  # 1. Use [`property: Page.mouse`] to click in the center of the element, or the specified `position`.
195
236
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
196
237
  #
197
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
198
- # Passing zero timeout disables this.
238
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
239
+ # zero timeout disables this.
199
240
  #
200
241
  # Shortcut for main frame's [`method: Frame.click`].
201
242
  def click(
@@ -233,16 +274,16 @@ module Playwright
233
274
  end
234
275
 
235
276
  # This method double clicks an element matching `selector` by performing the following steps:
236
- # 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
277
+ # 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
237
278
  # 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
238
279
  # element is detached during the checks, the whole action is retried.
239
280
  # 1. Scroll the element into view if needed.
240
281
  # 1. Use [`property: Page.mouse`] to double click in the center of the element, or the specified `position`.
241
282
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the
242
- # first click of the `dblclick()` triggers a navigation event, this method will reject.
283
+ # first click of the `dblclick()` triggers a navigation event, this method will throw.
243
284
  #
244
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
245
- # Passing zero timeout disables this.
285
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
286
+ # zero timeout disables this.
246
287
  #
247
288
  # > NOTE: `page.dblclick()` dispatches two `click` events and a single `dblclick` event.
248
289
  #
@@ -259,8 +300,8 @@ module Playwright
259
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)))
260
301
  end
261
302
 
262
- # The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the elment, `click`
263
- # is dispatched. This is equivalend to calling
303
+ # The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element,
304
+ # `click` is dispatched. This is equivalent to calling
264
305
  # [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
265
306
  #
266
307
  #
@@ -268,6 +309,10 @@ module Playwright
268
309
  # await page.dispatchEvent('button#submit', 'click');
269
310
  # ```
270
311
  #
312
+ # ```java
313
+ # page.dispatchEvent("button#submit", "click");
314
+ # ```
315
+ #
271
316
  # ```python async
272
317
  # await page.dispatch_event("button#submit", "click")
273
318
  # ```
@@ -297,6 +342,14 @@ module Playwright
297
342
  # await page.dispatchEvent('#source', 'dragstart', { dataTransfer });
298
343
  # ```
299
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
+ #
300
353
  # ```python async
301
354
  # # note you can only create data_transfer in chromium and firefox
302
355
  # data_transfer = await page.evaluate_handle("new DataTransfer()")
@@ -312,7 +365,6 @@ module Playwright
312
365
  wrap_impl(@impl.dispatch_event(unwrap_impl(selector), unwrap_impl(type), eventInit: unwrap_impl(eventInit), timeout: unwrap_impl(timeout)))
313
366
  end
314
367
 
315
- #
316
368
  #
317
369
  # ```js
318
370
  # await page.evaluate(() => matchMedia('screen').matches);
@@ -333,6 +385,25 @@ module Playwright
333
385
  # // → false
334
386
  # ```
335
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
+ #
336
407
  # ```python async
337
408
  # await page.evaluate("matchMedia('screen').matches")
338
409
  # # → True
@@ -382,6 +453,16 @@ module Playwright
382
453
  # // → false
383
454
  # ```
384
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
+ #
385
466
  # ```python async
386
467
  # await page.emulate_media(color_scheme="dark")
387
468
  # await page.evaluate("matchMedia('(prefers-color-scheme: dark)').matches")
@@ -419,6 +500,12 @@ module Playwright
419
500
  # const html = await page.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello');
420
501
  # ```
421
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
+ #
422
509
  # ```python async
423
510
  # search_value = await page.eval_on_selector("#search", "el => el.value")
424
511
  # preload_href = await page.eval_on_selector("link[rel=preload]", "el => el.href")
@@ -449,6 +536,10 @@ module Playwright
449
536
  # const divCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);
450
537
  # ```
451
538
  #
539
+ # ```java
540
+ # boolean divCounts = (boolean) page.evalOnSelectorAll("div", "(divs, min) => divs.length >= min", 10);
541
+ # ```
542
+ #
452
543
  # ```python async
453
544
  # div_counts = await page.eval_on_selector_all("div", "(divs, min) => divs.length >= min", 10)
454
545
  # ```
@@ -479,6 +570,13 @@ module Playwright
479
570
  # console.log(result); // prints "56"
480
571
  # ```
481
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
+ #
482
580
  # ```python async
483
581
  # result = await page.evaluate("([x, y]) => Promise.resolve(x * y)", [7, 8])
484
582
  # print(result) # prints "56"
@@ -498,6 +596,10 @@ module Playwright
498
596
  # console.log(await page.evaluate(`1 + ${x}`)); // prints "11"
499
597
  # ```
500
598
  #
599
+ # ```java
600
+ # System.out.println(page.evaluate("1 + 2")); // prints "3"
601
+ # ```
602
+ #
501
603
  # ```python async
502
604
  # print(await page.evaluate("1 + 2")) # prints "3"
503
605
  # x = 10
@@ -519,6 +621,12 @@ module Playwright
519
621
  # await bodyHandle.dispose();
520
622
  # ```
521
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
+ #
522
630
  # ```python async
523
631
  # body_handle = await page.query_selector("body")
524
632
  # html = await page.evaluate("([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
@@ -550,6 +658,11 @@ module Playwright
550
658
  # aWindowHandle; // Handle for the window object.
551
659
  # ```
552
660
  #
661
+ # ```java
662
+ # // Handle for the window object.
663
+ # JSHandle aWindowHandle = page.evaluateHandle("() => Promise.resolve(window)");
664
+ # ```
665
+ #
553
666
  # ```python async
554
667
  # a_window_handle = await page.evaluate_handle("Promise.resolve(window)")
555
668
  # a_window_handle # handle for the window object.
@@ -567,6 +680,10 @@ module Playwright
567
680
  # const aHandle = await page.evaluateHandle('document'); // Handle for the 'document'
568
681
  # ```
569
682
  #
683
+ # ```java
684
+ # JSHandle aHandle = page.evaluateHandle("document"); // Handle for the "document".
685
+ # ```
686
+ #
570
687
  # ```python async
571
688
  # a_handle = await page.evaluate_handle("document") # handle for the "document"
572
689
  # ```
@@ -585,6 +702,13 @@ module Playwright
585
702
  # await resultHandle.dispose();
586
703
  # ```
587
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
+ #
588
712
  # ```python async
589
713
  # a_handle = await page.evaluate_handle("document.body")
590
714
  # result_handle = await page.evaluate_handle("body => body.innerHTML", a_handle)
@@ -637,6 +761,30 @@ module Playwright
637
761
  # })();
638
762
  # ```
639
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
+ #
640
788
  # ```python async
641
789
  # import asyncio
642
790
  # from playwright.async_api import async_playwright
@@ -704,6 +852,20 @@ module Playwright
704
852
  # `);
705
853
  # ```
706
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
+ #
707
869
  # ```python async
708
870
  # async def print(source, element):
709
871
  # print(await element.text_content())
@@ -768,6 +930,44 @@ module Playwright
768
930
  # })();
769
931
  # ```
770
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
+ #
771
971
  # ```python async
772
972
  # import asyncio
773
973
  # import hashlib
@@ -862,6 +1062,10 @@ module Playwright
862
1062
  # const frame = page.frame('frame-name');
863
1063
  # ```
864
1064
  #
1065
+ # ```java
1066
+ # Frame frame = page.frame("frame-name");
1067
+ # ```
1068
+ #
865
1069
  # ```py
866
1070
  # frame = page.frame(name="frame-name")
867
1071
  # ```
@@ -871,6 +1075,10 @@ module Playwright
871
1075
  # const frame = page.frame({ url: /.*domain.*/ });
872
1076
  # ```
873
1077
  #
1078
+ # ```java
1079
+ # Frame frame = page.frameByUrl(Pattern.compile(".*domain.*");
1080
+ # ```
1081
+ #
874
1082
  # ```py
875
1083
  # frame = page.frame(url=r".*domain.*")
876
1084
  # ```
@@ -929,15 +1137,15 @@ module Playwright
929
1137
  end
930
1138
 
931
1139
  # This method hovers over an element matching `selector` by performing the following steps:
932
- # 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
1140
+ # 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
933
1141
  # 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
934
1142
  # element is detached during the checks, the whole action is retried.
935
1143
  # 1. Scroll the element into view if needed.
936
1144
  # 1. Use [`property: Page.mouse`] to hover over the center of the element, or the specified `position`.
937
1145
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
938
1146
  #
939
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
940
- # Passing zero timeout disables this.
1147
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
1148
+ # zero timeout disables this.
941
1149
  #
942
1150
  # Shortcut for main frame's [`method: Frame.hover`].
943
1151
  def hover(
@@ -984,12 +1192,14 @@ module Playwright
984
1192
  wrap_impl(@impl.enabled?(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
985
1193
  end
986
1194
 
987
- # Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible).
1195
+ # Returns whether the element is hidden, the opposite of [visible](./actionability.md#visible). `selector` that does not
1196
+ # match any elements is considered hidden.
988
1197
  def hidden?(selector, timeout: nil)
989
1198
  wrap_impl(@impl.hidden?(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
990
1199
  end
991
1200
 
992
- # Returns whether the element is [visible](./actionability.md#visible).
1201
+ # Returns whether the element is [visible](./actionability.md#visible). `selector` that does not match any elements is
1202
+ # considered not visible.
993
1203
  def visible?(selector, timeout: nil)
994
1204
  wrap_impl(@impl.visible?(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
995
1205
  end
@@ -1010,7 +1220,7 @@ module Playwright
1010
1220
  # User can inspect selectors or perform manual steps while paused. Resume will continue running the original script from
1011
1221
  # the place it was paused.
1012
1222
  #
1013
- # > NOTE: This method requires Playwright to be started in a headed mode, with a falsy [`options: headless`] value in the
1223
+ # > NOTE: This method requires Playwright to be started in a headed mode, with a falsy `headless` value in the
1014
1224
  # [`method: BrowserType.launch`].
1015
1225
  def pause
1016
1226
  raise NotImplementedError.new('pause is not implemented yet.')
@@ -1034,6 +1244,12 @@ module Playwright
1034
1244
  # await page.pdf({path: 'page.pdf'});
1035
1245
  # ```
1036
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
+ #
1037
1253
  # ```python async
1038
1254
  # # generates a pdf with "screen" media type.
1039
1255
  # await page.emulate_media(media="screen")
@@ -1107,7 +1323,7 @@ module Playwright
1107
1323
  # If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
1108
1324
  # texts.
1109
1325
  #
1110
- # Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When speficied with the
1326
+ # Shortcuts such as `key: "Control+o"` or `key: "Control+Shift+T"` are supported as well. When specified with the
1111
1327
  # modifier, modifier is pressed and being held while the subsequent key is being pressed.
1112
1328
  #
1113
1329
  #
@@ -1123,6 +1339,17 @@ module Playwright
1123
1339
  # await browser.close();
1124
1340
  # ```
1125
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
+ #
1126
1353
  # ```python async
1127
1354
  # page = await browser.new_page()
1128
1355
  # await page.goto("https://keycode.info")
@@ -1183,7 +1410,7 @@ module Playwright
1183
1410
  #
1184
1411
  # > NOTE: The handler will only be called for the first url if the response is a redirect.
1185
1412
  #
1186
- # An example of a naïve handler that aborts all image requests:
1413
+ # An example of a naive handler that aborts all image requests:
1187
1414
  #
1188
1415
  #
1189
1416
  # ```js
@@ -1193,6 +1420,13 @@ module Playwright
1193
1420
  # await browser.close();
1194
1421
  # ```
1195
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
+ #
1196
1430
  # ```python async
1197
1431
  # page = await browser.new_page()
1198
1432
  # await page.route("**/*.{png,jpg,jpeg}", lambda route: route.abort())
@@ -1217,6 +1451,13 @@ module Playwright
1217
1451
  # await browser.close();
1218
1452
  # ```
1219
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
+ #
1220
1461
  # ```python async
1221
1462
  # page = await browser.new_page()
1222
1463
  # await page.route(re.compile(r"(\.png$)|(\.jpg$)"), lambda route: route.abort())
@@ -1234,15 +1475,14 @@ module Playwright
1234
1475
  # Page routes take precedence over browser context routes (set up with [`method: BrowserContext.route`]) when request
1235
1476
  # matches both handlers.
1236
1477
  #
1478
+ # To remove a route with its handler you can use [`method: Page.unroute`].
1479
+ #
1237
1480
  # > NOTE: Enabling routing disables http cache.
1238
1481
  def route(url, handler)
1239
- raise NotImplementedError.new('route is not implemented yet.')
1482
+ wrap_impl(@impl.route(unwrap_impl(url), unwrap_impl(handler)))
1240
1483
  end
1241
1484
 
1242
1485
  # Returns the buffer with the captured screenshot.
1243
- #
1244
- # > NOTE: Screenshots take at least 1/6 second on Chromium OS X and Chromium Windows. See https://crbug.com/741689 for
1245
- # discussion.
1246
1486
  def screenshot(
1247
1487
  clip: nil,
1248
1488
  fullPage: nil,
@@ -1274,6 +1514,15 @@ module Playwright
1274
1514
  #
1275
1515
  # ```
1276
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
+ #
1277
1526
  # ```python async
1278
1527
  # # single selection matching the value
1279
1528
  # await page.select_option("select#colors", "blue")
@@ -1316,6 +1565,7 @@ module Playwright
1316
1565
  # - [`method: Page.reload`]
1317
1566
  # - [`method: Page.setContent`]
1318
1567
  # - [`method: Page.waitForNavigation`]
1568
+ # - [`method: Page.waitForURL`]
1319
1569
  #
1320
1570
  # > NOTE: [`method: Page.setDefaultNavigationTimeout`] takes priority over [`method: Page.setDefaultTimeout`],
1321
1571
  # [`method: BrowserContext.setDefaultTimeout`] and [`method: BrowserContext.setDefaultNavigationTimeout`].
@@ -1365,6 +1615,12 @@ module Playwright
1365
1615
  # await page.goto('https://example.com');
1366
1616
  # ```
1367
1617
  #
1618
+ # ```java
1619
+ # Page page = browser.newPage();
1620
+ # page.setViewportSize(640, 480);
1621
+ # page.navigate("https://example.com");
1622
+ # ```
1623
+ #
1368
1624
  # ```python async
1369
1625
  # page = await browser.new_page()
1370
1626
  # await page.set_viewport_size({"width": 640, "height": 480})
@@ -1382,15 +1638,15 @@ module Playwright
1382
1638
  alias_method :viewport_size=, :set_viewport_size
1383
1639
 
1384
1640
  # This method taps an element matching `selector` by performing the following steps:
1385
- # 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
1641
+ # 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
1386
1642
  # 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
1387
1643
  # element is detached during the checks, the whole action is retried.
1388
1644
  # 1. Scroll the element into view if needed.
1389
1645
  # 1. Use [`property: Page.touchscreen`] to tap the center of the element, or the specified `position`.
1390
1646
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
1391
1647
  #
1392
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
1393
- # Passing zero timeout disables this.
1648
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
1649
+ # zero timeout disables this.
1394
1650
  #
1395
1651
  # > NOTE: [`method: Page.tap`] requires that the `hasTouch` option of the browser context be set to true.
1396
1652
  #
@@ -1426,6 +1682,13 @@ module Playwright
1426
1682
  # await page.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a user
1427
1683
  # ```
1428
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
+ #
1429
1692
  # ```python async
1430
1693
  # await page.type("#mytextarea", "hello") # types instantly
1431
1694
  # await page.type("#mytextarea", "world", delay=100) # types slower, like a user
@@ -1447,27 +1710,32 @@ module Playwright
1447
1710
  end
1448
1711
 
1449
1712
  # This method unchecks an element matching `selector` by performing the following steps:
1450
- # 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
1451
- # 1. Ensure that matched element is a checkbox or a radio input. If not, this method rejects. If the element is already
1713
+ # 1. Find an element matching `selector`. If there is none, wait until a matching element is attached to the DOM.
1714
+ # 1. Ensure that matched element is a checkbox or a radio input. If not, this method throws. If the element is already
1452
1715
  # unchecked, this method returns immediately.
1453
1716
  # 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
1454
1717
  # element is detached during the checks, the whole action is retried.
1455
1718
  # 1. Scroll the element into view if needed.
1456
1719
  # 1. Use [`property: Page.mouse`] to click in the center of the element.
1457
1720
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
1458
- # 1. Ensure that the element is now unchecked. If not, this method rejects.
1721
+ # 1. Ensure that the element is now unchecked. If not, this method throws.
1459
1722
  #
1460
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
1461
- # Passing zero timeout disables this.
1723
+ # When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
1724
+ # zero timeout disables this.
1462
1725
  #
1463
1726
  # Shortcut for main frame's [`method: Frame.uncheck`].
1464
- def uncheck(selector, force: nil, noWaitAfter: nil, timeout: nil)
1465
- wrap_impl(@impl.uncheck(unwrap_impl(selector), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
1727
+ def uncheck(
1728
+ selector,
1729
+ force: nil,
1730
+ noWaitAfter: nil,
1731
+ 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)))
1466
1734
  end
1467
1735
 
1468
1736
  # Removes a route created with [`method: Page.route`]. When `handler` is not specified, removes all routes for the `url`.
1469
1737
  def unroute(url, handler: nil)
1470
- raise NotImplementedError.new('unroute is not implemented yet.')
1738
+ wrap_impl(@impl.unroute(unwrap_impl(url), handler: unwrap_impl(handler)))
1471
1739
  end
1472
1740
 
1473
1741
  # Shortcut for main frame's [`method: Frame.url`].
@@ -1477,13 +1745,27 @@ module Playwright
1477
1745
 
1478
1746
  # Video object associated with this page.
1479
1747
  def video
1480
- raise NotImplementedError.new('video is not implemented yet.')
1748
+ wrap_impl(@impl.video)
1481
1749
  end
1482
1750
 
1483
1751
  def viewport_size
1484
1752
  wrap_impl(@impl.viewport_size)
1485
1753
  end
1486
1754
 
1755
+ # Performs action and waits for a `ConsoleMessage` to be logged by in the page. If predicate is provided, it passes
1756
+ # `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.
1758
+ def expect_console_message(predicate: nil, timeout: nil, &block)
1759
+ wrap_impl(@impl.expect_console_message(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
1760
+ end
1761
+
1762
+ # Performs action and waits for a new `Download`. If predicate is provided, it passes `Download` value into the
1763
+ # `predicate` function and waits for `predicate(download)` to return a truthy value. Will throw an error if the page is
1764
+ # closed before the download event is fired.
1765
+ def expect_download(predicate: nil, timeout: nil, &block)
1766
+ wrap_impl(@impl.expect_download(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
1767
+ end
1768
+
1487
1769
  # Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
1488
1770
  # value. Will throw an error if the page is closed before the event is fired. Returns the event data value.
1489
1771
  #
@@ -1510,6 +1792,13 @@ module Playwright
1510
1792
  wrap_impl(@impl.expect_event(unwrap_impl(event), predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
1511
1793
  end
1512
1794
 
1795
+ # Performs action and waits for a new `FileChooser` to be created. If predicate is provided, it passes `FileChooser` value
1796
+ # into the `predicate` function and waits for `predicate(fileChooser)` to return a truthy value. Will throw an error if
1797
+ # the page is closed before the file chooser is opened.
1798
+ def expect_file_chooser(predicate: nil, timeout: nil, &block)
1799
+ wrap_impl(@impl.expect_file_chooser(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
1800
+ end
1801
+
1513
1802
  # Returns when the `expression` returns a truthy value. It resolves to a JSHandle of the truthy value.
1514
1803
  #
1515
1804
  # The [`method: Page.waitForFunction`] can be used to observe viewport size change:
@@ -1528,6 +1817,23 @@ module Playwright
1528
1817
  # })();
1529
1818
  # ```
1530
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
+ #
1531
1837
  # ```python async
1532
1838
  # import asyncio
1533
1839
  # from playwright.async_api import async_playwright
@@ -1569,6 +1875,11 @@ module Playwright
1569
1875
  # await page.waitForFunction(selector => !!document.querySelector(selector), selector);
1570
1876
  # ```
1571
1877
  #
1878
+ # ```java
1879
+ # String selector = ".foo";
1880
+ # page.waitForFunction("selector => !!document.querySelector(selector)", selector);
1881
+ # ```
1882
+ #
1572
1883
  # ```python async
1573
1884
  # selector = ".foo"
1574
1885
  # await page.wait_for_function("selector => !!document.querySelector(selector)", selector)
@@ -1595,6 +1906,11 @@ module Playwright
1595
1906
  # await page.waitForLoadState(); // The promise resolves after 'load' event.
1596
1907
  # ```
1597
1908
  #
1909
+ # ```java
1910
+ # page.click("button"); // Click triggers navigation.
1911
+ # page.waitForLoadState(); // The promise resolves after "load" event.
1912
+ # ```
1913
+ #
1598
1914
  # ```python async
1599
1915
  # await page.click("button") # click triggers navigation.
1600
1916
  # await page.wait_for_load_state() # the promise resolves after "load" event.
@@ -1615,6 +1931,14 @@ module Playwright
1615
1931
  # console.log(await popup.title()); // Popup is ready to use.
1616
1932
  # ```
1617
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
+ #
1618
1942
  # ```python async
1619
1943
  # async with page.expect_popup() as page_info:
1620
1944
  # await page.click("button") # click triggers a popup.
@@ -1654,6 +1978,13 @@ module Playwright
1654
1978
  # ]);
1655
1979
  # ```
1656
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
+ #
1657
1988
  # ```python async
1658
1989
  # async with page.expect_navigation():
1659
1990
  # await page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
@@ -1674,6 +2005,13 @@ module Playwright
1674
2005
  wrap_impl(@impl.expect_navigation(timeout: unwrap_impl(timeout), url: unwrap_impl(url), waitUntil: unwrap_impl(waitUntil), &wrap_block_call(block)))
1675
2006
  end
1676
2007
 
2008
+ # Performs action and waits for a popup `Page`. If predicate is provided, it passes [Popup] value into the `predicate`
2009
+ # function and waits for `predicate(page)` to return a truthy value. Will throw an error if the page is closed before the
2010
+ # popup event is fired.
2011
+ def expect_popup(predicate: nil, timeout: nil, &block)
2012
+ wrap_impl(@impl.expect_popup(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
2013
+ end
2014
+
1677
2015
  # Waits for the matching request and returns it.
1678
2016
  #
1679
2017
  #
@@ -1683,6 +2021,13 @@ module Playwright
1683
2021
  # return firstRequest.url();
1684
2022
  # ```
1685
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
+ #
1686
2031
  # ```python async
1687
2032
  # async with page.expect_request("http://example.com/resource") as first:
1688
2033
  # await page.click('button')
@@ -1720,16 +2065,36 @@ module Playwright
1720
2065
  # return finalResponse.ok();
1721
2066
  # ```
1722
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
+ #
1723
2074
  # ```python async
1724
- # first_response = await page.wait_for_response("https://example.com/resource")
1725
- # final_response = await page.wait_for_response(lambda response: response.url == "https://example.com" and response.status === 200)
1726
- # return final_response.ok
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
1727
2085
  # ```
1728
2086
  #
1729
2087
  # ```python sync
1730
- # first_response = page.wait_for_response("https://example.com/resource")
1731
- # final_response = page.wait_for_response(lambda response: response.url == "https://example.com" and response.status === 200)
1732
- # return final_response.ok
2088
+ # with page.expect_response("https://example.com/resource") as response_info:
2089
+ # page.click("input")
2090
+ # response = response_info.value
2091
+ # return response.ok
2092
+ #
2093
+ # # or with a lambda
2094
+ # with page.expect_response(lambda response: response.url == "https://example.com" and response.status === 200) as response_info:
2095
+ # page.click("input")
2096
+ # response = response_info.value
2097
+ # return response.ok
1733
2098
  # ```
1734
2099
  def expect_response(urlOrPredicate, timeout: nil)
1735
2100
  wrap_impl(@impl.expect_response(unwrap_impl(urlOrPredicate), timeout: unwrap_impl(timeout)))
@@ -1760,6 +2125,26 @@ module Playwright
1760
2125
  # })();
1761
2126
  # ```
1762
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
+ #
1763
2148
  # ```python async
1764
2149
  # import asyncio
1765
2150
  # from playwright.async_api import async_playwright
@@ -1811,6 +2196,11 @@ module Playwright
1811
2196
  # await page.waitForTimeout(1000);
1812
2197
  # ```
1813
2198
  #
2199
+ # ```java
2200
+ # // wait for 1 second
2201
+ # page.waitForTimeout(1000);
2202
+ # ```
2203
+ #
1814
2204
  # ```python async
1815
2205
  # # wait for 1 second
1816
2206
  # await page.wait_for_timeout(1000)
@@ -1826,47 +2216,47 @@ module Playwright
1826
2216
  raise NotImplementedError.new('wait_for_timeout is not implemented yet.')
1827
2217
  end
1828
2218
 
1829
- # This method returns all of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API)
1830
- # associated with the page.
2219
+ # Waits for the main frame to navigate to the given URL.
1831
2220
  #
1832
- # > NOTE: This does not contain ServiceWorkers
1833
- def workers
1834
- raise NotImplementedError.new('workers is not implemented yet.')
1835
- end
1836
-
1837
- # Performs action and waits for `download` event to fire. If predicate is provided, it passes `Download` value into the
1838
- # `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is
1839
- # closed before the download event is fired.
1840
- def expect_download(predicate: nil, timeout: nil)
1841
- raise NotImplementedError.new('expect_download is not implemented yet.')
1842
- end
1843
-
1844
- # Performs action and waits for `popup` event to fire. If predicate is provided, it passes [Popup] value into the
1845
- # `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is
1846
- # closed before the popup event is fired.
1847
- def expect_popup(predicate: nil, timeout: nil)
1848
- raise NotImplementedError.new('expect_popup is not implemented yet.')
2221
+ #
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
+ # ```python sync
2238
+ # page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
2239
+ # page.wait_for_url("**/target.html")
2240
+ # ```
2241
+ #
2242
+ # Shortcut for main frame's [`method: Frame.waitForURL`].
2243
+ def wait_for_url(url, timeout: nil, waitUntil: nil)
2244
+ wrap_impl(@impl.wait_for_url(unwrap_impl(url), timeout: unwrap_impl(timeout), waitUntil: unwrap_impl(waitUntil)))
1849
2245
  end
1850
2246
 
1851
- # Performs action and waits for `worker` event to fire. If predicate is provided, it passes `Worker` value into the
1852
- # `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is
1853
- # closed before the worker event is fired.
2247
+ # Performs action and waits for a new `Worker`. If predicate is provided, it passes `Worker` value into the `predicate`
2248
+ # function and waits for `predicate(worker)` to return a truthy value. Will throw an error if the page is closed before
2249
+ # the worker event is fired.
1854
2250
  def expect_worker(predicate: nil, timeout: nil)
1855
2251
  raise NotImplementedError.new('expect_worker is not implemented yet.')
1856
2252
  end
1857
2253
 
1858
- # Performs action and waits for `console` event to fire. If predicate is provided, it passes `ConsoleMessage` value into
1859
- # the `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is
1860
- # closed before the worker event is fired.
1861
- def expect_console_message(predicate: nil, timeout: nil)
1862
- raise NotImplementedError.new('expect_console_message is not implemented yet.')
1863
- end
1864
-
1865
- # Performs action and waits for `filechooser` event to fire. If predicate is provided, it passes `FileChooser` value into
1866
- # the `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is
1867
- # closed before the worker event is fired.
1868
- def expect_file_chooser(predicate: nil, timeout: nil)
1869
- raise NotImplementedError.new('expect_file_chooser is not implemented yet.')
2254
+ # This method returns all of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API)
2255
+ # associated with the page.
2256
+ #
2257
+ # > NOTE: This does not contain ServiceWorkers
2258
+ def workers
2259
+ raise NotImplementedError.new('workers is not implemented yet.')
1870
2260
  end
1871
2261
 
1872
2262
  # > NOTE: In most cases, you should use [`method: Page.waitForEvent`].
@@ -1878,6 +2268,26 @@ module Playwright
1878
2268
  raise NotImplementedError.new('wait_for_event is not implemented yet.')
1879
2269
  end
1880
2270
 
2271
+ # @nodoc
2272
+ def start_js_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil)
2273
+ wrap_impl(@impl.start_js_coverage(resetOnNavigation: unwrap_impl(resetOnNavigation), reportAnonymousScripts: unwrap_impl(reportAnonymousScripts)))
2274
+ end
2275
+
2276
+ # @nodoc
2277
+ def stop_js_coverage
2278
+ wrap_impl(@impl.stop_js_coverage)
2279
+ end
2280
+
2281
+ # @nodoc
2282
+ def start_css_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil)
2283
+ wrap_impl(@impl.start_css_coverage(resetOnNavigation: unwrap_impl(resetOnNavigation), reportAnonymousScripts: unwrap_impl(reportAnonymousScripts)))
2284
+ end
2285
+
2286
+ # @nodoc
2287
+ def stop_css_coverage
2288
+ wrap_impl(@impl.stop_css_coverage)
2289
+ end
2290
+
1881
2291
  # @nodoc
1882
2292
  def owned_context=(req)
1883
2293
  wrap_impl(@impl.owned_context=(unwrap_impl(req)))