playwright-ruby-client 1.51.0 → 1.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +5 -0
- data/README.md +4 -0
- data/documentation/docs/api/browser_context.md +7 -3
- data/documentation/docs/api/console_message.md +0 -3
- data/documentation/docs/api/experimental/android.md +10 -0
- data/documentation/docs/api/frame.md +1 -0
- data/documentation/docs/api/frame_locator.md +1 -0
- data/documentation/docs/api/locator.md +24 -0
- data/documentation/docs/api/locator_assertions.md +47 -1
- data/documentation/docs/api/mouse.md +2 -0
- data/documentation/docs/api/page.md +34 -2
- data/documentation/docs/api/route.md +2 -0
- data/documentation/docs/api/selectors.md +10 -0
- data/documentation/docs/api/tracing.md +8 -0
- data/documentation/docs/article/guides/inspector.md +1 -1
- data/documentation/docs/article/guides/playwright_on_alpine_linux.md +9 -69
- data/documentation/docs/include/api_coverage.md +8 -2
- data/documentation/package.json +3 -3
- data/documentation/yarn.lock +12372 -8623
- data/lib/playwright/channel.rb +6 -3
- data/lib/playwright/channel_owners/android.rb +12 -0
- data/lib/playwright/channel_owners/android_device.rb +6 -5
- data/lib/playwright/channel_owners/api_request_context.rb +6 -1
- data/lib/playwright/channel_owners/browser.rb +37 -6
- data/lib/playwright/channel_owners/browser_context.rb +47 -38
- data/lib/playwright/channel_owners/browser_type.rb +43 -14
- data/lib/playwright/channel_owners/element_handle.rb +22 -17
- data/lib/playwright/channel_owners/frame.rb +65 -34
- data/lib/playwright/channel_owners/page.rb +39 -9
- data/lib/playwright/channel_owners/playwright.rb +10 -4
- data/lib/playwright/channel_owners/web_socket.rb +1 -1
- data/lib/playwright/connection.rb +3 -0
- data/lib/playwright/console_message_impl.rb +3 -2
- data/lib/playwright/file_chooser_impl.rb +3 -2
- data/lib/playwright/frame_locator_impl.rb +5 -8
- data/lib/playwright/javascript/value_parser.rb +54 -2
- data/lib/playwright/locator_assertions_impl.rb +100 -34
- data/lib/playwright/locator_impl.rb +26 -36
- data/lib/playwright/page_assertions_impl.rb +16 -11
- data/lib/playwright/selectors_impl.rb +45 -0
- data/lib/playwright/test.rb +21 -3
- data/lib/playwright/timeout_settings.rb +5 -0
- data/lib/playwright/transport.rb +1 -1
- data/lib/playwright/utils.rb +0 -33
- data/lib/playwright/version.rb +2 -2
- data/lib/playwright/web_socket_client.rb +4 -1
- data/lib/playwright/web_socket_transport.rb +3 -1
- data/lib/playwright.rb +14 -14
- data/lib/playwright_api/android.rb +12 -7
- data/lib/playwright_api/android_device.rb +8 -8
- data/lib/playwright_api/api_request.rb +1 -0
- data/lib/playwright_api/api_request_context.rb +6 -6
- data/lib/playwright_api/browser.rb +6 -6
- data/lib/playwright_api/browser_context.rb +17 -17
- data/lib/playwright_api/browser_type.rb +6 -6
- data/lib/playwright_api/cdp_session.rb +6 -6
- data/lib/playwright_api/console_message.rb +0 -4
- data/lib/playwright_api/dialog.rb +6 -6
- data/lib/playwright_api/element_handle.rb +6 -6
- data/lib/playwright_api/frame.rb +12 -6
- data/lib/playwright_api/frame_locator.rb +1 -0
- data/lib/playwright_api/js_handle.rb +6 -6
- data/lib/playwright_api/locator.rb +30 -3
- data/lib/playwright_api/locator_assertions.rb +47 -3
- data/lib/playwright_api/mouse.rb +2 -0
- data/lib/playwright_api/page.rb +41 -13
- data/lib/playwright_api/playwright.rb +6 -6
- data/lib/playwright_api/request.rb +6 -6
- data/lib/playwright_api/response.rb +6 -6
- data/lib/playwright_api/route.rb +8 -6
- data/lib/playwright_api/selectors.rb +1 -28
- data/lib/playwright_api/tracing.rb +14 -6
- data/lib/playwright_api/web_socket.rb +6 -6
- data/lib/playwright_api/worker.rb +8 -8
- data/sig/playwright.rbs +15 -1
- metadata +6 -5
- data/lib/playwright/channel_owners/selectors.rb +0 -26
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8640cc3446239876e19fb40cfca695bde42bfe4e88d2bbd6659ccde5ff6d99d4
|
|
4
|
+
data.tar.gz: e8b748b832438a286de6786e8a44317aae282604815d9b7803f19fe47d24b876
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 39c49ab82a8bb4fe056dbbba337aa266a9b1b25ec8227fbffa8b2c7e4c19ef4f63148928d42bf3252784617efc99ea7571f32a98d6a77752079e97465a402e37
|
|
7
|
+
data.tar.gz: 20d89735083a1dc2e533cffdfc41da1fe366c9ff1d309138d2894dbca1d506252f579aff1f475caea8565e8229970e3601b4d7a52e5a97de9f7593b1f8f9c744
|
data/CONTRIBUTING.md
ADDED
data/README.md
CHANGED
|
@@ -187,6 +187,10 @@ When `Playwright.connect_to_playwright_server` is used, playwright_cli_executabl
|
|
|
187
187
|
|
|
188
188
|
For more detailed instraction, refer this article: https://playwright-ruby-client.vercel.app/docs/article/guides/playwright_on_alpine_linux
|
|
189
189
|
|
|
190
|
+
## Contributing
|
|
191
|
+
|
|
192
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and contributing guidelines.
|
|
193
|
+
|
|
190
194
|
## License
|
|
191
195
|
|
|
192
196
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -73,10 +73,14 @@ browser_context.add_init_script(path: "preload.js")
|
|
|
73
73
|
def background_pages
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
+
:::warning
|
|
76
77
|
|
|
77
|
-
|
|
78
|
+
Background pages have been removed from Chromium together with Manifest V2 extensions.
|
|
78
79
|
|
|
79
|
-
|
|
80
|
+
:::
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
Returns an empty list.
|
|
80
84
|
|
|
81
85
|
## browser
|
|
82
86
|
|
|
@@ -85,7 +89,7 @@ def browser
|
|
|
85
89
|
```
|
|
86
90
|
|
|
87
91
|
|
|
88
|
-
|
|
92
|
+
Gets the browser instance that owns the context. Returns `null` if the context is created outside of normal browser, e.g. Android or Electron.
|
|
89
93
|
|
|
90
94
|
## clear_cookies
|
|
91
95
|
|
|
@@ -74,6 +74,3 @@ def type
|
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
One of the following values: `'log'`, `'debug'`, `'info'`, `'error'`, `'warning'`, `'dir'`, `'dirxml'`, `'table'`,
|
|
78
|
-
`'trace'`, `'clear'`, `'startGroup'`, `'startGroupCollapsed'`, `'endGroup'`, `'assert'`, `'profile'`, `'profileEnd'`,
|
|
79
|
-
`'count'`, `'timeEnd'`.
|
|
@@ -30,3 +30,13 @@ def devices(host: nil, omitDriverInstall: nil, port: nil)
|
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
Returns the list of detected Android devices.
|
|
33
|
+
|
|
34
|
+
## set_default_timeout
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
def set_default_timeout(timeout)
|
|
38
|
+
```
|
|
39
|
+
alias: `default_timeout=`
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
This setting will change the default maximum time for all the methods accepting `timeout` option.
|
|
@@ -317,6 +317,23 @@ When all steps combined have not finished during the specified `timeout`, this m
|
|
|
317
317
|
|
|
318
318
|
**NOTE**: `element.dblclick()` dispatches two `click` events and a single `dblclick` event.
|
|
319
319
|
|
|
320
|
+
## describe
|
|
321
|
+
|
|
322
|
+
```
|
|
323
|
+
def describe(description)
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
Describes the locator, description is used in the trace viewer and reports.
|
|
328
|
+
Returns the locator pointing to the same element.
|
|
329
|
+
|
|
330
|
+
**Usage**
|
|
331
|
+
|
|
332
|
+
```ruby
|
|
333
|
+
button = page.get_by_test_id("btn-sub").describe("Subscribe button")
|
|
334
|
+
button.click
|
|
335
|
+
```
|
|
336
|
+
|
|
320
337
|
## dispatch_event
|
|
321
338
|
|
|
322
339
|
```
|
|
@@ -458,6 +475,12 @@ If `expression` throws or rejects, this method throws.
|
|
|
458
475
|
|
|
459
476
|
**Usage**
|
|
460
477
|
|
|
478
|
+
Passing argument to `expression`:
|
|
479
|
+
|
|
480
|
+
```ruby
|
|
481
|
+
page.get_by_test_id("myId").evaluate("(element, [x, y]) => element.textContent + ' ' + x * y", arg: [7, 8]) # => "myId text 56"
|
|
482
|
+
```
|
|
483
|
+
|
|
461
484
|
## evaluate_all
|
|
462
485
|
|
|
463
486
|
```
|
|
@@ -718,6 +741,7 @@ Many html elements have an implicitly [defined role](https://w3c.github.io/html-
|
|
|
718
741
|
```
|
|
719
742
|
def get_by_test_id(testId)
|
|
720
743
|
```
|
|
744
|
+
alias: `get_by_testid`
|
|
721
745
|
|
|
722
746
|
|
|
723
747
|
Locate element by the test id.
|
|
@@ -116,6 +116,15 @@ expect(locator).not_to be_visible(timeout: nil, visible: nil)
|
|
|
116
116
|
|
|
117
117
|
The opposite of [LocatorAssertions#to_be_visible](./locator_assertions#to_be_visible).
|
|
118
118
|
|
|
119
|
+
## not_to_contain_class
|
|
120
|
+
|
|
121
|
+
```ruby
|
|
122
|
+
expect(locator).not_to contain_class(expected, timeout: nil)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
The opposite of [LocatorAssertions#to_contain_class](./locator_assertions#to_contain_class).
|
|
127
|
+
|
|
119
128
|
## not_to_contain_text
|
|
120
129
|
|
|
121
130
|
```ruby
|
|
@@ -436,6 +445,43 @@ expect(
|
|
|
436
445
|
).to be_visible
|
|
437
446
|
```
|
|
438
447
|
|
|
448
|
+
## to_contain_class
|
|
449
|
+
|
|
450
|
+
```ruby
|
|
451
|
+
expect(locator).to contain_class(expected, timeout: nil)
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
Ensures the [Locator](./locator) points to an element with given CSS classes. All classes from the asserted value, separated by spaces, must be present in the [Element.classList](https://developer.mozilla.org/en-US/docs/Web/API/Element/classList) in any order.
|
|
456
|
+
|
|
457
|
+
**Usage**
|
|
458
|
+
|
|
459
|
+
```html
|
|
460
|
+
<div class='middle selected row' id='component'></div>
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
```ruby
|
|
464
|
+
locator = page.locator("#component")
|
|
465
|
+
expect(locator).to contain_class("middle selected row")
|
|
466
|
+
expect(locator).to contain_class("selected")
|
|
467
|
+
expect(locator).to contain_class("row middle")
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
When an array is passed, the method asserts that the list of elements located matches the corresponding list of expected class lists. Each element's class attribute is matched against the corresponding class in the array:
|
|
471
|
+
|
|
472
|
+
```html
|
|
473
|
+
<div class='list'>
|
|
474
|
+
<div class='component inactive'></div>
|
|
475
|
+
<div class='component active'></div>
|
|
476
|
+
<div class='component inactive'></div>
|
|
477
|
+
</div>
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
```ruby
|
|
481
|
+
locator = page.locator(".list > .component")
|
|
482
|
+
expect(locator).to contain_class(["inactive", "active", "inactive"])
|
|
483
|
+
```
|
|
484
|
+
|
|
439
485
|
## to_contain_text
|
|
440
486
|
|
|
441
487
|
```ruby
|
|
@@ -561,7 +607,7 @@ expect(locator).to have_class(expected, timeout: nil)
|
|
|
561
607
|
```
|
|
562
608
|
|
|
563
609
|
|
|
564
|
-
Ensures the [Locator](./locator) points to an element with given CSS classes. When a string is provided, it must fully match the element's `class` attribute. To match individual classes
|
|
610
|
+
Ensures the [Locator](./locator) points to an element with given CSS classes. When a string is provided, it must fully match the element's `class` attribute. To match individual classes use [LocatorAssertions#to_contain_class](./locator_assertions#to_contain_class).
|
|
565
611
|
|
|
566
612
|
**Usage**
|
|
567
613
|
|
|
@@ -7,6 +7,8 @@ sidebar_position: 10
|
|
|
7
7
|
|
|
8
8
|
The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport.
|
|
9
9
|
|
|
10
|
+
**NOTE**: If you want to debug where the mouse moved, you can use the [Trace viewer](https://playwright.dev/python/docs/trace-viewer-intro) or [Playwright Inspector](https://playwright.dev/python/docs/running-tests). A red dot showing the location of the mouse will be shown for every mouse action.
|
|
11
|
+
|
|
10
12
|
Every `page` object has its own Mouse, accessible with [Page#mouse](./page#mouse).
|
|
11
13
|
|
|
12
14
|
```ruby
|
|
@@ -724,6 +724,7 @@ Many html elements have an implicitly [defined role](https://w3c.github.io/html-
|
|
|
724
724
|
```
|
|
725
725
|
def get_by_test_id(testId)
|
|
726
726
|
```
|
|
727
|
+
alias: `get_by_testid`
|
|
727
728
|
|
|
728
729
|
|
|
729
730
|
Locate element by the test id.
|
|
@@ -993,6 +994,24 @@ def visible?(selector, strict: nil, timeout: nil)
|
|
|
993
994
|
|
|
994
995
|
Returns whether the element is [visible](https://playwright.dev/python/docs/actionability#visible). `selector` that does not match any elements is considered not visible.
|
|
995
996
|
|
|
997
|
+
## console_messages
|
|
998
|
+
|
|
999
|
+
```
|
|
1000
|
+
def console_messages
|
|
1001
|
+
```
|
|
1002
|
+
|
|
1003
|
+
|
|
1004
|
+
Returns up to (currently) 200 last console messages from this page. See [`event: Page.console`] for more details.
|
|
1005
|
+
|
|
1006
|
+
## page_errors
|
|
1007
|
+
|
|
1008
|
+
```
|
|
1009
|
+
def page_errors
|
|
1010
|
+
```
|
|
1011
|
+
|
|
1012
|
+
|
|
1013
|
+
Returns up to (currently) 200 last page errors from this page. See [`event: Page.pageError`] for more details.
|
|
1014
|
+
|
|
996
1015
|
## locator
|
|
997
1016
|
|
|
998
1017
|
```
|
|
@@ -1035,7 +1054,7 @@ def pause
|
|
|
1035
1054
|
```
|
|
1036
1055
|
|
|
1037
1056
|
|
|
1038
|
-
Pauses script execution. Playwright will stop executing the script and wait for the user to either press 'Resume'
|
|
1057
|
+
Pauses script execution. Playwright will stop executing the script and wait for the user to either press the 'Resume'
|
|
1039
1058
|
button in the page overlay or to call `playwright.resume()` in the DevTools console.
|
|
1040
1059
|
|
|
1041
1060
|
User can inspect selectors or perform manual steps while paused. Resume will continue running the original script from
|
|
@@ -1178,6 +1197,19 @@ def query_selector_all(selector)
|
|
|
1178
1197
|
The method finds all elements matching the specified selector within the page. If no elements match the selector, the
|
|
1179
1198
|
return value resolves to `[]`.
|
|
1180
1199
|
|
|
1200
|
+
## requests
|
|
1201
|
+
|
|
1202
|
+
```
|
|
1203
|
+
def requests
|
|
1204
|
+
```
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
Returns up to (currently) 100 last network request from this page. See [`event: Page.request`] for more details.
|
|
1208
|
+
|
|
1209
|
+
Returned requests should be accessed immediately, otherwise they might be collected to prevent unbounded memory growth as new requests come in. Once collected, retrieving most information about the request is impossible.
|
|
1210
|
+
|
|
1211
|
+
Note that requests reported through the [`event: Page.request`] request are not collected, so there is a trade off between efficient memory usage with [Page#requests](./page#requests) and the amount of available information reported through [`event: Page.request`].
|
|
1212
|
+
|
|
1181
1213
|
## reload
|
|
1182
1214
|
|
|
1183
1215
|
```
|
|
@@ -1820,7 +1852,7 @@ function will throw.
|
|
|
1820
1852
|
This method works across navigations:
|
|
1821
1853
|
|
|
1822
1854
|
```ruby
|
|
1823
|
-
%w[https://
|
|
1855
|
+
%w[https://playwright.dev/ https://playwright-ruby-client.vercel.app/].each do |current_url|
|
|
1824
1856
|
page.goto(current_url, waitUntil: "domcontentloaded")
|
|
1825
1857
|
element = page.wait_for_selector("img")
|
|
1826
1858
|
puts "Loaded image: #{element["src"]}"
|
|
@@ -49,6 +49,8 @@ The `headers` option applies to both the routed request and any redirects it ini
|
|
|
49
49
|
|
|
50
50
|
[Route#continue](./route#continue) will immediately send the request to the network, other matching handlers won't be invoked. Use [Route#fallback](./route#fallback) If you want next matching handler in the chain to be invoked.
|
|
51
51
|
|
|
52
|
+
**NOTE**: The `Cookie` header cannot be overridden using this method. If a value is provided, it will be ignored, and the cookie will be loaded from the browser's cookie store. To set custom cookies, use [BrowserContext#add_cookies](./browser_context#add_cookies).
|
|
53
|
+
|
|
52
54
|
## fallback
|
|
53
55
|
|
|
54
56
|
```
|
|
@@ -51,3 +51,13 @@ playwright.chromium.launch do |browser|
|
|
|
51
51
|
button_count # => 1
|
|
52
52
|
end
|
|
53
53
|
```
|
|
54
|
+
|
|
55
|
+
## set_test_id_attribute
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
def set_test_id_attribute(attributeName)
|
|
59
|
+
```
|
|
60
|
+
alias: `test_id_attribute=`
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
Defines custom attribute name to be used in [Page#get_by_test_id](./page#get_by_test_id). `data-testid` is used by default.
|
|
@@ -7,6 +7,10 @@ sidebar_position: 10
|
|
|
7
7
|
|
|
8
8
|
API for collecting and saving Playwright traces. Playwright traces can be opened in [Trace Viewer](https://playwright.dev/python/docs/trace-viewer) after Playwright script runs.
|
|
9
9
|
|
|
10
|
+
**NOTE**: You probably want to [enable tracing in your config file](https://playwright.dev/docs/api/class-testoptions#test-options-trace) instead of using `context.tracing`.
|
|
11
|
+
|
|
12
|
+
The `context.tracing` API captures browser operations and network activity, but it doesn't record test assertions (like `expect` calls). We recommend [enabling tracing through Playwright Test configuration](https://playwright.dev/docs/api/class-testoptions#test-options-trace), which includes those assertions and provides a more complete trace for debugging test failures.
|
|
13
|
+
|
|
10
14
|
Start recording a trace before performing actions. At the end, stop tracing and save it to a file.
|
|
11
15
|
|
|
12
16
|
```ruby
|
|
@@ -32,6 +36,10 @@ def start(
|
|
|
32
36
|
|
|
33
37
|
Start tracing.
|
|
34
38
|
|
|
39
|
+
**NOTE**: You probably want to [enable tracing in your config file](https://playwright.dev/docs/api/class-testoptions#test-options-trace) instead of using `Tracing.start`.
|
|
40
|
+
|
|
41
|
+
The `context.tracing` API captures browser operations and network activity, but it doesn't record test assertions (like `expect` calls). We recommend [enabling tracing through Playwright Test configuration](https://playwright.dev/docs/api/class-testoptions#test-options-trace), which includes those assertions and provides a more complete trace for debugging test failures.
|
|
42
|
+
|
|
35
43
|
**Usage**
|
|
36
44
|
|
|
37
45
|
```ruby
|
|
@@ -15,7 +15,7 @@ playwright.chromium.launch(headless: false) do |browser|
|
|
|
15
15
|
# This method call should be put just after creating BrowserContext.
|
|
16
16
|
context.enable_debug_console!
|
|
17
17
|
|
|
18
|
-
page = context.
|
|
18
|
+
page = context.new_page
|
|
19
19
|
page.goto('http://example.com/')
|
|
20
20
|
page.pause
|
|
21
21
|
end
|
|
@@ -25,6 +25,8 @@ However we may have trouble with bringing Playwright into:
|
|
|
25
25
|
|
|
26
26
|
This article introduces a way to separate environments into client (for executing Playwright script) and server (for working with browsers). The main use-case assumes Docker (using Alpine Linux), however the way can be applied also into other use-cases.
|
|
27
27
|
|
|
28
|
+
ref: https://playwright.dev/docs/docker#remote-connection
|
|
29
|
+
|
|
28
30
|
## Overview
|
|
29
31
|
|
|
30
32
|
Playwright Ruby client is running on Alpine Linux. It just sends/receives JSON messages of Playwright-protocol via WebSocket.
|
|
@@ -33,48 +35,25 @@ Playwright server is running on a container of [official Docker image](https://h
|
|
|
33
35
|
|
|
34
36
|

|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
Playwright provides two kind of methods to share the browser environments for clients.
|
|
39
|
-
|
|
40
|
-
When you want to share only one browser environment, Browser server is suitable. This feature is officially supported in Playwright.
|
|
41
|
-
|
|
42
|
-
- Server can be launched with [BrowserType#launchServer](https://playwright.dev/docs/api/class-browsertype#browser-type-launch-server) instead of `BrowserType#launch`.
|
|
38
|
+
- Server can be launched with `npx playwright run-server` CLI command.
|
|
43
39
|
- Client can connect to server with [BrowserType#connect](https://playwright.dev/docs/api/class-browsertype#browser-type-connect). In playwright-ruby-client, `BrowserType#connect` and not implemented yet and use `Playwright#connect_to_browser_server()` instead.
|
|
44
40
|
|
|
45
|
-
Another method is sharing all browser environment. This method is very simple, but not an official feature, and can be changed in future.
|
|
46
|
-
|
|
47
|
-
- Server can be launched with `playwright run-server` (CLI command).
|
|
48
|
-
- Client can connect to server with `Playwright.connect_to_playwright_server` instead of `Playwright.create`
|
|
49
|
-
|
|
50
|
-
## Playwright server/client
|
|
51
|
-
|
|
52
|
-
:::caution
|
|
53
|
-
|
|
54
|
-
This method is no longer supported on Playwright driver >= 1.35. See [this issue](https://github.com/YusukeIwaki/playwright-ruby-client/issues/254) for detail, and use Browser server/client method instead.
|
|
55
|
-
|
|
56
|
-
:::
|
|
57
|
-
|
|
58
41
|
### Client code
|
|
59
42
|
|
|
60
|
-
Many example uses `Playwright#create`, which internally uses Pipe (stdin/stdout) transport for Playwright-protocol messaging. Instead, **
|
|
43
|
+
Many example uses `Playwright#create`, which internally uses Pipe (stdin/stdout) transport for Playwright-protocol messaging. Instead, **use `Playwright#connect_to_browser_server(endpoint)`** for WebSocket transport.
|
|
61
44
|
|
|
62
45
|
```ruby {3}
|
|
63
46
|
require 'playwright'
|
|
64
47
|
|
|
65
|
-
Playwright.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
page.screenshot(path: 'github-microsoft-playwright.png')
|
|
70
|
-
end
|
|
48
|
+
Playwright.connect_to_browser_server('wss://example.com:8888/ws') do |browser|
|
|
49
|
+
page = browser.new_page
|
|
50
|
+
page.goto('https://github.com/microsoft/playwright')
|
|
51
|
+
page.screenshot(path: 'github-microsoft-playwright.png')
|
|
71
52
|
end
|
|
72
53
|
```
|
|
73
54
|
|
|
74
55
|
`wss://example.com:8888/ws` is an example of endpoint URL of the Playwright server. In local development environment, it is typically `"ws://127.0.0.1:#{port}/ws"`.
|
|
75
56
|
|
|
76
|
-
Note that `?browser=chromium` is important for server to determine which browser to prepare.
|
|
77
|
-
|
|
78
57
|
### Server code
|
|
79
58
|
|
|
80
59
|
With the [official Docker image](https://hub.docker.com/_/microsoft-playwright) or in the local development environment with Node.js, just execute `npx playwright install && npx playwright run-server --port $PORT --path /ws`. (`$PORT` is a port number of the server)
|
|
@@ -91,45 +70,6 @@ ENV PORT 8888
|
|
|
91
70
|
CMD ["./node_modules/.bin/playwright", "run-server", "--port", "$PORT", "--path", "/ws"]
|
|
92
71
|
```
|
|
93
72
|
|
|
94
|
-
## Browser server/client
|
|
95
|
-
|
|
96
|
-
### Client code
|
|
97
|
-
|
|
98
|
-
Use `Playwright#connect_to_playwright_server` and pass the WebSocket URL for browser server.
|
|
99
|
-
Note that this method requires a block with `Browser`, not `Playwright` or `BrowserType`.
|
|
100
|
-
|
|
101
|
-
```ruby
|
|
102
|
-
Playwright.connect_to_playwright_server(ws_url) do |browser|
|
|
103
|
-
page = browser.new_page
|
|
104
|
-
page.goto(...)
|
|
105
|
-
...
|
|
106
|
-
end
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Server code
|
|
110
|
-
|
|
111
|
-
For instant use, `npx playwright launch-server --browser chromium` generates a WebSocket endpoint URL with a random path.
|
|
112
|
-
|
|
113
|
-
More customization can be done by implementing JavaScript server like below:
|
|
114
|
-
|
|
115
|
-
```js
|
|
116
|
-
const playwright = require("playwright");
|
|
117
|
-
|
|
118
|
-
option = {
|
|
119
|
-
channel: "chrome-canary",
|
|
120
|
-
headless: false,
|
|
121
|
-
port: 8080,
|
|
122
|
-
wsPath: "ws",
|
|
123
|
-
};
|
|
124
|
-
playwright.chromium.launchServer(option).then((server) => {
|
|
125
|
-
console.log(server.wsEndpoint());
|
|
126
|
-
});
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
`port` and `wsPath` would be useful for generating static WebSocket endpoint URL.
|
|
130
|
-
Other available options for `BrowserType#launchServer` can be found here:
|
|
131
|
-
https://playwright.dev/docs/api/class-browsertype#browser-type-launch-server
|
|
132
|
-
|
|
133
73
|
## Debugging for connection
|
|
134
74
|
|
|
135
75
|
The client and server are really quiet. This chapter shows how to check if the communication on the WebSocket works well or not.
|
|
@@ -147,7 +87,7 @@ DEBUG=1 bundle exec ruby some-automation-with-playwright.rb
|
|
|
147
87
|
Just set an environment variable `DEBUG=pw:*` or `DEBUG=pw:server`
|
|
148
88
|
|
|
149
89
|
```
|
|
150
|
-
DEBUG=pw:* npx playwright
|
|
90
|
+
DEBUG=pw:* npx playwright run-server --browser chromium
|
|
151
91
|
```
|
|
152
92
|
|
|
153
93
|
See [the official documentation](https://playwright.dev/docs/debug/#verbose-api-logs) for details.
|
|
@@ -212,7 +212,7 @@
|
|
|
212
212
|
## Selectors
|
|
213
213
|
|
|
214
214
|
* register
|
|
215
|
-
*
|
|
215
|
+
* set_test_id_attribute
|
|
216
216
|
|
|
217
217
|
## Clock
|
|
218
218
|
|
|
@@ -301,6 +301,8 @@
|
|
|
301
301
|
* enabled?
|
|
302
302
|
* hidden?
|
|
303
303
|
* visible?
|
|
304
|
+
* console_messages
|
|
305
|
+
* page_errors
|
|
304
306
|
* locator
|
|
305
307
|
* main_frame
|
|
306
308
|
* opener
|
|
@@ -309,6 +311,7 @@
|
|
|
309
311
|
* press
|
|
310
312
|
* query_selector
|
|
311
313
|
* query_selector_all
|
|
314
|
+
* requests
|
|
312
315
|
* ~~add_locator_handler~~
|
|
313
316
|
* ~~remove_locator_handler~~
|
|
314
317
|
* reload
|
|
@@ -455,6 +458,7 @@
|
|
|
455
458
|
* click
|
|
456
459
|
* count
|
|
457
460
|
* dblclick
|
|
461
|
+
* describe
|
|
458
462
|
* dispatch_event
|
|
459
463
|
* drag_to
|
|
460
464
|
* element_handle
|
|
@@ -563,6 +567,7 @@
|
|
|
563
567
|
* not_to_be_hidden
|
|
564
568
|
* not_to_be_in_viewport
|
|
565
569
|
* not_to_be_visible
|
|
570
|
+
* not_to_contain_class
|
|
566
571
|
* not_to_contain_text
|
|
567
572
|
* not_to_have_accessible_description
|
|
568
573
|
* not_to_have_accessible_error_message
|
|
@@ -588,6 +593,7 @@
|
|
|
588
593
|
* to_be_hidden
|
|
589
594
|
* to_be_in_viewport
|
|
590
595
|
* to_be_visible
|
|
596
|
+
* to_contain_class
|
|
591
597
|
* to_contain_text
|
|
592
598
|
* to_have_accessible_description
|
|
593
599
|
* to_have_accessible_error_message
|
|
@@ -615,7 +621,7 @@
|
|
|
615
621
|
|
|
616
622
|
* ~~connect~~
|
|
617
623
|
* devices
|
|
618
|
-
*
|
|
624
|
+
* set_default_timeout
|
|
619
625
|
|
|
620
626
|
## AndroidDevice
|
|
621
627
|
|
data/documentation/package.json
CHANGED
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"write-heading-ids": "docusaurus write-heading-ids"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@docusaurus/core": "^3.
|
|
18
|
-
"@docusaurus/preset-classic": "^3.
|
|
19
|
-
"@mdx-js/react": "^3.
|
|
17
|
+
"@docusaurus/core": "^3.8.1",
|
|
18
|
+
"@docusaurus/preset-classic": "^3.8.1",
|
|
19
|
+
"@mdx-js/react": "^3.1.1",
|
|
20
20
|
"@svgr/webpack": "^8.1.0",
|
|
21
21
|
"clsx": "^2.0.0",
|
|
22
22
|
"file-loader": "^6.2.0",
|