playwright-ruby-client 0.6.1 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/docs/api/browser.md +4 -1
  3. data/documentation/docs/api/browser_context.md +3 -4
  4. data/documentation/docs/api/browser_type.md +54 -1
  5. data/documentation/docs/api/dialog.md +15 -18
  6. data/documentation/docs/api/element_handle.md +28 -50
  7. data/documentation/docs/api/experimental/android.md +3 -2
  8. data/documentation/docs/api/experimental/android_device.md +1 -0
  9. data/documentation/docs/api/file_chooser.md +4 -5
  10. data/documentation/docs/api/frame.md +3 -4
  11. data/documentation/docs/api/js_handle.md +11 -14
  12. data/documentation/docs/api/page.md +163 -230
  13. data/documentation/docs/api/route.md +20 -21
  14. data/documentation/docs/api/tracing.md +8 -15
  15. data/documentation/docs/api/web_socket.md +1 -1
  16. data/documentation/docs/api/worker.md +18 -1
  17. data/documentation/docs/article/guides/rails_integration.md +156 -2
  18. data/documentation/docs/article/guides/recording_video.md +79 -0
  19. data/documentation/docs/include/api_coverage.md +5 -4
  20. data/documentation/package.json +1 -1
  21. data/documentation/yarn.lock +478 -498
  22. data/lib/playwright/channel_owners/binding_call.rb +1 -1
  23. data/lib/playwright/channel_owners/browser.rb +15 -27
  24. data/lib/playwright/channel_owners/browser_context.rb +13 -5
  25. data/lib/playwright/channel_owners/browser_type.rb +23 -8
  26. data/lib/playwright/channel_owners/page.rb +8 -7
  27. data/lib/playwright/channel_owners/web_socket.rb +4 -0
  28. data/lib/playwright/channel_owners/worker.rb +4 -0
  29. data/lib/playwright/playwright_api.rb +16 -1
  30. data/lib/playwright/tracing_impl.rb +9 -9
  31. data/lib/playwright/version.rb +1 -1
  32. data/lib/playwright_api/android.rb +9 -8
  33. data/lib/playwright_api/android_device.rb +8 -7
  34. data/lib/playwright_api/browser.rb +12 -9
  35. data/lib/playwright_api/browser_context.rb +13 -14
  36. data/lib/playwright_api/browser_type.rb +13 -11
  37. data/lib/playwright_api/console_message.rb +6 -6
  38. data/lib/playwright_api/dialog.rb +6 -6
  39. data/lib/playwright_api/element_handle.rb +6 -6
  40. data/lib/playwright_api/frame.rb +6 -6
  41. data/lib/playwright_api/js_handle.rb +6 -6
  42. data/lib/playwright_api/page.rb +38 -24
  43. data/lib/playwright_api/playwright.rb +6 -6
  44. data/lib/playwright_api/request.rb +6 -6
  45. data/lib/playwright_api/response.rb +8 -8
  46. data/lib/playwright_api/route.rb +6 -6
  47. data/lib/playwright_api/selectors.rb +6 -6
  48. data/lib/playwright_api/tracing.rb +6 -12
  49. data/lib/playwright_api/web_socket.rb +22 -0
  50. data/lib/playwright_api/worker.rb +22 -0
  51. metadata +5 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b365f47558ade3fcf3d803a070cbd61eb4eae6279f0d93c1641a53d9b50ec232
4
- data.tar.gz: 353de7a190205c6d3d4542b3058afe24c0c634fe70811c15384b55d1cb464571
3
+ metadata.gz: 9b548b6927a468b4a1209e9002cc7ca6f20bf0ad7ad4091510336ed610d338bb
4
+ data.tar.gz: d8f5e411d5ee99460e77d3d922608996cde6de1a2199ee0f6425c7e3a5eb9a7b
5
5
  SHA512:
6
- metadata.gz: ec905a5051716af754993c11b5a484e5bf69a9b50cdb6681f583869d0cf70d23eb3265507d6739b6d006fc8419360dea8570f6fae6fc3ac8fdd6d44ae3547fd8
7
- data.tar.gz: cf06e3351a40457108080dea85af6c8e417ffda3bec6671f9280ad42bc5fde7e58cf039016fe11387a7cb3e1347e1391f1440d23c2e54e512ca70e39ba90db38
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: `{ browserContext: BrowserContext,
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 an `sha256` function to all pages in the context:
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
- traceDir: nil,
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
- ```python sync title=example_c954c35627e62be69e1f138f25d7377b13e18d08039d476946217827fa95db52.py
12
- from playwright.sync_api import sync_playwright
13
-
14
- def handle_dialog(dialog):
15
- print(dialog.message)
16
- dialog.dismiss()
17
-
18
- def run(playwright):
19
- chromium = playwright.chromium
20
- browser = chromium.launch()
21
- page = browser.new_page()
22
- page.on("dialog", handle_dialog)
23
- page.evaluate("alert('1')")
24
- browser.close()
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
- ```python sync title=example_5ba38bdc5d9e5ce7cfc9c8841eb0176efbb4690d18962066f9ee67f1e8b7b050.py
13
- from playwright.sync_api import sync_playwright
14
-
15
- def run(playwright):
16
- chromium = playwright.chromium
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
- ```python sync title=example_8382aa7cfb42a9a17e348e2f738279f1bd9a038f1ea35cc3cb244cc64d768f93.py
55
- box = element_handle.bounding_box()
56
- page.mouse.click(box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
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
- ```python sync title=example_3b86add6ce355082cd43f4ac0ba9e69c15960bbd7ca601d0618355fe53aa8902.py
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
- ```python sync title=example_6b70ea4cf0c7ae9c82cf0ed22ab0dbbb563e2d1419b35d04aa513cf91f0856f9.py
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("#source", "dragstart", {"dataTransfer": data_transfer})
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
- ```python sync title=example_f6a83ec555fcf23877c11cf55f02a8c89a7fc11d3324859feda42e592e129f4f.py
194
+ ```ruby
205
195
  tweet_handle = page.query_selector(".tweet")
206
- assert tweet_handle.eval_on_selector(".like", "node => node.innerText") == "100"
207
- assert tweet_handle.eval_on_selector(".retweets", "node => node.innerText") = "10"
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
- ```python sync title=example_11b54bf5ec18a0d0ceee0868651bb41ab5cd3afcc6b20d5c44f90d835c8d6f81.py
225
+ ```ruby
237
226
  feed_handle = page.query_selector(".feed")
238
- assert feed_handle.eval_on_selector_all(".tweet", "nodes => nodes.map(n => n.innerText)") == ["hello!", "hi!"]
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
- ```python sync title=example_dc2ce38846b91d234483ed8b915b785ffbd9403213279465acd6605f314fe736.py
454
+ ```ruby
467
455
  # single selection matching the value
468
- handle.select_option("blue")
456
+ element_handle.select_option(value: "blue")
469
457
  # single selection matching both the label
470
- handle.select_option(label="blue")
458
+ element_handle.select_option(label: "blue")
471
459
  # multiple selection
472
- handle.select_option(value=["red", "green", "blue"])
473
-
460
+ element_handle.select_option(value: ["red", "green", "blue"])
474
461
  ```
475
462
 
476
- ```python sync title=example_b4cdd4a1a4d0392c2d430e0fb5fc670df2d728b6907553650690a2d0377662e4.py
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
- handle.select_option(value="blue", { index: 2 }, "red")
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
- ```python sync title=example_2dc9720467640fd8bc581ed65159742e51ff91b209cb176fef8b95f14eaad54e.py
535
+ ```ruby
556
536
  element_handle.type("hello") # types instantly
557
- element_handle.type("world", delay=100) # types slower, like a user
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
- ```python sync title=example_d13faaf53454653ce45371b5cf337082a82bf7bbb0aada7e97f47d14963bd6b0.py
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. You can access android namespace via:
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
- ```sh js
15
+ ```bash js
15
16
  PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm i -D playwright
16
17
  ```
17
18
 
@@ -47,6 +47,7 @@ def launch_browser(
47
47
  record_har_path: nil,
48
48
  record_video_dir: nil,
49
49
  record_video_size: nil,
50
+ reducedMotion: nil,
50
51
  screen: nil,
51
52
  timezoneId: nil,
52
53
  userAgent: nil,
@@ -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
- ```python sync title=example_371975841dd417527a865b1501e3a8ba40f905b895cf3317ca90d9890e980843.py
10
- with page.expect_file_chooser() as fc_info:
11
- page.click("upload")
12
- file_chooser = fc_info.value
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
- ```python sync title=example_9daa37cfd3d747c9360d9544f64786bf49d291a6887b0efccc813215b62ae4c6.py
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
- ```python sync title=example_c408a96b8ac9c9bd54d915009c8b477eb75b7bf9e879fd76b32f3d4b6340a667.py
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
- ```python sync title=example_2400f96eaaed3bc6ef6b0a16ba48e83d38a166c7d55a5dba0025472cffc6f2be.py
52
+ ```ruby
54
53
  tweet_handle = page.query_selector(".tweet .retweets")
55
- assert tweet_handle.evaluate("node => node.innerText") == "10 retweets"
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 `jsHandle.evaluate` and `jsHandle.evaluateHandle` is that `jsHandle.evaluateHandle` returns
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 `jsHandle.evaluateHandle` returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), then `jsHandle.evaluateHandle` would wait
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
- ```python sync title=example_8292f0e8974d97d20be9bb303d55ccd2d50e42f954e0ada4958ddbef2c6c2977.py
89
- handle = page.evaluate_handle("{window, document}")
90
- properties = handle.get_properties()
91
- window_handle = properties.get("window")
92
- document_handle = properties.get("document")
93
- handle.dispose()
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