playwright-ruby-client 1.55.0 → 1.57.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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +5 -0
  3. data/README.md +4 -0
  4. data/documentation/docs/api/browser_context.md +6 -2
  5. data/documentation/docs/api/console_message.md +9 -0
  6. data/documentation/docs/api/element_handle.md +2 -0
  7. data/documentation/docs/api/frame.md +1 -0
  8. data/documentation/docs/api/locator.md +22 -0
  9. data/documentation/docs/api/page.md +32 -2
  10. data/documentation/docs/api/worker.md +20 -0
  11. data/documentation/docs/article/guides/playwright_on_alpine_linux.md +19 -0
  12. data/documentation/docs/article/guides/rails_integration.md +43 -2
  13. data/documentation/docs/include/api_coverage.md +6 -5
  14. data/documentation/package.json +3 -3
  15. data/documentation/yarn.lock +3754 -3372
  16. data/lib/playwright/channel_owners/browser_context.rb +7 -16
  17. data/lib/playwright/channel_owners/element_handle.rb +6 -2
  18. data/lib/playwright/channel_owners/frame.rb +9 -3
  19. data/lib/playwright/channel_owners/page.rb +49 -10
  20. data/lib/playwright/channel_owners/worker.rb +19 -0
  21. data/lib/playwright/console_message_impl.rb +4 -4
  22. data/lib/playwright/events.rb +1 -0
  23. data/lib/playwright/locator_assertions_impl.rb +5 -2
  24. data/lib/playwright/locator_impl.rb +25 -5
  25. data/lib/playwright/page_assertions_impl.rb +5 -2
  26. data/lib/playwright/version.rb +2 -2
  27. data/lib/playwright/web_socket_transport.rb +1 -1
  28. data/lib/playwright.rb +4 -0
  29. data/lib/playwright_api/browser_context.rb +2 -2
  30. data/lib/playwright_api/console_message.rb +6 -0
  31. data/lib/playwright_api/element_handle.rb +4 -2
  32. data/lib/playwright_api/frame.rb +2 -1
  33. data/lib/playwright_api/locator.rb +23 -4
  34. data/lib/playwright_api/page.rb +31 -12
  35. data/lib/playwright_api/worker.rb +20 -3
  36. data/sig/playwright.rbs +13 -12
  37. metadata +3 -5
  38. data/documentation/docs/api/accessibility.md +0 -66
  39. data/lib/playwright/accessibility_impl.rb +0 -50
  40. data/lib/playwright_api/accessibility.rb +0 -57
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6503261c50eaabe9ee7f02dfd5762e7e8bc26c472e3aeb2a0ba715036b97819e
4
- data.tar.gz: 3474c967a82b5eabe36b445ccf4132585847b11932c0b08d0429148172584eac
3
+ metadata.gz: 430aa6a1bab67d9edca2cce8f72c76578402ec3aab93f296366335d23894d3dd
4
+ data.tar.gz: 0efe7aba9e4c2e45f6374c957dad31630e66157124f4b1b5dc2589815d39e6fc
5
5
  SHA512:
6
- metadata.gz: a1ffd17d14ed76ce2cdda0350fddc987e2420e447d15c0c4defd315b91790886a53bcb5536829c05e10b6c9583e1aca806cd0b0262607e66316182de66ad343d
7
- data.tar.gz: 66631908582bf6017ef4fae6e0444e4219df00f0c735eb76c5fc357f19b50dabbd74230d4214d3b09c9d1f8dced7f9a2ab4c1e28275fd558cbbe9c280175ff32
6
+ metadata.gz: 5d19738002e6edef932c3eba936a99ffc3b54d805640a806cb3e255542d56b72be7526cf69c6752ed409c1337899f9c132494335c76b0231601c5cd7a596a677
7
+ data.tar.gz: 5864d506cb7f6cfc4d0a35a65900241ca7a686f2b5e59716f16e4d4f588e832153bcff19bf71fae82bda9b91e55a7c9ee1f974e33d1541ad1a49e78a51e4b341
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,5 @@
1
+ # Contributing
2
+
3
+ Thanks for your interest in contributing to `playwright-ruby-client`!
4
+
5
+ For development setup instructions and guidelines, please see [development/README.md](development/README.md).
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
- **NOTE**: Background pages are only supported on Chromium-based browsers.
78
+ Background pages have been removed from Chromium together with Manifest V2 extensions.
78
79
 
79
- All existing background pages in the context.
80
+ :::
81
+
82
+
83
+ Returns an empty list.
80
84
 
81
85
  ## browser
82
86
 
@@ -74,3 +74,12 @@ def type
74
74
  ```
75
75
 
76
76
 
77
+
78
+ ## worker
79
+
80
+ ```
81
+ def worker
82
+ ```
83
+
84
+
85
+ The web worker or service worker that produced this console message, if any. Note that console messages from web workers also have non-null [ConsoleMessage#page](./console_message#page).
@@ -103,6 +103,7 @@ def click(
103
103
  modifiers: nil,
104
104
  noWaitAfter: nil,
105
105
  position: nil,
106
+ steps: nil,
106
107
  timeout: nil,
107
108
  trial: nil)
108
109
  ```
@@ -138,6 +139,7 @@ def dblclick(
138
139
  modifiers: nil,
139
140
  noWaitAfter: nil,
140
141
  position: nil,
142
+ steps: nil,
141
143
  timeout: nil,
142
144
  trial: nil)
143
145
  ```
@@ -203,6 +203,7 @@ def drag_and_drop(
203
203
  force: nil,
204
204
  noWaitAfter: nil,
205
205
  sourcePosition: nil,
206
+ steps: nil,
206
207
  strict: nil,
207
208
  targetPosition: nil,
208
209
  timeout: nil,
@@ -235,6 +235,7 @@ def click(
235
235
  modifiers: nil,
236
236
  noWaitAfter: nil,
237
237
  position: nil,
238
+ steps: nil,
238
239
  timeout: nil,
239
240
  trial: nil)
240
241
  ```
@@ -296,6 +297,7 @@ def dblclick(
296
297
  modifiers: nil,
297
298
  noWaitAfter: nil,
298
299
  position: nil,
300
+ steps: nil,
299
301
  timeout: nil,
300
302
  trial: nil)
301
303
  ```
@@ -334,6 +336,25 @@ button = page.get_by_test_id("btn-sub").describe("Subscribe button")
334
336
  button.click
335
337
  ```
336
338
 
339
+ ## description
340
+
341
+ ```
342
+ def description
343
+ ```
344
+
345
+
346
+ Returns locator description previously set with [Locator#describe](./locator#describe). Returns `null` if no custom description has been set. Prefer `Locator.toString()` for a human-readable representation, as it uses the description when available.
347
+
348
+ **Usage**
349
+
350
+ ```ruby
351
+ button = page.get_by_role("button").describe("Subscribe button")
352
+ puts button.description # => "Subscribe button"
353
+
354
+ input = page.get_by_role("textbox")
355
+ puts input.description # => nil
356
+ ```
357
+
337
358
  ## dispatch_event
338
359
 
339
360
  ```
@@ -387,6 +408,7 @@ def drag_to(
387
408
  force: nil,
388
409
  noWaitAfter: nil,
389
410
  sourcePosition: nil,
411
+ steps: nil,
390
412
  targetPosition: nil,
391
413
  timeout: nil,
392
414
  trial: nil)
@@ -266,6 +266,7 @@ def drag_and_drop(
266
266
  force: nil,
267
267
  noWaitAfter: nil,
268
268
  sourcePosition: nil,
269
+ steps: nil,
269
270
  strict: nil,
270
271
  targetPosition: nil,
271
272
  timeout: nil,
@@ -994,6 +995,24 @@ def visible?(selector, strict: nil, timeout: nil)
994
995
 
995
996
  Returns whether the element is [visible](https://playwright.dev/python/docs/actionability#visible). `selector` that does not match any elements is considered not visible.
996
997
 
998
+ ## console_messages
999
+
1000
+ ```
1001
+ def console_messages
1002
+ ```
1003
+
1004
+
1005
+ Returns up to (currently) 200 last console messages from this page. See [`event: Page.console`] for more details.
1006
+
1007
+ ## page_errors
1008
+
1009
+ ```
1010
+ def page_errors
1011
+ ```
1012
+
1013
+
1014
+ Returns up to (currently) 200 last page errors from this page. See [`event: Page.pageError`] for more details.
1015
+
997
1016
  ## locator
998
1017
 
999
1018
  ```
@@ -1179,6 +1198,19 @@ def query_selector_all(selector)
1179
1198
  The method finds all elements matching the specified selector within the page. If no elements match the selector, the
1180
1199
  return value resolves to `[]`.
1181
1200
 
1201
+ ## requests
1202
+
1203
+ ```
1204
+ def requests
1205
+ ```
1206
+
1207
+
1208
+ Returns up to (currently) 100 last network request from this page. See [`event: Page.request`] for more details.
1209
+
1210
+ 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.
1211
+
1212
+ 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`].
1213
+
1182
1214
  ## reload
1183
1215
 
1184
1216
  ```
@@ -1901,8 +1933,6 @@ associated with the page.
1901
1933
 
1902
1934
  Playwright has ability to mock clock and passage of time.
1903
1935
 
1904
- ## accessibility
1905
-
1906
1936
  ## keyboard
1907
1937
 
1908
1938
  ## mouse
@@ -61,3 +61,23 @@ def url
61
61
  ```
62
62
 
63
63
 
64
+
65
+ ## expect_event
66
+
67
+ ```
68
+ def expect_event(event, predicate: nil, timeout: nil, &block)
69
+ ```
70
+
71
+
72
+ Waits for event to fire and passes its value into the predicate function.
73
+ Returns when the predicate returns truthy value.
74
+ Will throw an error if the page is closed before the event is fired.
75
+ Returns the event data value.
76
+
77
+ **Usage**
78
+
79
+ ```ruby
80
+ message = worker.expect_event("console") do
81
+ worker.evaluate("console.log(42)")
82
+ end
83
+ ```
@@ -54,6 +54,25 @@ end
54
54
 
55
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"`.
56
56
 
57
+ We can also pass launchOptions parameters using a `launch-options` query string like this:
58
+
59
+ ```ruby {3-4}
60
+ require 'json'
61
+
62
+ launch_params = { headless: false }
63
+ Playwright.connect_to_browser_server("wss://example.com:8888/ws?launch-options=#{launch_params.to_json}") do |browser|
64
+ page = browser.new_page
65
+ page.goto('https://github.com/microsoft/playwright')
66
+ page.screenshot(path: 'github-microsoft-playwright_headful.png')
67
+ end
68
+
69
+ Playwright.connect_to_browser_server('wss://example.com:8888/ws') do |browser|
70
+ page = browser.new_page
71
+ page.goto('https://github.com/microsoft/playwright')
72
+ page.screenshot(path: 'github-microsoft-playwright_headless.png')
73
+ end
74
+ ```
75
+
57
76
  ### Server code
58
77
 
59
78
  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)
@@ -23,7 +23,7 @@ Note that capybara-playwright-driver does not depend on Selenium. But `selenium-
23
23
  ## Register and configure Capybara driver
24
24
 
25
25
  ```rb
26
- Capybara.register_driver(:playwright) do |app|
26
+ Capybara.register_driver(:customized_playwright) do |app|
27
27
  Capybara::Playwright::Driver.new(app,
28
28
  browser_type: :chromium, # :chromium (default) or :firefox, :webkit
29
29
  headless: false, # true for headless mode (default), false for headful mode.
@@ -31,6 +31,38 @@ Capybara.register_driver(:playwright) do |app|
31
31
  end
32
32
  ```
33
33
 
34
+ :::note
35
+
36
+ Rails itself (since Rails 6.1) reserves the driver name `:playwright` for its built‑in integration (see [rails/rails#39987](https://github.com/rails/rails/issues/39987) and [YusukeIwaki/capybara-playwright-driver#93](https://github.com/YusukeIwaki/capybara-playwright-driver/issues/93)). **If you call `Capybara.register_driver(:playwright) { ... }` and then use `driven_by :playwright`, Rails' built‑in Playwright driver will be selected** instead of the one defined by `Capybara.register_driver(:playwright) { ... }`. Therefore, when you want to use the driver from this gem with custom options, register it with another name such as `:customized_playwright`.
37
+
38
+ :::
39
+
40
+ ### When running Playwright in a container
41
+
42
+ If Playwright is running in an independent container, with docker-compose.yaml config like this
43
+
44
+ ```
45
+ playwright: # this is our PLAYWRIGHT_HOST value
46
+ image: mcr.microsoft.com/playwright:v1.56.1-noble
47
+ command: >
48
+ /bin/sh -c "npx -y playwright@1.56.1 run-server --port 3000 --host 0.0.0.0 --path /ws"
49
+ init: true
50
+ restart: unless-stopped
51
+ ```
52
+
53
+ Configure capybara to use the `browser_server_endpoint_url`
54
+
55
+ ```rb
56
+ Capybara.register_driver(:playwright_remote) do |app|
57
+ Capybara::Playwright::Driver.new(
58
+ app,
59
+ browser_type: :chromium,
60
+ headless: true,
61
+ browser_server_endpoint_url: "ws://#{ENV.fetch('PLAYWRIGHT_HOST')}:3000/ws"
62
+ )
63
+ end
64
+ ```
65
+
34
66
  ### Update timeout
35
67
 
36
68
  Capybara sets the default value of timeout to _2 seconds_. Generally it is too short to wait for HTTP responses.
@@ -50,7 +82,16 @@ Capybara.default_driver = :playwright
50
82
  Capybara.javascript_driver = :playwright
51
83
  ```
52
84
 
53
- It is not mandatry. Without changing the default driver, you can still use Playwright driver by specifying `Capybara.current_driver = :playwright` (or `driven_by :playwright` in system spec) explicitly.
85
+ If you registered a customized driver (e.g. `:customized_playwright` as above) and want that to be the default, set:
86
+
87
+ ```rb
88
+ Capybara.default_driver = :customized_playwright
89
+ Capybara.javascript_driver = :customized_playwright
90
+ ```
91
+
92
+ Remember: choosing `:playwright` here will use Rails' built‑in driver, not the customized one from this gem.
93
+
94
+ It is not mandatory. Without changing the default driver, you can still use the customized Playwright driver by specifying `Capybara.current_driver = :customized_playwright` (or `driven_by :customized_playwright` in system spec) explicitly. Use `:playwright` only if you intend to run against Rails' built‑in Playwright driver (see issues: https://github.com/YusukeIwaki/capybara-playwright-driver/issues/93, https://github.com/rails/rails/issues/39987).
54
95
 
55
96
  ### (reference) Available driver options
56
97
 
@@ -129,10 +129,6 @@
129
129
  * wait_for_element_state
130
130
  * wait_for_selector
131
131
 
132
- ## Accessibility
133
-
134
- * snapshot
135
-
136
132
  ## FileChooser
137
133
 
138
134
  * element
@@ -208,6 +204,7 @@
208
204
  * evaluate
209
205
  * evaluate_handle
210
206
  * url
207
+ * expect_event
211
208
 
212
209
  ## Selectors
213
210
 
@@ -231,6 +228,7 @@
231
228
  * page
232
229
  * text
233
230
  * type
231
+ * worker
234
232
 
235
233
  ## Dialog
236
234
 
@@ -301,6 +299,8 @@
301
299
  * enabled?
302
300
  * hidden?
303
301
  * visible?
302
+ * console_messages
303
+ * page_errors
304
304
  * locator
305
305
  * main_frame
306
306
  * opener
@@ -309,6 +309,7 @@
309
309
  * press
310
310
  * query_selector
311
311
  * query_selector_all
312
+ * requests
312
313
  * ~~add_locator_handler~~
313
314
  * ~~remove_locator_handler~~
314
315
  * reload
@@ -353,7 +354,6 @@
353
354
  * workers
354
355
  * ~~wait_for_event~~
355
356
  * clock
356
- * accessibility
357
357
  * keyboard
358
358
  * mouse
359
359
  * request
@@ -456,6 +456,7 @@
456
456
  * count
457
457
  * dblclick
458
458
  * describe
459
+ * description
459
460
  * dispatch_event
460
461
  * drag_to
461
462
  * element_handle
@@ -14,9 +14,9 @@
14
14
  "write-heading-ids": "docusaurus write-heading-ids"
15
15
  },
16
16
  "dependencies": {
17
- "@docusaurus/core": "^3.1.1",
18
- "@docusaurus/preset-classic": "^3.1.1",
19
- "@mdx-js/react": "^3.0.0",
17
+ "@docusaurus/core": "^3.9.2",
18
+ "@docusaurus/preset-classic": "^3.9.2",
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",