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.
- checksums.yaml +4 -4
- data/README.md +20 -8
- data/docs/api_coverage.md +123 -73
- data/lib/playwright.rb +48 -9
- data/lib/playwright/channel.rb +12 -2
- data/lib/playwright/channel_owner.rb +3 -5
- data/lib/playwright/channel_owners/android.rb +1 -1
- data/lib/playwright/channel_owners/android_device.rb +11 -11
- data/lib/playwright/channel_owners/artifact.rb +30 -0
- data/lib/playwright/channel_owners/binding_call.rb +3 -0
- data/lib/playwright/channel_owners/browser.rb +22 -1
- data/lib/playwright/channel_owners/browser_context.rb +155 -4
- data/lib/playwright/channel_owners/browser_type.rb +28 -0
- data/lib/playwright/channel_owners/dialog.rb +28 -0
- data/lib/playwright/channel_owners/element_handle.rb +18 -5
- data/lib/playwright/channel_owners/frame.rb +40 -5
- data/lib/playwright/channel_owners/js_handle.rb +3 -3
- data/lib/playwright/channel_owners/page.rb +172 -51
- data/lib/playwright/channel_owners/playwright.rb +24 -27
- data/lib/playwright/channel_owners/request.rb +27 -3
- data/lib/playwright/channel_owners/response.rb +60 -0
- data/lib/playwright/channel_owners/route.rb +78 -0
- data/lib/playwright/channel_owners/selectors.rb +19 -1
- data/lib/playwright/channel_owners/stream.rb +15 -0
- data/lib/playwright/connection.rb +11 -32
- data/lib/playwright/download.rb +27 -0
- data/lib/playwright/errors.rb +6 -0
- data/lib/playwright/events.rb +2 -5
- data/lib/playwright/keyboard_impl.rb +1 -1
- data/lib/playwright/mouse_impl.rb +41 -0
- data/lib/playwright/playwright_api.rb +3 -1
- data/lib/playwright/route_handler_entry.rb +28 -0
- data/lib/playwright/select_option_values.rb +14 -4
- data/lib/playwright/transport.rb +28 -7
- data/lib/playwright/url_matcher.rb +1 -1
- data/lib/playwright/utils.rb +11 -2
- data/lib/playwright/version.rb +1 -1
- data/lib/playwright/video.rb +51 -0
- data/lib/playwright/wait_helper.rb +2 -2
- data/lib/playwright_api/accessibility.rb +39 -1
- data/lib/playwright_api/android.rb +72 -5
- data/lib/playwright_api/android_device.rb +139 -26
- data/lib/playwright_api/android_input.rb +17 -13
- data/lib/playwright_api/android_socket.rb +16 -0
- data/lib/playwright_api/android_web_view.rb +21 -0
- data/lib/playwright_api/browser.rb +87 -19
- data/lib/playwright_api/browser_context.rb +216 -32
- data/lib/playwright_api/browser_type.rb +45 -58
- data/lib/playwright_api/dialog.rb +54 -7
- data/lib/playwright_api/element_handle.rb +113 -33
- data/lib/playwright_api/file_chooser.rb +6 -1
- data/lib/playwright_api/frame.rb +238 -43
- data/lib/playwright_api/js_handle.rb +20 -2
- data/lib/playwright_api/keyboard.rb +48 -1
- data/lib/playwright_api/mouse.rb +26 -5
- data/lib/playwright_api/page.rb +534 -63
- data/lib/playwright_api/playwright.rb +43 -47
- data/lib/playwright_api/request.rb +38 -12
- data/lib/playwright_api/response.rb +27 -10
- data/lib/playwright_api/route.rb +51 -6
- data/lib/playwright_api/selectors.rb +28 -2
- data/lib/playwright_api/touchscreen.rb +1 -1
- data/lib/playwright_api/web_socket.rb +15 -0
- data/lib/playwright_api/worker.rb +25 -1
- data/playwright.gemspec +4 -2
- metadata +42 -14
- data/lib/playwright/channel_owners/chromium_browser.rb +0 -8
- data/lib/playwright/channel_owners/chromium_browser_context.rb +0 -8
- data/lib/playwright/channel_owners/download.rb +0 -27
- data/lib/playwright/channel_owners/firefox_browser.rb +0 -8
- data/lib/playwright/channel_owners/webkit_browser.rb +0 -8
- data/lib/playwright_api/binding_call.rb +0 -27
- data/lib/playwright_api/chromium_browser_context.rb +0 -59
- data/lib/playwright_api/download.rb +0 -100
- data/lib/playwright_api/video.rb +0 -24
@@ -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
|
-
|
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")
|
@@ -96,18 +115,25 @@ module Playwright
|
|
96
115
|
#
|
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
|
-
def add_init_script(
|
100
|
-
|
118
|
+
def add_init_script(path: nil, script: nil)
|
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
|
-
|
131
|
+
wrap_impl(@impl.browser)
|
106
132
|
end
|
107
133
|
|
108
134
|
# Clears context cookies.
|
109
135
|
def clear_cookies
|
110
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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.
|
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
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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,18 +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
|
-
|
666
|
+
wrap_impl(@impl.set_geolocation(unwrap_impl(geolocation)))
|
523
667
|
end
|
524
668
|
alias_method :geolocation=, :set_geolocation
|
525
669
|
|
526
|
-
# **DEPRECATED** Browsers may cache credentials after successful authentication. Create a new browser context instead.
|
527
|
-
def set_http_credentials(httpCredentials)
|
528
|
-
raise NotImplementedError.new('set_http_credentials is not implemented yet.')
|
529
|
-
end
|
530
|
-
alias_method :http_credentials=, :set_http_credentials
|
531
|
-
|
532
670
|
def set_offline(offline)
|
533
|
-
|
671
|
+
wrap_impl(@impl.set_offline(unwrap_impl(offline)))
|
534
672
|
end
|
535
673
|
alias_method :offline=, :set_offline
|
536
674
|
|
@@ -542,12 +680,58 @@ module Playwright
|
|
542
680
|
# Removes a route created with [`method: BrowserContext.route`]. When `handler` is not specified, removes all routes for
|
543
681
|
# the `url`.
|
544
682
|
def unroute(url, handler: nil)
|
545
|
-
|
683
|
+
wrap_impl(@impl.unroute(unwrap_impl(url), handler: unwrap_impl(handler)))
|
684
|
+
end
|
685
|
+
|
686
|
+
# Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
|
687
|
+
# value. Will throw an error if the context closes before the event is fired. Returns the event data value.
|
688
|
+
#
|
689
|
+
#
|
690
|
+
# ```js
|
691
|
+
# const [page, _] = await Promise.all([
|
692
|
+
# context.waitForEvent('page'),
|
693
|
+
# page.click('button')
|
694
|
+
# ]);
|
695
|
+
# ```
|
696
|
+
#
|
697
|
+
# ```java
|
698
|
+
# Page newPage = context.waitForPage(() -> page.click("button"));
|
699
|
+
# ```
|
700
|
+
#
|
701
|
+
# ```python async
|
702
|
+
# async with context.expect_event("page") as event_info:
|
703
|
+
# await page.click("button")
|
704
|
+
# page = await event_info.value
|
705
|
+
# ```
|
706
|
+
#
|
707
|
+
# ```python sync
|
708
|
+
# with context.expect_event("page") as event_info:
|
709
|
+
# page.click("button")
|
710
|
+
# page = event_info.value
|
711
|
+
# ```
|
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)))
|
714
|
+
end
|
715
|
+
|
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.
|
719
|
+
def expect_page(predicate: nil, timeout: nil)
|
720
|
+
wrap_impl(@impl.expect_page(predicate: unwrap_impl(predicate), timeout: unwrap_impl(timeout)))
|
721
|
+
end
|
722
|
+
|
723
|
+
# > NOTE: In most cases, you should use [`method: BrowserContext.waitForEvent`].
|
724
|
+
#
|
725
|
+
# Waits for given `event` to fire. If predicate is provided, it passes event's value into the `predicate` function and
|
726
|
+
# waits for `predicate(event)` to return a truthy value. Will throw an error if the socket is closed before the `event` is
|
727
|
+
# fired.
|
728
|
+
def wait_for_event(event, predicate: nil, timeout: nil)
|
729
|
+
raise NotImplementedError.new('wait_for_event is not implemented yet.')
|
546
730
|
end
|
547
731
|
|
548
732
|
# @nodoc
|
549
|
-
def
|
550
|
-
wrap_impl(@impl.
|
733
|
+
def options=(req)
|
734
|
+
wrap_impl(@impl.options=(unwrap_impl(req)))
|
551
735
|
end
|
552
736
|
|
553
737
|
# @nodoc
|
@@ -556,13 +740,13 @@ module Playwright
|
|
556
740
|
end
|
557
741
|
|
558
742
|
# @nodoc
|
559
|
-
def
|
560
|
-
wrap_impl(@impl.
|
743
|
+
def pause
|
744
|
+
wrap_impl(@impl.pause)
|
561
745
|
end
|
562
746
|
|
563
747
|
# @nodoc
|
564
|
-
def
|
565
|
-
wrap_impl(@impl.
|
748
|
+
def owner_page=(req)
|
749
|
+
wrap_impl(@impl.owner_page=(unwrap_impl(req)))
|
566
750
|
end
|
567
751
|
|
568
752
|
# -- inherited from EventEmitter --
|
@@ -15,6 +15,23 @@ 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 chromium = playwright.chromium();
|
25
|
+
# Browser browser = chromium.launch();
|
26
|
+
# Page page = browser.newPage();
|
27
|
+
# page.navigate("https://example.com");
|
28
|
+
# // other actions...
|
29
|
+
# browser.close();
|
30
|
+
# }
|
31
|
+
# }
|
32
|
+
# }
|
33
|
+
# ```
|
34
|
+
#
|
18
35
|
# ```python async
|
19
36
|
# import asyncio
|
20
37
|
# from playwright.async_api import async_playwright
|
@@ -49,11 +66,6 @@ module Playwright
|
|
49
66
|
# ```
|
50
67
|
class BrowserType < PlaywrightApi
|
51
68
|
|
52
|
-
# This methods attaches Playwright to an existing browser instance.
|
53
|
-
def connect(params)
|
54
|
-
raise NotImplementedError.new('connect is not implemented yet.')
|
55
|
-
end
|
56
|
-
|
57
69
|
# A path where Playwright expects to find a bundled browser executable.
|
58
70
|
def executable_path
|
59
71
|
wrap_impl(@impl.executable_path)
|
@@ -70,6 +82,12 @@ module Playwright
|
|
70
82
|
# });
|
71
83
|
# ```
|
72
84
|
#
|
85
|
+
# ```java
|
86
|
+
# // Or "firefox" or "webkit".
|
87
|
+
# Browser browser = chromium.launch(new BrowserType.LaunchOptions()
|
88
|
+
# .setIgnoreDefaultArgs(Arrays.asList("--mute-audio")));
|
89
|
+
# ```
|
90
|
+
#
|
73
91
|
# ```python async
|
74
92
|
# browser = await playwright.chromium.launch( # or "firefox" or "webkit".
|
75
93
|
# ignore_default_args=["--mute-audio"]
|
@@ -82,22 +100,23 @@ module Playwright
|
|
82
100
|
# )
|
83
101
|
# ```
|
84
102
|
#
|
85
|
-
# > **Chromium-only** Playwright can also be used to control the Chrome
|
86
|
-
# Chromium it is bundled with. There is no guarantee it will work with any other version. Use
|
87
|
-
# extreme caution.
|
103
|
+
# > **Chromium-only** Playwright can also be used to control the Google Chrome or Microsoft Edge browsers, but it works
|
104
|
+
# best with the version of Chromium it is bundled with. There is no guarantee it will work with any other version. Use
|
105
|
+
# `executablePath` option with extreme caution.
|
88
106
|
# >
|
89
107
|
# > If Google Chrome (rather than Chromium) is preferred, a
|
90
108
|
# [Chrome Canary](https://www.google.com/chrome/browser/canary.html) or
|
91
109
|
# [Dev Channel](https://www.chromium.org/getting-involved/dev-channel) build is suggested.
|
92
110
|
# >
|
93
|
-
# >
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
# [
|
111
|
+
# > Stock browsers like Google Chrome and Microsoft Edge are suitable for tests that require proprietary media codecs for
|
112
|
+
# video playback. See
|
113
|
+
# [this article](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for other
|
114
|
+
# differences between Chromium and Chrome.
|
115
|
+
# [This article](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md)
|
98
116
|
# describes some differences for Linux users.
|
99
117
|
def launch(
|
100
118
|
args: nil,
|
119
|
+
channel: nil,
|
101
120
|
chromiumSandbox: nil,
|
102
121
|
devtools: nil,
|
103
122
|
downloadsPath: nil,
|
@@ -108,14 +127,12 @@ module Playwright
|
|
108
127
|
handleSIGINT: nil,
|
109
128
|
handleSIGTERM: nil,
|
110
129
|
headless: nil,
|
111
|
-
ignoreAllDefaultArgs: nil,
|
112
130
|
ignoreDefaultArgs: nil,
|
113
|
-
logger: nil,
|
114
131
|
proxy: nil,
|
115
132
|
slowMo: nil,
|
116
133
|
timeout: nil,
|
117
134
|
&block)
|
118
|
-
wrap_impl(@impl.launch(args: unwrap_impl(args), chromiumSandbox: unwrap_impl(chromiumSandbox), devtools: unwrap_impl(devtools), downloadsPath: unwrap_impl(downloadsPath), env: unwrap_impl(env), executablePath: unwrap_impl(executablePath), firefoxUserPrefs: unwrap_impl(firefoxUserPrefs), handleSIGHUP: unwrap_impl(handleSIGHUP), handleSIGINT: unwrap_impl(handleSIGINT), handleSIGTERM: unwrap_impl(handleSIGTERM), headless: unwrap_impl(headless),
|
135
|
+
wrap_impl(@impl.launch(args: unwrap_impl(args), channel: unwrap_impl(channel), chromiumSandbox: unwrap_impl(chromiumSandbox), devtools: unwrap_impl(devtools), downloadsPath: unwrap_impl(downloadsPath), env: unwrap_impl(env), executablePath: unwrap_impl(executablePath), firefoxUserPrefs: unwrap_impl(firefoxUserPrefs), handleSIGHUP: unwrap_impl(handleSIGHUP), handleSIGINT: unwrap_impl(handleSIGINT), handleSIGTERM: unwrap_impl(handleSIGTERM), headless: unwrap_impl(headless), ignoreDefaultArgs: unwrap_impl(ignoreDefaultArgs), proxy: unwrap_impl(proxy), slowMo: unwrap_impl(slowMo), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
|
119
136
|
end
|
120
137
|
|
121
138
|
# Returns the persistent browser context instance.
|
@@ -127,6 +144,7 @@ module Playwright
|
|
127
144
|
acceptDownloads: nil,
|
128
145
|
args: nil,
|
129
146
|
bypassCSP: nil,
|
147
|
+
channel: nil,
|
130
148
|
chromiumSandbox: nil,
|
131
149
|
colorScheme: nil,
|
132
150
|
deviceScaleFactor: nil,
|
@@ -142,69 +160,38 @@ module Playwright
|
|
142
160
|
hasTouch: nil,
|
143
161
|
headless: nil,
|
144
162
|
httpCredentials: nil,
|
145
|
-
ignoreAllDefaultArgs: nil,
|
146
163
|
ignoreDefaultArgs: nil,
|
147
164
|
ignoreHTTPSErrors: nil,
|
148
165
|
isMobile: nil,
|
149
166
|
javaScriptEnabled: nil,
|
150
167
|
locale: nil,
|
151
|
-
|
168
|
+
noViewport: nil,
|
152
169
|
offline: nil,
|
153
170
|
permissions: nil,
|
154
171
|
proxy: nil,
|
155
|
-
|
156
|
-
|
172
|
+
record_har_omit_content: nil,
|
173
|
+
record_har_path: nil,
|
174
|
+
record_video_dir: nil,
|
175
|
+
record_video_size: nil,
|
176
|
+
screen: nil,
|
157
177
|
slowMo: nil,
|
158
178
|
timeout: nil,
|
159
179
|
timezoneId: nil,
|
160
180
|
userAgent: nil,
|
161
|
-
videoSize: nil,
|
162
|
-
videosPath: nil,
|
163
181
|
viewport: nil)
|
164
182
|
raise NotImplementedError.new('launch_persistent_context is not implemented yet.')
|
165
183
|
end
|
166
184
|
|
167
|
-
# Returns the browser app instance.
|
168
|
-
#
|
169
|
-
# Launches browser server that client can connect to. An example of launching a browser executable and connecting to it
|
170
|
-
# later:
|
171
|
-
#
|
172
|
-
#
|
173
|
-
# ```js
|
174
|
-
# const { chromium } = require('playwright'); // Or 'webkit' or 'firefox'.
|
175
|
-
#
|
176
|
-
# (async () => {
|
177
|
-
# const browserServer = await chromium.launchServer();
|
178
|
-
# const wsEndpoint = browserServer.wsEndpoint();
|
179
|
-
# // Use web socket endpoint later to establish a connection.
|
180
|
-
# const browser = await chromium.connect({ wsEndpoint });
|
181
|
-
# // Close browser instance.
|
182
|
-
# await browserServer.close();
|
183
|
-
# })();
|
184
|
-
# ```
|
185
|
-
def launch_server(
|
186
|
-
args: nil,
|
187
|
-
chromiumSandbox: nil,
|
188
|
-
devtools: nil,
|
189
|
-
downloadsPath: nil,
|
190
|
-
executablePath: nil,
|
191
|
-
firefoxUserPrefs: nil,
|
192
|
-
handleSIGHUP: nil,
|
193
|
-
handleSIGINT: nil,
|
194
|
-
handleSIGTERM: nil,
|
195
|
-
headless: nil,
|
196
|
-
logger: nil,
|
197
|
-
port: nil,
|
198
|
-
proxy: nil,
|
199
|
-
timeout: nil)
|
200
|
-
raise NotImplementedError.new('launch_server is not implemented yet.')
|
201
|
-
end
|
202
|
-
|
203
185
|
# Returns browser name. For example: `'chromium'`, `'webkit'` or `'firefox'`.
|
204
186
|
def name
|
205
187
|
wrap_impl(@impl.name)
|
206
188
|
end
|
207
189
|
|
190
|
+
# @nodoc
|
191
|
+
def connect_over_cdp(endpointURL, slowMo: nil, timeout: nil, &block)
|
192
|
+
wrap_impl(@impl.connect_over_cdp(unwrap_impl(endpointURL), slowMo: unwrap_impl(slowMo), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
|
193
|
+
end
|
194
|
+
|
208
195
|
# -- inherited from EventEmitter --
|
209
196
|
# @nodoc
|
210
197
|
def once(event, callback)
|