playwright-ruby-client 0.2.1 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) 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 +7 -7
  13. data/lib/playwright/channel_owners/frame.rb +26 -5
  14. data/lib/playwright/channel_owners/js_handle.rb +2 -2
  15. data/lib/playwright/channel_owners/page.rb +125 -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/select_option_values.rb +31 -22
  31. data/lib/playwright/transport.rb +29 -7
  32. data/lib/playwright/url_matcher.rb +1 -1
  33. data/lib/playwright/utils.rb +9 -0
  34. data/lib/playwright/version.rb +1 -1
  35. data/lib/playwright/video.rb +51 -0
  36. data/lib/playwright/wait_helper.rb +2 -2
  37. data/lib/playwright_api/accessibility.rb +39 -1
  38. data/lib/playwright_api/android.rb +74 -2
  39. data/lib/playwright_api/android_device.rb +141 -23
  40. data/lib/playwright_api/android_input.rb +17 -13
  41. data/lib/playwright_api/android_socket.rb +16 -0
  42. data/lib/playwright_api/android_web_view.rb +21 -0
  43. data/lib/playwright_api/browser.rb +77 -2
  44. data/lib/playwright_api/browser_context.rb +178 -25
  45. data/lib/playwright_api/browser_type.rb +40 -9
  46. data/lib/playwright_api/dialog.rb +54 -7
  47. data/lib/playwright_api/element_handle.rb +105 -31
  48. data/lib/playwright_api/file_chooser.rb +6 -1
  49. data/lib/playwright_api/frame.rb +229 -36
  50. data/lib/playwright_api/js_handle.rb +23 -0
  51. data/lib/playwright_api/keyboard.rb +48 -1
  52. data/lib/playwright_api/mouse.rb +26 -5
  53. data/lib/playwright_api/page.rb +491 -81
  54. data/lib/playwright_api/playwright.rb +21 -4
  55. data/lib/playwright_api/request.rb +30 -2
  56. data/lib/playwright_api/response.rb +21 -11
  57. data/lib/playwright_api/route.rb +51 -5
  58. data/lib/playwright_api/selectors.rb +27 -1
  59. data/lib/playwright_api/touchscreen.rb +1 -1
  60. data/lib/playwright_api/worker.rb +25 -1
  61. data/playwright.gemspec +4 -2
  62. metadata +42 -14
  63. data/lib/playwright/channel_owners/chromium_browser.rb +0 -8
  64. data/lib/playwright/channel_owners/chromium_browser_context.rb +0 -8
  65. data/lib/playwright/channel_owners/download.rb +0 -27
  66. data/lib/playwright/channel_owners/firefox_browser.rb +0 -8
  67. data/lib/playwright/channel_owners/webkit_browser.rb +0 -8
  68. data/lib/playwright_api/binding_call.rb +0 -27
  69. data/lib/playwright_api/chromium_browser_context.rb +0 -59
  70. data/lib/playwright_api/download.rb +0 -95
  71. data/lib/playwright_api/video.rb +0 -24
@@ -1,25 +1,29 @@
1
1
  module Playwright
2
- # @nodoc
3
2
  class AndroidInput < PlaywrightApi
4
3
 
5
- # @nodoc
6
- def type(text)
7
- wrap_impl(@impl.type(unwrap_impl(text)))
8
- end
9
-
10
- # @nodoc
11
- def tap_point(point)
12
- wrap_impl(@impl.tap_point(unwrap_impl(point)))
13
- end
14
-
15
- # @nodoc
4
+ # Performs a drag between `from` and `to` points.
16
5
  def drag(from, to, steps)
17
6
  wrap_impl(@impl.drag(unwrap_impl(from), unwrap_impl(to), unwrap_impl(steps)))
18
7
  end
19
8
 
20
- # @nodoc
9
+ # Presses the `key`.
21
10
  def press(key)
22
11
  wrap_impl(@impl.press(unwrap_impl(key)))
23
12
  end
13
+
14
+ # Swipes following the path defined by `segments`.
15
+ def swipe(from, segments, steps)
16
+ raise NotImplementedError.new('swipe is not implemented yet.')
17
+ end
18
+
19
+ # Taps at the specified `point`.
20
+ def tap_point(point)
21
+ wrap_impl(@impl.tap_point(unwrap_impl(point)))
22
+ end
23
+
24
+ # Types `text` into currently focused widget.
25
+ def type(text)
26
+ wrap_impl(@impl.type(unwrap_impl(text)))
27
+ end
24
28
  end
25
29
  end
@@ -0,0 +1,16 @@
1
+ module Playwright
2
+ # `AndroidSocket` is a way to communicate with a process launched on the `AndroidDevice`. Use
3
+ # [`method: AndroidDevice.open`] to open a socket.
4
+ class AndroidSocket < PlaywrightApi
5
+
6
+ # Closes the socket.
7
+ def close
8
+ raise NotImplementedError.new('close is not implemented yet.')
9
+ end
10
+
11
+ # Writes some `data` to the socket.
12
+ def write(data)
13
+ raise NotImplementedError.new('write is not implemented yet.')
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ module Playwright
2
+ # `AndroidWebView` represents a WebView open on the `AndroidDevice`. WebView is usually obtained using
3
+ # [`method: AndroidDevice.webView`].
4
+ class AndroidWebView < PlaywrightApi
5
+
6
+ # Connects to the WebView and returns a regular Playwright `Page` to interact with.
7
+ def page
8
+ raise NotImplementedError.new('page is not implemented yet.')
9
+ end
10
+
11
+ # WebView process PID.
12
+ def pid
13
+ raise NotImplementedError.new('pid is not implemented yet.')
14
+ end
15
+
16
+ # WebView package identifier.
17
+ def pkg
18
+ raise NotImplementedError.new('pkg is not implemented yet.')
19
+ end
20
+ end
21
+ end
@@ -15,6 +15,22 @@ module Playwright
15
15
  # })();
16
16
  # ```
17
17
  #
18
+ # ```java
19
+ # import com.microsoft.playwright.*;
20
+ #
21
+ # public class Example {
22
+ # public static void main(String[] args) {
23
+ # try (Playwright playwright = Playwright.create()) {
24
+ # BrowserType firefox = playwright.firefox()
25
+ # Browser browser = firefox.launch();
26
+ # Page page = browser.newPage();
27
+ # page.navigate('https://example.com');
28
+ # browser.close();
29
+ # }
30
+ # }
31
+ # }
32
+ # ```
33
+ #
18
34
  # ```python async
19
35
  # import asyncio
20
36
  # from playwright.async_api import async_playwright
@@ -69,6 +85,13 @@ module Playwright
69
85
  # console.log(browser.contexts().length); // prints `1`
70
86
  # ```
71
87
  #
88
+ # ```java
89
+ # Browser browser = pw.webkit().launch();
90
+ # System.out.println(browser.contexts().size()); // prints "0"
91
+ # BrowserContext context = browser.newContext();
92
+ # System.out.println(browser.contexts().size()); // prints "1"
93
+ # ```
94
+ #
72
95
  # ```python async
73
96
  # browser = await pw.webkit.launch()
74
97
  # print(len(browser.contexts())) # prints `0`
@@ -91,6 +114,13 @@ module Playwright
91
114
  wrap_impl(@impl.connected?)
92
115
  end
93
116
 
117
+ # > NOTE: CDP Sessions are only supported on Chromium-based browsers.
118
+ #
119
+ # Returns the newly created browser session.
120
+ def new_browser_cdp_session
121
+ raise NotImplementedError.new('new_browser_cdp_session is not implemented yet.')
122
+ end
123
+
94
124
  # Creates a new browser context. It won't share cookies/cache with other browser contexts.
95
125
  #
96
126
  #
@@ -105,6 +135,15 @@ module Playwright
105
135
  # })();
106
136
  # ```
107
137
  #
138
+ # ```java
139
+ # Browser browser = playwright.firefox().launch(); // Or 'chromium' or 'webkit'.
140
+ # // Create a new incognito browser context.
141
+ # BrowserContext context = browser.newContext();
142
+ # // Create a new page in a pristine context.
143
+ # Page page = context.newPage();
144
+ # page.navigate('https://example.com');
145
+ # ```
146
+ #
108
147
  # ```python async
109
148
  # browser = await playwright.firefox.launch() # or "chromium" or "webkit".
110
149
  # # create a new incognito browser context.
@@ -143,12 +182,13 @@ module Playwright
143
182
  record_har_path: nil,
144
183
  record_video_dir: nil,
145
184
  record_video_size: nil,
185
+ screen: nil,
146
186
  storageState: nil,
147
187
  timezoneId: nil,
148
188
  userAgent: nil,
149
189
  viewport: nil,
150
190
  &block)
151
- wrap_impl(@impl.new_context(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
191
+ wrap_impl(@impl.new_context(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), screen: unwrap_impl(screen), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
152
192
  end
153
193
 
154
194
  # Creates a new page in a new browser context. Closing this page will close the context as well.
@@ -177,11 +217,46 @@ module Playwright
177
217
  record_har_path: nil,
178
218
  record_video_dir: nil,
179
219
  record_video_size: nil,
220
+ screen: nil,
180
221
  storageState: nil,
181
222
  timezoneId: nil,
182
223
  userAgent: nil,
183
224
  viewport: nil)
184
- wrap_impl(@impl.new_page(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport)))
225
+ wrap_impl(@impl.new_page(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), screen: unwrap_impl(screen), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport)))
226
+ end
227
+
228
+ # > NOTE: Tracing is only supported on Chromium-based browsers.
229
+ #
230
+ # You can use [`method: Browser.startTracing`] and [`method: Browser.stopTracing`] to create a trace file that can be
231
+ # opened in Chrome DevTools performance panel.
232
+ #
233
+ #
234
+ # ```js
235
+ # await browser.startTracing(page, {path: 'trace.json'});
236
+ # await page.goto('https://www.google.com');
237
+ # await browser.stopTracing();
238
+ # ```
239
+ #
240
+ # ```python async
241
+ # await browser.start_tracing(page, path="trace.json")
242
+ # await page.goto("https://www.google.com")
243
+ # await browser.stop_tracing()
244
+ # ```
245
+ #
246
+ # ```python sync
247
+ # browser.start_tracing(page, path="trace.json")
248
+ # page.goto("https://www.google.com")
249
+ # browser.stop_tracing()
250
+ # ```
251
+ def start_tracing(page: nil, categories: nil, path: nil, screenshots: nil)
252
+ wrap_impl(@impl.start_tracing(page: unwrap_impl(page), categories: unwrap_impl(categories), path: unwrap_impl(path), screenshots: unwrap_impl(screenshots)))
253
+ end
254
+
255
+ # > NOTE: Tracing is only supported on Chromium-based browsers.
256
+ #
257
+ # Returns the buffer with trace data.
258
+ def stop_tracing
259
+ wrap_impl(@impl.stop_tracing)
185
260
  end
186
261
 
187
262
  # Returns the browser version.
@@ -20,6 +20,16 @@ module Playwright
20
20
  # await context.close();
21
21
  # ```
22
22
  #
23
+ # ```java
24
+ # // Create a new incognito browser context
25
+ # BrowserContext context = browser.newContext();
26
+ # // Create a new page inside context.
27
+ # Page page = context.newPage();
28
+ # page.navigate("https://example.com");
29
+ # // Dispose context once it"s no longer needed.
30
+ # context.close();
31
+ # ```
32
+ #
23
33
  # ```python async
24
34
  # # create a new incognito browser context
25
35
  # context = await browser.new_context()
@@ -49,6 +59,10 @@ module Playwright
49
59
  # await browserContext.addCookies([cookieObject1, cookieObject2]);
50
60
  # ```
51
61
  #
62
+ # ```java
63
+ # browserContext.addCookies(Arrays.asList(cookieObject1, cookieObject2));
64
+ # ```
65
+ #
52
66
  # ```python async
53
67
  # await browser_context.add_cookies([cookie_object1, cookie_object2])
54
68
  # ```
@@ -57,7 +71,7 @@ module Playwright
57
71
  # browser_context.add_cookies([cookie_object1, cookie_object2])
58
72
  # ```
59
73
  def add_cookies(cookies)
60
- raise NotImplementedError.new('add_cookies is not implemented yet.')
74
+ wrap_impl(@impl.add_cookies(unwrap_impl(cookies)))
61
75
  end
62
76
 
63
77
  # Adds a script which would be evaluated in one of the following scenarios:
@@ -84,6 +98,11 @@ module Playwright
84
98
  # });
85
99
  # ```
86
100
  #
101
+ # ```java
102
+ # // In your playwright script, assuming the preload.js file is in same directory.
103
+ # browserContext.addInitScript(Paths.get("preload.js"));
104
+ # ```
105
+ #
87
106
  # ```python async
88
107
  # # in your playwright script, assuming the preload.js file is in same directory.
89
108
  # await browser_context.add_init_script(path="preload.js")
@@ -97,17 +116,24 @@ module Playwright
97
116
  # > NOTE: The order of evaluation of multiple scripts installed via [`method: BrowserContext.addInitScript`] and
98
117
  # [`method: Page.addInitScript`] is not defined.
99
118
  def add_init_script(path: nil, script: nil)
100
- raise NotImplementedError.new('add_init_script is not implemented yet.')
119
+ wrap_impl(@impl.add_init_script(path: unwrap_impl(path), script: unwrap_impl(script)))
120
+ end
121
+
122
+ # > NOTE: Background pages are only supported on Chromium-based browsers.
123
+ #
124
+ # All existing background pages in the context.
125
+ def background_pages
126
+ raise NotImplementedError.new('background_pages is not implemented yet.')
101
127
  end
102
128
 
103
129
  # Returns the browser instance of the context. If it was launched as a persistent context null gets returned.
104
130
  def browser
105
- raise NotImplementedError.new('browser is not implemented yet.')
131
+ wrap_impl(@impl.browser)
106
132
  end
107
133
 
108
134
  # Clears context cookies.
109
135
  def clear_cookies
110
- raise NotImplementedError.new('clear_cookies is not implemented yet.')
136
+ wrap_impl(@impl.clear_cookies)
111
137
  end
112
138
 
113
139
  # Clears all permission overrides for the browser context.
@@ -120,6 +146,13 @@ module Playwright
120
146
  # context.clearPermissions();
121
147
  # ```
122
148
  #
149
+ # ```java
150
+ # BrowserContext context = browser.newContext();
151
+ # context.grantPermissions(Arrays.asList("clipboard-read"));
152
+ # // do stuff ..
153
+ # context.clearPermissions();
154
+ # ```
155
+ #
123
156
  # ```python async
124
157
  # context = await browser.new_context()
125
158
  # await context.grant_permissions(["clipboard-read"])
@@ -134,7 +167,7 @@ module Playwright
134
167
  # context.clear_permissions()
135
168
  # ```
136
169
  def clear_permissions
137
- raise NotImplementedError.new('clear_permissions is not implemented yet.')
170
+ wrap_impl(@impl.clear_permissions)
138
171
  end
139
172
 
140
173
  # Closes the browser context. All the pages that belong to the browser context will be closed.
@@ -147,7 +180,7 @@ module Playwright
147
180
  # If no URLs are specified, this method returns all cookies. If URLs are specified, only cookies that affect those URLs
148
181
  # are returned.
149
182
  def cookies(urls: nil)
150
- raise NotImplementedError.new('cookies is not implemented yet.')
183
+ wrap_impl(@impl.cookies(urls: unwrap_impl(urls)))
151
184
  end
152
185
 
153
186
  # The method adds a function called `name` on the `window` object of every frame in every page in the context. When
@@ -183,6 +216,30 @@ module Playwright
183
216
  # })();
184
217
  # ```
185
218
  #
219
+ # ```java
220
+ # import com.microsoft.playwright.*;
221
+ #
222
+ # public class Example {
223
+ # public static void main(String[] args) {
224
+ # try (Playwright playwright = Playwright.create()) {
225
+ # BrowserType webkit = playwright.webkit()
226
+ # Browser browser = webkit.launch(new BrowserType.LaunchOptions().setHeadless(false));
227
+ # BrowserContext context = browser.newContext();
228
+ # context.exposeBinding("pageURL", (source, args) -> source.page().url());
229
+ # Page page = context.newPage();
230
+ # page.setContent("<script>\n" +
231
+ # " async function onClick() {\n" +
232
+ # " document.querySelector('div').textContent = await window.pageURL();\n" +
233
+ # " }\n" +
234
+ # "</script>\n" +
235
+ # "<button onclick=\"onClick()\">Click me</button>\n" +
236
+ # "<div></div>");
237
+ # page.click("button");
238
+ # }
239
+ # }
240
+ # }
241
+ # ```
242
+ #
186
243
  # ```python async
187
244
  # import asyncio
188
245
  # from playwright.async_api import async_playwright
@@ -250,6 +307,20 @@ module Playwright
250
307
  # `);
251
308
  # ```
252
309
  #
310
+ # ```java
311
+ # context.exposeBinding("clicked", (source, args) -> {
312
+ # ElementHandle element = (ElementHandle) args[0];
313
+ # System.out.println(element.textContent());
314
+ # return null;
315
+ # }, new BrowserContext.ExposeBindingOptions().setHandle(true));
316
+ # page.setContent("" +
317
+ # "<script>\n" +
318
+ # " document.addEventListener('click', event => window.clicked(event.target));\n" +
319
+ # "</script>\n" +
320
+ # "<div>Click me</div>\n" +
321
+ # "<div>Or click me</div>\n");
322
+ # ```
323
+ #
253
324
  # ```python async
254
325
  # async def print(source, element):
255
326
  # print(await element.text_content())
@@ -278,7 +349,7 @@ module Playwright
278
349
  # """)
279
350
  # ```
280
351
  def expose_binding(name, callback, handle: nil)
281
- raise NotImplementedError.new('expose_binding is not implemented yet.')
352
+ wrap_impl(@impl.expose_binding(unwrap_impl(name), unwrap_impl(callback), handle: unwrap_impl(handle)))
282
353
  end
283
354
 
284
355
  # The method adds a function called `name` on the `window` object of every frame in every page in the context. When
@@ -313,6 +384,44 @@ module Playwright
313
384
  # })();
314
385
  # ```
315
386
  #
387
+ # ```java
388
+ # import com.microsoft.playwright.*;
389
+ #
390
+ # import java.nio.charset.StandardCharsets;
391
+ # import java.security.MessageDigest;
392
+ # import java.security.NoSuchAlgorithmException;
393
+ # import java.util.Base64;
394
+ #
395
+ # public class Example {
396
+ # public static void main(String[] args) {
397
+ # try (Playwright playwright = Playwright.create()) {
398
+ # BrowserType webkit = playwright.webkit()
399
+ # Browser browser = webkit.launch(new BrowserType.LaunchOptions().setHeadless(false));
400
+ # context.exposeFunction("sha1", args -> {
401
+ # String text = (String) args[0];
402
+ # MessageDigest crypto;
403
+ # try {
404
+ # crypto = MessageDigest.getInstance("SHA-1");
405
+ # } catch (NoSuchAlgorithmException e) {
406
+ # return null;
407
+ # }
408
+ # byte[] token = crypto.digest(text.getBytes(StandardCharsets.UTF_8));
409
+ # return Base64.getEncoder().encodeToString(token);
410
+ # });
411
+ # Page page = context.newPage();
412
+ # page.setContent("<script>\n" +
413
+ # " async function onClick() {\n" +
414
+ # " document.querySelector('div').textContent = await window.sha1('PLAYWRIGHT');\n" +
415
+ # " }\n" +
416
+ # "</script>\n" +
417
+ # "<button onclick=\"onClick()\">Click me</button>\n" +
418
+ # "<div></div>\n");
419
+ # page.click("button");
420
+ # }
421
+ # }
422
+ # }
423
+ # ```
424
+ #
316
425
  # ```python async
317
426
  # import asyncio
318
427
  # import hashlib
@@ -379,13 +488,20 @@ module Playwright
379
488
  # run(playwright)
380
489
  # ```
381
490
  def expose_function(name, callback)
382
- raise NotImplementedError.new('expose_function is not implemented yet.')
491
+ wrap_impl(@impl.expose_function(unwrap_impl(name), unwrap_impl(callback)))
383
492
  end
384
493
 
385
494
  # Grants specified permissions to the browser context. Only grants corresponding permissions to the given origin if
386
495
  # specified.
387
496
  def grant_permissions(permissions, origin: nil)
388
- raise NotImplementedError.new('grant_permissions is not implemented yet.')
497
+ wrap_impl(@impl.grant_permissions(unwrap_impl(permissions), origin: unwrap_impl(origin)))
498
+ end
499
+
500
+ # > NOTE: CDP sessions are only supported on Chromium-based browsers.
501
+ #
502
+ # Returns the newly created session.
503
+ def new_cdp_session(page)
504
+ raise NotImplementedError.new('new_cdp_session is not implemented yet.')
389
505
  end
390
506
 
391
507
  # Creates a new page in the browser context.
@@ -393,8 +509,7 @@ module Playwright
393
509
  wrap_impl(@impl.new_page)
394
510
  end
395
511
 
396
- # Returns all open pages in the context. Non visible pages, such as `"background_page"`, will not be listed here. You can
397
- # find them using [`method: ChromiumBrowserContext.backgroundPages`].
512
+ # Returns all open pages in the context.
398
513
  def pages
399
514
  wrap_impl(@impl.pages)
400
515
  end
@@ -402,7 +517,7 @@ module Playwright
402
517
  # Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
403
518
  # is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
404
519
  #
405
- # An example of a naïve handler that aborts all image requests:
520
+ # An example of a naive handler that aborts all image requests:
406
521
  #
407
522
  #
408
523
  # ```js
@@ -413,6 +528,14 @@ module Playwright
413
528
  # await browser.close();
414
529
  # ```
415
530
  #
531
+ # ```java
532
+ # BrowserContext context = browser.newContext();
533
+ # context.route("**/*.{png,jpg,jpeg}", route -> route.abort());
534
+ # Page page = context.newPage();
535
+ # page.navigate("https://example.com");
536
+ # browser.close();
537
+ # ```
538
+ #
416
539
  # ```python async
417
540
  # context = await browser.new_context()
418
541
  # page = await context.new_page()
@@ -440,6 +563,14 @@ module Playwright
440
563
  # await browser.close();
441
564
  # ```
442
565
  #
566
+ # ```java
567
+ # BrowserContext context = browser.newContext();
568
+ # context.route(Pattern.compile("(\\.png$)|(\\.jpg$)"), route -> route.abort());
569
+ # Page page = context.newPage();
570
+ # page.navigate("https://example.com");
571
+ # browser.close();
572
+ # ```
573
+ #
443
574
  # ```python async
444
575
  # context = await browser.new_context()
445
576
  # page = await context.new_page()
@@ -462,9 +593,18 @@ module Playwright
462
593
  # Page routes (set up with [`method: Page.route`]) take precedence over browser context routes when request matches both
463
594
  # handlers.
464
595
  #
596
+ # To remove a route with its handler you can use [`method: BrowserContext.unroute`].
597
+ #
465
598
  # > NOTE: Enabling routing disables http cache.
466
599
  def route(url, handler)
467
- raise NotImplementedError.new('route is not implemented yet.')
600
+ wrap_impl(@impl.route(unwrap_impl(url), unwrap_impl(handler)))
601
+ end
602
+
603
+ # > NOTE: Service workers are only supported on Chromium-based browsers.
604
+ #
605
+ # All existing service workers in the context.
606
+ def service_workers
607
+ raise NotImplementedError.new('service_workers is not implemented yet.')
468
608
  end
469
609
 
470
610
  # This setting will change the default maximum navigation time for the following methods and related shortcuts:
@@ -478,7 +618,7 @@ module Playwright
478
618
  # > NOTE: [`method: Page.setDefaultNavigationTimeout`] and [`method: Page.setDefaultTimeout`] take priority over
479
619
  # [`method: BrowserContext.setDefaultNavigationTimeout`].
480
620
  def set_default_navigation_timeout(timeout)
481
- raise NotImplementedError.new('set_default_navigation_timeout is not implemented yet.')
621
+ wrap_impl(@impl.set_default_navigation_timeout(unwrap_impl(timeout)))
482
622
  end
483
623
  alias_method :default_navigation_timeout=, :set_default_navigation_timeout
484
624
 
@@ -487,7 +627,7 @@ module Playwright
487
627
  # > NOTE: [`method: Page.setDefaultNavigationTimeout`], [`method: Page.setDefaultTimeout`] and
488
628
  # [`method: BrowserContext.setDefaultNavigationTimeout`] take priority over [`method: BrowserContext.setDefaultTimeout`].
489
629
  def set_default_timeout(timeout)
490
- raise NotImplementedError.new('set_default_timeout is not implemented yet.')
630
+ wrap_impl(@impl.set_default_timeout(unwrap_impl(timeout)))
491
631
  end
492
632
  alias_method :default_timeout=, :set_default_timeout
493
633
 
@@ -497,7 +637,7 @@ module Playwright
497
637
  #
498
638
  # > NOTE: [`method: BrowserContext.setExtraHTTPHeaders`] does not guarantee the order of headers in the outgoing requests.
499
639
  def set_extra_http_headers(headers)
500
- raise NotImplementedError.new('set_extra_http_headers is not implemented yet.')
640
+ wrap_impl(@impl.set_extra_http_headers(unwrap_impl(headers)))
501
641
  end
502
642
  alias_method :extra_http_headers=, :set_extra_http_headers
503
643
 
@@ -508,6 +648,10 @@ module Playwright
508
648
  # await browserContext.setGeolocation({latitude: 59.95, longitude: 30.31667});
509
649
  # ```
510
650
  #
651
+ # ```java
652
+ # browserContext.setGeolocation(new Geolocation(59.95, 30.31667));
653
+ # ```
654
+ #
511
655
  # ```python async
512
656
  # await browser_context.set_geolocation({"latitude": 59.95, "longitude": 30.31667})
513
657
  # ```
@@ -519,12 +663,12 @@ module Playwright
519
663
  # > NOTE: Consider using [`method: BrowserContext.grantPermissions`] to grant permissions for the browser context pages to
520
664
  # read its geolocation.
521
665
  def set_geolocation(geolocation)
522
- raise NotImplementedError.new('set_geolocation is not implemented yet.')
666
+ wrap_impl(@impl.set_geolocation(unwrap_impl(geolocation)))
523
667
  end
524
668
  alias_method :geolocation=, :set_geolocation
525
669
 
526
670
  def set_offline(offline)
527
- raise NotImplementedError.new('set_offline is not implemented yet.')
671
+ wrap_impl(@impl.set_offline(unwrap_impl(offline)))
528
672
  end
529
673
  alias_method :offline=, :set_offline
530
674
 
@@ -536,7 +680,7 @@ module Playwright
536
680
  # Removes a route created with [`method: BrowserContext.route`]. When `handler` is not specified, removes all routes for
537
681
  # the `url`.
538
682
  def unroute(url, handler: nil)
539
- raise NotImplementedError.new('unroute is not implemented yet.')
683
+ wrap_impl(@impl.unroute(unwrap_impl(url), handler: unwrap_impl(handler)))
540
684
  end
541
685
 
542
686
  # Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
@@ -550,6 +694,10 @@ module Playwright
550
694
  # ]);
551
695
  # ```
552
696
  #
697
+ # ```java
698
+ # Page newPage = context.waitForPage(() -> page.click("button"));
699
+ # ```
700
+ #
553
701
  # ```python async
554
702
  # async with context.expect_event("page") as event_info:
555
703
  # await page.click("button")
@@ -561,15 +709,15 @@ module Playwright
561
709
  # page.click("button")
562
710
  # page = event_info.value
563
711
  # ```
564
- def expect_event(event, predicate: nil, timeout: nil)
565
- raise NotImplementedError.new('expect_event is not implemented yet.')
712
+ def expect_event(event, predicate: nil, timeout: nil, &block)
713
+ wrap_impl(@impl.expect_event(unwrap_impl(event), predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
566
714
  end
567
715
 
568
- # Performs action and waits for `page` event to fire. If predicate is provided, it passes `Page` value into the
569
- # `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is
570
- # closed before the worker event is fired.
716
+ # Performs action and waits for a new `Page` to be created in the context. If predicate is provided, it passes `Page`
717
+ # value into the `predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if
718
+ # the context closes before new `Page` is created.
571
719
  def expect_page(predicate: nil, timeout: nil)
572
- raise NotImplementedError.new('expect_page is not implemented yet.')
720
+ wrap_impl(@impl.expect_page(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout)))
573
721
  end
574
722
 
575
723
  # > NOTE: In most cases, you should use [`method: BrowserContext.waitForEvent`].
@@ -596,6 +744,11 @@ module Playwright
596
744
  wrap_impl(@impl.options=(unwrap_impl(req)))
597
745
  end
598
746
 
747
+ # @nodoc
748
+ def pause
749
+ wrap_impl(@impl.pause)
750
+ end
751
+
599
752
  # -- inherited from EventEmitter --
600
753
  # @nodoc
601
754
  def once(event, callback)