playwright-ruby-client 1.15.1 → 1.17.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/docs/api/{fetch_request.md → api_request_context.md} +2 -2
  3. data/documentation/docs/api/browser_context.md +1 -1
  4. data/documentation/docs/api/element_handle.md +2 -3
  5. data/documentation/docs/api/frame.md +30 -0
  6. data/documentation/docs/api/frame_locator.md +70 -0
  7. data/documentation/docs/api/locator.md +35 -2
  8. data/documentation/docs/api/page.md +35 -4
  9. data/documentation/docs/api/request.md +3 -3
  10. data/documentation/docs/api/selectors.md +1 -1
  11. data/documentation/docs/api/tracing.md +2 -2
  12. data/documentation/docs/include/api_coverage.md +26 -7
  13. data/documentation/package.json +2 -2
  14. data/documentation/yarn.lock +1430 -1486
  15. data/lib/playwright/channel_owners/api_request_context.rb +4 -0
  16. data/lib/playwright/channel_owners/artifact.rb +1 -6
  17. data/lib/playwright/channel_owners/browser.rb +6 -8
  18. data/lib/playwright/channel_owners/browser_context.rb +5 -3
  19. data/lib/playwright/channel_owners/browser_type.rb +0 -1
  20. data/lib/playwright/channel_owners/fetch_request.rb +5 -1
  21. data/lib/playwright/channel_owners/frame.rb +13 -7
  22. data/lib/playwright/channel_owners/page.rb +18 -10
  23. data/lib/playwright/channel_owners/request.rb +9 -21
  24. data/lib/playwright/channel_owners/response.rb +0 -4
  25. data/lib/playwright/connection.rb +9 -0
  26. data/lib/playwright/frame_locator_impl.rb +49 -0
  27. data/lib/playwright/locator_impl.rb +17 -5
  28. data/lib/playwright/route_handler.rb +13 -1
  29. data/lib/playwright/tracing_impl.rb +6 -9
  30. data/lib/playwright/version.rb +2 -2
  31. data/lib/playwright/video.rb +3 -0
  32. data/lib/playwright.rb +2 -1
  33. data/lib/playwright_api/api_request_context.rb +149 -0
  34. data/lib/playwright_api/browser_context.rb +6 -1
  35. data/lib/playwright_api/element_handle.rb +2 -3
  36. data/lib/playwright_api/frame.rb +26 -1
  37. data/lib/playwright_api/frame_locator.rb +51 -0
  38. data/lib/playwright_api/locator.rb +25 -2
  39. data/lib/playwright_api/page.rb +35 -9
  40. data/lib/playwright_api/playwright.rb +5 -0
  41. data/lib/playwright_api/selectors.rb +2 -2
  42. data/lib/playwright_api/tracing.rb +4 -4
  43. data/lib/playwright_api/worker.rb +4 -4
  44. metadata +11 -7
  45. data/lib/playwright_api/fetch_request.rb +0 -74
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36f932a83b81283925520630e54a3c4b578d3231f2540f49ce27acf206c14e1e
4
- data.tar.gz: 13d5171781c20e6aba7df33828c2ec569d975328de72dff21bb31ae8d51838ea
3
+ metadata.gz: c2fe4b12d358a45b087eee4cdfc8aecb03b9e6df7d012158e4a04a042d290d13
4
+ data.tar.gz: ed57849806349f58419ead4e64164cafb94de892fa5d4be7cbf9f6e67867eb5d
5
5
  SHA512:
6
- metadata.gz: e25671c14ede2650a5cd2a2a9e2542e7c629e8bb4ff64c57fff23c91cf9b6cfdfda2549944118659a3a4db968c27c037b74e18e042d5d7c74f1dac9f073a6d50
7
- data.tar.gz: 05c22aaeb2cf8cdb61ed1f7ad67222ded55a8b14be33c7f1d8fb24dbb22e7040bd888216335e03b02dec716e0e3eb4f87351f9fddc28fae2dcd0cf04b311bbc8
6
+ metadata.gz: b4245e2cc937bf4dd85ab98848b4a56149d796d814407598e17258f64154d85f252a3f993e13c8a81bda0f0112ffc5c1fa93e699c7fb691e3bf7592f27cd6133
7
+ data.tar.gz: 5680b2040b8ff3927b952e9f5321355137c298c697b0ba5ecde686eb89545f8b3444e191da3fe8ba22315df6fc982e452bdff73d71774419ee32a08e9a0281ef
@@ -2,9 +2,9 @@
2
2
  sidebar_position: 10
3
3
  ---
4
4
 
5
- # FetchRequest
5
+ # APIRequestContext
6
6
 
7
- This API is used for Web API testing. You can use it to trigger API endpoints, configure micro-services, prepare
7
+ This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services, prepare
8
8
  environment or the service to your e2e test. When used on [Page](./page) or a [BrowserContext](./browser_context), this API will automatically use
9
9
  the cookies from the corresponding [BrowserContext](./browser_context). This means that if you log in using this API, your e2e test will be
10
10
  logged in and vice versa.
@@ -11,7 +11,7 @@ BrowserContexts provide a way to operate multiple independent browser sessions.
11
11
  If a page opens another page, e.g. with a `window.open` call, the popup will belong to the parent page's browser
12
12
  context.
13
13
 
14
- Playwright allows creation of "incognito" browser contexts with [Browser#new_context](./browser#new_context) method. "Incognito" browser
14
+ Playwright allows creating "incognito" browser contexts with [Browser#new_context](./browser#new_context) method. "Incognito" browser
15
15
  contexts don't write any browsing data to disk.
16
16
 
17
17
  ```ruby
@@ -9,6 +9,8 @@ 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
+ > NOTE: The use of ElementHandle is discouraged, use [Locator](./locator) objects and web-first assertions instead.
13
+
12
14
  ```ruby
13
15
  href_element = page.query_selector("a")
14
16
  href_element.click
@@ -20,9 +22,6 @@ ElementHandle prevents DOM element from garbage collection unless the handle is
20
22
  ElementHandle instances can be used as an argument in [Page#eval_on_selector](./page#eval_on_selector) and [Page#evaluate](./page#evaluate)
21
23
  methods.
22
24
 
23
- > NOTE: In most cases, you would want to use the [Locator](./locator) object instead. You should only use [ElementHandle](./element_handle) if you
24
- want to retain a handle to a particular DOM Node that you intend to pass into [Page#evaluate](./page#evaluate) as an argument.
25
-
26
25
  The difference between the [Locator](./locator) and ElementHandle is that the ElementHandle points to a particular element, while
27
26
  [Locator](./locator) captures the logic of how to retrieve an element.
28
27
 
@@ -218,6 +218,9 @@ def eval_on_selector(selector, expression, arg: nil, strict: nil)
218
218
 
219
219
  Returns the return value of `expression`.
220
220
 
221
+ > NOTE: This method does not wait for the element to pass actionability checks and therefore can lead to the flaky
222
+ tests. Use [Locator#evaluate](./locator#evaluate), other [Locator](./locator) helper methods or web-first assertions instead.
223
+
221
224
  The method finds an element matching the specified selector within the frame and passes it as a first argument to
222
225
  `expression`. See [Working with selectors](https://playwright.dev/python/docs/selectors) for more details. If no elements match the selector, the
223
226
  method throws an error.
@@ -243,6 +246,9 @@ def eval_on_selector_all(selector, expression, arg: nil)
243
246
 
244
247
  Returns the return value of `expression`.
245
248
 
249
+ > NOTE: In most cases, [Locator#evaluate_all](./locator#evaluate_all), other [Locator](./locator) helper methods and web-first assertions do a
250
+ better job.
251
+
246
252
  The method finds all elements matching the specified selector within the frame and passes an array of matched elements
247
253
  as a first argument to `expression`. See [Working with selectors](https://playwright.dev/python/docs/selectors) for more details.
248
254
 
@@ -384,6 +390,23 @@ puts frame == content_frame # => true
384
390
 
385
391
 
386
392
 
393
+ ## frame_locator
394
+
395
+ ```
396
+ def frame_locator(selector)
397
+ ```
398
+
399
+ When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in
400
+ that iframe. Following snippet locates element with text "Submit" in the iframe with id `my-frame`, like `<iframe
401
+ id="my-frame">`:
402
+
403
+ ```ruby
404
+ locator = frame.frame_locator("#my-iframe").locator("text=Submit")
405
+ locator.click
406
+ ```
407
+
408
+
409
+
387
410
  ## get_attribute
388
411
 
389
412
  ```
@@ -598,6 +621,8 @@ def query_selector(selector, strict: nil)
598
621
 
599
622
  Returns the ElementHandle pointing to the frame element.
600
623
 
624
+ > NOTE: The use of [ElementHandle](./element_handle) is discouraged, use [Locator](./locator) objects and web-first assertions instead.
625
+
601
626
  The method finds an element matching the specified selector within the frame. See
602
627
  [Working with selectors](https://playwright.dev/python/docs/selectors) for more details. If no elements match the selector, returns `null`.
603
628
 
@@ -609,6 +634,8 @@ def query_selector_all(selector)
609
634
 
610
635
  Returns the ElementHandles pointing to the frame elements.
611
636
 
637
+ > NOTE: The use of [ElementHandle](./element_handle) is discouraged, use [Locator](./locator) objects instead.
638
+
612
639
  The method finds all elements matching the specified selector within the frame. See
613
640
  [Working with selectors](https://playwright.dev/python/docs/selectors) for more details. If no elements match the selector, returns empty array.
614
641
 
@@ -878,6 +905,9 @@ def wait_for_selector(selector, state: nil, strict: nil, timeout: nil)
878
905
  Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
879
906
  `detached`.
880
907
 
908
+ > NOTE: Playwright automatically waits for element to be ready before performing an action. Using [Locator](./locator) objects and
909
+ web-first assertions make the code wait-for-selector-free.
910
+
881
911
  Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at
882
912
  the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
883
913
  selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.
@@ -0,0 +1,70 @@
1
+ ---
2
+ sidebar_position: 10
3
+ ---
4
+
5
+ # FrameLocator
6
+
7
+ FrameLocator represents a view to the `iframe` on the page. It captures the logic sufficient to retrieve the `iframe`
8
+ and locate elements in that iframe. FrameLocator can be created with either [Page#frame_locator](./page#frame_locator) or
9
+ [Locator#frame_locator](./locator#frame_locator) method.
10
+
11
+ ```ruby
12
+ locator = page.frame_locator("my-frame").locator("text=Submit")
13
+ locator.click
14
+ ```
15
+
16
+ **Strictness**
17
+
18
+ Frame locators are strict. This means that all operations on frame locators will throw if more than one element matches
19
+ given selector.
20
+
21
+ ```ruby
22
+ # Throws if there are several frames in DOM:
23
+ page.frame_locator('.result-frame').locator('button').click
24
+
25
+ # Works because we explicitly tell locator to pick the first frame:
26
+ page.frame_locator('.result-frame').first.locator('button').click
27
+ ```
28
+
29
+
30
+
31
+ ## first
32
+
33
+ ```
34
+ def first
35
+ ```
36
+
37
+ Returns locator to the first matching frame.
38
+
39
+ ## frame_locator
40
+
41
+ ```
42
+ def frame_locator(selector)
43
+ ```
44
+
45
+ When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in
46
+ that iframe.
47
+
48
+ ## last
49
+
50
+ ```
51
+ def last
52
+ ```
53
+
54
+ Returns locator to the last matching frame.
55
+
56
+ ## locator
57
+
58
+ ```
59
+ def locator(selector)
60
+ ```
61
+
62
+ The method finds an element matching the specified selector in the FrameLocator's subtree.
63
+
64
+ ## nth
65
+
66
+ ```
67
+ def nth(index)
68
+ ```
69
+
70
+ Returns locator to the n-th matching frame.
@@ -329,6 +329,22 @@ def focus(timeout: nil)
329
329
 
330
330
  Calls [focus](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on the element.
331
331
 
332
+ ## frame_locator
333
+
334
+ ```
335
+ def frame_locator(selector)
336
+ ```
337
+
338
+ When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in
339
+ that iframe:
340
+
341
+ ```ruby
342
+ locator = page.frame_locator("text=Submit").locator("text=Submit")
343
+ locator.click
344
+ ```
345
+
346
+
347
+
332
348
  ## get_attribute
333
349
 
334
350
  ```
@@ -445,8 +461,7 @@ Returns locator to the last matching element.
445
461
  def locator(selector)
446
462
  ```
447
463
 
448
- The method finds an element matching the specified selector in the [Locator](./locator)'s subtree. See
449
- [Working with selectors](https://playwright.dev/python/docs/selectors) for more details.
464
+ The method finds an element matching the specified selector in the [Locator](./locator)'s subtree.
450
465
 
451
466
  ## nth
452
467
 
@@ -677,3 +692,21 @@ If the element is detached from the DOM at any moment during the action, this me
677
692
 
678
693
  When all steps combined have not finished during the specified `timeout`, this method throws a `TimeoutError`. Passing
679
694
  zero timeout disables this.
695
+
696
+ ## wait_for
697
+
698
+ ```
699
+ def wait_for(state: nil, timeout: nil)
700
+ ```
701
+
702
+ Returns when element specified by locator satisfies the `state` option.
703
+
704
+ If target element already satisfies the condition, the method returns immediately. Otherwise, waits for up to `timeout`
705
+ milliseconds until the condition is met.
706
+
707
+ ```ruby
708
+ order_sent = page.locator("#order-sent")
709
+ order_sent.wait_for
710
+ ```
711
+
712
+
@@ -315,6 +315,9 @@ page.evaluate("matchMedia('(prefers-color-scheme: no-preference)').matches") # =
315
315
  def eval_on_selector(selector, expression, arg: nil, strict: nil)
316
316
  ```
317
317
 
318
+ > NOTE: This method does not wait for the element to pass actionability checks and therefore can lead to the flaky
319
+ tests. Use [Locator#evaluate](./locator#evaluate), other [Locator](./locator) helper methods or web-first assertions instead.
320
+
318
321
  The method finds an element matching the specified selector within the page and passes it as a first argument to
319
322
  `expression`. If no elements match the selector, the method throws an error. Returns the value of `expression`.
320
323
 
@@ -337,6 +340,9 @@ Shortcut for main frame's [Frame#eval_on_selector](./frame#eval_on_selector).
337
340
  def eval_on_selector_all(selector, expression, arg: nil)
338
341
  ```
339
342
 
343
+ > NOTE: In most cases, [Locator#evaluate_all](./locator#evaluate_all), other [Locator](./locator) helper methods and web-first assertions do a
344
+ better job.
345
+
340
346
  The method finds all elements matching the specified selector within the page and passes an array of matched elements as
341
347
  a first argument to `expression`. Returns the result of `expression` invocation.
342
348
 
@@ -575,6 +581,23 @@ frame = page.frame(url: /.*domain.*/)
575
581
 
576
582
 
577
583
 
584
+ ## frame_locator
585
+
586
+ ```
587
+ def frame_locator(selector)
588
+ ```
589
+
590
+ When working with iframes, you can create a frame locator that will enter the iframe and allow selecting elements in
591
+ that iframe. Following snippet locates element with text "Submit" in the iframe with id `my-frame`, like `<iframe
592
+ id="my-frame">`:
593
+
594
+ ```ruby
595
+ locator = page.frame_locator("#my-iframe").locator("text=Submit")
596
+ locator.click
597
+ ```
598
+
599
+
600
+
578
601
  ## frames
579
602
 
580
603
  ```
@@ -905,8 +928,10 @@ page.screenshot(path: "o.png")
905
928
  def query_selector(selector, strict: nil)
906
929
  ```
907
930
 
931
+ > NOTE: The use of [ElementHandle](./element_handle) is discouraged, use [Locator](./locator) objects and web-first assertions instead.
932
+
908
933
  The method finds an element matching the specified selector within the page. If no elements match the selector, the
909
- return value resolves to `null`. To wait for an element on the page, use [Page#wait_for_selector](./page#wait_for_selector).
934
+ return value resolves to `null`. To wait for an element on the page, use [Locator#wait_for](./locator#wait_for).
910
935
 
911
936
  Shortcut for main frame's [Frame#query_selector](./frame#query_selector).
912
937
 
@@ -916,6 +941,8 @@ Shortcut for main frame's [Frame#query_selector](./frame#query_selector).
916
941
  def query_selector_all(selector)
917
942
  ```
918
943
 
944
+ > NOTE: The use of [ElementHandle](./element_handle) is discouraged, use [Locator](./locator) objects and web-first assertions instead.
945
+
919
946
  The method finds all elements matching the specified selector within the page. If no elements match the selector, the
920
947
  return value resolves to `[]`.
921
948
 
@@ -927,8 +954,8 @@ Shortcut for main frame's [Frame#query_selector_all](./frame#query_selector_all)
927
954
  def reload(timeout: nil, waitUntil: nil)
928
955
  ```
929
956
 
930
- Returns the main resource response. In case of multiple redirects, the navigation will resolve with the response of the
931
- last redirect.
957
+ This method reloads the current page, in the same way as if the user had triggered a browser refresh. Returns the main
958
+ resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.
932
959
 
933
960
  ## route
934
961
 
@@ -1141,7 +1168,8 @@ In the case of multiple pages in a single browser, each page can have its own vi
1141
1168
  [Browser#new_context](./browser#new_context) allows to set viewport size (and more) for all pages in the context at once.
1142
1169
 
1143
1170
  `page.setViewportSize` will resize the page. A lot of websites don't expect phones to change size, so you should set the
1144
- viewport size before navigating to the page.
1171
+ viewport size before navigating to the page. [Page#set_viewport_size](./page#set_viewport_size) will also reset `screen` size, use
1172
+ [Browser#new_context](./browser#new_context) with `screen` and `viewport` parameters if you need better control of these properties.
1145
1173
 
1146
1174
  ```ruby
1147
1175
  page.viewport_size = { width: 640, height: 480 }
@@ -1483,6 +1511,9 @@ def wait_for_selector(selector, state: nil, strict: nil, timeout: nil)
1483
1511
  Returns when element specified by selector satisfies `state` option. Returns `null` if waiting for `hidden` or
1484
1512
  `detached`.
1485
1513
 
1514
+ > NOTE: Playwright automatically waits for element to be ready before performing an action. Using [Locator](./locator) objects and
1515
+ web-first assertions make the code wait-for-selector-free.
1516
+
1486
1517
  Wait for the `selector` to satisfy `state` option (either appear/disappear from dom, or become visible/hidden). If at
1487
1518
  the moment of calling the method `selector` already satisfies the condition, the method will return immediately. If the
1488
1519
  selector doesn't satisfy the condition for the `timeout` milliseconds, the function will throw.
@@ -127,10 +127,10 @@ def redirected_from
127
127
  Request that was redirected by the server to this one, if any.
128
128
 
129
129
  When the server responds with a redirect, Playwright creates a new [Request](./request) object. The two requests are connected by
130
- `redirectedFrom()` and `redirectedTo()` methods. When multiple server redirects has happened, it is possible to
131
- construct the whole redirect chain by repeatedly calling `redirectedFrom()`.
130
+ [redirected_from](./request#redirected_from) and [redirected_to](./request#redirected_to) methods. When multiple server redirects has happened, it is possible to
131
+ construct the whole redirect chain by repeatedly calling [redirected_from](./request#redirected_from).
132
132
 
133
- For example, if the website `http://example.com` redirects to `https://example.com`:
133
+ For example, if the website `http://github.com` redirects to `https://github.com`:
134
134
 
135
135
  ```ruby
136
136
  response = page.goto("http://github.com")
@@ -41,7 +41,7 @@ playwright.chromium.launch do |browser|
41
41
  page.click('tag=div >> text="Click me"')
42
42
 
43
43
  # Can use it in any methods supporting selectors.
44
- button_count = page.eval_on_selector_all('tag=button', 'buttons => buttons.length')
44
+ button_count = page.locator('tag=button').count
45
45
  button_count # => 1
46
46
  end
47
47
  ```
@@ -23,7 +23,7 @@ end
23
23
  ## start
24
24
 
25
25
  ```
26
- def start(name: nil, screenshots: nil, snapshots: nil)
26
+ def start(name: nil, screenshots: nil, snapshots: nil, title: nil)
27
27
  ```
28
28
 
29
29
  Start tracing.
@@ -40,7 +40,7 @@ context.tracing.stop(path: 'trace.zip')
40
40
  ## start_chunk
41
41
 
42
42
  ```
43
- def start_chunk
43
+ def start_chunk(title: nil)
44
44
  ```
45
45
 
46
46
  Start a new trace chunk. If you'd like to record multiple traces on the same [BrowserContext](./browser_context), use
@@ -1,5 +1,17 @@
1
1
  # API coverages
2
2
 
3
+ ## APIRequestContext
4
+
5
+ * ~~delete~~
6
+ * ~~dispose~~
7
+ * ~~fetch~~
8
+ * ~~get~~
9
+ * ~~head~~
10
+ * ~~patch~~
11
+ * ~~post~~
12
+ * ~~put~~
13
+ * ~~storage_state~~
14
+
3
15
  ## Request
4
16
 
5
17
  * all_headers
@@ -48,13 +60,6 @@
48
60
  * fulfill
49
61
  * request
50
62
 
51
- ## FetchRequest
52
-
53
- * ~~dispose~~
54
- * ~~fetch~~
55
- * ~~get~~
56
- * ~~post~~
57
-
58
63
  ## WebSocket
59
64
 
60
65
  * closed?
@@ -162,6 +167,7 @@
162
167
  * fill
163
168
  * focus
164
169
  * frame_element
170
+ * frame_locator
165
171
  * get_attribute
166
172
  * goto
167
173
  * hover
@@ -259,6 +265,7 @@
259
265
  * fill
260
266
  * focus
261
267
  * frame
268
+ * frame_locator
262
269
  * frames
263
270
  * get_attribute
264
271
  * go_back
@@ -354,6 +361,7 @@
354
361
  * expect_event
355
362
  * expect_page
356
363
  * ~~wait_for_event~~
364
+ * ~~request~~
357
365
  * tracing
358
366
 
359
367
  ## CDPSession
@@ -388,6 +396,7 @@
388
396
  * chromium
389
397
  * devices
390
398
  * firefox
399
+ * ~~request~~
391
400
  * selectors
392
401
  * webkit
393
402
 
@@ -416,6 +425,7 @@
416
425
  * fill
417
426
  * first
418
427
  * focus
428
+ * frame_locator
419
429
  * get_attribute
420
430
  * hover
421
431
  * inner_html
@@ -441,6 +451,15 @@
441
451
  * text_content
442
452
  * type
443
453
  * uncheck
454
+ * wait_for
455
+
456
+ ## FrameLocator
457
+
458
+ * first
459
+ * frame_locator
460
+ * last
461
+ * locator
462
+ * nth
444
463
 
445
464
  ## Android
446
465
 
@@ -14,8 +14,8 @@
14
14
  "write-heading-ids": "docusaurus write-heading-ids"
15
15
  },
16
16
  "dependencies": {
17
- "@docusaurus/core": "^2.0.0-beta.5",
18
- "@docusaurus/preset-classic": "^2.0.0-beta.5",
17
+ "@docusaurus/core": "^2.0.0-beta.6",
18
+ "@docusaurus/preset-classic": "^2.0.0-beta.6",
19
19
  "@mdx-js/react": "^1.6.21",
20
20
  "@svgr/webpack": "^5.5.0",
21
21
  "clsx": "^1.1.1",