playwright-ruby-client 0.9.0 → 1.14.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/documentation/docs/api/accessibility.md +51 -1
- data/documentation/docs/api/browser_context.md +28 -0
- data/documentation/docs/api/element_handle.md +4 -5
- data/documentation/docs/api/experimental/android.md +15 -2
- data/documentation/docs/api/frame.md +66 -97
- data/documentation/docs/api/locator.md +28 -41
- data/documentation/docs/api/mouse.md +3 -4
- data/documentation/docs/api/page.md +41 -1
- data/documentation/docs/api/request.md +15 -19
- data/documentation/docs/api/touchscreen.md +8 -0
- data/documentation/docs/api/tracing.md +13 -12
- data/documentation/docs/api/worker.md +46 -8
- data/documentation/docs/article/guides/inspector.md +1 -1
- data/documentation/docs/article/guides/playwright_on_alpine_linux.md +1 -1
- data/documentation/docs/article/guides/semi_automation.md +1 -1
- data/documentation/docs/article/guides/use_storage_state.md +78 -0
- data/documentation/docs/include/api_coverage.md +13 -13
- data/lib/playwright/accessibility_impl.rb +50 -0
- data/lib/playwright/channel_owners/browser_context.rb +45 -0
- data/lib/playwright/channel_owners/frame.rb +9 -0
- data/lib/playwright/channel_owners/page.rb +31 -2
- data/lib/playwright/channel_owners/request.rb +8 -8
- data/lib/playwright/channel_owners/worker.rb +23 -0
- data/lib/playwright/locator_impl.rb +3 -3
- data/lib/playwright/touchscreen_impl.rb +7 -0
- data/lib/playwright/tracing_impl.rb +9 -8
- data/lib/playwright/version.rb +1 -1
- data/lib/playwright_api/accessibility.rb +1 -1
- data/lib/playwright_api/android.rb +15 -2
- data/lib/playwright_api/browser_context.rb +8 -8
- data/lib/playwright_api/element_handle.rb +1 -1
- data/lib/playwright_api/frame.rb +5 -3
- data/lib/playwright_api/locator.rb +3 -3
- data/lib/playwright_api/page.rb +8 -6
- data/lib/playwright_api/touchscreen.rb +1 -1
- data/lib/playwright_api/worker.rb +13 -3
- metadata +4 -2
@@ -7,10 +7,9 @@ sidebar_position: 10
|
|
7
7
|
Locator represents a view to the element(s) on the page. It captures the logic sufficient to retrieve the element at any
|
8
8
|
given moment. Locator can be created with the [Page#locator](./page#locator) method.
|
9
9
|
|
10
|
-
```
|
10
|
+
```ruby
|
11
11
|
locator = page.locator("text=Submit")
|
12
|
-
locator.click
|
13
|
-
|
12
|
+
locator.click
|
14
13
|
```
|
15
14
|
|
16
15
|
The difference between the Locator and [ElementHandle](./element_handle) is that the latter points to a particular element, while Locator
|
@@ -72,10 +71,12 @@ Elements from child frames return the bounding box relative to the main frame, u
|
|
72
71
|
Assuming the page is static, it is safe to use bounding box coordinates to perform input. For example, the following
|
73
72
|
snippet should click the center of the element.
|
74
73
|
|
75
|
-
```
|
76
|
-
box = element.bounding_box
|
77
|
-
page.mouse.click(
|
78
|
-
|
74
|
+
```ruby
|
75
|
+
box = element.bounding_box
|
76
|
+
page.mouse.click(
|
77
|
+
box["x"] + box["width"] / 2,
|
78
|
+
box["y"] + box["height"] / 2,
|
79
|
+
)
|
79
80
|
```
|
80
81
|
|
81
82
|
|
@@ -177,9 +178,8 @@ The snippet below dispatches the `click` event on the element. Regardless of the
|
|
177
178
|
`click` is dispatched. This is equivalent to calling
|
178
179
|
[element.click()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click).
|
179
180
|
|
180
|
-
```
|
181
|
+
```ruby
|
181
182
|
element.dispatch_event("click")
|
182
|
-
|
183
183
|
```
|
184
184
|
|
185
185
|
Under the hood, it creates an instance of an event based on the given `type`, initializes it with `eventInit` properties
|
@@ -196,11 +196,10 @@ Since `eventInit` is event-specific, please refer to the events documentation fo
|
|
196
196
|
|
197
197
|
You can also specify [JSHandle](./js_handle) as the property value if you want live objects to be passed into the event:
|
198
198
|
|
199
|
-
```
|
199
|
+
```ruby
|
200
200
|
# note you can only create data_transfer in chromium and firefox
|
201
201
|
data_transfer = page.evaluate_handle("new DataTransfer()")
|
202
|
-
element.dispatch_event("
|
203
|
-
|
202
|
+
element.dispatch_event("dragstart", eventInit: { dataTransfer: data_transfer })
|
204
203
|
```
|
205
204
|
|
206
205
|
|
@@ -236,10 +235,9 @@ If `expression` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web
|
|
236
235
|
|
237
236
|
Examples:
|
238
237
|
|
239
|
-
```
|
240
|
-
|
241
|
-
|
242
|
-
|
238
|
+
```ruby
|
239
|
+
tweet = page.query_selector(".tweet .retweets")
|
240
|
+
tweet.evaluate("node => node.innerText") # => "10 retweets"
|
243
241
|
```
|
244
242
|
|
245
243
|
|
@@ -253,15 +251,14 @@ def evaluate_all(expression, arg: nil)
|
|
253
251
|
The method finds all elements matching the specified locator and passes an array of matched elements as a first argument
|
254
252
|
to `expression`. Returns the result of `expression` invocation.
|
255
253
|
|
256
|
-
If `expression` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then [
|
257
|
-
value.
|
254
|
+
If `expression` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then [Locator#evaluate_all](./locator#evaluate_all) would wait for the promise to resolve and
|
255
|
+
return its value.
|
258
256
|
|
259
257
|
Examples:
|
260
258
|
|
261
|
-
```
|
259
|
+
```ruby
|
262
260
|
elements = page.locator("div")
|
263
|
-
|
264
|
-
|
261
|
+
elements.evaluate_all("(divs, min) => divs.length >= min", arg: 10)
|
265
262
|
```
|
266
263
|
|
267
264
|
|
@@ -368,7 +365,7 @@ Returns the `element.innerText`.
|
|
368
365
|
def input_value(timeout: nil)
|
369
366
|
```
|
370
367
|
|
371
|
-
Returns `input.value` for `<input>` or `<textarea>` element. Throws for non-input elements.
|
368
|
+
Returns `input.value` for `<input>` or `<textarea>` or `<select>` element. Throws for non-input elements.
|
372
369
|
|
373
370
|
## checked?
|
374
371
|
|
@@ -518,26 +515,18 @@ Returns the array of option values that have been successfully selected.
|
|
518
515
|
|
519
516
|
Triggers a `change` and `input` event once all the provided options have been selected.
|
520
517
|
|
521
|
-
```
|
518
|
+
```ruby
|
522
519
|
# single selection matching the value
|
523
|
-
element.select_option("blue")
|
520
|
+
element.select_option(value: "blue")
|
524
521
|
# single selection matching both the label
|
525
|
-
element.select_option(label
|
522
|
+
element.select_option(label: "blue")
|
526
523
|
# multiple selection
|
527
|
-
element.select_option(value
|
528
|
-
|
524
|
+
element.select_option(value: ["red", "green", "blue"])
|
529
525
|
```
|
530
526
|
|
531
|
-
```
|
532
|
-
# single selection matching the value
|
533
|
-
element.select_option("blue")
|
534
|
-
# single selection matching both the value and the label
|
535
|
-
element.select_option(label="blue")
|
536
|
-
# multiple selection
|
537
|
-
element.select_option("red", "green", "blue")
|
527
|
+
```ruby
|
538
528
|
# multiple selection for blue, red and second option
|
539
|
-
element.select_option(value
|
540
|
-
|
529
|
+
element.select_option(value: "blue", index: 2, label: "red")
|
541
530
|
```
|
542
531
|
|
543
532
|
|
@@ -607,19 +596,17 @@ Focuses the element, and then sends a `keydown`, `keypress`/`input`, and `keyup`
|
|
607
596
|
|
608
597
|
To press a special key, like `Control` or `ArrowDown`, use [Locator#press](./locator#press).
|
609
598
|
|
610
|
-
```
|
599
|
+
```ruby
|
611
600
|
element.type("hello") # types instantly
|
612
|
-
element.type("world", delay
|
613
|
-
|
601
|
+
element.type("world", delay: 100) # types slower, like a user
|
614
602
|
```
|
615
603
|
|
616
604
|
An example of typing into a text field and then submitting the form:
|
617
605
|
|
618
|
-
```
|
606
|
+
```ruby
|
619
607
|
element = page.locator("input")
|
620
608
|
element.type("some text")
|
621
609
|
element.press("Enter")
|
622
|
-
|
623
610
|
```
|
624
611
|
|
625
612
|
|
@@ -8,16 +8,15 @@ The Mouse class operates in main-frame CSS pixels relative to the top-left corne
|
|
8
8
|
|
9
9
|
Every `page` object has its own Mouse, accessible with [Page#mouse](./page#mouse).
|
10
10
|
|
11
|
-
```
|
11
|
+
```ruby
|
12
12
|
# using ‘page.mouse’ to trace a 100x100 square.
|
13
13
|
page.mouse.move(0, 0)
|
14
|
-
page.mouse.down
|
14
|
+
page.mouse.down
|
15
15
|
page.mouse.move(0, 100)
|
16
16
|
page.mouse.move(100, 100)
|
17
17
|
page.mouse.move(100, 0)
|
18
18
|
page.mouse.move(0, 0)
|
19
|
-
page.mouse.up
|
20
|
-
|
19
|
+
page.mouse.up
|
21
20
|
```
|
22
21
|
|
23
22
|
|
@@ -269,7 +269,9 @@ def drag_and_drop(
|
|
269
269
|
target,
|
270
270
|
force: nil,
|
271
271
|
noWaitAfter: nil,
|
272
|
+
sourcePosition: nil,
|
272
273
|
strict: nil,
|
274
|
+
targetPosition: nil,
|
273
275
|
timeout: nil,
|
274
276
|
trial: nil)
|
275
277
|
```
|
@@ -686,7 +688,7 @@ Returns `element.innerText`.
|
|
686
688
|
def input_value(selector, strict: nil, timeout: nil)
|
687
689
|
```
|
688
690
|
|
689
|
-
Returns `input.value` for the selected `<input>` or `<textarea>` element. Throws for non-input elements.
|
691
|
+
Returns `input.value` for the selected `<input>` or `<textarea>` or `<select>` element. Throws for non-input elements.
|
690
692
|
|
691
693
|
## checked?
|
692
694
|
|
@@ -1466,6 +1468,23 @@ end
|
|
1466
1468
|
|
1467
1469
|
|
1468
1470
|
|
1471
|
+
## wait_for_timeout
|
1472
|
+
|
1473
|
+
```
|
1474
|
+
def wait_for_timeout(timeout)
|
1475
|
+
```
|
1476
|
+
|
1477
|
+
Waits for the given `timeout` in milliseconds.
|
1478
|
+
|
1479
|
+
Note that `page.waitForTimeout()` should only be used for debugging. Tests using the timer in production are going to be
|
1480
|
+
flaky. Use signals such as network events, selectors becoming visible and others instead.
|
1481
|
+
|
1482
|
+
```ruby
|
1483
|
+
page.wait_for_timeout(1000)
|
1484
|
+
```
|
1485
|
+
|
1486
|
+
Shortcut for main frame's [Frame#wait_for_timeout](./frame#wait_for_timeout).
|
1487
|
+
|
1469
1488
|
## wait_for_url
|
1470
1489
|
|
1471
1490
|
```
|
@@ -1489,6 +1508,27 @@ def expect_websocket(predicate: nil, timeout: nil, &block)
|
|
1489
1508
|
|
1490
1509
|
Performs action and waits for a new [WebSocket](./web_socket). If predicate is provided, it passes [WebSocket](./web_socket) value into the `predicate` function and waits for `predicate.call(web_socket)` to return a truthy value. Will throw an error if the page is closed before the WebSocket event is fired.
|
1491
1510
|
|
1511
|
+
## expect_worker
|
1512
|
+
|
1513
|
+
```
|
1514
|
+
def expect_worker(predicate: nil, timeout: nil, &block)
|
1515
|
+
```
|
1516
|
+
|
1517
|
+
Performs action and waits for a new [Worker](./worker). If predicate is provided, it passes [Worker](./worker) value into the `predicate`
|
1518
|
+
function and waits for `predicate(worker)` to return a truthy value. Will throw an error if the page is closed before
|
1519
|
+
the worker event is fired.
|
1520
|
+
|
1521
|
+
## workers
|
1522
|
+
|
1523
|
+
```
|
1524
|
+
def workers
|
1525
|
+
```
|
1526
|
+
|
1527
|
+
This method returns all of the dedicated [WebWorkers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API)
|
1528
|
+
associated with the page.
|
1529
|
+
|
1530
|
+
> NOTE: This does not contain ServiceWorkers
|
1531
|
+
|
1492
1532
|
## accessibility
|
1493
1533
|
|
1494
1534
|
## keyboard
|
@@ -28,9 +28,8 @@ The method returns `null` unless this request has failed, as reported by `reques
|
|
28
28
|
|
29
29
|
Example of logging of all the failed requests:
|
30
30
|
|
31
|
-
```
|
32
|
-
page.on("requestfailed",
|
33
|
-
|
31
|
+
```ruby
|
32
|
+
page.on("requestfailed", ->(request) { puts "#{request.url} #{request.failure}" })
|
34
33
|
```
|
35
34
|
|
36
35
|
|
@@ -108,18 +107,17 @@ construct the whole redirect chain by repeatedly calling `redirectedFrom()`.
|
|
108
107
|
|
109
108
|
For example, if the website `http://example.com` redirects to `https://example.com`:
|
110
109
|
|
111
|
-
```
|
112
|
-
response = page.goto("http://
|
113
|
-
|
114
|
-
|
110
|
+
```ruby
|
111
|
+
response = page.goto("http://github.com")
|
112
|
+
puts response.url # => "https://github.com"
|
113
|
+
puts response.request.redirected_from&.url # => "http://github.com"
|
115
114
|
```
|
116
115
|
|
117
116
|
If the website `https://google.com` has no redirects:
|
118
117
|
|
119
|
-
```
|
118
|
+
```ruby
|
120
119
|
response = page.goto("https://google.com")
|
121
|
-
|
122
|
-
|
120
|
+
puts response.request.redirected_from&.url # => nil
|
123
121
|
```
|
124
122
|
|
125
123
|
|
@@ -134,9 +132,8 @@ New request issued by the browser if the server responded with redirect.
|
|
134
132
|
|
135
133
|
This method is the opposite of [Request#redirected_from](./request#redirected_from):
|
136
134
|
|
137
|
-
```
|
138
|
-
|
139
|
-
|
135
|
+
```ruby
|
136
|
+
request.redirected_from.redirected_to # equals to request
|
140
137
|
```
|
141
138
|
|
142
139
|
|
@@ -169,12 +166,11 @@ Returns resource timing information for given request. Most of the timing values
|
|
169
166
|
`responseEnd` becomes available when request finishes. Find more information at
|
170
167
|
[Resource Timing API](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming).
|
171
168
|
|
172
|
-
```
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
169
|
+
```ruby
|
170
|
+
request = page.expect_event("requestfinished") do
|
171
|
+
page.goto("https://example.com")
|
172
|
+
end
|
173
|
+
puts request.timing
|
178
174
|
```
|
179
175
|
|
180
176
|
|
@@ -6,3 +6,11 @@ sidebar_position: 10
|
|
6
6
|
|
7
7
|
The Touchscreen class operates in main-frame CSS pixels relative to the top-left corner of the viewport. Methods on the
|
8
8
|
touchscreen can only be used in browser contexts that have been initialized with `hasTouch` set to true.
|
9
|
+
|
10
|
+
## tap_point
|
11
|
+
|
12
|
+
```
|
13
|
+
def tap_point(x, y)
|
14
|
+
```
|
15
|
+
|
16
|
+
Dispatches a `touchstart` and `touchend` event with a single touch at the position (`x`,`y`).
|
@@ -9,13 +9,14 @@ Playwright script runs.
|
|
9
9
|
|
10
10
|
Start with specifying the folder traces will be stored in:
|
11
11
|
|
12
|
-
```
|
13
|
-
browser
|
14
|
-
context =
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
```ruby
|
13
|
+
browser.new_page do |page|
|
14
|
+
context = page.context
|
15
|
+
|
16
|
+
context.tracing.start(screenshots: true, snapshots: true)
|
17
|
+
page.goto('https://playwright.dev')
|
18
|
+
context.tracing.stop(path: 'trace.zip')
|
19
|
+
end
|
19
20
|
```
|
20
21
|
|
21
22
|
|
@@ -28,12 +29,12 @@ def start(name: nil, screenshots: nil, snapshots: nil)
|
|
28
29
|
|
29
30
|
Start tracing.
|
30
31
|
|
31
|
-
```
|
32
|
-
context
|
33
|
-
page.goto("https://playwright.dev")
|
34
|
-
context.tracing.stop()
|
35
|
-
context.tracing.stop(path = "trace.zip")
|
32
|
+
```ruby
|
33
|
+
context = page.context
|
36
34
|
|
35
|
+
context.tracing.start(name: 'trace', screenshots: true, snapshots: true)
|
36
|
+
page.goto('https://playwright.dev')
|
37
|
+
context.tracing.stop(path: 'trace.zip')
|
37
38
|
```
|
38
39
|
|
39
40
|
|
@@ -8,17 +8,55 @@ The Worker class represents a [WebWorker](https://developer.mozilla.org/en-US/do
|
|
8
8
|
event is emitted on the page object to signal a worker creation. `close` event is emitted on the worker object when the
|
9
9
|
worker is gone.
|
10
10
|
|
11
|
-
```
|
12
|
-
def handle_worker(worker)
|
13
|
-
|
14
|
-
|
11
|
+
```ruby
|
12
|
+
def handle_worker(worker)
|
13
|
+
puts "worker created: #{worker.url}"
|
14
|
+
worker.once("close", -> (w) { puts "worker destroyed: #{w.url}" })
|
15
|
+
end
|
16
|
+
|
17
|
+
page.on('worker', method(:handle_worker))
|
18
|
+
|
19
|
+
puts "current workers:"
|
20
|
+
page.workers.each do |worker|
|
21
|
+
puts " #{worker.url}"
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
## evaluate
|
28
|
+
|
29
|
+
```
|
30
|
+
def evaluate(expression, arg: nil)
|
31
|
+
```
|
32
|
+
|
33
|
+
Returns the return value of `expression`.
|
34
|
+
|
35
|
+
If the function passed to the [Worker#evaluate](./worker#evaluate) returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then [Worker#evaluate](./worker#evaluate) would
|
36
|
+
wait for the promise to resolve and return its value.
|
15
37
|
|
16
|
-
|
38
|
+
If the function passed to the [Worker#evaluate](./worker#evaluate) returns a non-[Serializable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description) value, then
|
39
|
+
[Worker#evaluate](./worker#evaluate) returns `undefined`. Playwright also supports transferring some additional values that are
|
40
|
+
not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`.
|
17
41
|
|
18
|
-
|
19
|
-
for worker in page.workers:
|
20
|
-
print(" " + worker.url)
|
42
|
+
## evaluate_handle
|
21
43
|
|
22
44
|
```
|
45
|
+
def evaluate_handle(expression, arg: nil)
|
46
|
+
```
|
47
|
+
|
48
|
+
Returns the return value of `expression` as a [JSHandle](./js_handle).
|
49
|
+
|
50
|
+
The only difference between [Worker#evaluate](./worker#evaluate) and [Worker#evaluate_handle](./worker#evaluate_handle) is that
|
51
|
+
[Worker#evaluate_handle](./worker#evaluate_handle) returns [JSHandle](./js_handle).
|
52
|
+
|
53
|
+
If the function passed to the [Worker#evaluate_handle](./worker#evaluate_handle) returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then
|
54
|
+
[Worker#evaluate_handle](./worker#evaluate_handle) would wait for the promise to resolve and return its value.
|
55
|
+
|
56
|
+
## url
|
57
|
+
|
58
|
+
```
|
59
|
+
def url
|
60
|
+
```
|
23
61
|
|
24
62
|
|
@@ -10,7 +10,7 @@ This allow us to intermediate into automation, for example
|
|
10
10
|
* Authenticate with OAuth2 manually before automation
|
11
11
|
* Testing a page after some chrome extensions are installed manually
|
12
12
|
|
13
|
-
Keep in mind repeatedly that persistent browser context is NOT RECOMMENDED for most cases because it would bring many side effects.
|
13
|
+
Keep in mind repeatedly that persistent browser context is NOT RECOMMENDED for most cases because it would bring many side effects. Consider [reusing cookie and local storage](./use_storage_state) when you just want to keep authenticated across browser contexts.
|
14
14
|
|
15
15
|
## Pause automation for manual operation
|
16
16
|
|