playwright-ruby-client 1.28.1 → 1.29.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.
- checksums.yaml +4 -4
- data/documentation/docs/api/accessibility.md +9 -14
- data/documentation/docs/api/api_request_context.md +44 -41
- data/documentation/docs/api/api_response.md +13 -3
- data/documentation/docs/api/browser.md +24 -23
- data/documentation/docs/api/browser_context.md +71 -45
- data/documentation/docs/api/browser_type.md +21 -14
- data/documentation/docs/api/cdp_session.md +3 -5
- data/documentation/docs/api/console_message.md +7 -4
- data/documentation/docs/api/dialog.md +9 -5
- data/documentation/docs/api/download.md +19 -11
- data/documentation/docs/api/element_handle.md +125 -116
- data/documentation/docs/api/experimental/android.md +4 -5
- data/documentation/docs/api/experimental/android_device.md +11 -2
- data/documentation/docs/api/experimental/android_input.md +5 -0
- data/documentation/docs/api/file_chooser.md +6 -3
- data/documentation/docs/api/frame.md +182 -171
- data/documentation/docs/api/frame_locator.md +27 -38
- data/documentation/docs/api/js_handle.md +16 -10
- data/documentation/docs/api/keyboard.md +29 -16
- data/documentation/docs/api/locator.md +189 -140
- data/documentation/docs/api/mouse.md +9 -4
- data/documentation/docs/api/page.md +304 -289
- data/documentation/docs/api/playwright.md +8 -5
- data/documentation/docs/api/request.md +34 -15
- data/documentation/docs/api/response.md +27 -10
- data/documentation/docs/api/route.md +44 -12
- data/documentation/docs/api/selectors.md +5 -3
- data/documentation/docs/api/touchscreen.md +2 -0
- data/documentation/docs/api/tracing.md +11 -11
- data/documentation/docs/api/web_socket.md +9 -4
- data/documentation/docs/api/worker.md +12 -11
- data/documentation/docs/include/api_coverage.md +2 -0
- data/lib/playwright/channel_owners/api_request_context.rb +37 -2
- data/lib/playwright/channel_owners/browser_context.rb +22 -26
- data/lib/playwright/channel_owners/page.rb +35 -25
- data/lib/playwright/channel_owners/route.rb +28 -8
- data/lib/playwright/event_emitter.rb +6 -1
- data/lib/playwright/locator_impl.rb +8 -0
- data/lib/playwright/select_option_values.rb +2 -0
- data/lib/playwright/version.rb +2 -2
- data/lib/playwright_api/accessibility.rb +9 -13
- data/lib/playwright_api/android.rb +14 -12
- data/lib/playwright_api/android_device.rb +38 -13
- data/lib/playwright_api/android_input.rb +5 -0
- data/lib/playwright_api/android_socket.rb +4 -2
- data/lib/playwright_api/android_web_view.rb +5 -2
- data/lib/playwright_api/api_request.rb +6 -3
- data/lib/playwright_api/api_request_context.rb +52 -42
- data/lib/playwright_api/api_response.rb +13 -2
- data/lib/playwright_api/browser.rb +30 -22
- data/lib/playwright_api/browser_context.rb +82 -45
- data/lib/playwright_api/browser_type.rb +29 -19
- data/lib/playwright_api/cdp_session.rb +9 -10
- data/lib/playwright_api/console_message.rb +13 -8
- data/lib/playwright_api/dialog.rb +14 -10
- data/lib/playwright_api/download.rb +19 -9
- data/lib/playwright_api/element_handle.rb +122 -99
- data/lib/playwright_api/file_chooser.rb +6 -1
- data/lib/playwright_api/frame.rb +186 -141
- data/lib/playwright_api/frame_locator.rb +29 -32
- data/lib/playwright_api/js_handle.rb +22 -12
- data/lib/playwright_api/keyboard.rb +29 -14
- data/lib/playwright_api/locator.rb +183 -112
- data/lib/playwright_api/mouse.rb +9 -2
- data/lib/playwright_api/page.rb +307 -259
- data/lib/playwright_api/playwright.rb +17 -10
- data/lib/playwright_api/request.rb +40 -13
- data/lib/playwright_api/response.rb +33 -16
- data/lib/playwright_api/route.rb +50 -17
- data/lib/playwright_api/selectors.rb +12 -7
- data/lib/playwright_api/touchscreen.rb +2 -0
- data/lib/playwright_api/tracing.rb +17 -11
- data/lib/playwright_api/web_socket.rb +15 -10
- data/lib/playwright_api/worker.rb +20 -17
- data/playwright.gemspec +2 -2
- data/sig/playwright.rbs +559 -0
- metadata +10 -9
@@ -4,6 +4,7 @@ sidebar_position: 10
|
|
4
4
|
|
5
5
|
# Playwright
|
6
6
|
|
7
|
+
|
7
8
|
Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright
|
8
9
|
to drive automation:
|
9
10
|
|
@@ -22,14 +23,14 @@ Playwright.create(playwright_cli_executable_path: 'npx playwright') do |playwrig
|
|
22
23
|
end
|
23
24
|
```
|
24
25
|
|
25
|
-
|
26
|
-
|
27
26
|
## chromium
|
28
27
|
|
28
|
+
|
29
29
|
This object can be used to launch or connect to Chromium, returning instances of [Browser](./browser).
|
30
30
|
|
31
31
|
## devices
|
32
32
|
|
33
|
+
|
33
34
|
Returns a dictionary of devices to be used with [Browser#new_context](./browser#new_context) or [Browser#new_page](./browser#new_page).
|
34
35
|
|
35
36
|
```ruby
|
@@ -48,16 +49,18 @@ Playwright.create(playwright_cli_executable_path: 'npx playwright') do |playwrig
|
|
48
49
|
end
|
49
50
|
```
|
50
51
|
|
51
|
-
|
52
52
|
## firefox
|
53
53
|
|
54
|
+
|
54
55
|
This object can be used to launch or connect to Firefox, returning instances of [Browser](./browser).
|
55
56
|
|
56
57
|
## selectors
|
57
58
|
|
58
|
-
|
59
|
-
|
59
|
+
|
60
|
+
Selectors can be used to install custom selector engines. See
|
61
|
+
[extensibility](https://playwright.dev/python/docs/extensibility) for more information.
|
60
62
|
|
61
63
|
## webkit
|
62
64
|
|
65
|
+
|
63
66
|
This object can be used to launch or connect to WebKit, returning instances of [Browser](./browser).
|
@@ -4,6 +4,7 @@ sidebar_position: 10
|
|
4
4
|
|
5
5
|
# Request
|
6
6
|
|
7
|
+
|
7
8
|
Whenever the page sends a request for a network resource the following sequence of events are emitted by [Page](./page):
|
8
9
|
- [`event: Page.request`] emitted when the request is issued by the page.
|
9
10
|
- [`event: Page.response`] emitted when/if the response status and headers are received for the request.
|
@@ -12,8 +13,8 @@ Whenever the page sends a request for a network resource the following sequence
|
|
12
13
|
If request fails at some point, then instead of `'requestfinished'` event (and possibly instead of 'response' event),
|
13
14
|
the [`event: Page.requestFailed`] event is emitted.
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
**NOTE**: HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete
|
17
|
+
with `'requestfinished'` event.
|
17
18
|
|
18
19
|
If request gets a 'redirect' response, the request is successfully finished with the `requestfinished` event, and a new
|
19
20
|
request is issued to a redirected url.
|
@@ -24,6 +25,7 @@ request is issued to a redirected url.
|
|
24
25
|
def all_headers
|
25
26
|
```
|
26
27
|
|
28
|
+
|
27
29
|
An object with all the request HTTP headers associated with this request. The header names are lower-cased.
|
28
30
|
|
29
31
|
## failure
|
@@ -32,22 +34,24 @@ An object with all the request HTTP headers associated with this request. The he
|
|
32
34
|
def failure
|
33
35
|
```
|
34
36
|
|
37
|
+
|
35
38
|
The method returns `null` unless this request has failed, as reported by `requestfailed` event.
|
36
39
|
|
40
|
+
**Usage**
|
41
|
+
|
37
42
|
Example of logging of all the failed requests:
|
38
43
|
|
39
44
|
```ruby
|
40
45
|
page.on("requestfailed", ->(request) { puts "#{request.url} #{request.failure}" })
|
41
46
|
```
|
42
47
|
|
43
|
-
|
44
|
-
|
45
48
|
## frame
|
46
49
|
|
47
50
|
```
|
48
51
|
def frame
|
49
52
|
```
|
50
53
|
|
54
|
+
|
51
55
|
Returns the [Frame](./frame) that initiated this request.
|
52
56
|
|
53
57
|
## headers
|
@@ -56,9 +60,10 @@ Returns the [Frame](./frame) that initiated this request.
|
|
56
60
|
def headers
|
57
61
|
```
|
58
62
|
|
59
|
-
|
60
|
-
|
61
|
-
|
63
|
+
|
64
|
+
An object with the request HTTP headers. The header names are lower-cased.
|
65
|
+
Note that this method does not return security-related headers, including cookie-related ones.
|
66
|
+
You can use [Request#all_headers](./request#all_headers) for complete list of headers that include `cookie` information.
|
62
67
|
|
63
68
|
## headers_array
|
64
69
|
|
@@ -66,8 +71,9 @@ headers that include `cookie` information.
|
|
66
71
|
def headers_array
|
67
72
|
```
|
68
73
|
|
69
|
-
|
70
|
-
|
74
|
+
|
75
|
+
An array with all the request HTTP headers associated with this request. Unlike [Request#all_headers](./request#all_headers), header names are NOT lower-cased.
|
76
|
+
Headers with multiple entries, such as `Set-Cookie`, appear in the array multiple times.
|
71
77
|
|
72
78
|
## header_value
|
73
79
|
|
@@ -75,6 +81,7 @@ names are NOT lower-cased. Headers with multiple entries, such as `Set-Cookie`,
|
|
75
81
|
def header_value(name)
|
76
82
|
```
|
77
83
|
|
84
|
+
|
78
85
|
Returns the value of the header matching the name. The name is case insensitive.
|
79
86
|
|
80
87
|
## navigation_request?
|
@@ -83,6 +90,7 @@ Returns the value of the header matching the name. The name is case insensitive.
|
|
83
90
|
def navigation_request?
|
84
91
|
```
|
85
92
|
|
93
|
+
|
86
94
|
Whether this request is driving frame's navigation.
|
87
95
|
|
88
96
|
## method
|
@@ -91,6 +99,7 @@ Whether this request is driving frame's navigation.
|
|
91
99
|
def method
|
92
100
|
```
|
93
101
|
|
102
|
+
|
94
103
|
Request's method (GET, POST, etc.)
|
95
104
|
|
96
105
|
## post_data
|
@@ -99,6 +108,7 @@ Request's method (GET, POST, etc.)
|
|
99
108
|
def post_data
|
100
109
|
```
|
101
110
|
|
111
|
+
|
102
112
|
Request's post body, if any.
|
103
113
|
|
104
114
|
## post_data_buffer
|
@@ -107,6 +117,7 @@ Request's post body, if any.
|
|
107
117
|
def post_data_buffer
|
108
118
|
```
|
109
119
|
|
120
|
+
|
110
121
|
Request's post body in a binary form, if any.
|
111
122
|
|
112
123
|
## post_data_json
|
@@ -115,6 +126,7 @@ Request's post body in a binary form, if any.
|
|
115
126
|
def post_data_json
|
116
127
|
```
|
117
128
|
|
129
|
+
|
118
130
|
Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
|
119
131
|
|
120
132
|
When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned.
|
@@ -126,12 +138,15 @@ Otherwise it will be parsed as JSON.
|
|
126
138
|
def redirected_from
|
127
139
|
```
|
128
140
|
|
141
|
+
|
129
142
|
Request that was redirected by the server to this one, if any.
|
130
143
|
|
131
144
|
When the server responds with a redirect, Playwright creates a new [Request](./request) object. The two requests are connected by
|
132
145
|
[redirected_from](./request#redirected_from) and [redirected_to](./request#redirected_to) methods. When multiple server redirects has happened, it is possible to
|
133
146
|
construct the whole redirect chain by repeatedly calling [redirected_from](./request#redirected_from).
|
134
147
|
|
148
|
+
**Usage**
|
149
|
+
|
135
150
|
For example, if the website `http://github.com` redirects to `https://github.com`:
|
136
151
|
|
137
152
|
```ruby
|
@@ -147,30 +162,30 @@ response = page.goto("https://google.com")
|
|
147
162
|
puts response.request.redirected_from&.url # => nil
|
148
163
|
```
|
149
164
|
|
150
|
-
|
151
|
-
|
152
165
|
## redirected_to
|
153
166
|
|
154
167
|
```
|
155
168
|
def redirected_to
|
156
169
|
```
|
157
170
|
|
171
|
+
|
158
172
|
New request issued by the browser if the server responded with redirect.
|
159
173
|
|
174
|
+
**Usage**
|
175
|
+
|
160
176
|
This method is the opposite of [Request#redirected_from](./request#redirected_from):
|
161
177
|
|
162
178
|
```ruby
|
163
179
|
request.redirected_from.redirected_to # equals to request
|
164
180
|
```
|
165
181
|
|
166
|
-
|
167
|
-
|
168
182
|
## resource_type
|
169
183
|
|
170
184
|
```
|
171
185
|
def resource_type
|
172
186
|
```
|
173
187
|
|
188
|
+
|
174
189
|
Contains the request's resource type as it was perceived by the rendering engine. ResourceType will be one of the
|
175
190
|
following: `document`, `stylesheet`, `image`, `media`, `font`, `script`, `texttrack`, `xhr`, `fetch`, `eventsource`,
|
176
191
|
`websocket`, `manifest`, `other`.
|
@@ -181,6 +196,7 @@ following: `document`, `stylesheet`, `image`, `media`, `font`, `script`, `texttr
|
|
181
196
|
def response
|
182
197
|
```
|
183
198
|
|
199
|
+
|
184
200
|
Returns the matching [Response](./response) object, or `null` if the response was not received due to error.
|
185
201
|
|
186
202
|
## sizes
|
@@ -189,6 +205,7 @@ Returns the matching [Response](./response) object, or `null` if the response wa
|
|
189
205
|
def sizes
|
190
206
|
```
|
191
207
|
|
208
|
+
|
192
209
|
Returns resource size information for given request.
|
193
210
|
|
194
211
|
## timing
|
@@ -197,10 +214,13 @@ Returns resource size information for given request.
|
|
197
214
|
def timing
|
198
215
|
```
|
199
216
|
|
217
|
+
|
200
218
|
Returns resource timing information for given request. Most of the timing values become available upon the response,
|
201
219
|
`responseEnd` becomes available when request finishes. Find more information at
|
202
220
|
[Resource Timing API](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming).
|
203
221
|
|
222
|
+
**Usage**
|
223
|
+
|
204
224
|
```ruby
|
205
225
|
request = page.expect_event("requestfinished") do
|
206
226
|
page.goto("https://example.com")
|
@@ -208,12 +228,11 @@ end
|
|
208
228
|
puts request.timing
|
209
229
|
```
|
210
230
|
|
211
|
-
|
212
|
-
|
213
231
|
## url
|
214
232
|
|
215
233
|
```
|
216
234
|
def url
|
217
235
|
```
|
218
236
|
|
237
|
+
|
219
238
|
URL of the request.
|
@@ -4,6 +4,7 @@ sidebar_position: 10
|
|
4
4
|
|
5
5
|
# Response
|
6
6
|
|
7
|
+
|
7
8
|
[Response](./response) class represents responses which are received by page.
|
8
9
|
|
9
10
|
## all_headers
|
@@ -12,6 +13,7 @@ sidebar_position: 10
|
|
12
13
|
def all_headers
|
13
14
|
```
|
14
15
|
|
16
|
+
|
15
17
|
An object with all the response HTTP headers associated with this response.
|
16
18
|
|
17
19
|
## body
|
@@ -20,6 +22,7 @@ An object with all the response HTTP headers associated with this response.
|
|
20
22
|
def body
|
21
23
|
```
|
22
24
|
|
25
|
+
|
23
26
|
Returns the buffer with response body.
|
24
27
|
|
25
28
|
## finished
|
@@ -28,6 +31,7 @@ Returns the buffer with response body.
|
|
28
31
|
def finished
|
29
32
|
```
|
30
33
|
|
34
|
+
|
31
35
|
Waits for this response to finish, returns always `null`.
|
32
36
|
|
33
37
|
## frame
|
@@ -36,6 +40,7 @@ Waits for this response to finish, returns always `null`.
|
|
36
40
|
def frame
|
37
41
|
```
|
38
42
|
|
43
|
+
|
39
44
|
Returns the [Frame](./frame) that initiated this response.
|
40
45
|
|
41
46
|
## from_service_worker
|
@@ -44,8 +49,8 @@ Returns the [Frame](./frame) that initiated this response.
|
|
44
49
|
def from_service_worker
|
45
50
|
```
|
46
51
|
|
47
|
-
|
48
|
-
[FetchEvent.respondWith](https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/respondWith)).
|
52
|
+
|
53
|
+
Indicates whether this Response was fulfilled by a Service Worker's Fetch Handler (i.e. via [FetchEvent.respondWith](https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/respondWith)).
|
49
54
|
|
50
55
|
## headers
|
51
56
|
|
@@ -53,9 +58,10 @@ Indicates whether this Response was fulfilled by a Service Worker's Fetch Handle
|
|
53
58
|
def headers
|
54
59
|
```
|
55
60
|
|
56
|
-
|
57
|
-
|
58
|
-
|
61
|
+
|
62
|
+
An object with the response HTTP headers. The header names are lower-cased.
|
63
|
+
Note that this method does not return security-related headers, including cookie-related ones.
|
64
|
+
You can use [Response#all_headers](./response#all_headers) for complete list of headers that include `cookie` information.
|
59
65
|
|
60
66
|
## headers_array
|
61
67
|
|
@@ -63,8 +69,9 @@ of headers that include `cookie` information.
|
|
63
69
|
def headers_array
|
64
70
|
```
|
65
71
|
|
66
|
-
|
67
|
-
|
72
|
+
|
73
|
+
An array with all the request HTTP headers associated with this response. Unlike [Response#all_headers](./response#all_headers), header names are NOT lower-cased.
|
74
|
+
Headers with multiple entries, such as `Set-Cookie`, appear in the array multiple times.
|
68
75
|
|
69
76
|
## header_value
|
70
77
|
|
@@ -72,9 +79,9 @@ names are NOT lower-cased. Headers with multiple entries, such as `Set-Cookie`,
|
|
72
79
|
def header_value(name)
|
73
80
|
```
|
74
81
|
|
75
|
-
|
76
|
-
|
77
|
-
no headers are found, `null` is returned.
|
82
|
+
|
83
|
+
Returns the value of the header matching the name. The name is case insensitive. If multiple headers have
|
84
|
+
the same name (except `set-cookie`), they are returned as a list separated by `, `. For `set-cookie`, the `\n` separator is used. If no headers are found, `null` is returned.
|
78
85
|
|
79
86
|
## header_values
|
80
87
|
|
@@ -82,6 +89,7 @@ no headers are found, `null` is returned.
|
|
82
89
|
def header_values(name)
|
83
90
|
```
|
84
91
|
|
92
|
+
|
85
93
|
Returns all values of the headers matching the name, for example `set-cookie`. The name is case insensitive.
|
86
94
|
|
87
95
|
## json
|
@@ -90,6 +98,7 @@ Returns all values of the headers matching the name, for example `set-cookie`. T
|
|
90
98
|
def json
|
91
99
|
```
|
92
100
|
|
101
|
+
|
93
102
|
Returns the JSON representation of response body.
|
94
103
|
|
95
104
|
This method will throw if the response body is not parsable via `JSON.parse`.
|
@@ -100,6 +109,7 @@ This method will throw if the response body is not parsable via `JSON.parse`.
|
|
100
109
|
def ok
|
101
110
|
```
|
102
111
|
|
112
|
+
|
103
113
|
Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
|
104
114
|
|
105
115
|
## request
|
@@ -108,6 +118,7 @@ Contains a boolean stating whether the response was successful (status in the ra
|
|
108
118
|
def request
|
109
119
|
```
|
110
120
|
|
121
|
+
|
111
122
|
Returns the matching [Request](./request) object.
|
112
123
|
|
113
124
|
## security_details
|
@@ -116,6 +127,7 @@ Returns the matching [Request](./request) object.
|
|
116
127
|
def security_details
|
117
128
|
```
|
118
129
|
|
130
|
+
|
119
131
|
Returns SSL and other security information.
|
120
132
|
|
121
133
|
## server_addr
|
@@ -124,6 +136,7 @@ Returns SSL and other security information.
|
|
124
136
|
def server_addr
|
125
137
|
```
|
126
138
|
|
139
|
+
|
127
140
|
Returns the IP address and port of the server.
|
128
141
|
|
129
142
|
## status
|
@@ -132,6 +145,7 @@ Returns the IP address and port of the server.
|
|
132
145
|
def status
|
133
146
|
```
|
134
147
|
|
148
|
+
|
135
149
|
Contains the status code of the response (e.g., 200 for a success).
|
136
150
|
|
137
151
|
## status_text
|
@@ -140,6 +154,7 @@ Contains the status code of the response (e.g., 200 for a success).
|
|
140
154
|
def status_text
|
141
155
|
```
|
142
156
|
|
157
|
+
|
143
158
|
Contains the status text of the response (e.g. usually an "OK" for a success).
|
144
159
|
|
145
160
|
## text
|
@@ -148,6 +163,7 @@ Contains the status text of the response (e.g. usually an "OK" for a success).
|
|
148
163
|
def text
|
149
164
|
```
|
150
165
|
|
166
|
+
|
151
167
|
Returns the text representation of response body.
|
152
168
|
|
153
169
|
## url
|
@@ -156,4 +172,5 @@ Returns the text representation of response body.
|
|
156
172
|
def url
|
157
173
|
```
|
158
174
|
|
175
|
+
|
159
176
|
Contains the URL of the response.
|
@@ -4,6 +4,7 @@ sidebar_position: 10
|
|
4
4
|
|
5
5
|
# Route
|
6
6
|
|
7
|
+
|
7
8
|
Whenever a network route is set up with [Page#route](./page#route) or [BrowserContext#route](./browser_context#route), the [Route](./route) object
|
8
9
|
allows to handle the route.
|
9
10
|
|
@@ -15,6 +16,7 @@ Learn more about [networking](https://playwright.dev/python/docs/network).
|
|
15
16
|
def abort(errorCode: nil)
|
16
17
|
```
|
17
18
|
|
19
|
+
|
18
20
|
Aborts the route's request.
|
19
21
|
|
20
22
|
## continue
|
@@ -23,8 +25,11 @@ Aborts the route's request.
|
|
23
25
|
def continue(headers: nil, method: nil, postData: nil, url: nil)
|
24
26
|
```
|
25
27
|
|
28
|
+
|
26
29
|
Continues route's request with optional overrides.
|
27
30
|
|
31
|
+
**Usage**
|
32
|
+
|
28
33
|
```ruby
|
29
34
|
def handle(route, request)
|
30
35
|
# override headers
|
@@ -38,18 +43,19 @@ end
|
|
38
43
|
page.route("**/*", method(:handle))
|
39
44
|
```
|
40
45
|
|
41
|
-
|
42
|
-
|
43
46
|
## fallback
|
44
47
|
|
45
48
|
```
|
46
49
|
def fallback(headers: nil, method: nil, postData: nil, url: nil)
|
47
50
|
```
|
48
51
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
|
53
|
+
When several routes match the given pattern, they run in the order opposite to their registration.
|
54
|
+
That way the last registered route can always override all the previous ones. In the example below,
|
55
|
+
request will be handled by the bottom-most handler first, then it'll fall back to the previous one and
|
56
|
+
in the end will be aborted by the first registered route.
|
57
|
+
|
58
|
+
**Usage**
|
53
59
|
|
54
60
|
```ruby
|
55
61
|
page.route("**/*", -> (route,_) { route.abort }) # Runs last.
|
@@ -57,8 +63,9 @@ page.route("**/*", -> (route,_) { route.fallback }) # Runs second.
|
|
57
63
|
page.route("**/*", -> (route,_) { route.fallback }) # Runs first.
|
58
64
|
```
|
59
65
|
|
60
|
-
Registering multiple routes is useful when you want separate handlers to
|
61
|
-
|
66
|
+
Registering multiple routes is useful when you want separate handlers to
|
67
|
+
handle different kinds of requests, for example API calls vs page resources or
|
68
|
+
GET requests vs POST requests as in the example below.
|
62
69
|
|
63
70
|
```ruby
|
64
71
|
# Handle GET requests.
|
@@ -87,8 +94,8 @@ page.route("**/*", handle_get)
|
|
87
94
|
page.route("**/*", handle_post)
|
88
95
|
```
|
89
96
|
|
90
|
-
One can also modify request while falling back to the subsequent handler, that way intermediate
|
91
|
-
url, method, headers and postData of the request.
|
97
|
+
One can also modify request while falling back to the subsequent handler, that way intermediate
|
98
|
+
route handler can modify url, method, headers and postData of the request.
|
92
99
|
|
93
100
|
```ruby
|
94
101
|
def handle(route, request)
|
@@ -100,9 +107,31 @@ def handle(route, request)
|
|
100
107
|
|
101
108
|
route.fallback(headers: headers)
|
102
109
|
end
|
110
|
+
page.route("**/*", method(:handle))
|
111
|
+
```
|
112
|
+
|
113
|
+
## fetch
|
114
|
+
|
115
|
+
```
|
116
|
+
def fetch(headers: nil, method: nil, postData: nil, url: nil)
|
103
117
|
```
|
104
118
|
|
105
119
|
|
120
|
+
Performs the request and fetches result without fulfilling it, so that the response
|
121
|
+
could be modified and then fulfilled.
|
122
|
+
|
123
|
+
**Usage**
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
def handle(route, request)
|
127
|
+
response = route.fetch
|
128
|
+
json = response.json
|
129
|
+
json["message"]["big_red_dog"] = []
|
130
|
+
|
131
|
+
route.fulfill(response: response, json: json)
|
132
|
+
end
|
133
|
+
page.route("https://dog.ceo/api/breeds/list/all", method(:handle))
|
134
|
+
```
|
106
135
|
|
107
136
|
## fulfill
|
108
137
|
|
@@ -111,13 +140,17 @@ def fulfill(
|
|
111
140
|
body: nil,
|
112
141
|
contentType: nil,
|
113
142
|
headers: nil,
|
143
|
+
json: nil,
|
114
144
|
path: nil,
|
115
145
|
response: nil,
|
116
146
|
status: nil)
|
117
147
|
```
|
118
148
|
|
149
|
+
|
119
150
|
Fulfills route's request with given response.
|
120
151
|
|
152
|
+
**Usage**
|
153
|
+
|
121
154
|
An example of fulfilling all requests with 404 responses:
|
122
155
|
|
123
156
|
```ruby
|
@@ -136,12 +169,11 @@ An example of serving static file:
|
|
136
169
|
page.route("**/xhr_endpoint", ->(route, _) { route.fulfill(path: "mock_data.json") })
|
137
170
|
```
|
138
171
|
|
139
|
-
|
140
|
-
|
141
172
|
## request
|
142
173
|
|
143
174
|
```
|
144
175
|
def request
|
145
176
|
```
|
146
177
|
|
178
|
+
|
147
179
|
A request to be routed.
|
@@ -4,7 +4,8 @@ sidebar_position: 10
|
|
4
4
|
|
5
5
|
# Selectors
|
6
6
|
|
7
|
-
|
7
|
+
|
8
|
+
Selectors can be used to install custom selector engines. See [extensibility](https://playwright.dev/python/docs/extensibility) for more
|
8
9
|
information.
|
9
10
|
|
10
11
|
## register
|
@@ -13,6 +14,9 @@ information.
|
|
13
14
|
def register(name, contentScript: nil, path: nil, script: nil)
|
14
15
|
```
|
15
16
|
|
17
|
+
|
18
|
+
**Usage**
|
19
|
+
|
16
20
|
An example of registering selector engine that queries elements based on a tag name:
|
17
21
|
|
18
22
|
```ruby
|
@@ -45,5 +49,3 @@ playwright.chromium.launch do |browser|
|
|
45
49
|
button_count # => 1
|
46
50
|
end
|
47
51
|
```
|
48
|
-
|
49
|
-
|
@@ -4,6 +4,7 @@ sidebar_position: 10
|
|
4
4
|
|
5
5
|
# Touchscreen
|
6
6
|
|
7
|
+
|
7
8
|
The Touchscreen class operates in main-frame CSS pixels relative to the top-left corner of the viewport. Methods on the
|
8
9
|
touchscreen can only be used in browser contexts that have been initialized with `hasTouch` set to true.
|
9
10
|
|
@@ -13,4 +14,5 @@ touchscreen can only be used in browser contexts that have been initialized with
|
|
13
14
|
def tap_point(x, y)
|
14
15
|
```
|
15
16
|
|
17
|
+
|
16
18
|
Dispatches a `touchstart` and `touchend` event with a single touch at the position (`x`,`y`).
|
@@ -4,8 +4,8 @@ sidebar_position: 10
|
|
4
4
|
|
5
5
|
# Tracing
|
6
6
|
|
7
|
-
|
8
|
-
after Playwright script runs.
|
7
|
+
|
8
|
+
API for collecting and saving Playwright traces. Playwright traces can be opened in [Trace Viewer](https://playwright.dev/python/docs/trace-viewer) after Playwright script runs.
|
9
9
|
|
10
10
|
Start recording a trace before performing actions. At the end, stop tracing and save it to a file.
|
11
11
|
|
@@ -18,8 +18,6 @@ browser.new_context do |context|
|
|
18
18
|
end
|
19
19
|
```
|
20
20
|
|
21
|
-
|
22
|
-
|
23
21
|
## start
|
24
22
|
|
25
23
|
```
|
@@ -31,8 +29,11 @@ def start(
|
|
31
29
|
title: nil)
|
32
30
|
```
|
33
31
|
|
32
|
+
|
34
33
|
Start tracing.
|
35
34
|
|
35
|
+
**Usage**
|
36
|
+
|
36
37
|
```ruby
|
37
38
|
context.tracing.start(name: 'trace', screenshots: true, snapshots: true)
|
38
39
|
page = context.new_page
|
@@ -40,17 +41,16 @@ page.goto('https://playwright.dev')
|
|
40
41
|
context.tracing.stop(path: 'trace.zip')
|
41
42
|
```
|
42
43
|
|
43
|
-
|
44
|
-
|
45
44
|
## start_chunk
|
46
45
|
|
47
46
|
```
|
48
47
|
def start_chunk(title: nil)
|
49
48
|
```
|
50
49
|
|
51
|
-
|
52
|
-
[Tracing#start](./tracing#start) once, and then create multiple trace chunks with [Tracing#start_chunk](./tracing#start_chunk) and
|
53
|
-
|
50
|
+
|
51
|
+
Start a new trace chunk. If you'd like to record multiple traces on the same [BrowserContext](./browser_context), use [Tracing#start](./tracing#start) once, and then create multiple trace chunks with [Tracing#start_chunk](./tracing#start_chunk) and [Tracing#stop_chunk](./tracing#stop_chunk).
|
52
|
+
|
53
|
+
**Usage**
|
54
54
|
|
55
55
|
```ruby
|
56
56
|
context.tracing.start(name: "trace", screenshots: true, snapshots: true)
|
@@ -68,14 +68,13 @@ page.goto("http://example.com")
|
|
68
68
|
context.tracing.stop_chunk(path: "trace2.zip")
|
69
69
|
```
|
70
70
|
|
71
|
-
|
72
|
-
|
73
71
|
## stop
|
74
72
|
|
75
73
|
```
|
76
74
|
def stop(path: nil)
|
77
75
|
```
|
78
76
|
|
77
|
+
|
79
78
|
Stop tracing.
|
80
79
|
|
81
80
|
## stop_chunk
|
@@ -84,4 +83,5 @@ Stop tracing.
|
|
84
83
|
def stop_chunk(path: nil)
|
85
84
|
```
|
86
85
|
|
86
|
+
|
87
87
|
Stop the trace chunk. See [Tracing#start_chunk](./tracing#start_chunk) for more details about multiple trace chunks.
|