playwright-ruby-client 1.17.beta1 → 1.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/docs/api/api_request.md +7 -0
  3. data/documentation/docs/api/api_request_context.md +161 -0
  4. data/documentation/docs/api/api_response.md +104 -0
  5. data/documentation/docs/api/browser_context.md +4 -0
  6. data/documentation/docs/api/download.md +1 -3
  7. data/documentation/docs/api/frame.md +1 -1
  8. data/documentation/docs/api/frame_locator.md +10 -1
  9. data/documentation/docs/api/locator.md +19 -47
  10. data/documentation/docs/api/page.md +5 -1
  11. data/documentation/docs/include/api_coverage.md +35 -13
  12. data/lib/playwright/api_response_impl.rb +73 -0
  13. data/lib/playwright/channel_owners/api_request_context.rb +232 -0
  14. data/lib/playwright/channel_owners/browser_context.rb +8 -1
  15. data/lib/playwright/channel_owners/frame.rb +2 -2
  16. data/lib/playwright/channel_owners/local_utils.rb +14 -0
  17. data/lib/playwright/channel_owners/page.rb +6 -2
  18. data/lib/playwright/frame_locator_impl.rb +2 -1
  19. data/lib/playwright/locator_impl.rb +62 -3
  20. data/lib/playwright/tracing_impl.rb +21 -7
  21. data/lib/playwright/version.rb +2 -2
  22. data/lib/playwright_api/android.rb +6 -6
  23. data/lib/playwright_api/android_device.rb +8 -8
  24. data/lib/playwright_api/api_request.rb +20 -0
  25. data/lib/playwright_api/api_request_context.rb +61 -14
  26. data/lib/playwright_api/api_response.rb +81 -0
  27. data/lib/playwright_api/browser.rb +6 -6
  28. data/lib/playwright_api/browser_context.rb +12 -12
  29. data/lib/playwright_api/browser_type.rb +6 -6
  30. data/lib/playwright_api/cdp_session.rb +6 -6
  31. data/lib/playwright_api/console_message.rb +6 -6
  32. data/lib/playwright_api/dialog.rb +6 -6
  33. data/lib/playwright_api/download.rb +0 -4
  34. data/lib/playwright_api/element_handle.rb +6 -6
  35. data/lib/playwright_api/frame.rb +8 -8
  36. data/lib/playwright_api/frame_locator.rb +11 -2
  37. data/lib/playwright_api/js_handle.rb +6 -6
  38. data/lib/playwright_api/local_utils.rb +9 -0
  39. data/lib/playwright_api/locator.rb +16 -46
  40. data/lib/playwright_api/page.rb +17 -12
  41. data/lib/playwright_api/playwright.rb +6 -6
  42. data/lib/playwright_api/request.rb +6 -6
  43. data/lib/playwright_api/response.rb +6 -6
  44. data/lib/playwright_api/route.rb +6 -6
  45. data/lib/playwright_api/selectors.rb +6 -6
  46. data/lib/playwright_api/web_socket.rb +6 -6
  47. data/lib/playwright_api/worker.rb +8 -8
  48. data/playwright.gemspec +1 -1
  49. metadata +15 -8
@@ -3,6 +3,53 @@ module Playwright
3
3
  # environment or the service to your e2e test. When used on `Page` or a `BrowserContext`, this API will automatically use
4
4
  # the cookies from the corresponding `BrowserContext`. This means that if you log in using this API, your e2e test will be
5
5
  # logged in and vice versa.
6
+ #
7
+ # ```python sync
8
+ # import os
9
+ # from playwright.sync_api import sync_playwright
10
+ #
11
+ # REPO = "test-repo-1"
12
+ # USER = "github-username"
13
+ # API_TOKEN = os.getenv("GITHUB_API_TOKEN")
14
+ #
15
+ # with sync_playwright() as p:
16
+ # # This will launch a new browser, create a context and page. When making HTTP
17
+ # # requests with the internal APIRequestContext (e.g. `context.request` or `page.request`)
18
+ # # it will automatically set the cookies to the browser page and vise versa.
19
+ # browser = playwright.chromium.launch()
20
+ # context = browser.new_context(base_url="https://api.github.com")
21
+ # api_request_context = context.request
22
+ # page = context.new_page()
23
+ #
24
+ # # Alternatively you can create a APIRequestContext manually without having a browser context attached:
25
+ # # api_request_context = playwright.request.new_context(base_url="https://api.github.com")
26
+ #
27
+ #
28
+ # # Create a repository.
29
+ # response = api_request_context.post(
30
+ # "/user/repos",
31
+ # headers={
32
+ # "Accept": "application/vnd.github.v3+json",
33
+ # # Add GitHub personal access token.
34
+ # "Authorization": f"token {API_TOKEN}",
35
+ # },
36
+ # data={"name": REPO},
37
+ # )
38
+ # assert response.ok
39
+ # assert response.json()["name"] == REPO
40
+ #
41
+ # # Delete a repository.
42
+ # response = api_request_context.delete(
43
+ # f"/repos/{USER}/{REPO}",
44
+ # headers={
45
+ # "Accept": "application/vnd.github.v3+json",
46
+ # # Add GitHub personal access token.
47
+ # "Authorization": f"token {API_TOKEN}",
48
+ # },
49
+ # )
50
+ # assert response.ok
51
+ # assert await response.body() == '{"status": "ok"}'
52
+ # ```
6
53
  class APIRequestContext < PlaywrightApi
7
54
 
8
55
  # Sends HTTP(S) [DELETE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE) request and returns its
@@ -18,14 +65,14 @@ module Playwright
18
65
  multipart: nil,
19
66
  params: nil,
20
67
  timeout: nil)
21
- raise NotImplementedError.new('delete is not implemented yet.')
68
+ wrap_impl(@impl.delete(unwrap_impl(url), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
22
69
  end
23
70
 
24
71
  # All responses returned by [`method: APIRequestContext.get`] and similar methods are stored in the memory, so that you
25
72
  # can later call [`method: APIResponse.body`]. This method discards all stored responses, and makes
26
73
  # [`method: APIResponse.body`] throw "Response disposed" error.
27
74
  def dispose
28
- raise NotImplementedError.new('dispose is not implemented yet.')
75
+ wrap_impl(@impl.dispose)
29
76
  end
30
77
 
31
78
  # Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
@@ -41,7 +88,7 @@ module Playwright
41
88
  multipart: nil,
42
89
  params: nil,
43
90
  timeout: nil)
44
- raise NotImplementedError.new('fetch is not implemented yet.')
91
+ wrap_impl(@impl.fetch(unwrap_impl(urlOrRequest), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), method: unwrap_impl(method), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
45
92
  end
46
93
 
47
94
  # Sends HTTP(S) [GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET) request and returns its response. The
@@ -54,7 +101,7 @@ module Playwright
54
101
  ignoreHTTPSErrors: nil,
55
102
  params: nil,
56
103
  timeout: nil)
57
- raise NotImplementedError.new('get is not implemented yet.')
104
+ wrap_impl(@impl.get(unwrap_impl(url), failOnStatusCode: unwrap_impl(failOnStatusCode), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
58
105
  end
59
106
 
60
107
  # Sends HTTP(S) [HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD) request and returns its response.
@@ -67,7 +114,7 @@ module Playwright
67
114
  ignoreHTTPSErrors: nil,
68
115
  params: nil,
69
116
  timeout: nil)
70
- raise NotImplementedError.new('head is not implemented yet.')
117
+ wrap_impl(@impl.head(unwrap_impl(url), failOnStatusCode: unwrap_impl(failOnStatusCode), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
71
118
  end
72
119
 
73
120
  # Sends HTTP(S) [PATCH](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH) request and returns its response.
@@ -83,7 +130,7 @@ module Playwright
83
130
  multipart: nil,
84
131
  params: nil,
85
132
  timeout: nil)
86
- raise NotImplementedError.new('patch is not implemented yet.')
133
+ wrap_impl(@impl.patch(unwrap_impl(url), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
87
134
  end
88
135
 
89
136
  # Sends HTTP(S) [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) request and returns its response.
@@ -99,7 +146,7 @@ module Playwright
99
146
  multipart: nil,
100
147
  params: nil,
101
148
  timeout: nil)
102
- raise NotImplementedError.new('post is not implemented yet.')
149
+ wrap_impl(@impl.post(unwrap_impl(url), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
103
150
  end
104
151
 
105
152
  # Sends HTTP(S) [PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT) request and returns its response. The
@@ -115,7 +162,7 @@ module Playwright
115
162
  multipart: nil,
116
163
  params: nil,
117
164
  timeout: nil)
118
- raise NotImplementedError.new('put is not implemented yet.')
165
+ wrap_impl(@impl.put(unwrap_impl(url), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
119
166
  end
120
167
 
121
168
  # Returns storage state for this request context, contains current cookies and local storage snapshot if it was passed to
@@ -124,12 +171,6 @@ module Playwright
124
171
  raise NotImplementedError.new('storage_state is not implemented yet.')
125
172
  end
126
173
 
127
- # -- inherited from EventEmitter --
128
- # @nodoc
129
- def off(event, callback)
130
- event_emitter_proxy.off(event, callback)
131
- end
132
-
133
174
  # -- inherited from EventEmitter --
134
175
  # @nodoc
135
176
  def once(event, callback)
@@ -142,6 +183,12 @@ module Playwright
142
183
  event_emitter_proxy.on(event, callback)
143
184
  end
144
185
 
186
+ # -- inherited from EventEmitter --
187
+ # @nodoc
188
+ def off(event, callback)
189
+ event_emitter_proxy.off(event, callback)
190
+ end
191
+
145
192
  private def event_emitter_proxy
146
193
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
147
194
  end
@@ -0,0 +1,81 @@
1
+ module Playwright
2
+ # `APIResponse` class represents responses returned by [`method: APIRequestContext.get`] and similar methods.
3
+ #
4
+ # ```python sync
5
+ # from playwright.sync_api import sync_playwright
6
+ #
7
+ # with sync_playwright() as p:
8
+ # context = playwright.request.new_context()
9
+ # response = context.get("https://example.com/user/repos")
10
+ # assert response.ok
11
+ # assert response.status == 200
12
+ # assert response.headers["content-type"] == "application/json; charset=utf-8"
13
+ # assert response.json()["name"] == "foobar"
14
+ # assert response.body() == '{"status": "ok"}'
15
+ # ```
16
+ class APIResponse < PlaywrightApi
17
+
18
+ # Returns the buffer with response body.
19
+ def body
20
+ wrap_impl(@impl.body)
21
+ end
22
+
23
+ # Disposes the body of this response. If not called then the body will stay in memory until the context closes.
24
+ def dispose
25
+ wrap_impl(@impl.dispose)
26
+ end
27
+
28
+ # An object with all the response HTTP headers associated with this response.
29
+ def headers
30
+ wrap_impl(@impl.headers)
31
+ end
32
+
33
+ # An array with all the request HTTP headers associated with this response. Header names are not lower-cased. Headers with
34
+ # multiple entries, such as `Set-Cookie`, appear in the array multiple times.
35
+ def headers_array
36
+ wrap_impl(@impl.headers_array)
37
+ end
38
+
39
+ # Returns the JSON representation of response body.
40
+ #
41
+ # This method will throw if the response body is not parsable via `JSON.parse`.
42
+ def json
43
+ wrap_impl(@impl.json)
44
+ end
45
+
46
+ # Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
47
+ def ok
48
+ wrap_impl(@impl.ok)
49
+ end
50
+
51
+ # Contains the status code of the response (e.g., 200 for a success).
52
+ def status
53
+ wrap_impl(@impl.status)
54
+ end
55
+
56
+ # Contains the status text of the response (e.g. usually an "OK" for a success).
57
+ def status_text
58
+ wrap_impl(@impl.status_text)
59
+ end
60
+
61
+ # Returns the text representation of response body.
62
+ def text
63
+ wrap_impl(@impl.text)
64
+ end
65
+
66
+ # Contains the URL of the response.
67
+ def url
68
+ wrap_impl(@impl.url)
69
+ end
70
+
71
+ # @nodoc
72
+ def ok?
73
+ wrap_impl(@impl.ok?)
74
+ end
75
+
76
+ # @nodoc
77
+ def to_s
78
+ wrap_impl(@impl.to_s)
79
+ end
80
+ end
81
+ end
@@ -166,12 +166,6 @@ module Playwright
166
166
  wrap_impl(@impl.version)
167
167
  end
168
168
 
169
- # -- inherited from EventEmitter --
170
- # @nodoc
171
- def off(event, callback)
172
- event_emitter_proxy.off(event, callback)
173
- end
174
-
175
169
  # -- inherited from EventEmitter --
176
170
  # @nodoc
177
171
  def once(event, callback)
@@ -184,6 +178,12 @@ module Playwright
184
178
  event_emitter_proxy.on(event, callback)
185
179
  end
186
180
 
181
+ # -- inherited from EventEmitter --
182
+ # @nodoc
183
+ def off(event, callback)
184
+ event_emitter_proxy.off(event, callback)
185
+ end
186
+
187
187
  private def event_emitter_proxy
188
188
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
189
189
  end
@@ -22,7 +22,7 @@ module Playwright
22
22
 
23
23
  # API testing helper associated with this context. Requests made with this API will use context cookies.
24
24
  def request # property
25
- raise NotImplementedError.new('request is not implemented yet.')
25
+ wrap_impl(@impl.request)
26
26
  end
27
27
 
28
28
  def tracing # property
@@ -371,6 +371,11 @@ module Playwright
371
371
  raise NotImplementedError.new('wait_for_event is not implemented yet.')
372
372
  end
373
373
 
374
+ # @nodoc
375
+ def pause
376
+ wrap_impl(@impl.pause)
377
+ end
378
+
374
379
  # @nodoc
375
380
  def enable_debug_console!
376
381
  wrap_impl(@impl.enable_debug_console!)
@@ -386,22 +391,11 @@ module Playwright
386
391
  wrap_impl(@impl.owner_page=(unwrap_impl(req)))
387
392
  end
388
393
 
389
- # @nodoc
390
- def pause
391
- wrap_impl(@impl.pause)
392
- end
393
-
394
394
  # @nodoc
395
395
  def options=(req)
396
396
  wrap_impl(@impl.options=(unwrap_impl(req)))
397
397
  end
398
398
 
399
- # -- inherited from EventEmitter --
400
- # @nodoc
401
- def off(event, callback)
402
- event_emitter_proxy.off(event, callback)
403
- end
404
-
405
399
  # -- inherited from EventEmitter --
406
400
  # @nodoc
407
401
  def once(event, callback)
@@ -414,6 +408,12 @@ module Playwright
414
408
  event_emitter_proxy.on(event, callback)
415
409
  end
416
410
 
411
+ # -- inherited from EventEmitter --
412
+ # @nodoc
413
+ def off(event, callback)
414
+ event_emitter_proxy.off(event, callback)
415
+ end
416
+
417
417
  private def event_emitter_proxy
418
418
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
419
419
  end
@@ -146,12 +146,6 @@ module Playwright
146
146
  wrap_impl(@impl.name)
147
147
  end
148
148
 
149
- # -- inherited from EventEmitter --
150
- # @nodoc
151
- def off(event, callback)
152
- event_emitter_proxy.off(event, callback)
153
- end
154
-
155
149
  # -- inherited from EventEmitter --
156
150
  # @nodoc
157
151
  def once(event, callback)
@@ -164,6 +158,12 @@ module Playwright
164
158
  event_emitter_proxy.on(event, callback)
165
159
  end
166
160
 
161
+ # -- inherited from EventEmitter --
162
+ # @nodoc
163
+ def off(event, callback)
164
+ event_emitter_proxy.off(event, callback)
165
+ end
166
+
167
167
  private def event_emitter_proxy
168
168
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
169
169
  end
@@ -33,12 +33,6 @@ module Playwright
33
33
  wrap_impl(@impl.send_message(unwrap_impl(method), params: unwrap_impl(params)))
34
34
  end
35
35
 
36
- # -- inherited from EventEmitter --
37
- # @nodoc
38
- def off(event, callback)
39
- event_emitter_proxy.off(event, callback)
40
- end
41
-
42
36
  # -- inherited from EventEmitter --
43
37
  # @nodoc
44
38
  def once(event, callback)
@@ -51,6 +45,12 @@ module Playwright
51
45
  event_emitter_proxy.on(event, callback)
52
46
  end
53
47
 
48
+ # -- inherited from EventEmitter --
49
+ # @nodoc
50
+ def off(event, callback)
51
+ event_emitter_proxy.off(event, callback)
52
+ end
53
+
54
54
  private def event_emitter_proxy
55
55
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
56
56
  end
@@ -23,12 +23,6 @@ module Playwright
23
23
  wrap_impl(@impl.type)
24
24
  end
25
25
 
26
- # -- inherited from EventEmitter --
27
- # @nodoc
28
- def off(event, callback)
29
- event_emitter_proxy.off(event, callback)
30
- end
31
-
32
26
  # -- inherited from EventEmitter --
33
27
  # @nodoc
34
28
  def once(event, callback)
@@ -41,6 +35,12 @@ module Playwright
41
35
  event_emitter_proxy.on(event, callback)
42
36
  end
43
37
 
38
+ # -- inherited from EventEmitter --
39
+ # @nodoc
40
+ def off(event, callback)
41
+ event_emitter_proxy.off(event, callback)
42
+ end
43
+
44
44
  private def event_emitter_proxy
45
45
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
46
46
  end
@@ -58,12 +58,6 @@ module Playwright
58
58
  wrap_impl(@impl.accept_async(promptText: unwrap_impl(promptText)))
59
59
  end
60
60
 
61
- # -- inherited from EventEmitter --
62
- # @nodoc
63
- def off(event, callback)
64
- event_emitter_proxy.off(event, callback)
65
- end
66
-
67
61
  # -- inherited from EventEmitter --
68
62
  # @nodoc
69
63
  def once(event, callback)
@@ -76,6 +70,12 @@ module Playwright
76
70
  event_emitter_proxy.on(event, callback)
77
71
  end
78
72
 
73
+ # -- inherited from EventEmitter --
74
+ # @nodoc
75
+ def off(event, callback)
76
+ event_emitter_proxy.off(event, callback)
77
+ end
78
+
79
79
  private def event_emitter_proxy
80
80
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
81
81
  end
@@ -12,10 +12,6 @@ module Playwright
12
12
  # # wait for download to complete
13
13
  # path = download.path()
14
14
  # ```
15
- #
16
- # > NOTE: Browser context **must** be created with the `acceptDownloads` set to `true` when user needs access to the
17
- # downloaded content. If `acceptDownloads` is not set, download events are emitted, but the actual download is not
18
- # performed and user has no access to the downloaded files.
19
15
  class Download < PlaywrightApi
20
16
 
21
17
  # Cancels a download. Will not fail if the download is already finished or canceled. Upon successful cancellations,
@@ -551,12 +551,6 @@ module Playwright
551
551
  wrap_impl(@impl.wait_for_selector(unwrap_impl(selector), state: unwrap_impl(state), strict: unwrap_impl(strict), timeout: unwrap_impl(timeout)))
552
552
  end
553
553
 
554
- # -- inherited from EventEmitter --
555
- # @nodoc
556
- def off(event, callback)
557
- event_emitter_proxy.off(event, callback)
558
- end
559
-
560
554
  # -- inherited from EventEmitter --
561
555
  # @nodoc
562
556
  def once(event, callback)
@@ -569,6 +563,12 @@ module Playwright
569
563
  event_emitter_proxy.on(event, callback)
570
564
  end
571
565
 
566
+ # -- inherited from EventEmitter --
567
+ # @nodoc
568
+ def off(event, callback)
569
+ event_emitter_proxy.off(event, callback)
570
+ end
571
+
572
572
  private def event_emitter_proxy
573
573
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
574
574
  end
@@ -445,8 +445,8 @@ module Playwright
445
445
  # The method returns an element locator that can be used to perform actions in the frame. Locator is resolved to the
446
446
  # element immediately before performing an action, so a series of actions on the same locator can in fact be performed on
447
447
  # different DOM elements. That would happen if the DOM structure between those actions has changed.
448
- def locator(selector)
449
- wrap_impl(@impl.locator(unwrap_impl(selector)))
448
+ def locator(selector, hasText: nil)
449
+ wrap_impl(@impl.locator(unwrap_impl(selector), hasText: unwrap_impl(hasText)))
450
450
  end
451
451
 
452
452
  # Returns frame's name attribute as specified in the tag.
@@ -788,12 +788,6 @@ module Playwright
788
788
  wrap_impl(@impl.detached=(unwrap_impl(req)))
789
789
  end
790
790
 
791
- # -- inherited from EventEmitter --
792
- # @nodoc
793
- def off(event, callback)
794
- event_emitter_proxy.off(event, callback)
795
- end
796
-
797
791
  # -- inherited from EventEmitter --
798
792
  # @nodoc
799
793
  def once(event, callback)
@@ -806,6 +800,12 @@ module Playwright
806
800
  event_emitter_proxy.on(event, callback)
807
801
  end
808
802
 
803
+ # -- inherited from EventEmitter --
804
+ # @nodoc
805
+ def off(event, callback)
806
+ event_emitter_proxy.off(event, callback)
807
+ end
808
+
809
809
  private def event_emitter_proxy
810
810
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
811
811
  end
@@ -20,6 +20,15 @@ module Playwright
20
20
  # # Works because we explicitly tell locator to pick the first frame:
21
21
  # page.frame_locator('.result-frame').first.locator('button').click()
22
22
  # ```
23
+ #
24
+ # **Converting Locator to FrameLocator**
25
+ #
26
+ # If you have a `Locator` object pointing to an `iframe` it can be converted to `FrameLocator` using
27
+ # [`:scope`](https://developer.mozilla.org/en-US/docs/Web/CSS/:scope) CSS selector:
28
+ #
29
+ # ```python sync
30
+ # frameLocator = locator.frame_locator(":scope");
31
+ # ```
23
32
  class FrameLocator < PlaywrightApi
24
33
 
25
34
  # Returns locator to the first matching frame.
@@ -39,8 +48,8 @@ module Playwright
39
48
  end
40
49
 
41
50
  # The method finds an element matching the specified selector in the FrameLocator's subtree.
42
- def locator(selector)
43
- wrap_impl(@impl.locator(unwrap_impl(selector)))
51
+ def locator(selector, hasText: nil)
52
+ wrap_impl(@impl.locator(unwrap_impl(selector), hasText: unwrap_impl(hasText)))
44
53
  end
45
54
 
46
55
  # Returns locator to the n-th matching frame.
@@ -88,12 +88,6 @@ module Playwright
88
88
  wrap_impl(@impl.to_s)
89
89
  end
90
90
 
91
- # -- inherited from EventEmitter --
92
- # @nodoc
93
- def off(event, callback)
94
- event_emitter_proxy.off(event, callback)
95
- end
96
-
97
91
  # -- inherited from EventEmitter --
98
92
  # @nodoc
99
93
  def once(event, callback)
@@ -106,6 +100,12 @@ module Playwright
106
100
  event_emitter_proxy.on(event, callback)
107
101
  end
108
102
 
103
+ # -- inherited from EventEmitter --
104
+ # @nodoc
105
+ def off(event, callback)
106
+ event_emitter_proxy.off(event, callback)
107
+ end
108
+
109
109
  private def event_emitter_proxy
110
110
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
111
111
  end
@@ -0,0 +1,9 @@
1
+ module Playwright
2
+ class LocalUtils < PlaywrightApi
3
+
4
+ # @nodoc
5
+ def zip(zip_file, name_value_array)
6
+ wrap_impl(@impl.zip(unwrap_impl(zip_file), unwrap_impl(name_value_array)))
7
+ end
8
+ end
9
+ end
@@ -1,49 +1,8 @@
1
1
  module Playwright
2
- # Locator represents a view to the element(s) on the page. It captures the logic sufficient to retrieve the element at any
3
- # given moment. Locator can be created with the [`method: Page.locator`] method.
2
+ # Locators are the central piece of Playwright's auto-waiting and retry-ability. In a nutshell, locators represent a way
3
+ # to find element(s) on the page at any moment. Locator can be created with the [`method: Page.locator`] method.
4
4
  #
5
- # ```python sync
6
- # locator = page.locator("text=Submit")
7
- # locator.click()
8
- # ```
9
- #
10
- # The difference between the Locator and `ElementHandle` is that the latter points to a particular element, while Locator
11
- # captures the logic of how to retrieve that element.
12
- #
13
- # In the example below, handle points to a particular DOM element on page. If that element changes text or is used by
14
- # React to render an entirely different component, handle is still pointing to that very DOM element. This can lead to
15
- # unexpected behaviors.
16
- #
17
- # ```python sync
18
- # handle = page.query_selector("text=Submit")
19
- # handle.hover()
20
- # handle.click()
21
- # ```
22
- #
23
- # With the locator, every time the `element` is used, up-to-date DOM element is located in the page using the selector. So
24
- # in the snippet below, underlying DOM element is going to be located twice.
25
- #
26
- # ```python sync
27
- # locator = page.locator("text=Submit")
28
- # locator.hover()
29
- # locator.click()
30
- # ```
31
- #
32
- # **Strictness**
33
- #
34
- # Locators are strict. This means that all operations on locators that imply some target DOM element will throw if more
35
- # than one element matches given selector.
36
- #
37
- # ```python sync
38
- # # Throws if there are several buttons in DOM:
39
- # page.locator('button').click()
40
- #
41
- # # Works because we explicitly tell locator to pick the first element:
42
- # page.locator('button').first.click()
43
- #
44
- # # Works because count knows what to do with multiple matches:
45
- # page.locator('button').count()
46
- # ```
5
+ # [Learn more about locators](./locators.md).
47
6
  class Locator < PlaywrightApi
48
7
 
49
8
  # Returns an array of `node.innerText` values for all matching nodes.
@@ -183,6 +142,17 @@ module Playwright
183
142
  wrap_impl(@impl.dispatch_event(unwrap_impl(type), eventInit: unwrap_impl(eventInit), timeout: unwrap_impl(timeout)))
184
143
  end
185
144
 
145
+ def drag_to(
146
+ target,
147
+ force: nil,
148
+ noWaitAfter: nil,
149
+ sourcePosition: nil,
150
+ targetPosition: nil,
151
+ timeout: nil,
152
+ trial: nil)
153
+ wrap_impl(@impl.drag_to(unwrap_impl(target), force: unwrap_impl(force), noWaitAfter: unwrap_impl(noWaitAfter), sourcePosition: unwrap_impl(sourcePosition), targetPosition: unwrap_impl(targetPosition), timeout: unwrap_impl(timeout), trial: unwrap_impl(trial)))
154
+ end
155
+
186
156
  # Resolves given locator to the first matching DOM element. If no elements matching the query are visible, waits for them
187
157
  # up to a given timeout. If multiple elements match the selector, throws.
188
158
  def element_handle(timeout: nil)
@@ -350,8 +320,8 @@ module Playwright
350
320
  end
351
321
 
352
322
  # The method finds an element matching the specified selector in the `Locator`'s subtree.
353
- def locator(selector)
354
- wrap_impl(@impl.locator(unwrap_impl(selector)))
323
+ def locator(selector, hasText: nil)
324
+ wrap_impl(@impl.locator(unwrap_impl(selector), hasText: unwrap_impl(hasText)))
355
325
  end
356
326
 
357
327
  # Returns locator to the n-th matching element.