playwright-ruby-client 1.16.beta1 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) 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 +17 -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 +25 -7
  13. data/lib/playwright/channel.rb +1 -1
  14. data/lib/playwright/channel_owners/api_request_context.rb +4 -0
  15. data/lib/playwright/channel_owners/artifact.rb +1 -6
  16. data/lib/playwright/channel_owners/browser.rb +6 -8
  17. data/lib/playwright/channel_owners/browser_context.rb +5 -3
  18. data/lib/playwright/channel_owners/browser_type.rb +0 -1
  19. data/lib/playwright/channel_owners/fetch_request.rb +5 -1
  20. data/lib/playwright/channel_owners/frame.rb +10 -6
  21. data/lib/playwright/channel_owners/page.rb +18 -10
  22. data/lib/playwright/channel_owners/request.rb +9 -21
  23. data/lib/playwright/channel_owners/response.rb +0 -4
  24. data/lib/playwright/connection.rb +9 -0
  25. data/lib/playwright/frame_locator_impl.rb +49 -0
  26. data/lib/playwright/locator_impl.rb +13 -5
  27. data/lib/playwright/route_handler.rb +13 -1
  28. data/lib/playwright/tracing_impl.rb +6 -9
  29. data/lib/playwright/version.rb +2 -2
  30. data/lib/playwright/video.rb +3 -0
  31. data/lib/playwright.rb +2 -1
  32. data/lib/playwright_api/api_request_context.rb +149 -0
  33. data/lib/playwright_api/browser_context.rb +6 -1
  34. data/lib/playwright_api/element_handle.rb +2 -3
  35. data/lib/playwright_api/frame.rb +26 -1
  36. data/lib/playwright_api/frame_locator.rb +51 -0
  37. data/lib/playwright_api/locator.rb +12 -2
  38. data/lib/playwright_api/page.rb +35 -9
  39. data/lib/playwright_api/playwright.rb +5 -0
  40. data/lib/playwright_api/selectors.rb +2 -2
  41. data/lib/playwright_api/tracing.rb +4 -4
  42. metadata +12 -8
  43. data/lib/playwright_api/fetch_request.rb +0 -77
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac716fcd59a6c1b520004d0c5797dadaf77d8a5ec78dd60903cd424a2d9569ca
4
- data.tar.gz: 6ec8fb266d6ce38229ee17e68dec62e5ba42edb09ddd59814242fe5dd757c157
3
+ metadata.gz: 35d4a4e4ac3aa460997a5a9cd44b5272142ba89b480908f0e429fb97d7968337
4
+ data.tar.gz: 2a577b8683a2eba60ed97b88b183bd351477cbde0874b8d06d287be0ec4664e8
5
5
  SHA512:
6
- metadata.gz: 3c3fc4e0689b164b90791c9c288895966de3c42275df2c46f89fcd19999df2d830dd9fa081532d106a178ae17cd18807240ab3fe3c07f287f9906777b3bb0c72
7
- data.tar.gz: cec2ee542633b9b7c803de01fc3b700a7b78eeac15e156dca97d99b62f9142c9f749e90a006b44bf9d7108ffeed63329b64003da53603fd02fcb75374f6a33e1
6
+ metadata.gz: 283b87141e9ab9090488684973741983506da16d9ea991945589a1177cd99a5cf2c3b65b35770cc95a6ed3645514c35c9925e75aaffb949d58cbe6a47380c334
7
+ data.tar.gz: 7a6071b83e537784b58e6b350c1654a7dfa90bc99576f8ae1780c2104b30242ddd2e9651f6eb9f880a3a777e9345a5706373fbd66b64cc32739ce10cb389b5fb
@@ -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
 
@@ -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
@@ -443,6 +453,14 @@
443
453
  * uncheck
444
454
  * wait_for
445
455
 
456
+ ## FrameLocator
457
+
458
+ * first
459
+ * frame_locator
460
+ * last
461
+ * locator
462
+ * nth
463
+
446
464
  ## Android
447
465
 
448
466
  * devices
@@ -71,7 +71,7 @@ module Playwright
71
71
  {
72
72
  apiName: api_name,
73
73
  stack: stacks.map do |loc|
74
- { file: loc.absolute_path, line: loc.lineno, function: loc.label }
74
+ { file: loc.absolute_path || '', line: loc.lineno, function: loc.label }
75
75
  end,
76
76
  }
77
77
  end
@@ -0,0 +1,4 @@
1
+ module Playwright
2
+ define_channel_owner :APIRequestContext do
3
+ end
4
+ end
@@ -1,14 +1,13 @@
1
1
  module Playwright
2
2
  define_channel_owner :Artifact do
3
3
  private def after_initialize
4
- @remote = false
5
4
  @absolute_path = @initializer['absolutePath']
6
5
  end
7
6
 
8
7
  attr_reader :absolute_path
9
8
 
10
9
  def path_after_finished
11
- if @remote
10
+ if @connection.remote?
12
11
  raise "Path is not available when using browser_type.connect(). Use save_as() to save a local copy."
13
12
  end
14
13
  @channel.send_message_to_server('pathAfterFinished')
@@ -30,9 +29,5 @@ module Playwright
30
29
  def cancel
31
30
  @channel.send_message_to_server('cancel')
32
31
  end
33
-
34
- private def update_as_remote
35
- @remote = true
36
- end
37
32
  end
38
33
  end
@@ -7,7 +7,7 @@ module Playwright
7
7
  private def after_initialize
8
8
  @connected = true
9
9
  @closed_or_closing = false
10
- @remote = false
10
+ @should_close_connection_on_close = false
11
11
 
12
12
  @contexts = Set.new
13
13
  @channel.on('close', method(:on_close))
@@ -58,6 +58,9 @@ module Playwright
58
58
  return if @closed_or_closing
59
59
  @closed_or_closing = true
60
60
  @channel.send_message_to_server('close')
61
+ if @should_close_connection_on_close
62
+ @connection.stop
63
+ end
61
64
  nil
62
65
  rescue => err
63
66
  raise unless safe_close_error?(err)
@@ -99,13 +102,8 @@ module Playwright
99
102
  @contexts << context
100
103
  end
101
104
 
102
- # called from BrowserType#connectOverCDP
103
- private def update_as_remote
104
- @remote = true
105
- end
106
-
107
- private def remote?
108
- @remote
105
+ private def should_close_connection_on_close!
106
+ @should_close_connection_on_close = true
109
107
  end
110
108
 
111
109
  # called from BrowserContext#on_close with send(:remove_context), so keep private.
@@ -72,6 +72,11 @@ module Playwright
72
72
 
73
73
  if @routes.none? { |handler_entry| handler_entry.handle(wrapped_route, wrapped_request) }
74
74
  route.continue
75
+ else
76
+ @routes.reject!(&:expired?)
77
+ if @routes.count == 0
78
+ @channel.async_send_message_to_server('setNetworkInterceptionEnabled', enabled: false)
79
+ end
75
80
  end
76
81
  end
77
82
 
@@ -271,9 +276,6 @@ module Playwright
271
276
  def close
272
277
  if @options && @options.key?(:recordHar)
273
278
  har = ChannelOwners::Artifact.from(@channel.send_message_to_server('harExport'))
274
- if @browser.send(:remote?)
275
- har.update_as_remote
276
- end
277
279
  har.save_as(@options[:recordHar][:path])
278
280
  har.delete
279
281
  end
@@ -54,7 +54,6 @@ module Playwright
54
54
 
55
55
  result = @channel.send_message_to_server_result('connectOverCDP', params)
56
56
  browser = ChannelOwners::Browser.from(result['browser'])
57
- browser.send(:update_as_remote)
58
57
 
59
58
  if result['defaultContext']
60
59
  context = ChannelOwners::BrowserContext.from(result['defaultContext'])
@@ -1,4 +1,8 @@
1
+ require_relative './api_request_context'
2
+
1
3
  module Playwright
2
- define_channel_owner :FetchRequest do
4
+ module ChannelOwners
5
+ class FetchRequest < APIRequestContext
6
+ end
3
7
  end
4
8
  end
@@ -110,8 +110,8 @@ module Playwright
110
110
  def wait_for_load_state(state: nil, timeout: nil)
111
111
  option_state = state || 'load'
112
112
  option_timeout = timeout || @page.send(:timeout_settings).navigation_timeout
113
- unless %w(load domcontentloaded networkidle).include?(option_state)
114
- raise ArgumentError.new('state: expected one of (load|domcontentloaded|networkidle)')
113
+ unless %w(load domcontentloaded networkidle commit).include?(option_state)
114
+ raise ArgumentError.new('state: expected one of (load|domcontentloaded|networkidle|commit)')
115
115
  end
116
116
  if @load_states.include?(option_state)
117
117
  return
@@ -191,10 +191,6 @@ module Playwright
191
191
  @channel.send_message_to_server('isVisible', params)
192
192
  end
193
193
 
194
- def locator(selector)
195
- LocatorImpl.new(frame: self, timeout_settings: @page.send(:timeout_settings), selector: selector)
196
- end
197
-
198
194
  def dispatch_event(selector, type, eventInit: nil, strict: nil, timeout: nil)
199
195
  params = {
200
196
  selector: selector,
@@ -404,6 +400,14 @@ module Playwright
404
400
  nil
405
401
  end
406
402
 
403
+ def locator(selector)
404
+ LocatorImpl.new(frame: self, timeout_settings: @page.send(:timeout_settings), selector: selector)
405
+ end
406
+
407
+ def frame_locator(selector)
408
+ FrameLocatorImpl.new(frame: self, timeout_settings: @page.send(:timeout_settings), frame_selector: selector)
409
+ end
410
+
407
411
  def focus(selector, strict: nil, timeout: nil)
408
412
  params = { selector: selector, strict: strict, timeout: timeout }.compact
409
413
  @channel.send_message_to_server('focus', params)
@@ -100,6 +100,11 @@ module Playwright
100
100
 
101
101
  if @routes.none? { |handler_entry| handler_entry.handle(wrapped_route, wrapped_request) }
102
102
  @browser_context.send(:on_route, route, request)
103
+ else
104
+ @routes.reject!(&:expired?)
105
+ if @routes.count == 0
106
+ @channel.async_send_message_to_server('setNetworkInterceptionEnabled', enabled: false)
107
+ end
103
108
  end
104
109
  end
105
110
 
@@ -133,9 +138,6 @@ module Playwright
133
138
 
134
139
  private def on_download(params)
135
140
  artifact = ChannelOwners::Artifact.from(params['artifact'])
136
- if @browser_context.browser.send(:remote?)
137
- artifact.update_as_remote
138
- end
139
141
  download = DownloadImpl.new(
140
142
  page: self,
141
143
  url: params['url'],
@@ -147,9 +149,6 @@ module Playwright
147
149
 
148
150
  private def on_video(params)
149
151
  artifact = ChannelOwners::Artifact.from(params['artifact'])
150
- if @browser_context.browser.send(:remote?)
151
- artifact.update_as_remote
152
- end
153
152
  video.send(:set_artifact, artifact)
154
153
  end
155
154
 
@@ -256,10 +255,6 @@ module Playwright
256
255
  @main_frame.visible?(selector, strict: strict, timeout: timeout)
257
256
  end
258
257
 
259
- def locator(selector)
260
- @main_frame.locator(selector)
261
- end
262
-
263
258
  def dispatch_event(selector, type, eventInit: nil, strict: nil, timeout: nil)
264
259
  @main_frame.dispatch_event(selector, type, eventInit: eventInit, strict: strict, timeout: timeout)
265
260
  end
@@ -563,6 +558,14 @@ module Playwright
563
558
  timeout: timeout)
564
559
  end
565
560
 
561
+ def locator(selector)
562
+ @main_frame.locator(selector)
563
+ end
564
+
565
+ def frame_locator(selector)
566
+ @main_frame.frame_locator(selector)
567
+ end
568
+
566
569
  def focus(selector, strict: nil, timeout: nil)
567
570
  @main_frame.focus(selector, strict: strict, timeout: timeout)
568
571
  end
@@ -920,6 +923,11 @@ module Playwright
920
923
  @workers.delete(worker)
921
924
  end
922
925
 
926
+ # called from Video
927
+ private def remote_connection?
928
+ @connection.remote?
929
+ end
930
+
923
931
  # Expose guid for library developers.
924
932
  # Not intended to be used by users.
925
933
  def guid