playwright-ruby-client 0.9.0 → 1.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/docs/api/accessibility.md +51 -1
  3. data/documentation/docs/api/browser_context.md +28 -0
  4. data/documentation/docs/api/element_handle.md +4 -5
  5. data/documentation/docs/api/experimental/android.md +15 -2
  6. data/documentation/docs/api/frame.md +66 -97
  7. data/documentation/docs/api/locator.md +28 -41
  8. data/documentation/docs/api/mouse.md +3 -4
  9. data/documentation/docs/api/page.md +41 -1
  10. data/documentation/docs/api/request.md +15 -19
  11. data/documentation/docs/api/touchscreen.md +8 -0
  12. data/documentation/docs/api/tracing.md +13 -12
  13. data/documentation/docs/api/worker.md +46 -8
  14. data/documentation/docs/article/guides/inspector.md +1 -1
  15. data/documentation/docs/article/guides/playwright_on_alpine_linux.md +1 -1
  16. data/documentation/docs/article/guides/semi_automation.md +1 -1
  17. data/documentation/docs/article/guides/use_storage_state.md +78 -0
  18. data/documentation/docs/include/api_coverage.md +13 -13
  19. data/lib/playwright/accessibility_impl.rb +50 -0
  20. data/lib/playwright/channel_owners/browser_context.rb +45 -0
  21. data/lib/playwright/channel_owners/frame.rb +9 -0
  22. data/lib/playwright/channel_owners/page.rb +31 -2
  23. data/lib/playwright/channel_owners/request.rb +8 -8
  24. data/lib/playwright/channel_owners/worker.rb +23 -0
  25. data/lib/playwright/locator_impl.rb +3 -3
  26. data/lib/playwright/touchscreen_impl.rb +7 -0
  27. data/lib/playwright/tracing_impl.rb +9 -8
  28. data/lib/playwright/version.rb +1 -1
  29. data/lib/playwright_api/accessibility.rb +1 -1
  30. data/lib/playwright_api/android.rb +15 -2
  31. data/lib/playwright_api/browser_context.rb +8 -8
  32. data/lib/playwright_api/element_handle.rb +1 -1
  33. data/lib/playwright_api/frame.rb +5 -3
  34. data/lib/playwright_api/locator.rb +3 -3
  35. data/lib/playwright_api/page.rb +8 -6
  36. data/lib/playwright_api/touchscreen.rb +1 -1
  37. data/lib/playwright_api/worker.rb +13 -3
  38. 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
- ```python sync title=example_9f72eed0cd4b2405e6a115b812b36ff2624e889f9086925c47665333a7edabbc.py
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
- ```python sync title=example_4d635e937854fa2ee56b7c43151ded535940f0bbafc00cf48e8214bed86715eb.py
76
- box = element.bounding_box()
77
- page.mouse.click(box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
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
- ```python sync title=example_8d92b900a98c237ffdcb102ddc35660e37101bde7d107dc64d97a7edeed62a43.py
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
- ```python sync title=example_e369442a3ff291ab476da408ef63a63dacf47984dc766ff7189d82008ae2848b.py
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("#source", "dragstart", {"dataTransfer": data_transfer})
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
- ```python sync title=example_df39b3df921f81e7cfb71cd873b76a5e91e46b4aa41e1f164128cb322aa38305.py
240
- tweets = page.locator(".tweet .retweets")
241
- assert tweets.evaluate("node => node.innerText") == "10 retweets"
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 [`Locator.evaluateAll`] would wait for the promise to resolve and return its
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
- ```python sync title=example_32478e941514ed28b6ac221e6d54b55cf117038ecac6f4191db676480ab68d44.py
259
+ ```ruby
262
260
  elements = page.locator("div")
263
- div_counts = elements("(divs, min) => divs.length >= min", 10)
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
- ```python sync title=example_2825b0a50091868d1ce3ea0752d94ba32d826d504c1ac6842522796ca405913e.py
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="blue")
522
+ element.select_option(label: "blue")
526
523
  # multiple selection
527
- element.select_option(value=["red", "green", "blue"])
528
-
524
+ element.select_option(value: ["red", "green", "blue"])
529
525
  ```
530
526
 
531
- ```python sync title=example_3aaff4985dc38e64fad34696c88a6a68a633e26aabee6fc749125f3ee1784e34.py
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="blue", { index: 2 }, "red")
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
- ```python sync title=example_fa1712c0b6ceb96fcaa74790d33f2c2eefe2bd1f06e61b78e0bb84a6f22c7961.py
599
+ ```ruby
611
600
  element.type("hello") # types instantly
612
- element.type("world", delay=100) # types slower, like a user
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
- ```python sync title=example_adefe90dee78708d4375c20f081f12f2b71f2becb472a2e0d4fdc8cc49c37809.py
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
- ```python sync title=example_ba01da1f358cafb4c22b792488ff2f3de4dbd82d4ee1cc4050e3f0c24a2bd7dd.py
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
- ```py title=example_5f3f4534ab17f584cfd41ca38448ce7de9490b6588e29e73116ede3cb15a25a5.py
32
- page.on("requestfailed", lambda request: print(request.url + " " + request.failure))
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
- ```python sync title=example_89568fc86bf623eef37b68c6659b1a8524647c8365bb32a7a8af63bd86111075.py
112
- response = page.goto("http://example.com")
113
- print(response.request.redirected_from.url) # "http://example.com"
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
- ```python sync title=example_6d7b3fbf8d69dbe639b71fedc5a8977777fca29dfb16d38012bb07c496342472.py
118
+ ```ruby
120
119
  response = page.goto("https://google.com")
121
- print(response.request.redirected_from) # None
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
- ```py title=example_922623f4033e7ec2158787e54a8554655f7e1e20a024e4bf4f69337f781ab88a.py
138
- assert request.redirected_from.redirected_to == request
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
- ```python sync title=example_e2a297fe95fd0699b6a856c3be2f28106daa2615c0f4d6084f5012682a619d20.py
173
- with page.expect_event("requestfinished") as request_info:
174
- page.goto("http://example.com")
175
- request = request_info.value
176
- print(request.timing)
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
- ```python sync title=example_a767dfb400d98aef50f2767b94171d23474ea1ac1cf9b4d75d412936208e652d.py
13
- browser = chromium.launch()
14
- context = browser.new_context()
15
- context.tracing.start(screenshots=True, snapshots=True)
16
- page.goto("https://playwright.dev")
17
- context.tracing.stop(path = "trace.zip")
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
- ```python sync title=example_e611abc8b1066118d0c87eae1bbbb08df655f36d50a94402fc56b8713150997b.py
32
- context.tracing.start(name="trace", screenshots=True, snapshots=True)
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
- ```py title=example_29716fdd4471a97923a64eebeee96330ab508226a496ae8fd13f12eb07d55ee6.py
12
- def handle_worker(worker):
13
- print("worker created: " + worker.url)
14
- worker.on("close", lambda: print("worker destroyed: " + worker.url))
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
- page.on('worker', handle_worker)
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
- print("current workers:")
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
 
@@ -1,5 +1,5 @@
1
1
  ---
2
- sidebar_position: 6
2
+ sidebar_position: 7
3
3
  ---
4
4
 
5
5
  # Playwright inspector
@@ -1,5 +1,5 @@
1
1
  ---
2
- sidebar_position: 7
2
+ sidebar_position: 8
3
3
  ---
4
4
 
5
5
  # Playwright on Alpine Linux
@@ -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