playwright-ruby-client 0.8.1 → 1.14.beta3

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 (56) 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/download.md +97 -0
  5. data/documentation/docs/api/element_handle.md +28 -3
  6. data/documentation/docs/api/experimental/android.md +15 -2
  7. data/documentation/docs/api/frame.md +116 -114
  8. data/documentation/docs/api/locator.md +650 -0
  9. data/documentation/docs/api/mouse.md +3 -4
  10. data/documentation/docs/api/page.md +109 -19
  11. data/documentation/docs/api/request.md +15 -19
  12. data/documentation/docs/api/touchscreen.md +8 -0
  13. data/documentation/docs/api/tracing.md +13 -12
  14. data/documentation/docs/api/worker.md +37 -0
  15. data/documentation/docs/article/guides/inspector.md +31 -0
  16. data/documentation/docs/article/guides/playwright_on_alpine_linux.md +1 -1
  17. data/documentation/docs/article/guides/semi_automation.md +1 -1
  18. data/documentation/docs/include/api_coverage.md +70 -14
  19. data/lib/playwright.rb +0 -1
  20. data/lib/playwright/accessibility_impl.rb +50 -0
  21. data/lib/playwright/channel_owners/browser_context.rb +70 -0
  22. data/lib/playwright/channel_owners/frame.rb +79 -33
  23. data/lib/playwright/channel_owners/page.rb +133 -42
  24. data/lib/playwright/channel_owners/request.rb +8 -8
  25. data/lib/playwright/channel_owners/worker.rb +23 -0
  26. data/lib/playwright/{download.rb → download_impl.rb} +1 -1
  27. data/lib/playwright/javascript/expression.rb +5 -4
  28. data/lib/playwright/locator_impl.rb +314 -0
  29. data/lib/playwright/timeout_settings.rb +4 -4
  30. data/lib/playwright/touchscreen_impl.rb +7 -0
  31. data/lib/playwright/tracing_impl.rb +9 -8
  32. data/lib/playwright/version.rb +2 -2
  33. data/lib/playwright_api/accessibility.rb +1 -1
  34. data/lib/playwright_api/android.rb +21 -8
  35. data/lib/playwright_api/android_device.rb +6 -6
  36. data/lib/playwright_api/browser.rb +6 -6
  37. data/lib/playwright_api/browser_context.rb +16 -11
  38. data/lib/playwright_api/browser_type.rb +6 -6
  39. data/lib/playwright_api/cdp_session.rb +6 -6
  40. data/lib/playwright_api/console_message.rb +6 -6
  41. data/lib/playwright_api/dialog.rb +6 -6
  42. data/lib/playwright_api/download.rb +70 -0
  43. data/lib/playwright_api/element_handle.rb +34 -20
  44. data/lib/playwright_api/frame.rb +85 -53
  45. data/lib/playwright_api/js_handle.rb +6 -6
  46. data/lib/playwright_api/locator.rb +509 -0
  47. data/lib/playwright_api/page.rb +91 -57
  48. data/lib/playwright_api/playwright.rb +6 -6
  49. data/lib/playwright_api/request.rb +6 -6
  50. data/lib/playwright_api/response.rb +6 -6
  51. data/lib/playwright_api/route.rb +6 -6
  52. data/lib/playwright_api/selectors.rb +6 -6
  53. data/lib/playwright_api/touchscreen.rb +1 -1
  54. data/lib/playwright_api/web_socket.rb +6 -6
  55. data/lib/playwright_api/worker.rb +16 -6
  56. metadata +13 -6
@@ -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
 
@@ -104,6 +104,7 @@ def check(
104
104
  force: nil,
105
105
  noWaitAfter: nil,
106
106
  position: nil,
107
+ strict: nil,
107
108
  timeout: nil,
108
109
  trial: nil)
109
110
  ```
@@ -136,6 +137,7 @@ def click(
136
137
  modifiers: nil,
137
138
  noWaitAfter: nil,
138
139
  position: nil,
140
+ strict: nil,
139
141
  timeout: nil,
140
142
  trial: nil)
141
143
  ```
@@ -194,6 +196,7 @@ def dblclick(
194
196
  modifiers: nil,
195
197
  noWaitAfter: nil,
196
198
  position: nil,
199
+ strict: nil,
197
200
  timeout: nil,
198
201
  trial: nil)
199
202
  ```
@@ -217,7 +220,12 @@ Shortcut for main frame's [Frame#dblclick](./frame#dblclick).
217
220
  ## dispatch_event
218
221
 
219
222
  ```
220
- def dispatch_event(selector, type, eventInit: nil, timeout: nil)
223
+ def dispatch_event(
224
+ selector,
225
+ type,
226
+ eventInit: nil,
227
+ strict: nil,
228
+ timeout: nil)
221
229
  ```
222
230
 
223
231
  The snippet below dispatches the `click` event on the element. Regardless of the visibility state of the element,
@@ -261,6 +269,9 @@ def drag_and_drop(
261
269
  target,
262
270
  force: nil,
263
271
  noWaitAfter: nil,
272
+ sourcePosition: nil,
273
+ strict: nil,
274
+ targetPosition: nil,
264
275
  timeout: nil,
265
276
  trial: nil)
266
277
  ```
@@ -301,7 +312,7 @@ page.evaluate("matchMedia('(prefers-color-scheme: no-preference)').matches") # =
301
312
  ## eval_on_selector
302
313
 
303
314
  ```
304
- def eval_on_selector(selector, expression, arg: nil)
315
+ def eval_on_selector(selector, expression, arg: nil, strict: nil)
305
316
  ```
306
317
 
307
318
  The method finds an element matching the specified selector within the page and passes it as a first argument to
@@ -518,6 +529,7 @@ def fill(
518
529
  value,
519
530
  force: nil,
520
531
  noWaitAfter: nil,
532
+ strict: nil,
521
533
  timeout: nil)
522
534
  ```
523
535
 
@@ -537,7 +549,7 @@ Shortcut for main frame's [Frame#fill](./frame#fill).
537
549
  ## focus
538
550
 
539
551
  ```
540
- def focus(selector, timeout: nil)
552
+ def focus(selector, strict: nil, timeout: nil)
541
553
  ```
542
554
 
543
555
  This method fetches an element with `selector` and focuses it. If there's no element matching `selector`, the method
@@ -574,7 +586,7 @@ An array of all frames attached to the page.
574
586
  ## get_attribute
575
587
 
576
588
  ```
577
- def get_attribute(selector, name, timeout: nil)
589
+ def get_attribute(selector, name, strict: nil, timeout: nil)
578
590
  ```
579
591
 
580
592
  Returns element attribute value.
@@ -636,6 +648,7 @@ def hover(
636
648
  force: nil,
637
649
  modifiers: nil,
638
650
  position: nil,
651
+ strict: nil,
639
652
  timeout: nil,
640
653
  trial: nil)
641
654
  ```
@@ -656,7 +669,7 @@ Shortcut for main frame's [Frame#hover](./frame#hover).
656
669
  ## inner_html
657
670
 
658
671
  ```
659
- def inner_html(selector, timeout: nil)
672
+ def inner_html(selector, strict: nil, timeout: nil)
660
673
  ```
661
674
 
662
675
  Returns `element.innerHTML`.
@@ -664,7 +677,7 @@ Returns `element.innerHTML`.
664
677
  ## inner_text
665
678
 
666
679
  ```
667
- def inner_text(selector, timeout: nil)
680
+ def inner_text(selector, strict: nil, timeout: nil)
668
681
  ```
669
682
 
670
683
  Returns `element.innerText`.
@@ -672,15 +685,15 @@ Returns `element.innerText`.
672
685
  ## input_value
673
686
 
674
687
  ```
675
- def input_value(selector, timeout: nil)
688
+ def input_value(selector, strict: nil, timeout: nil)
676
689
  ```
677
690
 
678
- 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.
679
692
 
680
693
  ## checked?
681
694
 
682
695
  ```
683
- def checked?(selector, timeout: nil)
696
+ def checked?(selector, strict: nil, timeout: nil)
684
697
  ```
685
698
 
686
699
  Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
@@ -696,7 +709,7 @@ Indicates that the page has been closed.
696
709
  ## disabled?
697
710
 
698
711
  ```
699
- def disabled?(selector, timeout: nil)
712
+ def disabled?(selector, strict: nil, timeout: nil)
700
713
  ```
701
714
 
702
715
  Returns whether the element is disabled, the opposite of [enabled](https://playwright.dev/python/docs/actionability).
@@ -704,7 +717,7 @@ Returns whether the element is disabled, the opposite of [enabled](https://playw
704
717
  ## editable?
705
718
 
706
719
  ```
707
- def editable?(selector, timeout: nil)
720
+ def editable?(selector, strict: nil, timeout: nil)
708
721
  ```
709
722
 
710
723
  Returns whether the element is [editable](https://playwright.dev/python/docs/actionability).
@@ -712,7 +725,7 @@ Returns whether the element is [editable](https://playwright.dev/python/docs/act
712
725
  ## enabled?
713
726
 
714
727
  ```
715
- def enabled?(selector, timeout: nil)
728
+ def enabled?(selector, strict: nil, timeout: nil)
716
729
  ```
717
730
 
718
731
  Returns whether the element is [enabled](https://playwright.dev/python/docs/actionability).
@@ -720,7 +733,7 @@ Returns whether the element is [enabled](https://playwright.dev/python/docs/acti
720
733
  ## hidden?
721
734
 
722
735
  ```
723
- def hidden?(selector, timeout: nil)
736
+ def hidden?(selector, strict: nil, timeout: nil)
724
737
  ```
725
738
 
726
739
  Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/python/docs/actionability). `selector` that does not
@@ -729,12 +742,26 @@ match any elements is considered hidden.
729
742
  ## visible?
730
743
 
731
744
  ```
732
- def visible?(selector, timeout: nil)
745
+ def visible?(selector, strict: nil, timeout: nil)
733
746
  ```
734
747
 
735
748
  Returns whether the element is [visible](https://playwright.dev/python/docs/actionability). `selector` that does not match any elements is
736
749
  considered not visible.
737
750
 
751
+ ## locator
752
+
753
+ ```
754
+ def locator(selector)
755
+ ```
756
+
757
+ The method returns an element locator that can be used to perform actions on the page. Locator is resolved to the
758
+ element immediately before performing an action, so a series of actions on the same locator can in fact be performed on
759
+ different DOM elements. That would happen if the DOM structure between those actions has changed.
760
+
761
+ Note that locator always implies visibility, so it will always be locating visible elements.
762
+
763
+ Shortcut for main frame's [Frame#locator](./frame#locator).
764
+
738
765
  ## main_frame
739
766
 
740
767
  ```
@@ -751,6 +778,21 @@ def opener
751
778
 
752
779
  Returns the opener for popup pages and `null` for others. If the opener has been closed already the returns `null`.
753
780
 
781
+ ## pause
782
+
783
+ ```
784
+ def pause
785
+ ```
786
+
787
+ Pauses script execution. Playwright will stop executing the script and wait for the user to either press 'Resume' button
788
+ in the page overlay or to call `playwright.resume()` in the DevTools console.
789
+
790
+ User can inspect selectors or perform manual steps while paused. Resume will continue running the original script from
791
+ the place it was paused.
792
+
793
+ > NOTE: This method requires Playwright to be started in a headed mode, with a falsy `headless` value in the
794
+ [BrowserType#launch](./browser_type#launch).
795
+
754
796
  ## pdf
755
797
 
756
798
  ```
@@ -824,6 +866,7 @@ def press(
824
866
  key,
825
867
  delay: nil,
826
868
  noWaitAfter: nil,
869
+ strict: nil,
827
870
  timeout: nil)
828
871
  ```
829
872
 
@@ -861,7 +904,7 @@ page.screenshot(path: "o.png")
861
904
  ## query_selector
862
905
 
863
906
  ```
864
- def query_selector(selector)
907
+ def query_selector(selector, strict: nil)
865
908
  ```
866
909
 
867
910
  The method finds an element matching the specified selector within the page. If no elements match the selector, the
@@ -963,6 +1006,7 @@ def select_option(
963
1006
  label: nil,
964
1007
  force: nil,
965
1008
  noWaitAfter: nil,
1009
+ strict: nil,
966
1010
  timeout: nil)
967
1011
  ```
968
1012
 
@@ -1041,7 +1085,12 @@ The extra HTTP headers will be sent with every request the page initiates.
1041
1085
  ## set_input_files
1042
1086
 
1043
1087
  ```
1044
- def set_input_files(selector, files, noWaitAfter: nil, timeout: nil)
1088
+ def set_input_files(
1089
+ selector,
1090
+ files,
1091
+ noWaitAfter: nil,
1092
+ strict: nil,
1093
+ timeout: nil)
1045
1094
  ```
1046
1095
 
1047
1096
  This method expects `selector` to point to an
@@ -1079,6 +1128,7 @@ def tap_point(
1079
1128
  modifiers: nil,
1080
1129
  noWaitAfter: nil,
1081
1130
  position: nil,
1131
+ strict: nil,
1082
1132
  timeout: nil,
1083
1133
  trial: nil)
1084
1134
  ```
@@ -1101,7 +1151,7 @@ Shortcut for main frame's [Frame#tap_point](./frame#tap_point).
1101
1151
  ## text_content
1102
1152
 
1103
1153
  ```
1104
- def text_content(selector, timeout: nil)
1154
+ def text_content(selector, strict: nil, timeout: nil)
1105
1155
  ```
1106
1156
 
1107
1157
  Returns `element.textContent`.
@@ -1122,6 +1172,7 @@ def type(
1122
1172
  text,
1123
1173
  delay: nil,
1124
1174
  noWaitAfter: nil,
1175
+ strict: nil,
1125
1176
  timeout: nil)
1126
1177
  ```
1127
1178
 
@@ -1145,6 +1196,7 @@ def uncheck(
1145
1196
  force: nil,
1146
1197
  noWaitAfter: nil,
1147
1198
  position: nil,
1199
+ strict: nil,
1148
1200
  timeout: nil,
1149
1201
  trial: nil)
1150
1202
  ```
@@ -1213,7 +1265,7 @@ throw an error if the page is closed before the [`event: Page.console`] event is
1213
1265
  def expect_download(predicate: nil, timeout: nil, &block)
1214
1266
  ```
1215
1267
 
1216
- Performs action and waits for a new `Download`. If predicate is provided, it passes `Download` value into the
1268
+ Performs action and waits for a new [Download](./download). If predicate is provided, it passes [Download](./download) value into the
1217
1269
  `predicate` function and waits for `predicate(download)` to return a truthy value. Will throw an error if the page is
1218
1270
  closed before the download event is fired.
1219
1271
 
@@ -1394,7 +1446,7 @@ puts response.body
1394
1446
  ## wait_for_selector
1395
1447
 
1396
1448
  ```
1397
- def wait_for_selector(selector, state: nil, timeout: nil)
1449
+ def wait_for_selector(selector, state: nil, strict: nil, timeout: nil)
1398
1450
  ```
1399
1451
 
1400
1452
  Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
@@ -1416,6 +1468,23 @@ end
1416
1468
 
1417
1469
 
1418
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
+
1419
1488
  ## wait_for_url
1420
1489
 
1421
1490
  ```
@@ -1439,6 +1508,27 @@ def expect_websocket(predicate: nil, timeout: nil, &block)
1439
1508
 
1440
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.
1441
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
+
1442
1532
  ## accessibility
1443
1533
 
1444
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