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,298 @@
1
+ ---
2
+ sidebar_position: 10
3
+ ---
4
+
5
+ # APIRequestContext
6
+
7
+
8
+ This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services, prepare
9
+ environment or the service to your e2e test.
10
+
11
+ Each Playwright browser context has associated with it [APIRequestContext](./api_request_context) instance which shares cookie storage with
12
+ the browser context and can be accessed via [BrowserContext#request](./browser_context#request) or [Page#request](./page#request).
13
+ It is also possible to create a new APIRequestContext instance manually by calling [APIRequest#new_context](./api_request#new_context).
14
+
15
+ **Cookie management**
16
+
17
+ [APIRequestContext](./api_request_context) returned by [BrowserContext#request](./browser_context#request) and [Page#request](./page#request) shares cookie
18
+ storage with the corresponding [BrowserContext](./browser_context). Each API request will have `Cookie` header populated with the
19
+ values from the browser context. If the API response contains `Set-Cookie` header it will automatically update
20
+ [BrowserContext](./browser_context) cookies and requests made from the page will pick them up. This means that if you log in using
21
+ this API, your e2e test will be logged in and vice versa.
22
+
23
+ If you want API requests to not interfere with the browser cookies you should create a new [APIRequestContext](./api_request_context) by
24
+ calling [APIRequest#new_context](./api_request#new_context). Such [APIRequestContext](./api_request_context) object will have its own isolated cookie
25
+ storage.
26
+
27
+ ```ruby
28
+ playwright.chromium.launch do |browser|
29
+ # This will launch a new browser, create a context and page. When making HTTP
30
+ # requests with the internal APIRequestContext (e.g. `context.request` or `page.request`)
31
+ # it will automatically set the cookies to the browser page and vise versa.
32
+ context = browser.new_context(base_url: 'https://api.github,com')
33
+ api_request_context = context.request
34
+
35
+
36
+ # Create a repository.
37
+ response = api_request_context.post(
38
+ "/user/repos",
39
+ headers: {
40
+ "Accept": "application/vnd.github.v3+json",
41
+ "Authorization": "Bearer #{API_TOKEN}",
42
+ },
43
+ data: { name: 'test-repo-1' },
44
+ )
45
+ response.ok? # => true
46
+ response.json['name'] # => "test-repo-1"
47
+
48
+ # Delete a repository.
49
+ response = api_request_context.delete(
50
+ "/repos/YourName/test-repo-1",
51
+ headers: {
52
+ "Accept": "application/vnd.github.v3+json",
53
+ "Authorization": "Bearer #{API_TOKEN}",
54
+ },
55
+ )
56
+ response.ok? # => true
57
+ end
58
+ ```
59
+
60
+ ## delete
61
+
62
+ ```
63
+ def delete(
64
+ url,
65
+ data: nil,
66
+ failOnStatusCode: nil,
67
+ form: nil,
68
+ headers: nil,
69
+ ignoreHTTPSErrors: nil,
70
+ maxRedirects: nil,
71
+ maxRetries: nil,
72
+ multipart: nil,
73
+ params: nil,
74
+ timeout: nil)
75
+ ```
76
+
77
+
78
+ Sends HTTP(S) [DELETE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE) request and returns its response.
79
+ The method will populate request cookies from the context and update
80
+ context cookies from the response. The method will automatically follow redirects.
81
+
82
+ ## dispose
83
+
84
+ ```
85
+ def dispose(reason: nil)
86
+ ```
87
+
88
+
89
+ All responses returned by [APIRequestContext#get](./api_request_context#get) and similar methods are stored in the memory, so that you can later call [APIResponse#body](./api_response#body).This method discards all its resources, calling any method on disposed [APIRequestContext](./api_request_context) will throw an exception.
90
+
91
+ ## fetch
92
+
93
+ ```
94
+ def fetch(
95
+ urlOrRequest,
96
+ data: nil,
97
+ failOnStatusCode: nil,
98
+ form: nil,
99
+ headers: nil,
100
+ ignoreHTTPSErrors: nil,
101
+ maxRedirects: nil,
102
+ maxRetries: nil,
103
+ method: nil,
104
+ multipart: nil,
105
+ params: nil,
106
+ timeout: nil)
107
+ ```
108
+
109
+
110
+ Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
111
+ context cookies from the response. The method will automatically follow redirects.
112
+
113
+ **Usage**
114
+
115
+ JSON objects can be passed directly to the request:
116
+
117
+ ```ruby
118
+ data = {
119
+ title: "Book Title",
120
+ body: "John Doe",
121
+ }
122
+ api_request_context.fetch("https://example.com/api/create_book", method: 'post', data: data)
123
+ ```
124
+
125
+ 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:
126
+
127
+ ```ruby
128
+ api_request_context.fetch(
129
+ "https://example.com/api/upload_script",
130
+ method: 'post',
131
+ multipart: {
132
+ fileField: {
133
+ name: "f.js",
134
+ mimeType: "text/javascript",
135
+ buffer: "console.log(2022);",
136
+ },
137
+ },
138
+ )
139
+ ```
140
+
141
+ ## get
142
+
143
+ ```
144
+ def get(
145
+ url,
146
+ data: nil,
147
+ failOnStatusCode: nil,
148
+ form: nil,
149
+ headers: nil,
150
+ ignoreHTTPSErrors: nil,
151
+ maxRedirects: nil,
152
+ maxRetries: nil,
153
+ multipart: nil,
154
+ params: nil,
155
+ timeout: nil)
156
+ ```
157
+
158
+
159
+ Sends HTTP(S) [GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET) request and returns its response.
160
+ The method will populate request cookies from the context and update
161
+ context cookies from the response. The method will automatically follow redirects.
162
+
163
+ **Usage**
164
+
165
+ Request parameters can be configured with `params` option, they will be serialized into the URL search parameters:
166
+
167
+ ```ruby
168
+ query_params = {
169
+ isbn: "1234",
170
+ page: "23"
171
+ }
172
+ api_request_context.get("https://example.com/api/get_text", params: query_params)
173
+ ```
174
+
175
+ ## head
176
+
177
+ ```
178
+ def head(
179
+ url,
180
+ data: nil,
181
+ failOnStatusCode: nil,
182
+ form: nil,
183
+ headers: nil,
184
+ ignoreHTTPSErrors: nil,
185
+ maxRedirects: nil,
186
+ maxRetries: nil,
187
+ multipart: nil,
188
+ params: nil,
189
+ timeout: nil)
190
+ ```
191
+
192
+
193
+ Sends HTTP(S) [HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD) request and returns its response.
194
+ The method will populate request cookies from the context and update
195
+ context cookies from the response. The method will automatically follow redirects.
196
+
197
+ ## patch
198
+
199
+ ```
200
+ def patch(
201
+ url,
202
+ data: nil,
203
+ failOnStatusCode: nil,
204
+ form: nil,
205
+ headers: nil,
206
+ ignoreHTTPSErrors: nil,
207
+ maxRedirects: nil,
208
+ maxRetries: nil,
209
+ multipart: nil,
210
+ params: nil,
211
+ timeout: nil)
212
+ ```
213
+
214
+
215
+ Sends HTTP(S) [PATCH](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH) request and returns its response.
216
+ The method will populate request cookies from the context and update
217
+ context cookies from the response. The method will automatically follow redirects.
218
+
219
+ ## post
220
+
221
+ ```
222
+ def post(
223
+ url,
224
+ data: nil,
225
+ failOnStatusCode: nil,
226
+ form: nil,
227
+ headers: nil,
228
+ ignoreHTTPSErrors: nil,
229
+ maxRedirects: nil,
230
+ maxRetries: nil,
231
+ multipart: nil,
232
+ params: nil,
233
+ timeout: nil)
234
+ ```
235
+
236
+
237
+ Sends HTTP(S) [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) request and returns its response.
238
+ The method will populate request cookies from the context and update
239
+ context cookies from the response. The method will automatically follow redirects.
240
+
241
+ **Usage**
242
+
243
+ JSON objects can be passed directly to the request:
244
+
245
+ ```ruby
246
+ data = {
247
+ title: "Book Title",
248
+ body: "John Doe",
249
+ }
250
+ api_request_context.post("https://example.com/api/create_book", data: data)
251
+ ```
252
+
253
+ 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):
254
+
255
+ ```ruby
256
+ form_data = {
257
+ title: "Book Title",
258
+ body: "John Doe",
259
+ }
260
+ api_request_context.post("https://example.com/api/find_book", form: form_data)
261
+ ```
262
+
263
+ 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:
264
+
265
+ ```ruby
266
+ api_request_context.post(
267
+ "https://example.com/api/upload_script",
268
+ multipart: {
269
+ fileField: {
270
+ name: "f.js",
271
+ mimeType: "text/javascript",
272
+ buffer: "console.log(2022);",
273
+ },
274
+ },
275
+ )
276
+ ```
277
+
278
+ ## put
279
+
280
+ ```
281
+ def put(
282
+ url,
283
+ data: nil,
284
+ failOnStatusCode: nil,
285
+ form: nil,
286
+ headers: nil,
287
+ ignoreHTTPSErrors: nil,
288
+ maxRedirects: nil,
289
+ maxRetries: nil,
290
+ multipart: nil,
291
+ params: nil,
292
+ timeout: nil)
293
+ ```
294
+
295
+
296
+ Sends HTTP(S) [PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT) request and returns its response.
297
+ The method will populate request cookies from the context and update
298
+ context cookies from the response. The method will automatically follow redirects.
@@ -0,0 +1,114 @@
1
+ ---
2
+ sidebar_position: 10
3
+ ---
4
+
5
+ # APIResponse
6
+
7
+
8
+ [APIResponse](./api_response) class represents responses returned by [APIRequestContext#get](./api_request_context#get) and similar methods.
9
+
10
+ ```ruby
11
+ playwright.chromium.launch do |browser|
12
+ context = browser.new_context
13
+ response = context.request.get("https://example.com/user/repos")
14
+
15
+ response.ok? # => true
16
+ response.status # => 200
17
+ response.headers["content-type"] # => "application/json; charset=utf-8"
18
+ response.json # => { "name" => "Foo" }
19
+ response.body # => "{ \"name\" => \"Foo\" }"
20
+ end
21
+ ```
22
+
23
+ ## body
24
+
25
+ ```
26
+ def body
27
+ ```
28
+
29
+
30
+ Returns the buffer with response body.
31
+
32
+ ## dispose
33
+
34
+ ```
35
+ def dispose
36
+ ```
37
+
38
+
39
+ Disposes the body of this response. If not called then the body will stay in memory until the context closes.
40
+
41
+ ## headers
42
+
43
+ ```
44
+ def headers
45
+ ```
46
+
47
+
48
+ An object with all the response HTTP headers associated with this response.
49
+
50
+ ## headers_array
51
+
52
+ ```
53
+ def headers_array
54
+ ```
55
+
56
+
57
+ An array with all the response HTTP headers associated with this response. Header names are not lower-cased.
58
+ Headers with multiple entries, such as `Set-Cookie`, appear in the array multiple times.
59
+
60
+ ## json
61
+
62
+ ```
63
+ def json
64
+ ```
65
+
66
+
67
+ Returns the JSON representation of response body.
68
+
69
+ This method will throw if the response body is not parsable via `JSON.parse`.
70
+
71
+ ## ok
72
+
73
+ ```
74
+ def ok
75
+ ```
76
+
77
+
78
+ Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
79
+
80
+ ## status
81
+
82
+ ```
83
+ def status
84
+ ```
85
+
86
+
87
+ Contains the status code of the response (e.g., 200 for a success).
88
+
89
+ ## status_text
90
+
91
+ ```
92
+ def status_text
93
+ ```
94
+
95
+
96
+ Contains the status text of the response (e.g. usually an "OK" for a success).
97
+
98
+ ## text
99
+
100
+ ```
101
+ def text
102
+ ```
103
+
104
+
105
+ Returns the text representation of response body.
106
+
107
+ ## url
108
+
109
+ ```
110
+ def url
111
+ ```
112
+
113
+
114
+ Contains the URL of the response.
@@ -0,0 +1,237 @@
1
+ ---
2
+ sidebar_position: 10
3
+ ---
4
+
5
+ # Browser
6
+
7
+
8
+ A Browser is created via [BrowserType#launch](./browser_type#launch). An example of using a [Browser](./browser) to create a [Page](./page):
9
+
10
+ ```ruby
11
+ firefox = playwright.firefox
12
+ browser = firefox.launch
13
+ begin
14
+ page = browser.new_page
15
+ page.goto("https://example.com")
16
+ ensure
17
+ browser.close
18
+ end
19
+ ```
20
+
21
+ ## browser_type
22
+
23
+ ```
24
+ def browser_type
25
+ ```
26
+
27
+
28
+ Get the browser type (chromium, firefox or webkit) that the browser belongs to.
29
+
30
+ ## close
31
+
32
+ ```
33
+ def close(reason: nil)
34
+ ```
35
+
36
+
37
+ In case this browser is obtained using [BrowserType#launch](./browser_type#launch), closes the browser and all of its pages (if any
38
+ were opened).
39
+
40
+ In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from the
41
+ browser server.
42
+
43
+ **NOTE**: This is similar to force-quitting the browser. To close pages gracefully and ensure you receive page close events, call [BrowserContext#close](./browser_context#close) on any [BrowserContext](./browser_context) instances you explicitly created earlier using [Browser#new_context](./browser#new_context) **before** calling [Browser#close](./browser#close).
44
+
45
+ The [Browser](./browser) object itself is considered to be disposed and cannot be used anymore.
46
+
47
+ ## contexts
48
+
49
+ ```
50
+ def contexts
51
+ ```
52
+
53
+
54
+ Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.
55
+
56
+ **Usage**
57
+
58
+ ```ruby
59
+ playwright.webkit.launch do |browser|
60
+ puts browser.contexts.count # => 0
61
+ context = browser.new_context
62
+ puts browser.contexts.count # => 1
63
+ end
64
+ ```
65
+
66
+ ## connected?
67
+
68
+ ```
69
+ def connected?
70
+ ```
71
+
72
+
73
+ Indicates that the browser is connected.
74
+
75
+ ## new_browser_cdp_session
76
+
77
+ ```
78
+ def new_browser_cdp_session
79
+ ```
80
+
81
+
82
+ **NOTE**: CDP Sessions are only supported on Chromium-based browsers.
83
+
84
+ Returns the newly created browser session.
85
+
86
+ ## new_context
87
+
88
+ ```
89
+ def new_context(
90
+ acceptDownloads: nil,
91
+ baseURL: nil,
92
+ bypassCSP: nil,
93
+ clientCertificates: nil,
94
+ colorScheme: nil,
95
+ contrast: nil,
96
+ deviceScaleFactor: nil,
97
+ extraHTTPHeaders: nil,
98
+ forcedColors: nil,
99
+ geolocation: nil,
100
+ hasTouch: nil,
101
+ httpCredentials: nil,
102
+ ignoreHTTPSErrors: nil,
103
+ isMobile: nil,
104
+ javaScriptEnabled: nil,
105
+ locale: nil,
106
+ noViewport: nil,
107
+ offline: nil,
108
+ permissions: nil,
109
+ proxy: nil,
110
+ record_har_content: nil,
111
+ record_har_mode: nil,
112
+ record_har_omit_content: nil,
113
+ record_har_path: nil,
114
+ record_har_url_filter: nil,
115
+ record_video_dir: nil,
116
+ record_video_size: nil,
117
+ reducedMotion: nil,
118
+ screen: nil,
119
+ serviceWorkers: nil,
120
+ storageState: nil,
121
+ strictSelectors: nil,
122
+ timezoneId: nil,
123
+ userAgent: nil,
124
+ viewport: nil,
125
+ &block)
126
+ ```
127
+
128
+
129
+ Creates a new browser context. It won't share cookies/cache with other browser contexts.
130
+
131
+ **NOTE**: If directly using this method to create [BrowserContext](./browser_context)s, it is best practice to explicitly close the returned context via [BrowserContext#close](./browser_context#close) when your code is done with the [BrowserContext](./browser_context),
132
+ and before calling [Browser#close](./browser#close). This will ensure the `context` is closed gracefully and any artifacts—like HARs and videos—are fully flushed and saved.
133
+
134
+ **Usage**
135
+
136
+ ```ruby
137
+ playwright.firefox.launch do |browser| # or "chromium.launch" or "webkit.launch".
138
+ # create a new incognito browser context.
139
+ browser.new_context do |context|
140
+ # create a new page in a pristine context.
141
+ page = context.new_page
142
+ page.goto("https://example.com")
143
+ end
144
+ end
145
+ ```
146
+
147
+ ## new_page
148
+
149
+ ```
150
+ def new_page(
151
+ acceptDownloads: nil,
152
+ baseURL: nil,
153
+ bypassCSP: nil,
154
+ clientCertificates: nil,
155
+ colorScheme: nil,
156
+ contrast: nil,
157
+ deviceScaleFactor: nil,
158
+ extraHTTPHeaders: nil,
159
+ forcedColors: nil,
160
+ geolocation: nil,
161
+ hasTouch: nil,
162
+ httpCredentials: nil,
163
+ ignoreHTTPSErrors: nil,
164
+ isMobile: nil,
165
+ javaScriptEnabled: nil,
166
+ locale: nil,
167
+ noViewport: nil,
168
+ offline: nil,
169
+ permissions: nil,
170
+ proxy: nil,
171
+ record_har_content: nil,
172
+ record_har_mode: nil,
173
+ record_har_omit_content: nil,
174
+ record_har_path: nil,
175
+ record_har_url_filter: nil,
176
+ record_video_dir: nil,
177
+ record_video_size: nil,
178
+ reducedMotion: nil,
179
+ screen: nil,
180
+ serviceWorkers: nil,
181
+ storageState: nil,
182
+ strictSelectors: nil,
183
+ timezoneId: nil,
184
+ userAgent: nil,
185
+ viewport: nil,
186
+ &block)
187
+ ```
188
+
189
+
190
+ Creates a new page in a new browser context. Closing this page will close the context as well.
191
+
192
+ This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and
193
+ testing frameworks should explicitly create [Browser#new_context](./browser#new_context) followed by the
194
+ [BrowserContext#new_page](./browser_context#new_page) to control their exact life times.
195
+
196
+ ## start_tracing
197
+
198
+ ```
199
+ def start_tracing(page: nil, categories: nil, path: nil, screenshots: nil)
200
+ ```
201
+
202
+
203
+ **NOTE**: This API controls [Chromium Tracing](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool) which is a low-level chromium-specific debugging tool. API to control [Playwright Tracing](https://playwright.dev/python/docs/trace-viewer) could be found [here](./tracing).
204
+
205
+ You can use [Browser#start_tracing](./browser#start_tracing) and [Browser#stop_tracing](./browser#stop_tracing) to create a trace file that can
206
+ be opened in Chrome DevTools performance panel.
207
+
208
+ **Usage**
209
+
210
+ ```ruby
211
+ browser.start_tracing(page: page, path: "trace.json")
212
+ begin
213
+ page.goto("https://www.google.com")
214
+ ensure
215
+ browser.stop_tracing
216
+ end
217
+ ```
218
+
219
+ ## stop_tracing
220
+
221
+ ```
222
+ def stop_tracing
223
+ ```
224
+
225
+
226
+ **NOTE**: This API controls [Chromium Tracing](https://www.chromium.org/developers/how-tos/trace-event-profiling-tool) which is a low-level chromium-specific debugging tool. API to control [Playwright Tracing](https://playwright.dev/python/docs/trace-viewer) could be found [here](./tracing).
227
+
228
+ Returns the buffer with trace data.
229
+
230
+ ## version
231
+
232
+ ```
233
+ def version
234
+ ```
235
+
236
+
237
+ Returns the browser version.