playwright-ruby-client 1.22.0 → 1.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/docs/api/accessibility.md +8 -0
  3. data/documentation/docs/api/api_request_context.md +8 -8
  4. data/documentation/docs/api/browser.md +30 -5
  5. data/documentation/docs/api/browser_context.md +20 -7
  6. data/documentation/docs/api/browser_type.md +4 -0
  7. data/documentation/docs/api/download.md +1 -1
  8. data/documentation/docs/api/element_handle.md +1 -6
  9. data/documentation/docs/api/experimental/android_device.md +4 -0
  10. data/documentation/docs/api/file_chooser.md +1 -1
  11. data/documentation/docs/api/locator.md +15 -7
  12. data/documentation/docs/api/page.md +21 -4
  13. data/documentation/docs/api/request.md +3 -1
  14. data/documentation/docs/api/response.md +12 -1
  15. data/documentation/docs/api/route.md +65 -0
  16. data/documentation/docs/api/selectors.md +2 -2
  17. data/documentation/docs/api/tracing.md +1 -1
  18. data/documentation/docs/include/api_coverage.md +5 -3
  19. data/documentation/package.json +4 -4
  20. data/documentation/yarn.lock +1876 -1304
  21. data/lib/playwright/channel.rb +1 -3
  22. data/lib/playwright/channel_owner.rb +13 -1
  23. data/lib/playwright/channel_owners/browser.rb +13 -0
  24. data/lib/playwright/channel_owners/browser_context.rb +82 -14
  25. data/lib/playwright/channel_owners/browser_type.rb +4 -0
  26. data/lib/playwright/channel_owners/frame.rb +16 -2
  27. data/lib/playwright/channel_owners/local_utils.rb +29 -0
  28. data/lib/playwright/channel_owners/page.rb +43 -15
  29. data/lib/playwright/channel_owners/request.rb +31 -6
  30. data/lib/playwright/channel_owners/response.rb +6 -0
  31. data/lib/playwright/channel_owners/route.rb +104 -45
  32. data/lib/playwright/connection.rb +20 -9
  33. data/lib/playwright/har_router.rb +82 -0
  34. data/lib/playwright/http_headers.rb +1 -1
  35. data/lib/playwright/javascript/regex.rb +23 -0
  36. data/lib/playwright/javascript/value_parser.rb +4 -0
  37. data/lib/playwright/javascript/value_serializer.rb +5 -4
  38. data/lib/playwright/javascript.rb +1 -0
  39. data/lib/playwright/locator_impl.rb +3 -5
  40. data/lib/playwright/route_handler.rb +2 -6
  41. data/lib/playwright/utils.rb +31 -6
  42. data/lib/playwright/version.rb +2 -2
  43. data/lib/playwright.rb +2 -0
  44. data/lib/playwright_api/accessibility.rb +8 -0
  45. data/lib/playwright_api/android_device.rb +5 -1
  46. data/lib/playwright_api/api_request_context.rb +8 -8
  47. data/lib/playwright_api/browser.rb +28 -2
  48. data/lib/playwright_api/browser_context.rb +19 -9
  49. data/lib/playwright_api/browser_type.rb +8 -2
  50. data/lib/playwright_api/download.rb +1 -1
  51. data/lib/playwright_api/element_handle.rb +1 -12
  52. data/lib/playwright_api/file_chooser.rb +1 -1
  53. data/lib/playwright_api/locator.rb +13 -13
  54. data/lib/playwright_api/page.rb +19 -6
  55. data/lib/playwright_api/request.rb +8 -1
  56. data/lib/playwright_api/response.rb +14 -1
  57. data/lib/playwright_api/route.rb +61 -2
  58. data/lib/playwright_api/selectors.rb +1 -1
  59. data/lib/playwright_api/tracing.rb +1 -1
  60. metadata +5 -4
  61. data/lib/playwright_api/local_utils.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82040f41eb8c972a8e3415aac148c27218e9fcbb00d7e09832bd75da506d2367
4
- data.tar.gz: a42be0ab4e00bb0ef36516474cca8220147d8c635e44c581c799ee65e396721f
3
+ metadata.gz: 8d7e01f93c5fa8ffd804062e0414e9de40204674ef1b070f296c0108259ca015
4
+ data.tar.gz: 75bdb822a5c3cc8ffe7e8dc011d8697c2cb00aa95895e7486068c09839a9c667
5
5
  SHA512:
6
- metadata.gz: 615d15f014ca5f175d9da7504583693903d0ebd4c3d47522bf2f5c0add5aa01f26551300834b86cd944a2eacb2ef38062c341ec14f1177b7f517a16dab6e90fe
7
- data.tar.gz: 97de038214b07abfbeb9eece923c0b031793b8939107df5f7b37268dbb4598c188dc88c4870766cf31d0bf28416610f46c996518a2f37fc8c73d5b672f713005
6
+ metadata.gz: 9499d48e15c5201718f8e4569f1e28b5f66d2bd14c11b4c3a1c98c4e4ca2c39ababc74b3af1db1e2bcabbc4234fd6034eaa0c71b09b925654c468fdf65dd0547
7
+ data.tar.gz: 622a2e2bd96af9e65255b1abdb52f5768091af4cc8d5a6368b60237e363a8cd3bdbc1673ef1d745d017583206b6d8011f92300228b27a14e69bdc6558392de30
@@ -4,6 +4,10 @@ sidebar_position: 10
4
4
 
5
5
  # Accessibility
6
6
 
7
+ **DEPRECATED** This class is deprecated. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you
8
+ need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for
9
+ integration with Axe.
10
+
7
11
  The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by
8
12
  assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or
9
13
  [switches](https://en.wikipedia.org/wiki/Switch_access).
@@ -24,6 +28,10 @@ only the "interesting" nodes of the tree.
24
28
  def snapshot(interestingOnly: nil, root: nil)
25
29
  ```
26
30
 
31
+ **DEPRECATED** This method is deprecated. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you
32
+ need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for
33
+ integration with Axe.
34
+
27
35
  Captures the current state of the accessibility tree. The returned object represents the root accessible node of the
28
36
  page.
29
37
 
@@ -13,14 +13,14 @@ possible to create a new APIRequestContext instance manually by calling [APIRequ
13
13
 
14
14
  **Cookie management**
15
15
 
16
- [APIRequestContext](./api_request_context) retuned by [BrowserContext#request](./browser_context#request) and [Page#request](./page#request) shares cookie storage
17
- with the corresponding [BrowserContext](./browser_context). Each API request will have `Cookie` header populated with the values from the
18
- browser context. If the API response contains `Set-Cookie` header it will automatically update [BrowserContext](./browser_context) cookies
19
- and requests made from the page will pick them up. This means that if you log in using this API, your e2e test will be
20
- logged in and vice versa.
21
-
22
- If you want API requests to not interfere with the browser cookies you shoud create a new [APIRequestContext](./api_request_context) by calling
23
- [APIRequest#new_context](./api_request#new_context). Such [APIRequestContext](./api_request_context) object will have its own isolated cookie storage.
16
+ [APIRequestContext](./api_request_context) returned by [BrowserContext#request](./browser_context#request) and [Page#request](./page#request) shares cookie
17
+ storage with the corresponding [BrowserContext](./browser_context). Each API request will have `Cookie` header populated with the values
18
+ from the browser context. If the API response contains `Set-Cookie` header it will automatically update [BrowserContext](./browser_context)
19
+ cookies and requests made from the page will pick them up. This means that if you log in using this API, your e2e test
20
+ will be logged in and vice versa.
21
+
22
+ If you want API requests to not interfere with the browser cookies you should create a new [APIRequestContext](./api_request_context) by
23
+ calling [APIRequest#new_context](./api_request#new_context). Such [APIRequestContext](./api_request_context) object will have its own isolated cookie storage.
24
24
 
25
25
  ```ruby
26
26
  playwright.chromium.launch do |browser|
@@ -21,6 +21,14 @@ end
21
21
 
22
22
 
23
23
 
24
+ ## browser_type
25
+
26
+ ```
27
+ def browser_type
28
+ ```
29
+
30
+ Get the browser type (chromium, firefox or webkit) that the browser belongs to.
31
+
24
32
  ## close
25
33
 
26
34
  ```
@@ -33,6 +41,10 @@ were opened).
33
41
  In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from the
34
42
  browser server.
35
43
 
44
+ > NOTE: This is similar to force quitting the browser. Therefore, you should call [BrowserContext#close](./browser_context#close) on
45
+ any [BrowserContext](./browser_context)'s you explicitly created earlier with [Browser#new_context](./browser#new_context) **before** calling
46
+ [Browser#close](./browser#close).
47
+
36
48
  The [Browser](./browser) object itself is considered to be disposed and cannot be used anymore.
37
49
 
38
50
  ## contexts
@@ -93,12 +105,16 @@ def new_context(
93
105
  offline: nil,
94
106
  permissions: nil,
95
107
  proxy: nil,
108
+ record_har_content: nil,
109
+ record_har_mode: nil,
96
110
  record_har_omit_content: nil,
97
111
  record_har_path: nil,
112
+ record_har_url_filter: nil,
98
113
  record_video_dir: nil,
99
114
  record_video_size: nil,
100
115
  reducedMotion: nil,
101
116
  screen: nil,
117
+ serviceWorkers: nil,
102
118
  storageState: nil,
103
119
  strictSelectors: nil,
104
120
  timezoneId: nil,
@@ -109,14 +125,19 @@ def new_context(
109
125
 
110
126
  Creates a new browser context. It won't share cookies/cache with other browser contexts.
111
127
 
128
+ > NOTE: If directly using this method to create [BrowserContext](./browser_context)s, it is best practice to explicitly close the returned
129
+ context via [BrowserContext#close](./browser_context#close) when your code is done with the [BrowserContext](./browser_context), and before calling
130
+ [Browser#close](./browser#close). This will ensure the `context` is closed gracefully and any artifacts—like HARs and
131
+ videos—are fully flushed and saved.
132
+
112
133
  ```ruby
113
134
  playwright.firefox.launch do |browser| # or "chromium.launch" or "webkit.launch".
114
135
  # create a new incognito browser context.
115
- context = browser.new_context
116
-
117
- # create a new page in a pristine context.
118
- page = context.new_page()
119
- page.goto("https://example.com")
136
+ browser.new_context do |context|
137
+ # create a new page in a pristine context.
138
+ page = context.new_page
139
+ page.goto("https://example.com")
140
+ end
120
141
  end
121
142
  ```
122
143
 
@@ -144,12 +165,16 @@ def new_page(
144
165
  offline: nil,
145
166
  permissions: nil,
146
167
  proxy: nil,
168
+ record_har_content: nil,
169
+ record_har_mode: nil,
147
170
  record_har_omit_content: nil,
148
171
  record_har_path: nil,
172
+ record_har_url_filter: nil,
149
173
  record_video_dir: nil,
150
174
  record_video_size: nil,
151
175
  reducedMotion: nil,
152
176
  screen: nil,
177
+ serviceWorkers: nil,
153
178
  storageState: nil,
154
179
  strictSelectors: nil,
155
180
  timezoneId: nil,
@@ -23,7 +23,7 @@ page = context.new_page
23
23
  page.goto("https://example.com")
24
24
 
25
25
  # dispose context once it is no longer needed.
26
- context.close()
26
+ context.close
27
27
  ```
28
28
 
29
29
 
@@ -161,7 +161,7 @@ page.content = <<~HTML
161
161
  <div></div>
162
162
  HTML
163
163
 
164
- page.click("button")
164
+ page.locator("button").click
165
165
  ```
166
166
 
167
167
  An example of passing an element handle:
@@ -184,7 +184,7 @@ page.content = <<~HTML
184
184
  <div>Or click me</div>
185
185
  HTML
186
186
 
187
- page.click('div')
187
+ page.locator('div').first.click
188
188
  ```
189
189
 
190
190
 
@@ -222,7 +222,7 @@ page.content = <<~HTML
222
222
  <button onclick="onClick()">Click me</button>
223
223
  <div></div>
224
224
  HTML
225
- page.click("button")
225
+ page.locator("button").click
226
226
  ```
227
227
 
228
228
 
@@ -271,9 +271,9 @@ def route(url, handler, times: nil)
271
271
  Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
272
272
  is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
273
273
 
274
- > NOTE: [Page#route](./page#route) will not intercept requests intercepted by Service Worker. See
274
+ > NOTE: [BrowserContext#route](./browser_context#route) will not intercept requests intercepted by Service Worker. See
275
275
  [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using
276
- request interception. Via `await context.addInitScript(() => delete window.navigator.serviceWorker);`
276
+ request interception by setting `Browser.newContext.serviceWorkers` to `'block'`.
277
277
 
278
278
  An example of a naive handler that aborts all image requests:
279
279
 
@@ -315,6 +315,19 @@ To remove a route with its handler you can use [BrowserContext#unroute](./browse
315
315
 
316
316
  > NOTE: Enabling routing disables http cache.
317
317
 
318
+ ## route_from_har
319
+
320
+ ```
321
+ def route_from_har(har, notFound: nil, update: nil, url: nil)
322
+ ```
323
+
324
+ If specified the network requests that are made in the context will be served from the HAR file. Read more about
325
+ [Replaying from HAR](https://playwright.dev/python/docs/network).
326
+
327
+ Playwright will not serve requests intercepted by Service Worker from the HAR file. See
328
+ [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using
329
+ request interception by setting `Browser.newContext.serviceWorkers` to `'block'`.
330
+
318
331
  ## service_workers
319
332
 
320
333
  ```
@@ -421,7 +434,7 @@ value. Will throw an error if the context closes before the event is fired. Retu
421
434
 
422
435
  ```ruby
423
436
  new_page = browser_context.expect_event('page') do
424
- page.click('button')
437
+ page.locator('button').click
425
438
  end
426
439
  ```
427
440
 
@@ -131,12 +131,16 @@ def launch_persistent_context(
131
131
  offline: nil,
132
132
  permissions: nil,
133
133
  proxy: nil,
134
+ record_har_content: nil,
135
+ record_har_mode: nil,
134
136
  record_har_omit_content: nil,
135
137
  record_har_path: nil,
138
+ record_har_url_filter: nil,
136
139
  record_video_dir: nil,
137
140
  record_video_size: nil,
138
141
  reducedMotion: nil,
139
142
  screen: nil,
143
+ serviceWorkers: nil,
140
144
  slowMo: nil,
141
145
  strictSelectors: nil,
142
146
  timeout: nil,
@@ -12,7 +12,7 @@ Download event is emitted once the download starts. Download path becomes availa
12
12
 
13
13
  ```ruby
14
14
  download = page.expect_download do
15
- page.click('a')
15
+ page.locator('a').click
16
16
  end
17
17
 
18
18
  # wait for download to complete
@@ -55,7 +55,7 @@ def bounding_box
55
55
  This method returns the bounding box of the element, or `null` if the element is not visible. The bounding box is
56
56
  calculated relative to the main frame viewport - which is usually the same as the browser window.
57
57
 
58
- Scrolling affects the returned bonding box, similarly to
58
+ Scrolling affects the returned bounding box, similarly to
59
59
  [Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect). That
60
60
  means `x` and/or `y` may be negative.
61
61
 
@@ -504,11 +504,6 @@ element_handle.select_option(label: "blue")
504
504
  element_handle.select_option(value: ["red", "green", "blue"])
505
505
  ```
506
506
 
507
- ```ruby
508
- # multiple selection for blue, red and second option
509
- element_handle.select_option(value: "blue", index: 2, label: "red")
510
- ```
511
-
512
507
 
513
508
 
514
509
  ## select_text
@@ -45,12 +45,16 @@ def launch_browser(
45
45
  noViewport: nil,
46
46
  offline: nil,
47
47
  permissions: nil,
48
+ record_har_content: nil,
49
+ record_har_mode: nil,
48
50
  record_har_omit_content: nil,
49
51
  record_har_path: nil,
52
+ record_har_url_filter: nil,
50
53
  record_video_dir: nil,
51
54
  record_video_size: nil,
52
55
  reducedMotion: nil,
53
56
  screen: nil,
57
+ serviceWorkers: nil,
54
58
  strictSelectors: nil,
55
59
  timezoneId: nil,
56
60
  userAgent: nil,
@@ -8,7 +8,7 @@ sidebar_position: 10
8
8
 
9
9
  ```ruby
10
10
  file_chooser = page.expect_file_chooser do
11
- page.click("upload") # action to trigger file uploading
11
+ page.locator("upload").click # action to trigger file uploading
12
12
  end
13
13
  file_chooser.set_files("myfile.pdf")
14
14
  ```
@@ -34,7 +34,7 @@ def bounding_box(timeout: nil)
34
34
  This method returns the bounding box of the element, or `null` if the element is not visible. The bounding box is
35
35
  calculated relative to the main frame viewport - which is usually the same as the browser window.
36
36
 
37
- Scrolling affects the returned bonding box, similarly to
37
+ Scrolling affects the returned bounding box, similarly to
38
38
  [Element.getBoundingClientRect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect). That
39
39
  means `x` and/or `y` may be negative.
40
40
 
@@ -291,7 +291,19 @@ To send fine-grained keyboard events, use [Locator#type](./locator#type).
291
291
  def filter(has: nil, hasText: nil)
292
292
  ```
293
293
 
294
- This method narrows existing locator according to the options, for example filters by text.
294
+ This method narrows existing locator according to the options, for example filters by text. It can be chained to filter
295
+ multiple times.
296
+
297
+ ```ruby
298
+ row_locator = page.locator("tr")
299
+ # ...
300
+ row_locator.
301
+ filter(has_text="text in column 1").
302
+ filter(has=page.locator("tr", has_text="column 2 button")).
303
+ screenshot
304
+ ```
305
+
306
+
295
307
 
296
308
  ## first
297
309
 
@@ -330,6 +342,7 @@ locator.click
330
342
  ```
331
343
  def get_attribute(name, timeout: nil)
332
344
  ```
345
+ alias: `[]`
333
346
 
334
347
  Returns element attribute value.
335
348
 
@@ -564,11 +577,6 @@ element.select_option(label: "blue")
564
577
  element.select_option(value: ["red", "green", "blue"])
565
578
  ```
566
579
 
567
- ```ruby
568
- # multiple selection for blue, red and second option
569
- element.select_option(value: "blue", index: 2, label: "red")
570
- ```
571
-
572
580
 
573
581
 
574
582
  ## select_text
@@ -462,7 +462,7 @@ page.content = <<~HTML
462
462
  <button onclick="onClick()">Click me</button>
463
463
  <div></div>
464
464
  HTML
465
- page.click("button")
465
+ page.locator("button").click
466
466
  ```
467
467
 
468
468
  An example of passing an element handle:
@@ -483,7 +483,7 @@ page.content = <<~HTML
483
483
  <div>Or click me</div>
484
484
  HTML
485
485
 
486
- page.click('div')
486
+ page.locator('div').first.click
487
487
  ```
488
488
 
489
489
 
@@ -522,7 +522,7 @@ page.content = <<~HTML
522
522
  <button onclick="onClick()">Click me</button>
523
523
  <div></div>
524
524
  HTML
525
- page.click("button")
525
+ page.locator("button").click
526
526
  ```
527
527
 
528
528
 
@@ -975,7 +975,7 @@ Once routing is enabled, every request matching the url pattern will stall unles
975
975
  > NOTE: The handler will only be called for the first url if the response is a redirect.
976
976
  > NOTE: [Page#route](./page#route) will not intercept requests intercepted by Service Worker. See
977
977
  [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using
978
- request interception. Via `await context.addInitScript(() => delete window.navigator.serviceWorker);`
978
+ request interception by setting `Browser.newContext.serviceWorkers` to `'block'`.
979
979
 
980
980
  An example of a naive handler that aborts all image requests:
981
981
 
@@ -1013,6 +1013,19 @@ To remove a route with its handler you can use [Page#unroute](./page#unroute).
1013
1013
 
1014
1014
  > NOTE: Enabling routing disables http cache.
1015
1015
 
1016
+ ## route_from_har
1017
+
1018
+ ```
1019
+ def route_from_har(har, notFound: nil, update: nil, url: nil)
1020
+ ```
1021
+
1022
+ If specified the network requests that are made in the page will be served from the HAR file. Read more about
1023
+ [Replaying from HAR](https://playwright.dev/python/docs/network).
1024
+
1025
+ Playwright will not serve requests intercepted by Service Worker from the HAR file. See
1026
+ [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using
1027
+ request interception by setting `Browser.newContext.serviceWorkers` to `'block'`.
1028
+
1016
1029
  ## screenshot
1017
1030
 
1018
1031
  ```
@@ -1609,6 +1622,10 @@ associated with the page.
1609
1622
 
1610
1623
  ## accessibility
1611
1624
 
1625
+ **DEPRECATED** This property is deprecated. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you
1626
+ need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for
1627
+ integration with Axe.
1628
+
1612
1629
  ## keyboard
1613
1630
 
1614
1631
  ## mouse
@@ -56,7 +56,9 @@ Returns the [Frame](./frame) that initiated this request.
56
56
  def headers
57
57
  ```
58
58
 
59
- **DEPRECATED** Incomplete list of headers as seen by the rendering engine. Use [Request#all_headers](./request#all_headers) instead.
59
+ An object with the request HTTP headers. The header names are lower-cased. Note that this method does not return
60
+ security-related headers, including cookie-related ones. You can use [Request#all_headers](./request#all_headers) for complete list of
61
+ headers that include `cookie` information.
60
62
 
61
63
  ## headers_array
62
64
 
@@ -38,13 +38,24 @@ def frame
38
38
 
39
39
  Returns the [Frame](./frame) that initiated this response.
40
40
 
41
+ ## from_service_worker
42
+
43
+ ```
44
+ def from_service_worker
45
+ ```
46
+
47
+ Indicates whether this Response was fulfilled by a Service Worker's Fetch Handler (i.e. via
48
+ [FetchEvent.respondWith](https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/respondWith)).
49
+
41
50
  ## headers
42
51
 
43
52
  ```
44
53
  def headers
45
54
  ```
46
55
 
47
- **DEPRECATED** Incomplete list of headers as seen by the rendering engine. Use [Response#all_headers](./response#all_headers) instead.
56
+ An object with the response HTTP headers. The header names are lower-cased. Note that this method does not return
57
+ security-related headers, including cookie-related ones. You can use [Response#all_headers](./response#all_headers) for complete list
58
+ of headers that include `cookie` information.
48
59
 
49
60
  ## headers_array
50
61
 
@@ -31,6 +31,7 @@ def handle(route, request)
31
31
  headers = request.headers
32
32
  headers['foo'] = 'bar' # set "foo" header
33
33
  headers['user-agent'] = 'Unknown Browser' # modify user-agent
34
+ headers.delete('bar') # remove "bar" header
34
35
 
35
36
  route.continue(headers: headers)
36
37
  end
@@ -39,6 +40,70 @@ page.route("**/*", method(:handle))
39
40
 
40
41
 
41
42
 
43
+ ## fallback
44
+
45
+ ```
46
+ def fallback(headers: nil, method: nil, postData: nil, url: nil)
47
+ ```
48
+
49
+ When several routes match the given pattern, they run in the order opposite to their registration. That way the last
50
+ registered route can always override all the previous ones. In the example below, request will be handled by the
51
+ bottom-most handler first, then it'll fall back to the previous one and in the end will be aborted by the first
52
+ registered route.
53
+
54
+ ```ruby
55
+ page.route("**/*", -> (route,_) { route.abort }) # Runs last.
56
+ page.route("**/*", -> (route,_) { route.fallback }) # Runs second.
57
+ page.route("**/*", -> (route,_) { route.fallback }) # Runs first.
58
+ ```
59
+
60
+ Registering multiple routes is useful when you want separate handlers to handle different kinds of requests, for example
61
+ API calls vs page resources or GET requests vs POST requests as in the example below.
62
+
63
+ ```ruby
64
+ # Handle GET requests.
65
+ def handle_post(route, request)
66
+ if request.method != "GET"
67
+ route.fallback
68
+ return
69
+ end
70
+
71
+ # Handling GET only.
72
+ # ...
73
+ end
74
+
75
+ # Handle POST requests.
76
+ def handle_post(route)
77
+ if request.method != "POST"
78
+ route.fallback
79
+ return
80
+ end
81
+
82
+ # Handling POST only.
83
+ # ...
84
+ end
85
+
86
+ page.route("**/*", handle_get)
87
+ page.route("**/*", handle_post)
88
+ ```
89
+
90
+ One can also modify request while falling back to the subsequent handler, that way intermediate route handler can modify
91
+ url, method, headers and postData of the request.
92
+
93
+ ```ruby
94
+ def handle(route, request)
95
+ # override headers
96
+ headers = request.headers
97
+ headers['foo'] = 'bar' # set "foo" header
98
+ headers['user-agent'] = 'Unknown Browser' # modify user-agent
99
+ headers.delete('bar') # remove "bar" header
100
+
101
+ route.fallback(headers: headers)
102
+ end
103
+ ```
104
+
105
+
106
+
42
107
  ## fulfill
43
108
 
44
109
  ```
@@ -36,9 +36,9 @@ playwright.chromium.launch do |browser|
36
36
  page.content = '<div><button>Click me</button></div>'
37
37
 
38
38
  # Use the selector prefixed with its name.
39
- button = page.query_selector('tag=button')
39
+ button = page.locator('tag=button')
40
40
  # Combine it with other selector engines.
41
- page.click('tag=div >> text="Click me"')
41
+ page.locator('tag=div >> text="Click me"').click
42
42
 
43
43
  # Can use it in any methods supporting selectors.
44
44
  button_count = page.locator('tag=button').count
@@ -58,7 +58,7 @@ page = context.new_page
58
58
  page.goto("https://playwright.dev")
59
59
 
60
60
  context.tracing.start_chunk
61
- page.click("text=Get Started")
61
+ page.locator("text=Get Started").click
62
62
  # Everything between start_chunk and stop_chunk will be recorded in the trace.
63
63
  context.tracing.stop_chunk(path: "trace1.zip")
64
64
 
@@ -27,6 +27,7 @@
27
27
  * body
28
28
  * finished
29
29
  * frame
30
+ * from_service_worker
30
31
  * headers
31
32
  * headers_array
32
33
  * header_value
@@ -45,6 +46,7 @@
45
46
 
46
47
  * abort
47
48
  * continue
49
+ * fallback
48
50
  * fulfill
49
51
  * request
50
52
 
@@ -280,6 +282,7 @@
280
282
  * query_selector_all
281
283
  * reload
282
284
  * route
285
+ * route_from_har
283
286
  * screenshot
284
287
  * select_option
285
288
  * set_checked
@@ -339,6 +342,7 @@
339
342
  * new_page
340
343
  * pages
341
344
  * route
345
+ * route_from_har
342
346
  * service_workers
343
347
  * set_default_navigation_timeout
344
348
  * set_default_timeout
@@ -360,6 +364,7 @@
360
364
 
361
365
  ## Browser
362
366
 
367
+ * browser_type
363
368
  * close
364
369
  * contexts
365
370
  * connected?
@@ -454,9 +459,6 @@
454
459
  * locator
455
460
  * nth
456
461
 
457
- ## LocalUtils
458
-
459
-
460
462
  ## APIResponse
461
463
 
462
464
  * body
@@ -14,11 +14,11 @@
14
14
  "write-heading-ids": "docusaurus write-heading-ids"
15
15
  },
16
16
  "dependencies": {
17
- "@docusaurus/core": "^2.0.0-beta.18",
18
- "@docusaurus/preset-classic": "^2.0.0-beta.18",
17
+ "@docusaurus/core": "^2.0.1",
18
+ "@docusaurus/preset-classic": "^2.0.1",
19
19
  "@mdx-js/react": "^1.6.22",
20
- "@svgr/webpack": "^6.2.1",
21
- "clsx": "^1.1.1",
20
+ "@svgr/webpack": "^6.3.1",
21
+ "clsx": "^1.2.1",
22
22
  "file-loader": "^6.2.0",
23
23
  "react": "^18.0.0",
24
24
  "react-dom": "^18.0.0",