playwright-ruby-client 1.61.0 → 1.62.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/README.md +12 -17
- data/documentation/docs/api/api_response.md +12 -0
- data/documentation/docs/api/browser_context.md +5 -3
- data/documentation/docs/api/browser_type.md +2 -0
- data/documentation/docs/api/credentials.md +6 -2
- data/documentation/docs/api/element_handle.md +7 -0
- data/documentation/docs/api/frame.md +8 -0
- data/documentation/docs/api/locator.md +29 -0
- data/documentation/docs/api/locator_assertions.md +4 -2
- data/documentation/docs/api/page.md +14 -0
- data/documentation/docs/api/playwright.md +2 -2
- data/documentation/docs/article/getting_started.md +12 -11
- data/documentation/docs/article/guides/download_playwright_driver.md +11 -32
- data/documentation/docs/article/guides/launch_browser.md +5 -4
- data/documentation/docs/article/guides/playwright_on_alpine_linux.md +6 -5
- data/documentation/docs/article/guides/rails_integration.md +72 -4
- data/documentation/docs/article/guides/rails_integration_with_null_driver.md +4 -3
- data/documentation/docs/article/guides/semi_automation.md +1 -1
- data/documentation/docs/article/guides/use_storage_state.md +1 -1
- data/documentation/docs/include/api_coverage.md +2 -0
- data/documentation/docusaurus.config.js +31 -0
- data/documentation/package.json +3 -0
- data/documentation/yarn.lock +159 -174
- data/lib/playwright/api_response_impl.rb +16 -0
- data/lib/playwright/channel_owners/browser_context.rb +6 -2
- data/lib/playwright/channel_owners/element_handle.rb +14 -4
- data/lib/playwright/channel_owners/frame.rb +14 -0
- data/lib/playwright/channel_owners/page.rb +19 -8
- data/lib/playwright/connection.rb +9 -1
- data/lib/playwright/locator_assertions_impl.rb +14 -1
- data/lib/playwright/locator_impl.rb +28 -5
- data/lib/playwright/screencast.rb +20 -6
- data/lib/playwright/screenshot_utils.rb +24 -0
- data/lib/playwright/test.rb +12 -2
- data/lib/playwright/url_matcher.rb +120 -4
- data/lib/playwright/version.rb +2 -2
- data/lib/playwright.rb +2 -2
- data/lib/playwright_api/api_request_context.rb +6 -6
- data/lib/playwright_api/api_response.rb +9 -0
- data/lib/playwright_api/browser.rb +6 -6
- data/lib/playwright_api/browser_context.rb +14 -12
- data/lib/playwright_api/browser_type.rb +8 -6
- data/lib/playwright_api/cdp_session.rb +6 -6
- data/lib/playwright_api/credentials.rb +6 -2
- data/lib/playwright_api/dialog.rb +6 -6
- data/lib/playwright_api/element_handle.rb +20 -13
- data/lib/playwright_api/frame.rb +29 -21
- data/lib/playwright_api/js_handle.rb +6 -6
- data/lib/playwright_api/locator.rb +39 -13
- data/lib/playwright_api/locator_assertions.rb +6 -4
- data/lib/playwright_api/page.rb +37 -23
- data/lib/playwright_api/playwright.rb +6 -6
- data/lib/playwright_api/request.rb +8 -8
- data/lib/playwright_api/response.rb +6 -6
- data/lib/playwright_api/route.rb +6 -6
- data/lib/playwright_api/tracing.rb +6 -6
- data/lib/playwright_api/web_socket.rb +6 -6
- data/lib/playwright_api/worker.rb +8 -8
- data/playwright.gemspec +5 -0
- data/sig/playwright.rbs +41 -39
- metadata +7 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
sidebar_position: 2
|
|
3
|
+
description: Launch Chromium, Firefox, or WebKit from Ruby and configure browser launch options.
|
|
3
4
|
---
|
|
4
5
|
|
|
5
6
|
# Launch Browser
|
|
@@ -13,7 +14,7 @@ In order to launch browser, it is required to create Playwright session.
|
|
|
13
14
|
In previous examples,
|
|
14
15
|
|
|
15
16
|
```rb
|
|
16
|
-
Playwright.create(playwright_cli_executable_path: '
|
|
17
|
+
Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright-core') do |playwright|
|
|
17
18
|
# Play with `playwright` here
|
|
18
19
|
end
|
|
19
20
|
```
|
|
@@ -23,7 +24,7 @@ this is the exact procedure for creating Playwright session. Choose either metho
|
|
|
23
24
|
### Define scoped Playwright session with block
|
|
24
25
|
|
|
25
26
|
```rb
|
|
26
|
-
Playwright.create(playwright_cli_executable_path: '
|
|
27
|
+
Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright-core') do |playwright|
|
|
27
28
|
# Play with `playwright` here
|
|
28
29
|
end
|
|
29
30
|
```
|
|
@@ -41,7 +42,7 @@ class SomeClass
|
|
|
41
42
|
|
|
42
43
|
def start_playwright
|
|
43
44
|
# Start Playwright driver (runs `playwright run-driver` internally)
|
|
44
|
-
@playwright_exec = Playwright.create(playwright_cli_executable_path: '
|
|
45
|
+
@playwright_exec = Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright-core')
|
|
45
46
|
end
|
|
46
47
|
|
|
47
48
|
def stop_playwright!
|
|
@@ -102,7 +103,7 @@ Use `Browser#new_context` to prepare a new browser window and use `BrowserContex
|
|
|
102
103
|
Also we can use `Browser#new_page` to create a new window and new tab at once.
|
|
103
104
|
|
|
104
105
|
```rb
|
|
105
|
-
Playwright.create(playwright_cli_executable_path: '
|
|
106
|
+
Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright-core') do |playwright|
|
|
106
107
|
playwright.chromium.launch(headless: false) do |browser| # Chromium task icon appears.
|
|
107
108
|
context = browser.new_context # Prepare new window.
|
|
108
109
|
page = context.new_page # Open new window and new tab here. (about:blank)
|
|
@@ -35,7 +35,7 @@ Playwright server is running on a container of [official Docker image](https://h
|
|
|
35
35
|
|
|
36
36
|

|
|
37
37
|
|
|
38
|
-
- Server can be launched with `
|
|
38
|
+
- Server can be launched with the `playwright-core run-server` CLI command.
|
|
39
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.
|
|
40
40
|
|
|
41
41
|
### Client code
|
|
@@ -75,7 +75,7 @@ end
|
|
|
75
75
|
|
|
76
76
|
### Server code
|
|
77
77
|
|
|
78
|
-
With the [official Docker image](https://hub.docker.com/_/microsoft-playwright) or in the local development environment with Node.js,
|
|
78
|
+
With the [official Docker image](https://hub.docker.com/_/microsoft-playwright) or in the local development environment with Node.js, install a matching `playwright-core` package and use its local CLI. (`$PORT` is a port number of the server.)
|
|
79
79
|
|
|
80
80
|
If custom Docker image is preferred, build it as follows:
|
|
81
81
|
|
|
@@ -83,10 +83,11 @@ If custom Docker image is preferred, build it as follows:
|
|
|
83
83
|
FROM mcr.microsoft.com/playwright
|
|
84
84
|
|
|
85
85
|
WORKDIR /root
|
|
86
|
-
|
|
86
|
+
ARG PLAYWRIGHT_CORE_VERSION=1.62.1
|
|
87
|
+
RUN npm install "playwright-core@$PLAYWRIGHT_CORE_VERSION" && ./node_modules/.bin/playwright-core install
|
|
87
88
|
|
|
88
89
|
ENV PORT 8888
|
|
89
|
-
CMD ["./node_modules/.bin/playwright", "run-server", "--port", "$PORT", "--path", "/ws"]
|
|
90
|
+
CMD ["./node_modules/.bin/playwright-core", "run-server", "--port", "$PORT", "--path", "/ws"]
|
|
90
91
|
```
|
|
91
92
|
|
|
92
93
|
## Debugging for connection
|
|
@@ -106,7 +107,7 @@ DEBUG=1 bundle exec ruby some-automation-with-playwright.rb
|
|
|
106
107
|
Just set an environment variable `DEBUG=pw:*` or `DEBUG=pw:server`
|
|
107
108
|
|
|
108
109
|
```
|
|
109
|
-
DEBUG=pw:*
|
|
110
|
+
DEBUG=pw:* ./node_modules/.bin/playwright-core run-server --browser chromium
|
|
110
111
|
```
|
|
111
112
|
|
|
112
113
|
See [the official documentation](https://playwright.dev/docs/debug/#verbose-api-logs) for details.
|
|
@@ -45,7 +45,7 @@ If Playwright is running in an independent container, with docker-compose.yaml c
|
|
|
45
45
|
playwright: # this is our PLAYWRIGHT_HOST value
|
|
46
46
|
image: mcr.microsoft.com/playwright:v1.57.0-noble
|
|
47
47
|
command: >
|
|
48
|
-
/bin/sh -c "
|
|
48
|
+
/bin/sh -c "npm install --no-save playwright-core@1.57.0 && ./node_modules/.bin/playwright-core run-server --port 3000 --host 0.0.0.0 --path /ws"
|
|
49
49
|
init: true
|
|
50
50
|
restart: unless-stopped
|
|
51
51
|
```
|
|
@@ -144,8 +144,8 @@ These parameters can be passed into `Capybara::Playwright::Driver.new`
|
|
|
144
144
|
|
|
145
145
|
```ruby
|
|
146
146
|
driver_opts = {
|
|
147
|
-
# `playwright` command path.
|
|
148
|
-
playwright_cli_executable_path: './node_modules/.bin/playwright',
|
|
147
|
+
# `playwright-core` command path.
|
|
148
|
+
playwright_cli_executable_path: './node_modules/.bin/playwright-core',
|
|
149
149
|
|
|
150
150
|
# Use firefox for testing.
|
|
151
151
|
browser_type: :firefox,
|
|
@@ -264,7 +264,7 @@ This example code would attach the trace zip file to Allure report for each test
|
|
|
264
264
|
We can download and show the trace with `playwright show-trace` command.
|
|
265
265
|
|
|
266
266
|
```
|
|
267
|
-
|
|
267
|
+
./node_modules/.bin/playwright-core show-trace ababcdcdefef.zip
|
|
268
268
|
```
|
|
269
269
|
|
|
270
270
|

|
|
@@ -276,3 +276,71 @@ Instead of the easy configuration using `on_save_trace`, we can also use `page.d
|
|
|
276
276
|
- Playwright doesn't allow clicking invisible DOM elements or moving elements. `click` sometimes doesn't work as Selenium does. See the detail in https://playwright.dev/docs/actionability/
|
|
277
277
|
- `current_window.maximize` and `current_window.fullscreen` work only on headful (non-headless) mode, as selenium driver does.
|
|
278
278
|
- `Capybara::Node::Element#drag_to` does not accept `html5` parameter. HTML5 drag and drop is not fully supported in Playwright.
|
|
279
|
+
|
|
280
|
+
#### Selenium migration incompatibilities
|
|
281
|
+
|
|
282
|
+
Some Selenium-backed Capybara behavior depends on WebDriver implementation details or accepts patterns outside Capybara's documented API. `capybara-playwright-driver` does not try to emulate these Selenium-specific behaviors when they conflict with Playwright's actionability, dialog, or rendered text model.
|
|
283
|
+
|
|
284
|
+
##### Modal dialogs must be handled before the action that opens them
|
|
285
|
+
|
|
286
|
+
Use Capybara's block-oriented modal API:
|
|
287
|
+
|
|
288
|
+
```ruby
|
|
289
|
+
accept_alert('message') do
|
|
290
|
+
click_button 'Open alert'
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
accept_confirm('Are you sure?') do
|
|
294
|
+
click_button 'Delete'
|
|
295
|
+
end
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Selenium-backed Capybara may sometimes handle an already-open modal after the action has returned:
|
|
299
|
+
|
|
300
|
+
```ruby
|
|
301
|
+
click_button 'Delete'
|
|
302
|
+
accept_confirm('Are you sure?')
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
This pattern is not portable to Playwright. In Playwright, the action that opens a JavaScript dialog does not complete until the dialog is handled, so the driver cannot wait for later Ruby code to call `accept_alert`, `accept_confirm`, or another modal helper.
|
|
306
|
+
|
|
307
|
+
Wrap the action that opens the dialog in `accept_alert`, `accept_confirm`, `dismiss_confirm`, `accept_prompt`, or `dismiss_prompt`.
|
|
308
|
+
|
|
309
|
+
##### Clicking a disabled element waits for actionability
|
|
310
|
+
|
|
311
|
+
Selenium-backed Capybara may return from a second click on an already-disabled button without changing the page. Playwright waits for the element to become actionable, then times out. This is expected Playwright behavior, and commonly appears in migration work around double-submit prevention tests.
|
|
312
|
+
|
|
313
|
+
Instead of attempting a second click on a disabled control, assert the disabled state and the expected result:
|
|
314
|
+
|
|
315
|
+
```ruby
|
|
316
|
+
expect(button).to be_disabled
|
|
317
|
+
expect(page).to have_text('submitted')
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Alternatively, assert the relevant server or client state directly.
|
|
321
|
+
|
|
322
|
+
##### Visible text follows rendered `innerText` behavior
|
|
323
|
+
|
|
324
|
+
When a `<br>` is hidden with CSS, Selenium-backed Capybara may still preserve a newline in text extraction. Playwright follows the browser's rendered `innerText` behavior: a hidden `<br>` does not create a rendered line break.
|
|
325
|
+
|
|
326
|
+
For example:
|
|
327
|
+
|
|
328
|
+
```html
|
|
329
|
+
<p>not submitted.<br class="hidden">click submit.</p>
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
If the `<br>` is hidden with `display: none`, Playwright-style visible text is:
|
|
333
|
+
|
|
334
|
+
```ruby
|
|
335
|
+
"not submitted.click submit."
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
not:
|
|
339
|
+
|
|
340
|
+
```ruby
|
|
341
|
+
"not submitted.\nclick submit."
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
Avoid newline-sensitive expectations around responsive or hidden line break elements, or assert the browser-rendered text that users actually see.
|
|
345
|
+
|
|
346
|
+
These examples are not exhaustive. If you find another Capybara/Selenium migration incompatibility, please open an issue at [capybara-playwright-driver issues](https://github.com/YusukeIwaki/capybara-playwright-driver/issues) with the reproduction HTML and the Ruby/Capybara code that reproduces it.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
sidebar_position: 4
|
|
3
|
+
description: Use native Playwright APIs in Rails system tests while retaining Capybara only for test server lifecycle management.
|
|
3
4
|
---
|
|
4
5
|
|
|
5
6
|
# Use Capybara without DSL
|
|
@@ -56,7 +57,7 @@ RSpec.configure do |config|
|
|
|
56
57
|
# Rails server is launched here, at the first time of accessing Capybara.current_session.server
|
|
57
58
|
base_url = Capybara.current_session.server.base_url
|
|
58
59
|
|
|
59
|
-
Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
|
|
60
|
+
Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright-core') do |playwright|
|
|
60
61
|
# pass any option for Playwright#launch and Browser#new_page as you prefer.
|
|
61
62
|
playwright.chromium.launch(headless: false) do |browser|
|
|
62
63
|
@playwright_page = browser.new_page(baseURL: base_url)
|
|
@@ -98,7 +99,7 @@ module PlaywrightBrowser
|
|
|
98
99
|
|
|
99
100
|
def start!
|
|
100
101
|
@fiber = Fiber.new do
|
|
101
|
-
Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
|
|
102
|
+
Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright-core') do |playwright|
|
|
102
103
|
playwright.chromium.launch(headless: false) do |browser|
|
|
103
104
|
Fiber.yield(browser)
|
|
104
105
|
end
|
|
@@ -152,7 +153,7 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
|
|
152
153
|
driven_by :null
|
|
153
154
|
|
|
154
155
|
def self.playwright
|
|
155
|
-
@playwright ||= Playwright.create(playwright_cli_executable_path: Rails.root.join("node_modules/.bin/playwright"))
|
|
156
|
+
@playwright ||= Playwright.create(playwright_cli_executable_path: Rails.root.join("node_modules/.bin/playwright-core"))
|
|
156
157
|
end
|
|
157
158
|
|
|
158
159
|
def before_setup
|
|
@@ -54,7 +54,7 @@ We have to enable it for installing Chrome extension, by passing these 3 paramet
|
|
|
54
54
|
require 'playwright'
|
|
55
55
|
require 'pry'
|
|
56
56
|
|
|
57
|
-
Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
|
|
57
|
+
Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright-core') do |playwright|
|
|
58
58
|
launch_params = {
|
|
59
59
|
acceptDownloads: true,
|
|
60
60
|
channel: 'chrome',
|
|
@@ -24,7 +24,7 @@ require 'pry'
|
|
|
24
24
|
|
|
25
25
|
force_login = !File.exist?('github_state.json')
|
|
26
26
|
|
|
27
|
-
Playwright.create(playwright_cli_executable_path: '
|
|
27
|
+
Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright-core') do |playwright|
|
|
28
28
|
if force_login
|
|
29
29
|
# Use headful mode for manual operation.
|
|
30
30
|
playwright.chromium.launch(headless: false, channel: 'chrome') do |browser|
|
|
@@ -9,6 +9,37 @@ module.exports = {
|
|
|
9
9
|
favicon: 'img/playwright-logo.svg',
|
|
10
10
|
organizationName: 'YusukeIwaki', // Usually your GitHub org/user name.
|
|
11
11
|
projectName: 'playwright-ruby-client', // Usually your repo name.
|
|
12
|
+
plugins: [
|
|
13
|
+
[
|
|
14
|
+
'docusaurus-plugin-llms',
|
|
15
|
+
{
|
|
16
|
+
generateLLMsTxt: true,
|
|
17
|
+
generateLLMsFullTxt: false,
|
|
18
|
+
generateMarkdownFiles: true,
|
|
19
|
+
docsDir: 'docs',
|
|
20
|
+
title: 'playwright-ruby-client',
|
|
21
|
+
description: 'Ruby client for Playwright, including API reference and integration guides.',
|
|
22
|
+
rootContent: `This is a community-maintained Ruby client for Playwright.
|
|
23
|
+
|
|
24
|
+
Important usage notes:
|
|
25
|
+
- The gem does not include Node.js or Playwright. Install the compatible \`playwright-core\` npm package separately and pass \`node_modules/.bin/playwright-core\` to \`Playwright.create\`.
|
|
26
|
+
- Determine the compatible Playwright version from \`Playwright::COMPATIBLE_PLAYWRIGHT_VERSION\`; do not assume the newest npm package is compatible.
|
|
27
|
+
- Use playwright-ruby-client for native Playwright APIs. Use capybara-playwright-driver when compatibility with the Capybara DSL is more important.
|
|
28
|
+
- Prefer the Ruby examples and signatures in this documentation over examples for other Playwright language bindings.`,
|
|
29
|
+
includeOrder: [
|
|
30
|
+
'article/getting_started.md',
|
|
31
|
+
'article/guides/**/*.md',
|
|
32
|
+
'api/playwright.md',
|
|
33
|
+
'api/**/*.md',
|
|
34
|
+
'article/api_coverage.mdx',
|
|
35
|
+
],
|
|
36
|
+
includeUnmatchedLast: true,
|
|
37
|
+
ignoreFiles: ['include/**'],
|
|
38
|
+
excludeImports: true,
|
|
39
|
+
removeDuplicateHeadings: true,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
],
|
|
12
43
|
themeConfig: {
|
|
13
44
|
image: 'img/playwright-ruby-client.png',
|
|
14
45
|
navbar: {
|