playwright-ruby-client 0.1.0 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -8
  3. data/docs/api_coverage.md +123 -73
  4. data/lib/playwright.rb +48 -9
  5. data/lib/playwright/channel.rb +12 -2
  6. data/lib/playwright/channel_owner.rb +3 -5
  7. data/lib/playwright/channel_owners/android.rb +1 -1
  8. data/lib/playwright/channel_owners/android_device.rb +11 -11
  9. data/lib/playwright/channel_owners/artifact.rb +30 -0
  10. data/lib/playwright/channel_owners/binding_call.rb +3 -0
  11. data/lib/playwright/channel_owners/browser.rb +22 -1
  12. data/lib/playwright/channel_owners/browser_context.rb +155 -4
  13. data/lib/playwright/channel_owners/browser_type.rb +28 -0
  14. data/lib/playwright/channel_owners/dialog.rb +28 -0
  15. data/lib/playwright/channel_owners/element_handle.rb +18 -5
  16. data/lib/playwright/channel_owners/frame.rb +40 -5
  17. data/lib/playwright/channel_owners/js_handle.rb +3 -3
  18. data/lib/playwright/channel_owners/page.rb +172 -51
  19. data/lib/playwright/channel_owners/playwright.rb +24 -27
  20. data/lib/playwright/channel_owners/request.rb +27 -3
  21. data/lib/playwright/channel_owners/response.rb +60 -0
  22. data/lib/playwright/channel_owners/route.rb +78 -0
  23. data/lib/playwright/channel_owners/selectors.rb +19 -1
  24. data/lib/playwright/channel_owners/stream.rb +15 -0
  25. data/lib/playwright/connection.rb +11 -32
  26. data/lib/playwright/download.rb +27 -0
  27. data/lib/playwright/errors.rb +6 -0
  28. data/lib/playwright/events.rb +2 -5
  29. data/lib/playwright/keyboard_impl.rb +1 -1
  30. data/lib/playwright/mouse_impl.rb +41 -0
  31. data/lib/playwright/playwright_api.rb +3 -1
  32. data/lib/playwright/route_handler_entry.rb +28 -0
  33. data/lib/playwright/select_option_values.rb +14 -4
  34. data/lib/playwright/transport.rb +28 -7
  35. data/lib/playwright/url_matcher.rb +1 -1
  36. data/lib/playwright/utils.rb +11 -2
  37. data/lib/playwright/version.rb +1 -1
  38. data/lib/playwright/video.rb +51 -0
  39. data/lib/playwright/wait_helper.rb +2 -2
  40. data/lib/playwright_api/accessibility.rb +39 -1
  41. data/lib/playwright_api/android.rb +72 -5
  42. data/lib/playwright_api/android_device.rb +139 -26
  43. data/lib/playwright_api/android_input.rb +17 -13
  44. data/lib/playwright_api/android_socket.rb +16 -0
  45. data/lib/playwright_api/android_web_view.rb +21 -0
  46. data/lib/playwright_api/browser.rb +87 -19
  47. data/lib/playwright_api/browser_context.rb +216 -32
  48. data/lib/playwright_api/browser_type.rb +45 -58
  49. data/lib/playwright_api/dialog.rb +54 -7
  50. data/lib/playwright_api/element_handle.rb +113 -33
  51. data/lib/playwright_api/file_chooser.rb +6 -1
  52. data/lib/playwright_api/frame.rb +238 -43
  53. data/lib/playwright_api/js_handle.rb +20 -2
  54. data/lib/playwright_api/keyboard.rb +48 -1
  55. data/lib/playwright_api/mouse.rb +26 -5
  56. data/lib/playwright_api/page.rb +534 -63
  57. data/lib/playwright_api/playwright.rb +43 -47
  58. data/lib/playwright_api/request.rb +38 -12
  59. data/lib/playwright_api/response.rb +27 -10
  60. data/lib/playwright_api/route.rb +51 -6
  61. data/lib/playwright_api/selectors.rb +28 -2
  62. data/lib/playwright_api/touchscreen.rb +1 -1
  63. data/lib/playwright_api/web_socket.rb +15 -0
  64. data/lib/playwright_api/worker.rb +25 -1
  65. data/playwright.gemspec +4 -2
  66. metadata +42 -14
  67. data/lib/playwright/channel_owners/chromium_browser.rb +0 -8
  68. data/lib/playwright/channel_owners/chromium_browser_context.rb +0 -8
  69. data/lib/playwright/channel_owners/download.rb +0 -27
  70. data/lib/playwright/channel_owners/firefox_browser.rb +0 -8
  71. data/lib/playwright/channel_owners/webkit_browser.rb +0 -8
  72. data/lib/playwright_api/binding_call.rb +0 -27
  73. data/lib/playwright_api/chromium_browser_context.rb +0 -59
  74. data/lib/playwright_api/download.rb +0 -100
  75. 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()
@@ -123,8 +141,8 @@ module Playwright
123
141
  end
124
142
 
125
143
  # @nodoc
126
- def after_initialize
127
- wrap_impl(@impl.after_initialize)
144
+ def to_s
145
+ wrap_impl(@impl.to_s)
128
146
  end
129
147
 
130
148
  # -- inherited from EventEmitter --
@@ -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)
@@ -96,12 +127,6 @@ module Playwright
96
127
  wrap_impl(@impl.accessibility)
97
128
  end
98
129
 
99
- # Browser-specific Coverage implementation, only available for Chromium atm. See
100
- # `ChromiumCoverage`(#class-chromiumcoverage) for more details.
101
- def coverage # property
102
- raise NotImplementedError.new('coverage is not implemented yet.')
103
- end
104
-
105
130
  def keyboard # property
106
131
  wrap_impl(@impl.keyboard)
107
132
  end
@@ -136,6 +161,11 @@ module Playwright
136
161
  # await page.addInitScript({ path: './preload.js' });
137
162
  # ```
138
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
+ #
139
169
  # ```python async
140
170
  # # in your playwright script, assuming the preload.js file is in same directory
141
171
  # await page.add_init_script(path="./preload.js")
@@ -148,8 +178,8 @@ module Playwright
148
178
  #
149
179
  # > NOTE: The order of evaluation of multiple scripts installed via [`method: BrowserContext.addInitScript`] and
150
180
  # [`method: Page.addInitScript`] is not defined.
151
- def add_init_script(script, arg: nil)
152
- wrap_impl(@impl.add_init_script(unwrap_impl(script), arg: unwrap_impl(arg)))
181
+ def add_init_script(path: nil, script: nil)
182
+ wrap_impl(@impl.add_init_script(path: unwrap_impl(path), script: unwrap_impl(script)))
153
183
  end
154
184
 
155
185
  # Adds a `<script>` tag into the page with the desired url or content. Returns the added tag when the script's onload
@@ -174,34 +204,39 @@ module Playwright
174
204
  end
175
205
 
176
206
  # This method checks an element matching `selector` by performing the following steps:
177
- # 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
178
- # 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
179
209
  # checked, this method returns immediately.
180
210
  # 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
181
211
  # element is detached during the checks, the whole action is retried.
182
212
  # 1. Scroll the element into view if needed.
183
213
  # 1. Use [`property: Page.mouse`] to click in the center of the element.
184
214
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
185
- # 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.
186
216
  #
187
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
188
- # 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.
189
219
  #
190
220
  # Shortcut for main frame's [`method: Frame.check`].
191
- def check(selector, force: nil, noWaitAfter: nil, timeout: nil)
192
- 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)))
193
228
  end
194
229
 
195
230
  # This method clicks an element matching `selector` by performing the following steps:
196
- # 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.
197
232
  # 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
198
233
  # element is detached during the checks, the whole action is retried.
199
234
  # 1. Scroll the element into view if needed.
200
235
  # 1. Use [`property: Page.mouse`] to click in the center of the element, or the specified `position`.
201
236
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
202
237
  #
203
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
204
- # 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.
205
240
  #
206
241
  # Shortcut for main frame's [`method: Frame.click`].
207
242
  def click(
@@ -239,16 +274,16 @@ module Playwright
239
274
  end
240
275
 
241
276
  # This method double clicks an element matching `selector` by performing the following steps:
242
- # 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.
243
278
  # 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
244
279
  # element is detached during the checks, the whole action is retried.
245
280
  # 1. Scroll the element into view if needed.
246
281
  # 1. Use [`property: Page.mouse`] to double click in the center of the element, or the specified `position`.
247
282
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set. Note that if the
248
- # 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.
249
284
  #
250
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
251
- # 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.
252
287
  #
253
288
  # > NOTE: `page.dblclick()` dispatches two `click` events and a single `dblclick` event.
254
289
  #
@@ -265,8 +300,8 @@ module Playwright
265
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)))
266
301
  end
267
302
 
268
- # The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the elment, `click`
269
- # 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
270
305
  # [element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
271
306
  #
272
307
  #
@@ -274,6 +309,10 @@ module Playwright
274
309
  # await page.dispatchEvent('button#submit', 'click');
275
310
  # ```
276
311
  #
312
+ # ```java
313
+ # page.dispatchEvent("button#submit", "click");
314
+ # ```
315
+ #
277
316
  # ```python async
278
317
  # await page.dispatch_event("button#submit", "click")
279
318
  # ```
@@ -303,6 +342,14 @@ module Playwright
303
342
  # await page.dispatchEvent('#source', 'dragstart', { dataTransfer });
304
343
  # ```
305
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
+ #
306
353
  # ```python async
307
354
  # # note you can only create data_transfer in chromium and firefox
308
355
  # data_transfer = await page.evaluate_handle("new DataTransfer()")
@@ -318,7 +365,6 @@ module Playwright
318
365
  wrap_impl(@impl.dispatch_event(unwrap_impl(selector), unwrap_impl(type), eventInit: unwrap_impl(eventInit), timeout: unwrap_impl(timeout)))
319
366
  end
320
367
 
321
- #
322
368
  #
323
369
  # ```js
324
370
  # await page.evaluate(() => matchMedia('screen').matches);
@@ -339,6 +385,25 @@ module Playwright
339
385
  # // → false
340
386
  # ```
341
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
+ #
342
407
  # ```python async
343
408
  # await page.evaluate("matchMedia('screen').matches")
344
409
  # # → True
@@ -388,6 +453,16 @@ module Playwright
388
453
  # // → false
389
454
  # ```
390
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
+ #
391
466
  # ```python async
392
467
  # await page.emulate_media(color_scheme="dark")
393
468
  # await page.evaluate("matchMedia('(prefers-color-scheme: dark)').matches")
@@ -425,6 +500,12 @@ module Playwright
425
500
  # const html = await page.$eval('.main-container', (e, suffix) => e.outerHTML + suffix, 'hello');
426
501
  # ```
427
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
+ #
428
509
  # ```python async
429
510
  # search_value = await page.eval_on_selector("#search", "el => el.value")
430
511
  # preload_href = await page.eval_on_selector("link[rel=preload]", "el => el.href")
@@ -455,6 +536,10 @@ module Playwright
455
536
  # const divCounts = await page.$$eval('div', (divs, min) => divs.length >= min, 10);
456
537
  # ```
457
538
  #
539
+ # ```java
540
+ # boolean divCounts = (boolean) page.evalOnSelectorAll("div", "(divs, min) => divs.length >= min", 10);
541
+ # ```
542
+ #
458
543
  # ```python async
459
544
  # div_counts = await page.eval_on_selector_all("div", "(divs, min) => divs.length >= min", 10)
460
545
  # ```
@@ -485,6 +570,13 @@ module Playwright
485
570
  # console.log(result); // prints "56"
486
571
  # ```
487
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
+ #
488
580
  # ```python async
489
581
  # result = await page.evaluate("([x, y]) => Promise.resolve(x * y)", [7, 8])
490
582
  # print(result) # prints "56"
@@ -504,6 +596,10 @@ module Playwright
504
596
  # console.log(await page.evaluate(`1 + ${x}`)); // prints "11"
505
597
  # ```
506
598
  #
599
+ # ```java
600
+ # System.out.println(page.evaluate("1 + 2")); // prints "3"
601
+ # ```
602
+ #
507
603
  # ```python async
508
604
  # print(await page.evaluate("1 + 2")) # prints "3"
509
605
  # x = 10
@@ -525,6 +621,12 @@ module Playwright
525
621
  # await bodyHandle.dispose();
526
622
  # ```
527
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
+ #
528
630
  # ```python async
529
631
  # body_handle = await page.query_selector("body")
530
632
  # html = await page.evaluate("([body, suffix]) => body.innerHTML + suffix", [body_handle, "hello"])
@@ -556,6 +658,11 @@ module Playwright
556
658
  # aWindowHandle; // Handle for the window object.
557
659
  # ```
558
660
  #
661
+ # ```java
662
+ # // Handle for the window object.
663
+ # JSHandle aWindowHandle = page.evaluateHandle("() => Promise.resolve(window)");
664
+ # ```
665
+ #
559
666
  # ```python async
560
667
  # a_window_handle = await page.evaluate_handle("Promise.resolve(window)")
561
668
  # a_window_handle # handle for the window object.
@@ -573,6 +680,10 @@ module Playwright
573
680
  # const aHandle = await page.evaluateHandle('document'); // Handle for the 'document'
574
681
  # ```
575
682
  #
683
+ # ```java
684
+ # JSHandle aHandle = page.evaluateHandle("document"); // Handle for the "document".
685
+ # ```
686
+ #
576
687
  # ```python async
577
688
  # a_handle = await page.evaluate_handle("document") # handle for the "document"
578
689
  # ```
@@ -591,6 +702,13 @@ module Playwright
591
702
  # await resultHandle.dispose();
592
703
  # ```
593
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
+ #
594
712
  # ```python async
595
713
  # a_handle = await page.evaluate_handle("document.body")
596
714
  # result_handle = await page.evaluate_handle("body => body.innerHTML", a_handle)
@@ -643,6 +761,30 @@ module Playwright
643
761
  # })();
644
762
  # ```
645
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
+ #
646
788
  # ```python async
647
789
  # import asyncio
648
790
  # from playwright.async_api import async_playwright
@@ -710,6 +852,20 @@ module Playwright
710
852
  # `);
711
853
  # ```
712
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
+ #
713
869
  # ```python async
714
870
  # async def print(source, element):
715
871
  # print(await element.text_content())
@@ -774,6 +930,44 @@ module Playwright
774
930
  # })();
775
931
  # ```
776
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
+ #
777
971
  # ```python async
778
972
  # import asyncio
779
973
  # import hashlib
@@ -868,6 +1062,10 @@ module Playwright
868
1062
  # const frame = page.frame('frame-name');
869
1063
  # ```
870
1064
  #
1065
+ # ```java
1066
+ # Frame frame = page.frame("frame-name");
1067
+ # ```
1068
+ #
871
1069
  # ```py
872
1070
  # frame = page.frame(name="frame-name")
873
1071
  # ```
@@ -877,11 +1075,15 @@ module Playwright
877
1075
  # const frame = page.frame({ url: /.*domain.*/ });
878
1076
  # ```
879
1077
  #
1078
+ # ```java
1079
+ # Frame frame = page.frameByUrl(Pattern.compile(".*domain.*");
1080
+ # ```
1081
+ #
880
1082
  # ```py
881
1083
  # frame = page.frame(url=r".*domain.*")
882
1084
  # ```
883
- def frame(frameSelector)
884
- wrap_impl(@impl.frame(unwrap_impl(frameSelector)))
1085
+ def frame(name: nil, url: nil)
1086
+ wrap_impl(@impl.frame(name: unwrap_impl(name), url: unwrap_impl(url)))
885
1087
  end
886
1088
 
887
1089
  # An array of all frames attached to the page.
@@ -935,15 +1137,15 @@ module Playwright
935
1137
  end
936
1138
 
937
1139
  # This method hovers over an element matching `selector` by performing the following steps:
938
- # 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.
939
1141
  # 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
940
1142
  # element is detached during the checks, the whole action is retried.
941
1143
  # 1. Scroll the element into view if needed.
942
1144
  # 1. Use [`property: Page.mouse`] to hover over the center of the element, or the specified `position`.
943
1145
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
944
1146
  #
945
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
946
- # 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.
947
1149
  #
948
1150
  # Shortcut for main frame's [`method: Frame.hover`].
949
1151
  def hover(
@@ -990,12 +1192,14 @@ module Playwright
990
1192
  wrap_impl(@impl.enabled?(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
991
1193
  end
992
1194
 
993
- # 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.
994
1197
  def hidden?(selector, timeout: nil)
995
1198
  wrap_impl(@impl.hidden?(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
996
1199
  end
997
1200
 
998
- # 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.
999
1203
  def visible?(selector, timeout: nil)
1000
1204
  wrap_impl(@impl.visible?(unwrap_impl(selector), timeout: unwrap_impl(timeout)))
1001
1205
  end
@@ -1016,7 +1220,7 @@ module Playwright
1016
1220
  # User can inspect selectors or perform manual steps while paused. Resume will continue running the original script from
1017
1221
  # the place it was paused.
1018
1222
  #
1019
- # > 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
1020
1224
  # [`method: BrowserType.launch`].
1021
1225
  def pause
1022
1226
  raise NotImplementedError.new('pause is not implemented yet.')
@@ -1040,6 +1244,12 @@ module Playwright
1040
1244
  # await page.pdf({path: 'page.pdf'});
1041
1245
  # ```
1042
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
+ #
1043
1253
  # ```python async
1044
1254
  # # generates a pdf with "screen" media type.
1045
1255
  # await page.emulate_media(media="screen")
@@ -1113,7 +1323,7 @@ module Playwright
1113
1323
  # If `key` is a single character, it is case-sensitive, so the values `a` and `A` will generate different respective
1114
1324
  # texts.
1115
1325
  #
1116
- # 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
1117
1327
  # modifier, modifier is pressed and being held while the subsequent key is being pressed.
1118
1328
  #
1119
1329
  #
@@ -1129,6 +1339,17 @@ module Playwright
1129
1339
  # await browser.close();
1130
1340
  # ```
1131
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
+ #
1132
1353
  # ```python async
1133
1354
  # page = await browser.new_page()
1134
1355
  # await page.goto("https://keycode.info")
@@ -1189,7 +1410,7 @@ module Playwright
1189
1410
  #
1190
1411
  # > NOTE: The handler will only be called for the first url if the response is a redirect.
1191
1412
  #
1192
- # An example of a naïve handler that aborts all image requests:
1413
+ # An example of a naive handler that aborts all image requests:
1193
1414
  #
1194
1415
  #
1195
1416
  # ```js
@@ -1199,6 +1420,13 @@ module Playwright
1199
1420
  # await browser.close();
1200
1421
  # ```
1201
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
+ #
1202
1430
  # ```python async
1203
1431
  # page = await browser.new_page()
1204
1432
  # await page.route("**/*.{png,jpg,jpeg}", lambda route: route.abort())
@@ -1223,6 +1451,13 @@ module Playwright
1223
1451
  # await browser.close();
1224
1452
  # ```
1225
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
+ #
1226
1461
  # ```python async
1227
1462
  # page = await browser.new_page()
1228
1463
  # await page.route(re.compile(r"(\.png$)|(\.jpg$)"), lambda route: route.abort())
@@ -1240,15 +1475,14 @@ module Playwright
1240
1475
  # Page routes take precedence over browser context routes (set up with [`method: BrowserContext.route`]) when request
1241
1476
  # matches both handlers.
1242
1477
  #
1478
+ # To remove a route with its handler you can use [`method: Page.unroute`].
1479
+ #
1243
1480
  # > NOTE: Enabling routing disables http cache.
1244
1481
  def route(url, handler)
1245
- raise NotImplementedError.new('route is not implemented yet.')
1482
+ wrap_impl(@impl.route(unwrap_impl(url), unwrap_impl(handler)))
1246
1483
  end
1247
1484
 
1248
1485
  # Returns the buffer with the captured screenshot.
1249
- #
1250
- # > NOTE: Screenshots take at least 1/6 second on Chromium OS X and Chromium Windows. See https://crbug.com/741689 for
1251
- # discussion.
1252
1486
  def screenshot(
1253
1487
  clip: nil,
1254
1488
  fullPage: nil,
@@ -1280,6 +1514,15 @@ module Playwright
1280
1514
  #
1281
1515
  # ```
1282
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
+ #
1283
1526
  # ```python async
1284
1527
  # # single selection matching the value
1285
1528
  # await page.select_option("select#colors", "blue")
@@ -1299,8 +1542,15 @@ module Playwright
1299
1542
  # ```
1300
1543
  #
1301
1544
  # Shortcut for main frame's [`method: Frame.selectOption`]
1302
- def select_option(selector, values, noWaitAfter: nil, timeout: nil)
1303
- wrap_impl(@impl.select_option(unwrap_impl(selector), unwrap_impl(values), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
1545
+ def select_option(
1546
+ selector,
1547
+ element: nil,
1548
+ index: nil,
1549
+ value: nil,
1550
+ label: nil,
1551
+ noWaitAfter: nil,
1552
+ timeout: nil)
1553
+ wrap_impl(@impl.select_option(unwrap_impl(selector), element: unwrap_impl(element), index: unwrap_impl(index), value: unwrap_impl(value), label: unwrap_impl(label), noWaitAfter: unwrap_impl(noWaitAfter), timeout: unwrap_impl(timeout)))
1304
1554
  end
1305
1555
 
1306
1556
  def set_content(html, timeout: nil, waitUntil: nil)
@@ -1315,6 +1565,7 @@ module Playwright
1315
1565
  # - [`method: Page.reload`]
1316
1566
  # - [`method: Page.setContent`]
1317
1567
  # - [`method: Page.waitForNavigation`]
1568
+ # - [`method: Page.waitForURL`]
1318
1569
  #
1319
1570
  # > NOTE: [`method: Page.setDefaultNavigationTimeout`] takes priority over [`method: Page.setDefaultTimeout`],
1320
1571
  # [`method: BrowserContext.setDefaultTimeout`] and [`method: BrowserContext.setDefaultNavigationTimeout`].
@@ -1364,6 +1615,12 @@ module Playwright
1364
1615
  # await page.goto('https://example.com');
1365
1616
  # ```
1366
1617
  #
1618
+ # ```java
1619
+ # Page page = browser.newPage();
1620
+ # page.setViewportSize(640, 480);
1621
+ # page.navigate("https://example.com");
1622
+ # ```
1623
+ #
1367
1624
  # ```python async
1368
1625
  # page = await browser.new_page()
1369
1626
  # await page.set_viewport_size({"width": 640, "height": 480})
@@ -1381,15 +1638,15 @@ module Playwright
1381
1638
  alias_method :viewport_size=, :set_viewport_size
1382
1639
 
1383
1640
  # This method taps an element matching `selector` by performing the following steps:
1384
- # 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.
1385
1642
  # 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
1386
1643
  # element is detached during the checks, the whole action is retried.
1387
1644
  # 1. Scroll the element into view if needed.
1388
1645
  # 1. Use [`property: Page.touchscreen`] to tap the center of the element, or the specified `position`.
1389
1646
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
1390
1647
  #
1391
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
1392
- # 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.
1393
1650
  #
1394
1651
  # > NOTE: [`method: Page.tap`] requires that the `hasTouch` option of the browser context be set to true.
1395
1652
  #
@@ -1425,6 +1682,13 @@ module Playwright
1425
1682
  # await page.type('#mytextarea', 'World', {delay: 100}); // Types slower, like a user
1426
1683
  # ```
1427
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
+ #
1428
1692
  # ```python async
1429
1693
  # await page.type("#mytextarea", "hello") # types instantly
1430
1694
  # await page.type("#mytextarea", "world", delay=100) # types slower, like a user
@@ -1446,27 +1710,32 @@ module Playwright
1446
1710
  end
1447
1711
 
1448
1712
  # This method unchecks an element matching `selector` by performing the following steps:
1449
- # 1. Find an element match matching `selector`. If there is none, wait until a matching element is attached to the DOM.
1450
- # 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
1451
1715
  # unchecked, this method returns immediately.
1452
1716
  # 1. Wait for [actionability](./actionability.md) checks on the matched element, unless `force` option is set. If the
1453
1717
  # element is detached during the checks, the whole action is retried.
1454
1718
  # 1. Scroll the element into view if needed.
1455
1719
  # 1. Use [`property: Page.mouse`] to click in the center of the element.
1456
1720
  # 1. Wait for initiated navigations to either succeed or fail, unless `noWaitAfter` option is set.
1457
- # 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.
1458
1722
  #
1459
- # When all steps combined have not finished during the specified `timeout`, this method rejects with a `TimeoutError`.
1460
- # 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.
1461
1725
  #
1462
1726
  # Shortcut for main frame's [`method: Frame.uncheck`].
1463
- def uncheck(selector, force: nil, noWaitAfter: nil, timeout: nil)
1464
- 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)))
1465
1734
  end
1466
1735
 
1467
1736
  # Removes a route created with [`method: Page.route`]. When `handler` is not specified, removes all routes for the `url`.
1468
1737
  def unroute(url, handler: nil)
1469
- raise NotImplementedError.new('unroute is not implemented yet.')
1738
+ wrap_impl(@impl.unroute(unwrap_impl(url), handler: unwrap_impl(handler)))
1470
1739
  end
1471
1740
 
1472
1741
  # Shortcut for main frame's [`method: Frame.url`].
@@ -1476,13 +1745,60 @@ module Playwright
1476
1745
 
1477
1746
  # Video object associated with this page.
1478
1747
  def video
1479
- raise NotImplementedError.new('video is not implemented yet.')
1748
+ wrap_impl(@impl.video)
1480
1749
  end
1481
1750
 
1482
1751
  def viewport_size
1483
1752
  wrap_impl(@impl.viewport_size)
1484
1753
  end
1485
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
+
1769
+ # Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
1770
+ # value. Will throw an error if the page is closed before the event is fired. Returns the event data value.
1771
+ #
1772
+ #
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
+ # ```python sync
1787
+ # with page.expect_event("framenavigated") as event_info:
1788
+ # page.click("button")
1789
+ # frame = event_info.value
1790
+ # ```
1791
+ def expect_event(event, predicate: nil, timeout: nil, &block)
1792
+ wrap_impl(@impl.expect_event(unwrap_impl(event), predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
1793
+ end
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
+
1486
1802
  # Returns when the `expression` returns a truthy value. It resolves to a JSHandle of the truthy value.
1487
1803
  #
1488
1804
  # The [`method: Page.waitForFunction`] can be used to observe viewport size change:
@@ -1501,6 +1817,23 @@ module Playwright
1501
1817
  # })();
1502
1818
  # ```
1503
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
+ #
1504
1837
  # ```python async
1505
1838
  # import asyncio
1506
1839
  # from playwright.async_api import async_playwright
@@ -1542,6 +1875,11 @@ module Playwright
1542
1875
  # await page.waitForFunction(selector => !!document.querySelector(selector), selector);
1543
1876
  # ```
1544
1877
  #
1878
+ # ```java
1879
+ # String selector = ".foo";
1880
+ # page.waitForFunction("selector => !!document.querySelector(selector)", selector);
1881
+ # ```
1882
+ #
1545
1883
  # ```python async
1546
1884
  # selector = ".foo"
1547
1885
  # await page.wait_for_function("selector => !!document.querySelector(selector)", selector)
@@ -1568,6 +1906,11 @@ module Playwright
1568
1906
  # await page.waitForLoadState(); // The promise resolves after 'load' event.
1569
1907
  # ```
1570
1908
  #
1909
+ # ```java
1910
+ # page.click("button"); // Click triggers navigation.
1911
+ # page.waitForLoadState(); // The promise resolves after "load" event.
1912
+ # ```
1913
+ #
1571
1914
  # ```python async
1572
1915
  # await page.click("button") # click triggers navigation.
1573
1916
  # await page.wait_for_load_state() # the promise resolves after "load" event.
@@ -1588,6 +1931,14 @@ module Playwright
1588
1931
  # console.log(await popup.title()); // Popup is ready to use.
1589
1932
  # ```
1590
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
+ #
1591
1942
  # ```python async
1592
1943
  # async with page.expect_popup() as page_info:
1593
1944
  # await page.click("button") # click triggers a popup.
@@ -1627,6 +1978,13 @@ module Playwright
1627
1978
  # ]);
1628
1979
  # ```
1629
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
+ #
1630
1988
  # ```python async
1631
1989
  # async with page.expect_navigation():
1632
1990
  # await page.click("a.delayed-navigation") # clicking the link will indirectly cause a navigation
@@ -1647,6 +2005,13 @@ module Playwright
1647
2005
  wrap_impl(@impl.expect_navigation(timeout: unwrap_impl(timeout), url: unwrap_impl(url), waitUntil: unwrap_impl(waitUntil), &wrap_block_call(block)))
1648
2006
  end
1649
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
+
1650
2015
  # Waits for the matching request and returns it.
1651
2016
  #
1652
2017
  #
@@ -1656,6 +2021,13 @@ module Playwright
1656
2021
  # return firstRequest.url();
1657
2022
  # ```
1658
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
+ #
1659
2031
  # ```python async
1660
2032
  # async with page.expect_request("http://example.com/resource") as first:
1661
2033
  # await page.click('button')
@@ -1693,16 +2065,36 @@ module Playwright
1693
2065
  # return finalResponse.ok();
1694
2066
  # ```
1695
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
+ #
1696
2074
  # ```python async
1697
- # first_response = await page.wait_for_response("https://example.com/resource")
1698
- # final_response = await page.wait_for_response(lambda response: response.url == "https://example.com" and response.status === 200)
1699
- # 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
1700
2085
  # ```
1701
2086
  #
1702
2087
  # ```python sync
1703
- # first_response = page.wait_for_response("https://example.com/resource")
1704
- # final_response = page.wait_for_response(lambda response: response.url == "https://example.com" and response.status === 200)
1705
- # 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
1706
2098
  # ```
1707
2099
  def expect_response(urlOrPredicate, timeout: nil)
1708
2100
  wrap_impl(@impl.expect_response(unwrap_impl(urlOrPredicate), timeout: unwrap_impl(timeout)))
@@ -1733,6 +2125,26 @@ module Playwright
1733
2125
  # })();
1734
2126
  # ```
1735
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
+ #
1736
2148
  # ```python async
1737
2149
  # import asyncio
1738
2150
  # from playwright.async_api import async_playwright
@@ -1784,6 +2196,11 @@ module Playwright
1784
2196
  # await page.waitForTimeout(1000);
1785
2197
  # ```
1786
2198
  #
2199
+ # ```java
2200
+ # // wait for 1 second
2201
+ # page.waitForTimeout(1000);
2202
+ # ```
2203
+ #
1787
2204
  # ```python async
1788
2205
  # # wait for 1 second
1789
2206
  # await page.wait_for_timeout(1000)
@@ -1799,6 +2216,41 @@ module Playwright
1799
2216
  raise NotImplementedError.new('wait_for_timeout is not implemented yet.')
1800
2217
  end
1801
2218
 
2219
+ # Waits for the main frame to navigate to the given URL.
2220
+ #
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)))
2245
+ end
2246
+
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.
2250
+ def expect_worker(predicate: nil, timeout: nil)
2251
+ raise NotImplementedError.new('expect_worker is not implemented yet.')
2252
+ end
2253
+
1802
2254
  # This method returns all of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API)
1803
2255
  # associated with the page.
1804
2256
  #
@@ -1807,14 +2259,33 @@ module Playwright
1807
2259
  raise NotImplementedError.new('workers is not implemented yet.')
1808
2260
  end
1809
2261
 
2262
+ # > NOTE: In most cases, you should use [`method: Page.waitForEvent`].
2263
+ #
2264
+ # 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
2266
+ # fired.
2267
+ def wait_for_event(event, predicate: nil, timeout: nil)
2268
+ raise NotImplementedError.new('wait_for_event is not implemented yet.')
2269
+ end
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
+
1810
2281
  # @nodoc
1811
- def after_initialize
1812
- wrap_impl(@impl.after_initialize)
2282
+ def start_css_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil)
2283
+ wrap_impl(@impl.start_css_coverage(resetOnNavigation: unwrap_impl(resetOnNavigation), reportAnonymousScripts: unwrap_impl(reportAnonymousScripts)))
1813
2284
  end
1814
2285
 
1815
2286
  # @nodoc
1816
- def expect_event(event, optionsOrPredicate: nil, &block)
1817
- wrap_impl(@impl.expect_event(unwrap_impl(event), optionsOrPredicate: unwrap_impl(optionsOrPredicate), &wrap_block_call(block)))
2287
+ def stop_css_coverage
2288
+ wrap_impl(@impl.stop_css_coverage)
1818
2289
  end
1819
2290
 
1820
2291
  # @nodoc