playwright-ruby-client 0.8.0 → 1.14.beta2

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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/docs/api/accessibility.md +52 -1
  3. data/documentation/docs/api/browser.md +8 -2
  4. data/documentation/docs/api/browser_context.md +28 -0
  5. data/documentation/docs/api/browser_type.md +1 -0
  6. data/documentation/docs/api/download.md +97 -0
  7. data/documentation/docs/api/element_handle.md +28 -3
  8. data/documentation/docs/api/experimental/android_device.md +1 -0
  9. data/documentation/docs/api/frame.md +78 -18
  10. data/documentation/docs/api/keyboard.md +11 -20
  11. data/documentation/docs/api/locator.md +650 -0
  12. data/documentation/docs/api/page.md +124 -20
  13. data/documentation/docs/api/touchscreen.md +8 -0
  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 +91 -0
  17. data/documentation/docs/article/guides/semi_automation.md +5 -1
  18. data/documentation/docs/include/api_coverage.md +72 -15
  19. data/lib/playwright.rb +0 -1
  20. data/lib/playwright/accessibility_impl.rb +50 -0
  21. data/lib/playwright/channel_owners/artifact.rb +4 -0
  22. data/lib/playwright/channel_owners/browser_context.rb +77 -3
  23. data/lib/playwright/channel_owners/frame.rb +101 -35
  24. data/lib/playwright/channel_owners/page.rb +157 -56
  25. data/lib/playwright/channel_owners/worker.rb +23 -0
  26. data/lib/playwright/{download.rb → download_impl.rb} +5 -1
  27. data/lib/playwright/javascript/expression.rb +5 -4
  28. data/lib/playwright/locator_impl.rb +314 -0
  29. data/lib/playwright/route_handler_entry.rb +3 -2
  30. data/lib/playwright/timeout_settings.rb +4 -4
  31. data/lib/playwright/touchscreen_impl.rb +7 -0
  32. data/lib/playwright/tracing_impl.rb +9 -8
  33. data/lib/playwright/url_matcher.rb +12 -2
  34. data/lib/playwright/version.rb +2 -2
  35. data/lib/playwright_api/accessibility.rb +1 -1
  36. data/lib/playwright_api/android.rb +6 -6
  37. data/lib/playwright_api/android_device.rb +8 -7
  38. data/lib/playwright_api/browser.rb +16 -10
  39. data/lib/playwright_api/browser_context.rb +16 -11
  40. data/lib/playwright_api/browser_type.rb +8 -7
  41. data/lib/playwright_api/cdp_session.rb +6 -6
  42. data/lib/playwright_api/console_message.rb +6 -6
  43. data/lib/playwright_api/dialog.rb +6 -6
  44. data/lib/playwright_api/download.rb +70 -0
  45. data/lib/playwright_api/element_handle.rb +34 -20
  46. data/lib/playwright_api/frame.rb +94 -52
  47. data/lib/playwright_api/js_handle.rb +6 -6
  48. data/lib/playwright_api/locator.rb +509 -0
  49. data/lib/playwright_api/page.rb +101 -57
  50. data/lib/playwright_api/playwright.rb +6 -6
  51. data/lib/playwright_api/request.rb +6 -6
  52. data/lib/playwright_api/response.rb +6 -6
  53. data/lib/playwright_api/route.rb +6 -11
  54. data/lib/playwright_api/selectors.rb +6 -6
  55. data/lib/playwright_api/touchscreen.rb +1 -1
  56. data/lib/playwright_api/web_socket.rb +6 -6
  57. data/lib/playwright_api/worker.rb +16 -6
  58. metadata +14 -6
@@ -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,
@@ -253,6 +261,23 @@ page.dispatch_event("#source", "dragstart", eventInit: { dataTransfer: data_tran
253
261
 
254
262
 
255
263
 
264
+ ## drag_and_drop
265
+
266
+ ```
267
+ def drag_and_drop(
268
+ source,
269
+ target,
270
+ force: nil,
271
+ noWaitAfter: nil,
272
+ sourcePosition: nil,
273
+ strict: nil,
274
+ targetPosition: nil,
275
+ timeout: nil,
276
+ trial: nil)
277
+ ```
278
+
279
+
280
+
256
281
  ## emulate_media
257
282
 
258
283
  ```
@@ -287,7 +312,7 @@ page.evaluate("matchMedia('(prefers-color-scheme: no-preference)').matches") # =
287
312
  ## eval_on_selector
288
313
 
289
314
  ```
290
- def eval_on_selector(selector, expression, arg: nil)
315
+ def eval_on_selector(selector, expression, arg: nil, strict: nil)
291
316
  ```
292
317
 
293
318
  The method finds an element matching the specified selector within the page and passes it as a first argument to
@@ -504,6 +529,7 @@ def fill(
504
529
  value,
505
530
  force: nil,
506
531
  noWaitAfter: nil,
532
+ strict: nil,
507
533
  timeout: nil)
508
534
  ```
509
535
 
@@ -523,7 +549,7 @@ Shortcut for main frame's [Frame#fill](./frame#fill).
523
549
  ## focus
524
550
 
525
551
  ```
526
- def focus(selector, timeout: nil)
552
+ def focus(selector, strict: nil, timeout: nil)
527
553
  ```
528
554
 
529
555
  This method fetches an element with `selector` and focuses it. If there's no element matching `selector`, the method
@@ -560,7 +586,7 @@ An array of all frames attached to the page.
560
586
  ## get_attribute
561
587
 
562
588
  ```
563
- def get_attribute(selector, name, timeout: nil)
589
+ def get_attribute(selector, name, strict: nil, timeout: nil)
564
590
  ```
565
591
 
566
592
  Returns element attribute value.
@@ -622,6 +648,7 @@ def hover(
622
648
  force: nil,
623
649
  modifiers: nil,
624
650
  position: nil,
651
+ strict: nil,
625
652
  timeout: nil,
626
653
  trial: nil)
627
654
  ```
@@ -642,7 +669,7 @@ Shortcut for main frame's [Frame#hover](./frame#hover).
642
669
  ## inner_html
643
670
 
644
671
  ```
645
- def inner_html(selector, timeout: nil)
672
+ def inner_html(selector, strict: nil, timeout: nil)
646
673
  ```
647
674
 
648
675
  Returns `element.innerHTML`.
@@ -650,7 +677,7 @@ Returns `element.innerHTML`.
650
677
  ## inner_text
651
678
 
652
679
  ```
653
- def inner_text(selector, timeout: nil)
680
+ def inner_text(selector, strict: nil, timeout: nil)
654
681
  ```
655
682
 
656
683
  Returns `element.innerText`.
@@ -658,15 +685,15 @@ Returns `element.innerText`.
658
685
  ## input_value
659
686
 
660
687
  ```
661
- def input_value(selector, timeout: nil)
688
+ def input_value(selector, strict: nil, timeout: nil)
662
689
  ```
663
690
 
664
- 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.
665
692
 
666
693
  ## checked?
667
694
 
668
695
  ```
669
- def checked?(selector, timeout: nil)
696
+ def checked?(selector, strict: nil, timeout: nil)
670
697
  ```
671
698
 
672
699
  Returns whether the element is checked. Throws if the element is not a checkbox or radio input.
@@ -682,7 +709,7 @@ Indicates that the page has been closed.
682
709
  ## disabled?
683
710
 
684
711
  ```
685
- def disabled?(selector, timeout: nil)
712
+ def disabled?(selector, strict: nil, timeout: nil)
686
713
  ```
687
714
 
688
715
  Returns whether the element is disabled, the opposite of [enabled](https://playwright.dev/python/docs/actionability).
@@ -690,7 +717,7 @@ Returns whether the element is disabled, the opposite of [enabled](https://playw
690
717
  ## editable?
691
718
 
692
719
  ```
693
- def editable?(selector, timeout: nil)
720
+ def editable?(selector, strict: nil, timeout: nil)
694
721
  ```
695
722
 
696
723
  Returns whether the element is [editable](https://playwright.dev/python/docs/actionability).
@@ -698,7 +725,7 @@ Returns whether the element is [editable](https://playwright.dev/python/docs/act
698
725
  ## enabled?
699
726
 
700
727
  ```
701
- def enabled?(selector, timeout: nil)
728
+ def enabled?(selector, strict: nil, timeout: nil)
702
729
  ```
703
730
 
704
731
  Returns whether the element is [enabled](https://playwright.dev/python/docs/actionability).
@@ -706,7 +733,7 @@ Returns whether the element is [enabled](https://playwright.dev/python/docs/acti
706
733
  ## hidden?
707
734
 
708
735
  ```
709
- def hidden?(selector, timeout: nil)
736
+ def hidden?(selector, strict: nil, timeout: nil)
710
737
  ```
711
738
 
712
739
  Returns whether the element is hidden, the opposite of [visible](https://playwright.dev/python/docs/actionability). `selector` that does not
@@ -715,12 +742,26 @@ match any elements is considered hidden.
715
742
  ## visible?
716
743
 
717
744
  ```
718
- def visible?(selector, timeout: nil)
745
+ def visible?(selector, strict: nil, timeout: nil)
719
746
  ```
720
747
 
721
748
  Returns whether the element is [visible](https://playwright.dev/python/docs/actionability). `selector` that does not match any elements is
722
749
  considered not visible.
723
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
+
724
765
  ## main_frame
725
766
 
726
767
  ```
@@ -737,6 +778,21 @@ def opener
737
778
 
738
779
  Returns the opener for popup pages and `null` for others. If the opener has been closed already the returns `null`.
739
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
+
740
796
  ## pdf
741
797
 
742
798
  ```
@@ -810,6 +866,7 @@ def press(
810
866
  key,
811
867
  delay: nil,
812
868
  noWaitAfter: nil,
869
+ strict: nil,
813
870
  timeout: nil)
814
871
  ```
815
872
 
@@ -847,7 +904,7 @@ page.screenshot(path: "o.png")
847
904
  ## query_selector
848
905
 
849
906
  ```
850
- def query_selector(selector)
907
+ def query_selector(selector, strict: nil)
851
908
  ```
852
909
 
853
910
  The method finds an element matching the specified selector within the page. If no elements match the selector, the
@@ -949,6 +1006,7 @@ def select_option(
949
1006
  label: nil,
950
1007
  force: nil,
951
1008
  noWaitAfter: nil,
1009
+ strict: nil,
952
1010
  timeout: nil)
953
1011
  ```
954
1012
 
@@ -1027,7 +1085,12 @@ The extra HTTP headers will be sent with every request the page initiates.
1027
1085
  ## set_input_files
1028
1086
 
1029
1087
  ```
1030
- 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)
1031
1094
  ```
1032
1095
 
1033
1096
  This method expects `selector` to point to an
@@ -1065,6 +1128,7 @@ def tap_point(
1065
1128
  modifiers: nil,
1066
1129
  noWaitAfter: nil,
1067
1130
  position: nil,
1131
+ strict: nil,
1068
1132
  timeout: nil,
1069
1133
  trial: nil)
1070
1134
  ```
@@ -1087,7 +1151,7 @@ Shortcut for main frame's [Frame#tap_point](./frame#tap_point).
1087
1151
  ## text_content
1088
1152
 
1089
1153
  ```
1090
- def text_content(selector, timeout: nil)
1154
+ def text_content(selector, strict: nil, timeout: nil)
1091
1155
  ```
1092
1156
 
1093
1157
  Returns `element.textContent`.
@@ -1108,6 +1172,7 @@ def type(
1108
1172
  text,
1109
1173
  delay: nil,
1110
1174
  noWaitAfter: nil,
1175
+ strict: nil,
1111
1176
  timeout: nil)
1112
1177
  ```
1113
1178
 
@@ -1131,6 +1196,7 @@ def uncheck(
1131
1196
  force: nil,
1132
1197
  noWaitAfter: nil,
1133
1198
  position: nil,
1199
+ strict: nil,
1134
1200
  timeout: nil,
1135
1201
  trial: nil)
1136
1202
  ```
@@ -1199,7 +1265,7 @@ throw an error if the page is closed before the [`event: Page.console`] event is
1199
1265
  def expect_download(predicate: nil, timeout: nil, &block)
1200
1266
  ```
1201
1267
 
1202
- 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
1203
1269
  `predicate` function and waits for `predicate(download)` to return a truthy value. Will throw an error if the page is
1204
1270
  closed before the download event is fired.
1205
1271
 
@@ -1320,7 +1386,7 @@ Performs action and waits for a popup [Page](./page). If predicate is provided,
1320
1386
  def expect_request(urlOrPredicate, timeout: nil, &block)
1321
1387
  ```
1322
1388
 
1323
- Waits for the matching request and returns it. See [waiting for event](https://playwright.dev/python/docs/events) for more details
1389
+ Waits for the matching request and returns it. See [waiting for event](https://playwright.dev/python/docs/events) for more details
1324
1390
  about events.
1325
1391
 
1326
1392
  ```ruby
@@ -1380,7 +1446,7 @@ puts response.body
1380
1446
  ## wait_for_selector
1381
1447
 
1382
1448
  ```
1383
- def wait_for_selector(selector, state: nil, timeout: nil)
1449
+ def wait_for_selector(selector, state: nil, strict: nil, timeout: nil)
1384
1450
  ```
1385
1451
 
1386
1452
  Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
@@ -1402,6 +1468,23 @@ end
1402
1468
 
1403
1469
 
1404
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
+
1405
1488
  ## wait_for_url
1406
1489
 
1407
1490
  ```
@@ -1425,6 +1508,27 @@ def expect_websocket(predicate: nil, timeout: nil, &block)
1425
1508
 
1426
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.
1427
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
+
1428
1532
  ## accessibility
1429
1533
 
1430
1534
  ## keyboard
@@ -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`).
@@ -22,3 +22,40 @@ for worker in page.workers:
22
22
  ```
23
23
 
24
24
 
25
+
26
+ ## evaluate
27
+
28
+ ```
29
+ def evaluate(expression, arg: nil)
30
+ ```
31
+
32
+ Returns the return value of `expression`.
33
+
34
+ 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
35
+ wait for the promise to resolve and return its value.
36
+
37
+ 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
38
+ [Worker#evaluate](./worker#evaluate) returns `undefined`. Playwright also supports transferring some additional values that are
39
+ not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`.
40
+
41
+ ## evaluate_handle
42
+
43
+ ```
44
+ def evaluate_handle(expression, arg: nil)
45
+ ```
46
+
47
+ Returns the return value of `expression` as a [JSHandle](./js_handle).
48
+
49
+ The only difference between [Worker#evaluate](./worker#evaluate) and [Worker#evaluate_handle](./worker#evaluate_handle) is that
50
+ [Worker#evaluate_handle](./worker#evaluate_handle) returns [JSHandle](./js_handle).
51
+
52
+ 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
53
+ [Worker#evaluate_handle](./worker#evaluate_handle) would wait for the promise to resolve and return its value.
54
+
55
+ ## url
56
+
57
+ ```
58
+ def url
59
+ ```
60
+
61
+
@@ -0,0 +1,31 @@
1
+ ---
2
+ sidebar_position: 6
3
+ ---
4
+
5
+ # Playwright inspector
6
+
7
+ Playwright provides an useful inspector.
8
+ https://playwright.dev/docs/inspector/
9
+
10
+ ## Overview
11
+
12
+ ```ruby {4,8}
13
+ playwright.chromium.launch(headless: false) do |browser|
14
+ browser.new_context do |context|
15
+ # This method call should be put just after creating BrowserContext.
16
+ context.enable_debug_console!
17
+
18
+ page = context.new_pagè
19
+ page.goto('http://example.com/')
20
+ page.pause
21
+ end
22
+ end
23
+ ```
24
+
25
+ `page.pause` requires Playwright debug session, and it can be enabled by calling `BrowserContext#enable_debug_console!` in advance.
26
+
27
+ Note that since Ruby is not officially supported in Playwright, many limitations exist. We CANNOT
28
+
29
+ * Launch inspector via `PWDEBUG=1`
30
+ * Debug without inspector UI (`PWDEBUG=console` is not working well)
31
+ * Show Ruby code in inspector