playwright-ruby-client 0.0.8 → 1.58.1.alpha1

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 (209) hide show
  1. checksums.yaml +4 -4
  2. data/AGENTS.md +4 -0
  3. data/CLAUDE/api_generation.md +28 -0
  4. data/CLAUDE/ci_expectations.md +23 -0
  5. data/CLAUDE/gem_release_flow.md +39 -0
  6. data/CLAUDE/past_upgrade_pr_patterns.md +42 -0
  7. data/CLAUDE/playwright_upgrade_workflow.md +35 -0
  8. data/CLAUDE/rspec_debugging.md +30 -0
  9. data/CLAUDE/unimplemented_examples.md +18 -0
  10. data/CLAUDE.md +32 -0
  11. data/CONTRIBUTING.md +5 -0
  12. data/README.md +60 -16
  13. data/documentation/README.md +33 -0
  14. data/documentation/babel.config.js +3 -0
  15. data/documentation/docs/api/api_request.md +7 -0
  16. data/documentation/docs/api/api_request_context.md +298 -0
  17. data/documentation/docs/api/api_response.md +114 -0
  18. data/documentation/docs/api/browser.md +237 -0
  19. data/documentation/docs/api/browser_context.md +503 -0
  20. data/documentation/docs/api/browser_type.md +184 -0
  21. data/documentation/docs/api/cdp_session.md +44 -0
  22. data/documentation/docs/api/clock.md +154 -0
  23. data/documentation/docs/api/console_message.md +85 -0
  24. data/documentation/docs/api/dialog.md +84 -0
  25. data/documentation/docs/api/download.md +111 -0
  26. data/documentation/docs/api/element_handle.md +694 -0
  27. data/documentation/docs/api/experimental/_category_.yml +3 -0
  28. data/documentation/docs/api/experimental/android.md +42 -0
  29. data/documentation/docs/api/experimental/android_device.md +109 -0
  30. data/documentation/docs/api/experimental/android_input.md +43 -0
  31. data/documentation/docs/api/experimental/android_socket.md +7 -0
  32. data/documentation/docs/api/experimental/android_web_view.md +7 -0
  33. data/documentation/docs/api/file_chooser.md +53 -0
  34. data/documentation/docs/api/frame.md +1218 -0
  35. data/documentation/docs/api/frame_locator.md +348 -0
  36. data/documentation/docs/api/js_handle.md +121 -0
  37. data/documentation/docs/api/keyboard.md +170 -0
  38. data/documentation/docs/api/locator.md +1495 -0
  39. data/documentation/docs/api/locator_assertions.md +827 -0
  40. data/documentation/docs/api/mouse.md +86 -0
  41. data/documentation/docs/api/page.md +1946 -0
  42. data/documentation/docs/api/page_assertions.md +65 -0
  43. data/documentation/docs/api/playwright.md +66 -0
  44. data/documentation/docs/api/request.md +255 -0
  45. data/documentation/docs/api/response.md +176 -0
  46. data/documentation/docs/api/route.md +205 -0
  47. data/documentation/docs/api/selectors.md +63 -0
  48. data/documentation/docs/api/touchscreen.md +22 -0
  49. data/documentation/docs/api/tracing.md +129 -0
  50. data/documentation/docs/api/web_socket.md +51 -0
  51. data/documentation/docs/api/worker.md +83 -0
  52. data/documentation/docs/article/api_coverage.mdx +11 -0
  53. data/documentation/docs/article/getting_started.md +161 -0
  54. data/documentation/docs/article/guides/_category_.yml +3 -0
  55. data/documentation/docs/article/guides/download_playwright_driver.md +55 -0
  56. data/documentation/docs/article/guides/inspector.md +31 -0
  57. data/documentation/docs/article/guides/launch_browser.md +121 -0
  58. data/documentation/docs/article/guides/playwright_on_alpine_linux.md +112 -0
  59. data/documentation/docs/article/guides/rails_integration.md +278 -0
  60. data/documentation/docs/article/guides/rails_integration_with_null_driver.md +145 -0
  61. data/documentation/docs/article/guides/recording_video.md +79 -0
  62. data/documentation/docs/article/guides/rspec_integration.md +59 -0
  63. data/documentation/docs/article/guides/semi_automation.md +71 -0
  64. data/documentation/docs/article/guides/use_storage_state.md +78 -0
  65. data/documentation/docs/include/api_coverage.md +671 -0
  66. data/documentation/docusaurus.config.js +114 -0
  67. data/documentation/package.json +39 -0
  68. data/documentation/sidebars.js +15 -0
  69. data/documentation/src/components/HomepageFeatures.js +61 -0
  70. data/documentation/src/components/HomepageFeatures.module.css +13 -0
  71. data/documentation/src/css/custom.css +44 -0
  72. data/documentation/src/pages/index.js +49 -0
  73. data/documentation/src/pages/index.module.css +41 -0
  74. data/documentation/src/pages/markdown-page.md +7 -0
  75. data/documentation/static/.nojekyll +0 -0
  76. data/documentation/static/img/playwright-logo.svg +9 -0
  77. data/documentation/static/img/playwright-ruby-client.png +0 -0
  78. data/documentation/static/img/undraw_dropdown_menu.svg +1 -0
  79. data/documentation/static/img/undraw_web_development.svg +1 -0
  80. data/documentation/static/img/undraw_windows.svg +1 -0
  81. data/documentation/yarn.lock +9005 -0
  82. data/lib/playwright/{input_types/android_input.rb → android_input_impl.rb} +5 -1
  83. data/lib/playwright/api_implementation.rb +18 -0
  84. data/lib/playwright/api_response_impl.rb +77 -0
  85. data/lib/playwright/channel.rb +62 -1
  86. data/lib/playwright/channel_owner.rb +70 -7
  87. data/lib/playwright/channel_owners/android.rb +16 -3
  88. data/lib/playwright/channel_owners/android_device.rb +22 -66
  89. data/lib/playwright/channel_owners/api_request_context.rb +247 -0
  90. data/lib/playwright/channel_owners/artifact.rb +40 -0
  91. data/lib/playwright/channel_owners/binding_call.rb +70 -0
  92. data/lib/playwright/channel_owners/browser.rb +114 -22
  93. data/lib/playwright/channel_owners/browser_context.rb +589 -15
  94. data/lib/playwright/channel_owners/browser_type.rb +90 -1
  95. data/lib/playwright/channel_owners/cdp_session.rb +19 -0
  96. data/lib/playwright/channel_owners/dialog.rb +32 -0
  97. data/lib/playwright/channel_owners/element_handle.rb +107 -43
  98. data/lib/playwright/channel_owners/fetch_request.rb +8 -0
  99. data/lib/playwright/channel_owners/frame.rb +334 -104
  100. data/lib/playwright/channel_owners/js_handle.rb +9 -13
  101. data/lib/playwright/channel_owners/local_utils.rb +82 -0
  102. data/lib/playwright/channel_owners/page.rb +778 -95
  103. data/lib/playwright/channel_owners/playwright.rb +25 -30
  104. data/lib/playwright/channel_owners/request.rb +120 -18
  105. data/lib/playwright/channel_owners/response.rb +113 -0
  106. data/lib/playwright/channel_owners/route.rb +181 -0
  107. data/lib/playwright/channel_owners/stream.rb +30 -0
  108. data/lib/playwright/channel_owners/tracing.rb +117 -0
  109. data/lib/playwright/channel_owners/web_socket.rb +96 -0
  110. data/lib/playwright/channel_owners/worker.rb +46 -0
  111. data/lib/playwright/channel_owners/writable_stream.rb +14 -0
  112. data/lib/playwright/clock_impl.rb +67 -0
  113. data/lib/playwright/connection.rb +111 -63
  114. data/lib/playwright/console_message_impl.rb +29 -0
  115. data/lib/playwright/download_impl.rb +32 -0
  116. data/lib/playwright/errors.rb +42 -5
  117. data/lib/playwright/event_emitter.rb +17 -3
  118. data/lib/playwright/event_emitter_proxy.rb +49 -0
  119. data/lib/playwright/events.rb +10 -5
  120. data/lib/playwright/file_chooser_impl.rb +24 -0
  121. data/lib/playwright/frame_locator_impl.rb +66 -0
  122. data/lib/playwright/har_router.rb +89 -0
  123. data/lib/playwright/http_headers.rb +14 -0
  124. data/lib/playwright/input_files.rb +102 -15
  125. data/lib/playwright/javascript/expression.rb +7 -11
  126. data/lib/playwright/javascript/regex.rb +23 -0
  127. data/lib/playwright/javascript/source_url.rb +16 -0
  128. data/lib/playwright/javascript/value_parser.rb +108 -19
  129. data/lib/playwright/javascript/value_serializer.rb +47 -8
  130. data/lib/playwright/javascript/visitor_info.rb +26 -0
  131. data/lib/playwright/javascript.rb +2 -10
  132. data/lib/playwright/{input_types/keyboard.rb → keyboard_impl.rb} +6 -2
  133. data/lib/playwright/locator_assertions_impl.rb +571 -0
  134. data/lib/playwright/locator_impl.rb +544 -0
  135. data/lib/playwright/locator_utils.rb +136 -0
  136. data/lib/playwright/mouse_impl.rb +57 -0
  137. data/lib/playwright/page_assertions_impl.rb +154 -0
  138. data/lib/playwright/playwright_api.rb +102 -30
  139. data/lib/playwright/raw_headers.rb +61 -0
  140. data/lib/playwright/route_handler.rb +78 -0
  141. data/lib/playwright/select_option_values.rb +34 -13
  142. data/lib/playwright/selectors_impl.rb +45 -0
  143. data/lib/playwright/test.rb +102 -0
  144. data/lib/playwright/timeout_settings.rb +9 -4
  145. data/lib/playwright/touchscreen_impl.rb +14 -0
  146. data/lib/playwright/transport.rb +61 -10
  147. data/lib/playwright/url_matcher.rb +24 -2
  148. data/lib/playwright/utils.rb +48 -13
  149. data/lib/playwright/version.rb +2 -1
  150. data/lib/playwright/video.rb +54 -0
  151. data/lib/playwright/waiter.rb +166 -0
  152. data/lib/playwright/web_socket_client.rb +167 -0
  153. data/lib/playwright/web_socket_transport.rb +116 -0
  154. data/lib/playwright.rb +188 -11
  155. data/lib/playwright_api/android.rb +46 -11
  156. data/lib/playwright_api/android_device.rb +182 -31
  157. data/lib/playwright_api/android_input.rb +22 -13
  158. data/lib/playwright_api/android_socket.rb +18 -0
  159. data/lib/playwright_api/android_web_view.rb +24 -0
  160. data/lib/playwright_api/api_request.rb +26 -0
  161. data/lib/playwright_api/api_request_context.rb +311 -0
  162. data/lib/playwright_api/api_response.rb +92 -0
  163. data/lib/playwright_api/browser.rb +116 -103
  164. data/lib/playwright_api/browser_context.rb +290 -389
  165. data/lib/playwright_api/browser_type.rb +96 -118
  166. data/lib/playwright_api/cdp_session.rb +36 -39
  167. data/lib/playwright_api/clock.rb +121 -0
  168. data/lib/playwright_api/console_message.rb +35 -19
  169. data/lib/playwright_api/dialog.rb +53 -50
  170. data/lib/playwright_api/download.rb +49 -43
  171. data/lib/playwright_api/element_handle.rb +354 -402
  172. data/lib/playwright_api/file_chooser.rb +15 -18
  173. data/lib/playwright_api/frame.rb +703 -603
  174. data/lib/playwright_api/frame_locator.rb +285 -0
  175. data/lib/playwright_api/js_handle.rb +50 -76
  176. data/lib/playwright_api/keyboard.rb +67 -146
  177. data/lib/playwright_api/locator.rb +1304 -0
  178. data/lib/playwright_api/locator_assertions.rb +704 -0
  179. data/lib/playwright_api/mouse.rb +23 -29
  180. data/lib/playwright_api/page.rb +1196 -1176
  181. data/lib/playwright_api/page_assertions.rb +60 -0
  182. data/lib/playwright_api/playwright.rb +54 -122
  183. data/lib/playwright_api/request.rb +112 -74
  184. data/lib/playwright_api/response.rb +92 -20
  185. data/lib/playwright_api/route.rb +152 -62
  186. data/lib/playwright_api/selectors.rb +47 -61
  187. data/lib/playwright_api/touchscreen.rb +8 -2
  188. data/lib/playwright_api/tracing.rb +128 -0
  189. data/lib/playwright_api/web_socket.rb +43 -5
  190. data/lib/playwright_api/worker.rb +74 -34
  191. data/playwright.gemspec +14 -9
  192. data/sig/playwright.rbs +658 -0
  193. metadata +216 -50
  194. data/docs/api_coverage.md +0 -354
  195. data/lib/playwright/channel_owners/chromium_browser.rb +0 -8
  196. data/lib/playwright/channel_owners/chromium_browser_context.rb +0 -8
  197. data/lib/playwright/channel_owners/console_message.rb +0 -21
  198. data/lib/playwright/channel_owners/firefox_browser.rb +0 -8
  199. data/lib/playwright/channel_owners/selectors.rb +0 -4
  200. data/lib/playwright/channel_owners/webkit_browser.rb +0 -8
  201. data/lib/playwright/input_type.rb +0 -19
  202. data/lib/playwright/input_types/mouse.rb +0 -4
  203. data/lib/playwright/input_types/touchscreen.rb +0 -4
  204. data/lib/playwright/javascript/function.rb +0 -67
  205. data/lib/playwright/wait_helper.rb +0 -73
  206. data/lib/playwright_api/accessibility.rb +0 -93
  207. data/lib/playwright_api/binding_call.rb +0 -23
  208. data/lib/playwright_api/chromium_browser_context.rb +0 -57
  209. data/lib/playwright_api/video.rb +0 -24
@@ -0,0 +1,311 @@
1
+ module Playwright
2
+ #
3
+ # This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services, prepare
4
+ # environment or the service to your e2e test.
5
+ #
6
+ # Each Playwright browser context has associated with it `APIRequestContext` instance which shares cookie storage with
7
+ # the browser context and can be accessed via [`property: BrowserContext.request`] or [`property: Page.request`].
8
+ # It is also possible to create a new APIRequestContext instance manually by calling [`method: APIRequest.newContext`].
9
+ #
10
+ # **Cookie management**
11
+ #
12
+ # `APIRequestContext` returned by [`property: BrowserContext.request`] and [`property: Page.request`] shares cookie
13
+ # storage with the corresponding `BrowserContext`. Each API request will have `Cookie` header populated with the
14
+ # values from the browser context. If the API response contains `Set-Cookie` header it will automatically update
15
+ # `BrowserContext` cookies and requests made from the page will pick them up. This means that if you log in using
16
+ # this API, your e2e test will be logged in and vice versa.
17
+ #
18
+ # If you want API requests to not interfere with the browser cookies you should create a new `APIRequestContext` by
19
+ # calling [`method: APIRequest.newContext`]. Such `APIRequestContext` object will have its own isolated cookie
20
+ # storage.
21
+ #
22
+ # ```python sync
23
+ # import os
24
+ # from playwright.sync_api import sync_playwright
25
+ #
26
+ # REPO = "test-repo-1"
27
+ # USER = "github-username"
28
+ # API_TOKEN = os.getenv("GITHUB_API_TOKEN")
29
+ #
30
+ # with sync_playwright() as p:
31
+ # # This will launch a new browser, create a context and page. When making HTTP
32
+ # # requests with the internal APIRequestContext (e.g. `context.request` or `page.request`)
33
+ # # it will automatically set the cookies to the browser page and vice versa.
34
+ # browser = p.chromium.launch()
35
+ # context = browser.new_context(base_url="https://api.github.com")
36
+ # api_request_context = context.request
37
+ # page = context.new_page()
38
+ #
39
+ # # Alternatively you can create a APIRequestContext manually without having a browser context attached:
40
+ # # api_request_context = p.request.new_context(base_url="https://api.github.com")
41
+ #
42
+ #
43
+ # # Create a repository.
44
+ # response = api_request_context.post(
45
+ # "/user/repos",
46
+ # headers={
47
+ # "Accept": "application/vnd.github.v3+json",
48
+ # # Add GitHub personal access token.
49
+ # "Authorization": f"token {API_TOKEN}",
50
+ # },
51
+ # data={"name": REPO},
52
+ # )
53
+ # assert response.ok
54
+ # assert response.json()["name"] == REPO
55
+ #
56
+ # # Delete a repository.
57
+ # response = api_request_context.delete(
58
+ # f"/repos/{USER}/{REPO}",
59
+ # headers={
60
+ # "Accept": "application/vnd.github.v3+json",
61
+ # # Add GitHub personal access token.
62
+ # "Authorization": f"token {API_TOKEN}",
63
+ # },
64
+ # )
65
+ # assert response.ok
66
+ # assert await response.body() == '{"status": "ok"}'
67
+ # ```
68
+ class APIRequestContext < PlaywrightApi
69
+
70
+ #
71
+ # Sends HTTP(S) [DELETE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE) request and returns its response.
72
+ # The method will populate request cookies from the context and update
73
+ # context cookies from the response. The method will automatically follow redirects.
74
+ def delete(
75
+ url,
76
+ data: nil,
77
+ failOnStatusCode: nil,
78
+ form: nil,
79
+ headers: nil,
80
+ ignoreHTTPSErrors: nil,
81
+ maxRedirects: nil,
82
+ maxRetries: nil,
83
+ multipart: nil,
84
+ params: nil,
85
+ timeout: nil)
86
+ 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), maxRedirects: unwrap_impl(maxRedirects), maxRetries: unwrap_impl(maxRetries), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
87
+ end
88
+
89
+ #
90
+ # All responses returned by [`method: APIRequestContext.get`] and similar methods are stored in the memory, so that you can later call [`method: APIResponse.body`].This method discards all its resources, calling any method on disposed `APIRequestContext` will throw an exception.
91
+ def dispose(reason: nil)
92
+ wrap_impl(@impl.dispose(reason: unwrap_impl(reason)))
93
+ end
94
+
95
+ #
96
+ # Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
97
+ # context cookies from the response. The method will automatically follow redirects.
98
+ #
99
+ # **Usage**
100
+ #
101
+ # JSON objects can be passed directly to the request:
102
+ #
103
+ # ```python
104
+ # data = {
105
+ # "title": "Book Title",
106
+ # "body": "John Doe",
107
+ # }
108
+ # api_request_context.fetch("https://example.com/api/createBook", method="post", data=data)
109
+ # ```
110
+ #
111
+ # The common way to send file(s) in the body of a request is to upload them as form fields with `multipart/form-data` encoding, by specifiying the `multipart` parameter:
112
+ #
113
+ # ```python
114
+ # api_request_context.fetch(
115
+ # "https://example.com/api/uploadScript", method="post",
116
+ # multipart={
117
+ # "fileField": {
118
+ # "name": "f.js",
119
+ # "mimeType": "text/javascript",
120
+ # "buffer": b"console.log(2022);",
121
+ # },
122
+ # })
123
+ # ```
124
+ def fetch(
125
+ urlOrRequest,
126
+ data: nil,
127
+ failOnStatusCode: nil,
128
+ form: nil,
129
+ headers: nil,
130
+ ignoreHTTPSErrors: nil,
131
+ maxRedirects: nil,
132
+ maxRetries: nil,
133
+ method: nil,
134
+ multipart: nil,
135
+ params: nil,
136
+ timeout: nil)
137
+ 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), maxRedirects: unwrap_impl(maxRedirects), maxRetries: unwrap_impl(maxRetries), method: unwrap_impl(method), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
138
+ end
139
+
140
+ #
141
+ # Sends HTTP(S) [GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET) request and returns its response.
142
+ # The method will populate request cookies from the context and update
143
+ # context cookies from the response. The method will automatically follow redirects.
144
+ #
145
+ # **Usage**
146
+ #
147
+ # Request parameters can be configured with `params` option, they will be serialized into the URL search parameters:
148
+ #
149
+ # ```python
150
+ # query_params = {
151
+ # "isbn": "1234",
152
+ # "page": "23"
153
+ # }
154
+ # api_request_context.get("https://example.com/api/getText", params=query_params)
155
+ # ```
156
+ def get(
157
+ url,
158
+ data: nil,
159
+ failOnStatusCode: nil,
160
+ form: nil,
161
+ headers: nil,
162
+ ignoreHTTPSErrors: nil,
163
+ maxRedirects: nil,
164
+ maxRetries: nil,
165
+ multipart: nil,
166
+ params: nil,
167
+ timeout: nil)
168
+ wrap_impl(@impl.get(unwrap_impl(url), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), maxRedirects: unwrap_impl(maxRedirects), maxRetries: unwrap_impl(maxRetries), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
169
+ end
170
+
171
+ #
172
+ # Sends HTTP(S) [HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD) request and returns its response.
173
+ # The method will populate request cookies from the context and update
174
+ # context cookies from the response. The method will automatically follow redirects.
175
+ def head(
176
+ url,
177
+ data: nil,
178
+ failOnStatusCode: nil,
179
+ form: nil,
180
+ headers: nil,
181
+ ignoreHTTPSErrors: nil,
182
+ maxRedirects: nil,
183
+ maxRetries: nil,
184
+ multipart: nil,
185
+ params: nil,
186
+ timeout: nil)
187
+ wrap_impl(@impl.head(unwrap_impl(url), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), maxRedirects: unwrap_impl(maxRedirects), maxRetries: unwrap_impl(maxRetries), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
188
+ end
189
+
190
+ #
191
+ # Sends HTTP(S) [PATCH](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH) request and returns its response.
192
+ # The method will populate request cookies from the context and update
193
+ # context cookies from the response. The method will automatically follow redirects.
194
+ def patch(
195
+ url,
196
+ data: nil,
197
+ failOnStatusCode: nil,
198
+ form: nil,
199
+ headers: nil,
200
+ ignoreHTTPSErrors: nil,
201
+ maxRedirects: nil,
202
+ maxRetries: nil,
203
+ multipart: nil,
204
+ params: nil,
205
+ timeout: nil)
206
+ 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), maxRedirects: unwrap_impl(maxRedirects), maxRetries: unwrap_impl(maxRetries), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
207
+ end
208
+
209
+ #
210
+ # Sends HTTP(S) [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) request and returns its response.
211
+ # The method will populate request cookies from the context and update
212
+ # context cookies from the response. The method will automatically follow redirects.
213
+ #
214
+ # **Usage**
215
+ #
216
+ # JSON objects can be passed directly to the request:
217
+ #
218
+ # ```python
219
+ # data = {
220
+ # "title": "Book Title",
221
+ # "body": "John Doe",
222
+ # }
223
+ # api_request_context.post("https://example.com/api/createBook", data=data)
224
+ # ```
225
+ #
226
+ # To send form data to the server use `form` option. Its value will be encoded into the request body with `application/x-www-form-urlencoded` encoding (see below how to use `multipart/form-data` form encoding to send files):
227
+ #
228
+ # ```python
229
+ # formData = {
230
+ # "title": "Book Title",
231
+ # "body": "John Doe",
232
+ # }
233
+ # api_request_context.post("https://example.com/api/findBook", form=formData)
234
+ # ```
235
+ #
236
+ # The common way to send file(s) in the body of a request is to upload them as form fields with `multipart/form-data` encoding. Use `FormData` to construct request body and pass it to the request as `multipart` parameter:
237
+ #
238
+ # ```python
239
+ # api_request_context.post(
240
+ # "https://example.com/api/uploadScript'",
241
+ # multipart={
242
+ # "fileField": {
243
+ # "name": "f.js",
244
+ # "mimeType": "text/javascript",
245
+ # "buffer": b"console.log(2022);",
246
+ # },
247
+ # })
248
+ # ```
249
+ def post(
250
+ url,
251
+ data: nil,
252
+ failOnStatusCode: nil,
253
+ form: nil,
254
+ headers: nil,
255
+ ignoreHTTPSErrors: nil,
256
+ maxRedirects: nil,
257
+ maxRetries: nil,
258
+ multipart: nil,
259
+ params: nil,
260
+ timeout: nil)
261
+ 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), maxRedirects: unwrap_impl(maxRedirects), maxRetries: unwrap_impl(maxRetries), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
262
+ end
263
+
264
+ #
265
+ # Sends HTTP(S) [PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT) request and returns its response.
266
+ # The method will populate request cookies from the context and update
267
+ # context cookies from the response. The method will automatically follow redirects.
268
+ def put(
269
+ url,
270
+ data: nil,
271
+ failOnStatusCode: nil,
272
+ form: nil,
273
+ headers: nil,
274
+ ignoreHTTPSErrors: nil,
275
+ maxRedirects: nil,
276
+ maxRetries: nil,
277
+ multipart: nil,
278
+ params: nil,
279
+ timeout: nil)
280
+ 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), maxRedirects: unwrap_impl(maxRedirects), maxRetries: unwrap_impl(maxRetries), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
281
+ end
282
+
283
+ #
284
+ # Returns storage state for this request context, contains current cookies and local storage snapshot if it was passed to the constructor.
285
+ def storage_state(indexedDB: nil, path: nil)
286
+ raise NotImplementedError.new('storage_state is not implemented yet.')
287
+ end
288
+
289
+ # -- inherited from EventEmitter --
290
+ # @nodoc
291
+ def once(event, callback)
292
+ event_emitter_proxy.once(event, callback)
293
+ end
294
+
295
+ # -- inherited from EventEmitter --
296
+ # @nodoc
297
+ def on(event, callback)
298
+ event_emitter_proxy.on(event, callback)
299
+ end
300
+
301
+ # -- inherited from EventEmitter --
302
+ # @nodoc
303
+ def off(event, callback)
304
+ event_emitter_proxy.off(event, callback)
305
+ end
306
+
307
+ private def event_emitter_proxy
308
+ @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
309
+ end
310
+ end
311
+ end
@@ -0,0 +1,92 @@
1
+ module Playwright
2
+ #
3
+ # `APIResponse` class represents responses returned by [`method: APIRequestContext.get`] and similar methods.
4
+ #
5
+ # ```python sync
6
+ # from playwright.sync_api import sync_playwright
7
+ #
8
+ # with sync_playwright() as p:
9
+ # context = playwright.request.new_context()
10
+ # response = context.get("https://example.com/user/repos")
11
+ # assert response.ok
12
+ # assert response.status == 200
13
+ # assert response.headers["content-type"] == "application/json; charset=utf-8"
14
+ # assert response.json()["name"] == "foobar"
15
+ # assert response.body() == '{"status": "ok"}'
16
+ # ```
17
+ class APIResponse < PlaywrightApi
18
+
19
+ #
20
+ # Returns the buffer with response body.
21
+ def body
22
+ wrap_impl(@impl.body)
23
+ end
24
+
25
+ #
26
+ # Disposes the body of this response. If not called then the body will stay in memory until the context closes.
27
+ def dispose
28
+ wrap_impl(@impl.dispose)
29
+ end
30
+
31
+ #
32
+ # An object with all the response HTTP headers associated with this response.
33
+ def headers
34
+ wrap_impl(@impl.headers)
35
+ end
36
+
37
+ #
38
+ # An array with all the response HTTP headers associated with this response. Header names are not lower-cased.
39
+ # Headers with multiple entries, such as `Set-Cookie`, appear in the array multiple times.
40
+ def headers_array
41
+ wrap_impl(@impl.headers_array)
42
+ end
43
+
44
+ #
45
+ # Returns the JSON representation of response body.
46
+ #
47
+ # This method will throw if the response body is not parsable via `JSON.parse`.
48
+ def json
49
+ wrap_impl(@impl.json)
50
+ end
51
+
52
+ #
53
+ # Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
54
+ def ok
55
+ wrap_impl(@impl.ok)
56
+ end
57
+
58
+ #
59
+ # Contains the status code of the response (e.g., 200 for a success).
60
+ def status
61
+ wrap_impl(@impl.status)
62
+ end
63
+
64
+ #
65
+ # Contains the status text of the response (e.g. usually an "OK" for a success).
66
+ def status_text
67
+ wrap_impl(@impl.status_text)
68
+ end
69
+
70
+ #
71
+ # Returns the text representation of response body.
72
+ def text
73
+ wrap_impl(@impl.text)
74
+ end
75
+
76
+ #
77
+ # Contains the URL of the response.
78
+ def url
79
+ wrap_impl(@impl.url)
80
+ end
81
+
82
+ # @nodoc
83
+ def ok?
84
+ wrap_impl(@impl.ok?)
85
+ end
86
+
87
+ # @nodoc
88
+ def to_s
89
+ wrap_impl(@impl.to_s)
90
+ end
91
+ end
92
+ end