playwright-ruby-client 0.6.1 → 0.6.6
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/documentation/docs/api/browser.md +4 -1
- data/documentation/docs/api/browser_context.md +3 -4
- data/documentation/docs/api/browser_type.md +54 -1
- data/documentation/docs/api/dialog.md +15 -18
- data/documentation/docs/api/element_handle.md +28 -50
- data/documentation/docs/api/experimental/android.md +3 -2
- data/documentation/docs/api/experimental/android_device.md +1 -0
- data/documentation/docs/api/file_chooser.md +4 -5
- data/documentation/docs/api/frame.md +3 -4
- data/documentation/docs/api/js_handle.md +11 -14
- data/documentation/docs/api/page.md +163 -230
- data/documentation/docs/api/route.md +20 -21
- data/documentation/docs/api/tracing.md +8 -15
- data/documentation/docs/api/web_socket.md +1 -1
- data/documentation/docs/api/worker.md +18 -1
- data/documentation/docs/article/guides/rails_integration.md +156 -2
- data/documentation/docs/article/guides/recording_video.md +79 -0
- data/documentation/docs/include/api_coverage.md +5 -4
- data/documentation/package.json +1 -1
- data/documentation/yarn.lock +478 -498
- data/lib/playwright/channel_owners/binding_call.rb +1 -1
- data/lib/playwright/channel_owners/browser.rb +15 -27
- data/lib/playwright/channel_owners/browser_context.rb +13 -5
- data/lib/playwright/channel_owners/browser_type.rb +23 -8
- data/lib/playwright/channel_owners/page.rb +8 -7
- data/lib/playwright/channel_owners/web_socket.rb +4 -0
- data/lib/playwright/channel_owners/worker.rb +4 -0
- data/lib/playwright/playwright_api.rb +16 -1
- data/lib/playwright/tracing_impl.rb +9 -9
- data/lib/playwright/version.rb +1 -1
- data/lib/playwright_api/android.rb +9 -8
- data/lib/playwright_api/android_device.rb +8 -7
- data/lib/playwright_api/browser.rb +12 -9
- data/lib/playwright_api/browser_context.rb +13 -14
- data/lib/playwright_api/browser_type.rb +13 -11
- data/lib/playwright_api/console_message.rb +6 -6
- data/lib/playwright_api/dialog.rb +6 -6
- data/lib/playwright_api/element_handle.rb +6 -6
- data/lib/playwright_api/frame.rb +6 -6
- data/lib/playwright_api/js_handle.rb +6 -6
- data/lib/playwright_api/page.rb +38 -24
- data/lib/playwright_api/playwright.rb +6 -6
- data/lib/playwright_api/request.rb +6 -6
- data/lib/playwright_api/response.rb +8 -8
- data/lib/playwright_api/route.rb +6 -6
- data/lib/playwright_api/selectors.rb +6 -6
- data/lib/playwright_api/tracing.rb +6 -12
- data/lib/playwright_api/web_socket.rb +22 -0
- data/lib/playwright_api/worker.rb +22 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b548b6927a468b4a1209e9002cc7ca6f20bf0ad7ad4091510336ed610d338bb
|
4
|
+
data.tar.gz: d8f5e411d5ee99460e77d3d922608996cde6de1a2199ee0f6425c7e3a5eb9a7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 645bd780e189153fabc25de3a58b490ae5fb919c8ed9b81f701c8bed0e910483be9cb2c901bda8f4619153bb18924240ae43841b197479665883567980ffd29c
|
7
|
+
data.tar.gz: 50af6ab226985f5bd7a7631fab3959c4215a6bae7d57d32c5cd9787f7d43a8ed2bbe599443a611a9eafd73e7e8dd74ace7783781a95d04357d5a9ff4c4e69313
|
@@ -85,6 +85,7 @@ def new_context(
|
|
85
85
|
record_har_path: nil,
|
86
86
|
record_video_dir: nil,
|
87
87
|
record_video_size: nil,
|
88
|
+
reducedMotion: nil,
|
88
89
|
screen: nil,
|
89
90
|
storageState: nil,
|
90
91
|
timezoneId: nil,
|
@@ -132,11 +133,13 @@ def new_page(
|
|
132
133
|
record_har_path: nil,
|
133
134
|
record_video_dir: nil,
|
134
135
|
record_video_size: nil,
|
136
|
+
reducedMotion: nil,
|
135
137
|
screen: nil,
|
136
138
|
storageState: nil,
|
137
139
|
timezoneId: nil,
|
138
140
|
userAgent: nil,
|
139
|
-
viewport: nil
|
141
|
+
viewport: nil,
|
142
|
+
&block)
|
140
143
|
```
|
141
144
|
|
142
145
|
Creates a new page in a new browser context. Closing this page will close the context as well.
|
@@ -131,8 +131,7 @@ The method adds a function called `name` on the `window` object of every frame i
|
|
131
131
|
called, the function executes `callback` and returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) which resolves to the return value of `callback`. If
|
132
132
|
the `callback` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), it will be awaited.
|
133
133
|
|
134
|
-
The first argument of the `callback` function contains information about the caller: `{
|
135
|
-
page: Page, frame: Frame }`.
|
134
|
+
The first argument of the `callback` function contains information about the caller: `{ browser_context: BrowserContext, page: Page, frame: Frame }`.
|
136
135
|
|
137
136
|
See [Page#expose_binding](./page#expose_binding) for page-only version.
|
138
137
|
|
@@ -193,7 +192,7 @@ If the `callback` returns a [Promise](https://developer.mozilla.org/en-US/docs/W
|
|
193
192
|
|
194
193
|
See [Page#expose_function](./page#expose_function) for page-only version.
|
195
194
|
|
196
|
-
An example of adding
|
195
|
+
An example of adding a `sha256` function to all pages in the context:
|
197
196
|
|
198
197
|
```ruby
|
199
198
|
require 'digest'
|
@@ -230,7 +229,7 @@ specified.
|
|
230
229
|
## new_page
|
231
230
|
|
232
231
|
```
|
233
|
-
def new_page
|
232
|
+
def new_page(&block)
|
234
233
|
```
|
235
234
|
|
236
235
|
Creates a new page in the browser context.
|
@@ -65,7 +65,7 @@ def launch(
|
|
65
65
|
proxy: nil,
|
66
66
|
slowMo: nil,
|
67
67
|
timeout: nil,
|
68
|
-
|
68
|
+
tracesDir: nil,
|
69
69
|
&block)
|
70
70
|
```
|
71
71
|
|
@@ -96,6 +96,59 @@ differences between Chromium and Chrome.
|
|
96
96
|
[This article](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md)
|
97
97
|
describes some differences for Linux users.
|
98
98
|
|
99
|
+
## launch_persistent_context
|
100
|
+
|
101
|
+
```
|
102
|
+
def launch_persistent_context(
|
103
|
+
userDataDir,
|
104
|
+
acceptDownloads: nil,
|
105
|
+
args: nil,
|
106
|
+
bypassCSP: nil,
|
107
|
+
channel: nil,
|
108
|
+
chromiumSandbox: nil,
|
109
|
+
colorScheme: nil,
|
110
|
+
deviceScaleFactor: nil,
|
111
|
+
devtools: nil,
|
112
|
+
downloadsPath: nil,
|
113
|
+
env: nil,
|
114
|
+
executablePath: nil,
|
115
|
+
extraHTTPHeaders: nil,
|
116
|
+
geolocation: nil,
|
117
|
+
handleSIGHUP: nil,
|
118
|
+
handleSIGINT: nil,
|
119
|
+
handleSIGTERM: nil,
|
120
|
+
hasTouch: nil,
|
121
|
+
headless: nil,
|
122
|
+
httpCredentials: nil,
|
123
|
+
ignoreDefaultArgs: nil,
|
124
|
+
ignoreHTTPSErrors: nil,
|
125
|
+
isMobile: nil,
|
126
|
+
javaScriptEnabled: nil,
|
127
|
+
locale: nil,
|
128
|
+
noViewport: nil,
|
129
|
+
offline: nil,
|
130
|
+
permissions: nil,
|
131
|
+
proxy: nil,
|
132
|
+
record_har_omit_content: nil,
|
133
|
+
record_har_path: nil,
|
134
|
+
record_video_dir: nil,
|
135
|
+
record_video_size: nil,
|
136
|
+
reducedMotion: nil,
|
137
|
+
screen: nil,
|
138
|
+
slowMo: nil,
|
139
|
+
timeout: nil,
|
140
|
+
timezoneId: nil,
|
141
|
+
tracesDir: nil,
|
142
|
+
userAgent: nil,
|
143
|
+
viewport: nil,
|
144
|
+
&block)
|
145
|
+
```
|
146
|
+
|
147
|
+
Returns the persistent browser context instance.
|
148
|
+
|
149
|
+
Launches browser that uses persistent storage located at `userDataDir` and returns the only context. Closing this
|
150
|
+
context will automatically close the browser.
|
151
|
+
|
99
152
|
## name
|
100
153
|
|
101
154
|
```
|
@@ -8,24 +8,21 @@ sidebar_position: 10
|
|
8
8
|
|
9
9
|
An example of using [Dialog](./dialog) class:
|
10
10
|
|
11
|
-
```
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
with sync_playwright() as playwright:
|
27
|
-
run(playwright)
|
28
|
-
|
11
|
+
```ruby
|
12
|
+
def handle_dialog(dialog)
|
13
|
+
puts "[#{dialog.type}] #{dialog.message}"
|
14
|
+
if dialog.message =~ /foo/
|
15
|
+
dialog.accept_async
|
16
|
+
else
|
17
|
+
dialog.dismiss
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
page.on("dialog", method(:handle_dialog))
|
22
|
+
page.evaluate("confirm('foo')") # will be accepted
|
23
|
+
# => [confirm] foo
|
24
|
+
page.evaluate("alert('bar')") # will be dismissed
|
25
|
+
# => [alert] bar
|
29
26
|
```
|
30
27
|
|
31
28
|
> NOTE: Dialogs are dismissed automatically, unless there is a [`event: Page.dialog`] listener. When listener is
|
@@ -9,21 +9,11 @@ sidebar_position: 10
|
|
9
9
|
ElementHandle represents an in-page DOM element. ElementHandles can be created with the [Page#query_selector](./page#query_selector)
|
10
10
|
method.
|
11
11
|
|
12
|
-
```
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
browser = chromium.launch()
|
18
|
-
page = browser.new_page()
|
19
|
-
page.goto("https://example.com")
|
20
|
-
href_element = page.query_selector("a")
|
21
|
-
href_element.click()
|
22
|
-
# ...
|
23
|
-
|
24
|
-
with sync_playwright() as playwright:
|
25
|
-
run(playwright)
|
26
|
-
|
12
|
+
```ruby
|
13
|
+
page.goto("https://example.com")
|
14
|
+
href_element = page.query_selector("a")
|
15
|
+
href_element.click
|
16
|
+
# ...
|
27
17
|
```
|
28
18
|
|
29
19
|
ElementHandle prevents DOM element from garbage collection unless the handle is disposed with
|
@@ -51,10 +41,12 @@ Elements from child frames return the bounding box relative to the main frame, u
|
|
51
41
|
Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the following
|
52
42
|
snippet should click the center of the element.
|
53
43
|
|
54
|
-
```
|
55
|
-
box = element_handle.bounding_box
|
56
|
-
page.mouse.click(
|
57
|
-
|
44
|
+
```ruby
|
45
|
+
box = element_handle.bounding_box
|
46
|
+
page.mouse.click(
|
47
|
+
box["x"] + box["width"] / 2,
|
48
|
+
box["y"] + box["height"] / 2,
|
49
|
+
)
|
58
50
|
```
|
59
51
|
|
60
52
|
|
@@ -156,9 +148,8 @@ The snippet below dispatches the `click` event on the element. Regardless of the
|
|
156
148
|
`click` is dispatched. This is equivalent to calling
|
157
149
|
[element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
|
158
150
|
|
159
|
-
```
|
151
|
+
```ruby
|
160
152
|
element_handle.dispatch_event("click")
|
161
|
-
|
162
153
|
```
|
163
154
|
|
164
155
|
Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties
|
@@ -175,11 +166,10 @@ Since `eventInit` is event-specific, please refer to the events documentation fo
|
|
175
166
|
|
176
167
|
You can also specify [JSHandle](./js_handle) as the property value if you want live objects to be passed into the event:
|
177
168
|
|
178
|
-
```
|
169
|
+
```ruby
|
179
170
|
# note you can only create data_transfer in chromium and firefox
|
180
171
|
data_transfer = page.evaluate_handle("new DataTransfer()")
|
181
|
-
element_handle.dispatch_event("
|
182
|
-
|
172
|
+
element_handle.dispatch_event("dragstart", eventInit: { dataTransfer: data_transfer })
|
183
173
|
```
|
184
174
|
|
185
175
|
|
@@ -201,11 +191,10 @@ and return its value.
|
|
201
191
|
|
202
192
|
Examples:
|
203
193
|
|
204
|
-
```
|
194
|
+
```ruby
|
205
195
|
tweet_handle = page.query_selector(".tweet")
|
206
|
-
|
207
|
-
|
208
|
-
|
196
|
+
tweet_handle.eval_on_selector(".like", "node => node.innerText") # => "100"
|
197
|
+
tweet_handle.eval_on_selector(".retweets", "node => node.innerText") # => "10"
|
209
198
|
```
|
210
199
|
|
211
200
|
|
@@ -233,10 +222,9 @@ Examples:
|
|
233
222
|
</div>
|
234
223
|
```
|
235
224
|
|
236
|
-
```
|
225
|
+
```ruby
|
237
226
|
feed_handle = page.query_selector(".feed")
|
238
|
-
|
239
|
-
|
227
|
+
feed_handle.eval_on_selector_all(".tweet", "nodes => nodes.map(n => n.innerText)") # => ["hello!", "hi!"]
|
240
228
|
```
|
241
229
|
|
242
230
|
|
@@ -463,26 +451,18 @@ Returns the array of option values that have been successfully selected.
|
|
463
451
|
|
464
452
|
Triggers a `change` and `input` event once all the provided options have been selected.
|
465
453
|
|
466
|
-
```
|
454
|
+
```ruby
|
467
455
|
# single selection matching the value
|
468
|
-
|
456
|
+
element_handle.select_option(value: "blue")
|
469
457
|
# single selection matching both the label
|
470
|
-
|
458
|
+
element_handle.select_option(label: "blue")
|
471
459
|
# multiple selection
|
472
|
-
|
473
|
-
|
460
|
+
element_handle.select_option(value: ["red", "green", "blue"])
|
474
461
|
```
|
475
462
|
|
476
|
-
```
|
477
|
-
# single selection matching the value
|
478
|
-
handle.select_option("blue")
|
479
|
-
# single selection matching both the value and the label
|
480
|
-
handle.select_option(label="blue")
|
481
|
-
# multiple selection
|
482
|
-
handle.select_option("red", "green", "blue")
|
463
|
+
```ruby
|
483
464
|
# multiple selection for blue, red and second option
|
484
|
-
|
485
|
-
|
465
|
+
element_handle.select_option(value: "blue", index: 2, label: "red")
|
486
466
|
```
|
487
467
|
|
488
468
|
|
@@ -552,19 +532,17 @@ Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup`
|
|
552
532
|
|
553
533
|
To press a special key, like `Control` or `ArrowDown`, use [ElementHandle#press](./element_handle#press).
|
554
534
|
|
555
|
-
```
|
535
|
+
```ruby
|
556
536
|
element_handle.type("hello") # types instantly
|
557
|
-
element_handle.type("world", delay
|
558
|
-
|
537
|
+
element_handle.type("world", delay: 100) # types slower, like a user
|
559
538
|
```
|
560
539
|
|
561
540
|
An example of typing into a text field and then submitting the form:
|
562
541
|
|
563
|
-
```
|
542
|
+
```ruby
|
564
543
|
element_handle = page.query_selector("input")
|
565
544
|
element_handle.type("some text")
|
566
545
|
element_handle.press("Enter")
|
567
|
-
|
568
546
|
```
|
569
547
|
|
570
548
|
|
@@ -4,14 +4,15 @@ sidebar_position: 10
|
|
4
4
|
|
5
5
|
# Android
|
6
6
|
|
7
|
-
Playwright has **experimental** support for Android automation.
|
7
|
+
Playwright has **experimental** support for Android automation. See [here](https://playwright.dev/python/docs/mobile) for more information. You can
|
8
|
+
access android namespace via:
|
8
9
|
|
9
10
|
An example of the Android automation script would be:
|
10
11
|
|
11
12
|
Note that since you don't need Playwright to install web browsers when testing Android, you can omit browser download
|
12
13
|
via setting the following environment variable when installing Playwright:
|
13
14
|
|
14
|
-
```
|
15
|
+
```bash js
|
15
16
|
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm i -D playwright
|
16
17
|
```
|
17
18
|
|
@@ -6,12 +6,11 @@ sidebar_position: 10
|
|
6
6
|
|
7
7
|
[FileChooser](./file_chooser) objects are dispatched by the page in the [`event: Page.fileChooser`] event.
|
8
8
|
|
9
|
-
```
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
```ruby
|
10
|
+
file_chooser = page.expect_file_chooser do
|
11
|
+
page.click("upload") # action to trigger file uploading
|
12
|
+
end
|
13
13
|
file_chooser.set_files("myfile.pdf")
|
14
|
-
|
15
14
|
```
|
16
15
|
|
17
16
|
|
@@ -308,9 +308,8 @@ a_window_handle # handle for the window object.
|
|
308
308
|
|
309
309
|
A string can also be passed in instead of a function.
|
310
310
|
|
311
|
-
```
|
311
|
+
```ruby
|
312
312
|
a_handle = page.evaluate_handle("document") # handle for the "document"
|
313
|
-
|
314
313
|
```
|
315
314
|
|
316
315
|
[JSHandle](./js_handle) instances can be passed as an argument to the [Frame#evaluate_handle](./frame#evaluate_handle):
|
@@ -318,8 +317,8 @@ a_handle = page.evaluate_handle("document") # handle for the "document"
|
|
318
317
|
```ruby
|
319
318
|
body_handle = page.evaluate_handle("document.body")
|
320
319
|
result_handle = page.evaluate_handle("body => body.innerHTML", arg: body_handle)
|
321
|
-
puts result_handle.json_value
|
322
|
-
result_handle.dispose
|
320
|
+
puts result_handle.json_value
|
321
|
+
result_handle.dispose
|
323
322
|
```
|
324
323
|
|
325
324
|
|
@@ -7,10 +7,9 @@ sidebar_position: 10
|
|
7
7
|
JSHandle represents an in-page JavaScript object. JSHandles can be created with the [Page#evaluate_handle](./page#evaluate_handle)
|
8
8
|
method.
|
9
9
|
|
10
|
-
```
|
10
|
+
```ruby
|
11
11
|
window_handle = page.evaluate_handle("window")
|
12
12
|
# ...
|
13
|
-
|
14
13
|
```
|
15
14
|
|
16
15
|
JSHandle prevents the referenced JavaScript object being garbage collected unless the handle is exposed with
|
@@ -50,10 +49,9 @@ If `expression` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web
|
|
50
49
|
|
51
50
|
Examples:
|
52
51
|
|
53
|
-
```
|
52
|
+
```ruby
|
54
53
|
tweet_handle = page.query_selector(".tweet .retweets")
|
55
|
-
|
56
|
-
|
54
|
+
tweet_handle.evaluate("node => node.innerText") # => "10 retweets"
|
57
55
|
```
|
58
56
|
|
59
57
|
|
@@ -68,10 +66,10 @@ Returns the return value of `expression` as a [JSHandle](./js_handle).
|
|
68
66
|
|
69
67
|
This method passes this handle as the first argument to `expression`.
|
70
68
|
|
71
|
-
The only difference between
|
69
|
+
The only difference between [JSHandle#evaluate](./js_handle#evaluate) and [JSHandle#evaluate_handle](./js_handle#evaluate_handle) is that [JSHandle#evaluate_handle](./js_handle#evaluate_handle) returns
|
72
70
|
[JSHandle](./js_handle).
|
73
71
|
|
74
|
-
If the function passed to the
|
72
|
+
If the function passed to the [JSHandle#evaluate_handle](./js_handle#evaluate_handle) returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then [JSHandle#evaluate_handle](./js_handle#evaluate_handle) would wait
|
75
73
|
for the promise to resolve and return its value.
|
76
74
|
|
77
75
|
See [Page#evaluate_handle](./page#evaluate_handle) for more details.
|
@@ -85,13 +83,12 @@ alias: `properties`
|
|
85
83
|
|
86
84
|
The method returns a map with **own property names** as keys and JSHandle instances for the property values.
|
87
85
|
|
88
|
-
```
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
86
|
+
```ruby
|
87
|
+
page.goto('https://example.com/')
|
88
|
+
window_handle = page.evaluate_handle("window")
|
89
|
+
properties = window_handle.properties
|
90
|
+
puts properties
|
91
|
+
window_handle.dispose
|
95
92
|
```
|
96
93
|
|
97
94
|
|