playwright-ruby-client 1.18.0 → 1.18.3
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/api_request.md +7 -0
- data/documentation/docs/api/api_request_context.md +157 -45
- data/documentation/docs/api/api_response.md +104 -0
- data/documentation/docs/api/browser_context.md +4 -0
- data/documentation/docs/api/page.md +4 -0
- data/documentation/docs/include/api_coverage.md +31 -14
- data/lib/playwright/api_response_impl.rb +73 -0
- data/lib/playwright/channel_owners/api_request_context.rb +232 -0
- data/lib/playwright/channel_owners/browser_context.rb +3 -1
- data/lib/playwright/channel_owners/page.rb +4 -0
- data/lib/playwright/transport.rb +14 -1
- data/lib/playwright/version.rb +2 -2
- data/lib/playwright_api/android.rb +6 -6
- data/lib/playwright_api/android_device.rb +6 -6
- data/lib/playwright_api/api_request.rb +20 -0
- data/lib/playwright_api/api_request_context.rb +14 -14
- data/lib/playwright_api/api_response.rb +81 -0
- data/lib/playwright_api/browser.rb +6 -6
- data/lib/playwright_api/browser_context.rb +9 -9
- data/lib/playwright_api/browser_type.rb +6 -6
- data/lib/playwright_api/cdp_session.rb +6 -6
- data/lib/playwright_api/console_message.rb +6 -6
- data/lib/playwright_api/dialog.rb +6 -6
- data/lib/playwright_api/element_handle.rb +6 -6
- data/lib/playwright_api/frame.rb +6 -6
- data/lib/playwright_api/js_handle.rb +6 -6
- data/lib/playwright_api/page.rb +11 -11
- data/lib/playwright_api/playwright.rb +6 -6
- data/lib/playwright_api/request.rb +6 -6
- data/lib/playwright_api/response.rb +6 -6
- data/lib/playwright_api/route.rb +6 -6
- data/lib/playwright_api/selectors.rb +6 -6
- data/lib/playwright_api/web_socket.rb +6 -6
- data/lib/playwright_api/worker.rb +6 -6
- metadata +9 -4
|
@@ -1,4 +1,236 @@
|
|
|
1
|
+
require 'base64'
|
|
2
|
+
|
|
1
3
|
module Playwright
|
|
2
4
|
define_channel_owner :APIRequestContext do
|
|
5
|
+
def dispose
|
|
6
|
+
@channel.send_message_to_server('dispose')
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def delete(
|
|
10
|
+
url,
|
|
11
|
+
data: nil,
|
|
12
|
+
failOnStatusCode: nil,
|
|
13
|
+
form: nil,
|
|
14
|
+
headers: nil,
|
|
15
|
+
ignoreHTTPSErrors: nil,
|
|
16
|
+
multipart: nil,
|
|
17
|
+
params: nil,
|
|
18
|
+
timeout: nil)
|
|
19
|
+
fetch(
|
|
20
|
+
url,
|
|
21
|
+
method: 'DELETE',
|
|
22
|
+
data: data,
|
|
23
|
+
failOnStatusCode: failOnStatusCode,
|
|
24
|
+
form: form,
|
|
25
|
+
headers: headers,
|
|
26
|
+
ignoreHTTPSErrors: ignoreHTTPSErrors,
|
|
27
|
+
multipart: multipart,
|
|
28
|
+
params: params,
|
|
29
|
+
timeout: timeout,
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def head(
|
|
34
|
+
url,
|
|
35
|
+
failOnStatusCode: nil,
|
|
36
|
+
headers: nil,
|
|
37
|
+
ignoreHTTPSErrors: nil,
|
|
38
|
+
params: nil,
|
|
39
|
+
timeout: nil)
|
|
40
|
+
fetch(
|
|
41
|
+
url,
|
|
42
|
+
method: 'HEAD',
|
|
43
|
+
failOnStatusCode: failOnStatusCode,
|
|
44
|
+
headers: headers,
|
|
45
|
+
ignoreHTTPSErrors: ignoreHTTPSErrors,
|
|
46
|
+
params: params,
|
|
47
|
+
timeout: timeout,
|
|
48
|
+
)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def get(
|
|
52
|
+
url,
|
|
53
|
+
failOnStatusCode: nil,
|
|
54
|
+
headers: nil,
|
|
55
|
+
ignoreHTTPSErrors: nil,
|
|
56
|
+
params: nil,
|
|
57
|
+
timeout: nil)
|
|
58
|
+
fetch(
|
|
59
|
+
url,
|
|
60
|
+
method: 'GET',
|
|
61
|
+
failOnStatusCode: failOnStatusCode,
|
|
62
|
+
headers: headers,
|
|
63
|
+
ignoreHTTPSErrors: ignoreHTTPSErrors,
|
|
64
|
+
params: params,
|
|
65
|
+
timeout: timeout,
|
|
66
|
+
)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def patch(
|
|
70
|
+
url,
|
|
71
|
+
data: nil,
|
|
72
|
+
failOnStatusCode: nil,
|
|
73
|
+
form: nil,
|
|
74
|
+
headers: nil,
|
|
75
|
+
ignoreHTTPSErrors: nil,
|
|
76
|
+
multipart: nil,
|
|
77
|
+
params: nil,
|
|
78
|
+
timeout: nil)
|
|
79
|
+
fetch(
|
|
80
|
+
url,
|
|
81
|
+
method: 'PATCH',
|
|
82
|
+
data: data,
|
|
83
|
+
failOnStatusCode: failOnStatusCode,
|
|
84
|
+
form: form,
|
|
85
|
+
headers: headers,
|
|
86
|
+
ignoreHTTPSErrors: ignoreHTTPSErrors,
|
|
87
|
+
multipart: multipart,
|
|
88
|
+
params: params,
|
|
89
|
+
timeout: timeout,
|
|
90
|
+
)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def put(
|
|
94
|
+
url,
|
|
95
|
+
data: nil,
|
|
96
|
+
failOnStatusCode: nil,
|
|
97
|
+
form: nil,
|
|
98
|
+
headers: nil,
|
|
99
|
+
ignoreHTTPSErrors: nil,
|
|
100
|
+
multipart: nil,
|
|
101
|
+
params: nil,
|
|
102
|
+
timeout: nil)
|
|
103
|
+
fetch(
|
|
104
|
+
url,
|
|
105
|
+
method: 'PUT',
|
|
106
|
+
data: data,
|
|
107
|
+
failOnStatusCode: failOnStatusCode,
|
|
108
|
+
form: form,
|
|
109
|
+
headers: headers,
|
|
110
|
+
ignoreHTTPSErrors: ignoreHTTPSErrors,
|
|
111
|
+
multipart: multipart,
|
|
112
|
+
params: params,
|
|
113
|
+
timeout: timeout,
|
|
114
|
+
)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def post(
|
|
118
|
+
url,
|
|
119
|
+
data: nil,
|
|
120
|
+
failOnStatusCode: nil,
|
|
121
|
+
form: nil,
|
|
122
|
+
headers: nil,
|
|
123
|
+
ignoreHTTPSErrors: nil,
|
|
124
|
+
multipart: nil,
|
|
125
|
+
params: nil,
|
|
126
|
+
timeout: nil)
|
|
127
|
+
fetch(
|
|
128
|
+
url,
|
|
129
|
+
method: 'POST',
|
|
130
|
+
data: data,
|
|
131
|
+
failOnStatusCode: failOnStatusCode,
|
|
132
|
+
form: form,
|
|
133
|
+
headers: headers,
|
|
134
|
+
ignoreHTTPSErrors: ignoreHTTPSErrors,
|
|
135
|
+
multipart: multipart,
|
|
136
|
+
params: params,
|
|
137
|
+
timeout: timeout,
|
|
138
|
+
)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def fetch(
|
|
142
|
+
urlOrRequest,
|
|
143
|
+
data: nil,
|
|
144
|
+
failOnStatusCode: nil,
|
|
145
|
+
form: nil,
|
|
146
|
+
headers: nil,
|
|
147
|
+
ignoreHTTPSErrors: nil,
|
|
148
|
+
method: nil,
|
|
149
|
+
multipart: nil,
|
|
150
|
+
params: nil,
|
|
151
|
+
timeout: nil)
|
|
152
|
+
|
|
153
|
+
if [ChannelOwners::Request, String].none? { |type| urlOrRequest.is_a?(type) }
|
|
154
|
+
raise ArgumentError.new("First argument must be either URL string or Request")
|
|
155
|
+
end
|
|
156
|
+
if [data, form, multipart].compact.count > 1
|
|
157
|
+
raise ArgumentError.new("Only one of 'data', 'form' or 'multipart' can be specified")
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
request = urlOrRequest.is_a?(ChannelOwners::Request) ? urlOrRequest : nil
|
|
161
|
+
headers_obj = headers || request&.headers
|
|
162
|
+
fetch_params = {
|
|
163
|
+
url: request&.url || urlOrRequest,
|
|
164
|
+
params: object_to_array(params),
|
|
165
|
+
method: method || request&.method || 'GET',
|
|
166
|
+
headers: headers_obj ? HttpHeaders.new(headers_obj).as_serialized : nil,
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
json_data = nil
|
|
170
|
+
form_data = nil
|
|
171
|
+
multipart_data = nil
|
|
172
|
+
post_data_buffer = nil
|
|
173
|
+
if data
|
|
174
|
+
case data
|
|
175
|
+
when String
|
|
176
|
+
if headers_obj&.any? { |key, value| key.downcase == 'content-type' && value == 'application/json' }
|
|
177
|
+
json_data = data
|
|
178
|
+
else
|
|
179
|
+
post_data_buffer = data
|
|
180
|
+
end
|
|
181
|
+
when Hash, Array, Numeric, true, false
|
|
182
|
+
json_data = data
|
|
183
|
+
else
|
|
184
|
+
raise ArgumentError.new("Unsupported 'data' type: #{data.class}")
|
|
185
|
+
end
|
|
186
|
+
elsif form
|
|
187
|
+
form_data = object_to_array(form)
|
|
188
|
+
elsif multipart
|
|
189
|
+
multipart_data = multipart.map do |name, value|
|
|
190
|
+
if file_payload?(value)
|
|
191
|
+
{ name: name, file: file_payload_to_json(value) }
|
|
192
|
+
else
|
|
193
|
+
{ name: name, value: value.to_s }
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
if !json_data && !form_data && !multipart_data
|
|
199
|
+
post_data_buffer ||= request&.post_data_buffer
|
|
200
|
+
end
|
|
201
|
+
if post_data_buffer
|
|
202
|
+
fetch_params[:postData] = Base64.strict_encode64(post_data_buffer)
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
fetch_params[:jsonData] = json_data
|
|
206
|
+
fetch_params[:formData] = form_data
|
|
207
|
+
fetch_params[:multipartData] = multipart_data
|
|
208
|
+
fetch_params[:timeout] = timeout
|
|
209
|
+
fetch_params[:failOnStatusCode] = failOnStatusCode
|
|
210
|
+
fetch_params[:ignoreHTTPSErrors] = ignoreHTTPSErrors
|
|
211
|
+
fetch_params.compact!
|
|
212
|
+
response = @channel.send_message_to_server('fetch', fetch_params)
|
|
213
|
+
|
|
214
|
+
APIResponseImpl.new(self, response)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
private def file_payload?(value)
|
|
218
|
+
value.is_a?(Hash) &&
|
|
219
|
+
%w(name mimeType buffer).all? { |key| value.has_key?(key) || value.has_key?(key.to_sym) }
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
private def file_payload_to_json(payload)
|
|
223
|
+
{
|
|
224
|
+
name: payload[:name] || payload['name'],
|
|
225
|
+
mimeType: payload[:mimeType] || payload['mimeType'],
|
|
226
|
+
buffer: Base64.strict_encode64(payload[:buffer] || payload['buffer'])
|
|
227
|
+
}
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
private def object_to_array(hash)
|
|
231
|
+
hash&.map do |key, value|
|
|
232
|
+
{ name: key, value: value.to_s }
|
|
233
|
+
end
|
|
234
|
+
end
|
|
3
235
|
end
|
|
4
236
|
end
|
|
@@ -4,7 +4,7 @@ module Playwright
|
|
|
4
4
|
include Utils::Errors::SafeCloseError
|
|
5
5
|
attr_accessor :browser
|
|
6
6
|
attr_writer :owner_page, :options
|
|
7
|
-
attr_reader :tracing
|
|
7
|
+
attr_reader :tracing, :request
|
|
8
8
|
|
|
9
9
|
private def after_initialize
|
|
10
10
|
@pages = Set.new
|
|
@@ -15,6 +15,8 @@ module Playwright
|
|
|
15
15
|
@background_pages = Set.new
|
|
16
16
|
|
|
17
17
|
@tracing = TracingImpl.new(@channel, self)
|
|
18
|
+
@request = ChannelOwners::APIRequestContext.from(@initializer['APIRequestContext'])
|
|
19
|
+
|
|
18
20
|
@channel.on('bindingCall', ->(params) { on_binding(ChannelOwners::BindingCall.from(params['binding'])) })
|
|
19
21
|
@channel.once('close', ->(_) { on_close })
|
|
20
22
|
@channel.on('page', ->(params) { on_page(ChannelOwners::Page.from(params['page']) )})
|
data/lib/playwright/transport.rb
CHANGED
|
@@ -46,7 +46,8 @@ module Playwright
|
|
|
46
46
|
#
|
|
47
47
|
# @note This method blocks until playwright-cli exited. Consider using Thread or Future.
|
|
48
48
|
def async_run
|
|
49
|
-
|
|
49
|
+
popen3_args = {}
|
|
50
|
+
@stdin, @stdout, @stderr, @thread = run_driver_with_open3
|
|
50
51
|
@stdin.binmode # Ensure Strings are written 1:1 without encoding conversion, necessary for integer values
|
|
51
52
|
|
|
52
53
|
Thread.new { handle_stdout }
|
|
@@ -55,6 +56,18 @@ module Playwright
|
|
|
55
56
|
|
|
56
57
|
private
|
|
57
58
|
|
|
59
|
+
def run_driver_with_open3
|
|
60
|
+
Open3.popen3("#{@driver_executable_path} run-driver", { pgroup: true })
|
|
61
|
+
rescue ArgumentError => err
|
|
62
|
+
# Windows doesn't accept pgroup parameter.
|
|
63
|
+
# ArgumentError: wrong exec option symbol: pgroup
|
|
64
|
+
if err.message =~ /pgroup/
|
|
65
|
+
Open3.popen3("#{@driver_executable_path} run-driver")
|
|
66
|
+
else
|
|
67
|
+
raise
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
58
71
|
def handle_stdout(packet_size: 32_768)
|
|
59
72
|
while chunk = @stdout.read(4)
|
|
60
73
|
length = chunk.unpack1('V') # unsigned 32bit, little endian
|
data/lib/playwright/version.rb
CHANGED
|
@@ -38,20 +38,20 @@ module Playwright
|
|
|
38
38
|
|
|
39
39
|
# -- inherited from EventEmitter --
|
|
40
40
|
# @nodoc
|
|
41
|
-
def
|
|
42
|
-
event_emitter_proxy.
|
|
41
|
+
def off(event, callback)
|
|
42
|
+
event_emitter_proxy.off(event, callback)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
# -- inherited from EventEmitter --
|
|
46
46
|
# @nodoc
|
|
47
|
-
def
|
|
48
|
-
event_emitter_proxy.
|
|
47
|
+
def once(event, callback)
|
|
48
|
+
event_emitter_proxy.once(event, callback)
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
# -- inherited from EventEmitter --
|
|
52
52
|
# @nodoc
|
|
53
|
-
def
|
|
54
|
-
event_emitter_proxy.
|
|
53
|
+
def on(event, callback)
|
|
54
|
+
event_emitter_proxy.on(event, callback)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
private def event_emitter_proxy
|
|
@@ -176,20 +176,20 @@ module Playwright
|
|
|
176
176
|
|
|
177
177
|
# -- inherited from EventEmitter --
|
|
178
178
|
# @nodoc
|
|
179
|
-
def
|
|
180
|
-
event_emitter_proxy.
|
|
179
|
+
def off(event, callback)
|
|
180
|
+
event_emitter_proxy.off(event, callback)
|
|
181
181
|
end
|
|
182
182
|
|
|
183
183
|
# -- inherited from EventEmitter --
|
|
184
184
|
# @nodoc
|
|
185
|
-
def
|
|
186
|
-
event_emitter_proxy.
|
|
185
|
+
def once(event, callback)
|
|
186
|
+
event_emitter_proxy.once(event, callback)
|
|
187
187
|
end
|
|
188
188
|
|
|
189
189
|
# -- inherited from EventEmitter --
|
|
190
190
|
# @nodoc
|
|
191
|
-
def
|
|
192
|
-
event_emitter_proxy.
|
|
191
|
+
def on(event, callback)
|
|
192
|
+
event_emitter_proxy.on(event, callback)
|
|
193
193
|
end
|
|
194
194
|
|
|
195
195
|
private def event_emitter_proxy
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Playwright
|
|
2
|
+
# Exposes API that can be used for the Web API testing. Each Playwright browser context has a APIRequestContext instance
|
|
3
|
+
# attached which shares cookies with the page context. Its also possible to create a new APIRequestContext instance
|
|
4
|
+
# manually. For more information see [here](./class-apirequestcontext).
|
|
5
|
+
class APIRequest < PlaywrightApi
|
|
6
|
+
|
|
7
|
+
# Creates new instances of `APIRequestContext`.
|
|
8
|
+
def new_context(
|
|
9
|
+
baseURL: nil,
|
|
10
|
+
extraHTTPHeaders: nil,
|
|
11
|
+
httpCredentials: nil,
|
|
12
|
+
ignoreHTTPSErrors: nil,
|
|
13
|
+
proxy: nil,
|
|
14
|
+
storageState: nil,
|
|
15
|
+
timeout: nil,
|
|
16
|
+
userAgent: nil)
|
|
17
|
+
raise NotImplementedError.new('new_context is not implemented yet.')
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -65,14 +65,14 @@ module Playwright
|
|
|
65
65
|
multipart: nil,
|
|
66
66
|
params: nil,
|
|
67
67
|
timeout: nil)
|
|
68
|
-
|
|
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)))
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
# All responses returned by [`method: APIRequestContext.get`] and similar methods are stored in the memory, so that you
|
|
72
72
|
# can later call [`method: APIResponse.body`]. This method discards all stored responses, and makes
|
|
73
73
|
# [`method: APIResponse.body`] throw "Response disposed" error.
|
|
74
74
|
def dispose
|
|
75
|
-
|
|
75
|
+
wrap_impl(@impl.dispose)
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
# Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
|
|
@@ -88,7 +88,7 @@ module Playwright
|
|
|
88
88
|
multipart: nil,
|
|
89
89
|
params: nil,
|
|
90
90
|
timeout: nil)
|
|
91
|
-
|
|
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)))
|
|
92
92
|
end
|
|
93
93
|
|
|
94
94
|
# Sends HTTP(S) [GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET) request and returns its response. The
|
|
@@ -101,7 +101,7 @@ module Playwright
|
|
|
101
101
|
ignoreHTTPSErrors: nil,
|
|
102
102
|
params: nil,
|
|
103
103
|
timeout: nil)
|
|
104
|
-
|
|
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)))
|
|
105
105
|
end
|
|
106
106
|
|
|
107
107
|
# Sends HTTP(S) [HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD) request and returns its response.
|
|
@@ -114,7 +114,7 @@ module Playwright
|
|
|
114
114
|
ignoreHTTPSErrors: nil,
|
|
115
115
|
params: nil,
|
|
116
116
|
timeout: nil)
|
|
117
|
-
|
|
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)))
|
|
118
118
|
end
|
|
119
119
|
|
|
120
120
|
# Sends HTTP(S) [PATCH](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH) request and returns its response.
|
|
@@ -130,7 +130,7 @@ module Playwright
|
|
|
130
130
|
multipart: nil,
|
|
131
131
|
params: nil,
|
|
132
132
|
timeout: nil)
|
|
133
|
-
|
|
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)))
|
|
134
134
|
end
|
|
135
135
|
|
|
136
136
|
# Sends HTTP(S) [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) request and returns its response.
|
|
@@ -146,7 +146,7 @@ module Playwright
|
|
|
146
146
|
multipart: nil,
|
|
147
147
|
params: nil,
|
|
148
148
|
timeout: nil)
|
|
149
|
-
|
|
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)))
|
|
150
150
|
end
|
|
151
151
|
|
|
152
152
|
# Sends HTTP(S) [PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT) request and returns its response. The
|
|
@@ -162,7 +162,7 @@ module Playwright
|
|
|
162
162
|
multipart: nil,
|
|
163
163
|
params: nil,
|
|
164
164
|
timeout: nil)
|
|
165
|
-
|
|
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)))
|
|
166
166
|
end
|
|
167
167
|
|
|
168
168
|
# Returns storage state for this request context, contains current cookies and local storage snapshot if it was passed to
|
|
@@ -173,20 +173,20 @@ module Playwright
|
|
|
173
173
|
|
|
174
174
|
# -- inherited from EventEmitter --
|
|
175
175
|
# @nodoc
|
|
176
|
-
def
|
|
177
|
-
event_emitter_proxy.
|
|
176
|
+
def off(event, callback)
|
|
177
|
+
event_emitter_proxy.off(event, callback)
|
|
178
178
|
end
|
|
179
179
|
|
|
180
180
|
# -- inherited from EventEmitter --
|
|
181
181
|
# @nodoc
|
|
182
|
-
def
|
|
183
|
-
event_emitter_proxy.
|
|
182
|
+
def once(event, callback)
|
|
183
|
+
event_emitter_proxy.once(event, callback)
|
|
184
184
|
end
|
|
185
185
|
|
|
186
186
|
# -- inherited from EventEmitter --
|
|
187
187
|
# @nodoc
|
|
188
|
-
def
|
|
189
|
-
event_emitter_proxy.
|
|
188
|
+
def on(event, callback)
|
|
189
|
+
event_emitter_proxy.on(event, callback)
|
|
190
190
|
end
|
|
191
191
|
|
|
192
192
|
private def event_emitter_proxy
|
|
@@ -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
|
|
@@ -168,20 +168,20 @@ module Playwright
|
|
|
168
168
|
|
|
169
169
|
# -- inherited from EventEmitter --
|
|
170
170
|
# @nodoc
|
|
171
|
-
def
|
|
172
|
-
event_emitter_proxy.
|
|
171
|
+
def off(event, callback)
|
|
172
|
+
event_emitter_proxy.off(event, callback)
|
|
173
173
|
end
|
|
174
174
|
|
|
175
175
|
# -- inherited from EventEmitter --
|
|
176
176
|
# @nodoc
|
|
177
|
-
def
|
|
178
|
-
event_emitter_proxy.
|
|
177
|
+
def once(event, callback)
|
|
178
|
+
event_emitter_proxy.once(event, callback)
|
|
179
179
|
end
|
|
180
180
|
|
|
181
181
|
# -- inherited from EventEmitter --
|
|
182
182
|
# @nodoc
|
|
183
|
-
def
|
|
184
|
-
event_emitter_proxy.
|
|
183
|
+
def on(event, callback)
|
|
184
|
+
event_emitter_proxy.on(event, callback)
|
|
185
185
|
end
|
|
186
186
|
|
|
187
187
|
private def event_emitter_proxy
|
|
@@ -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
|
-
|
|
25
|
+
wrap_impl(@impl.request)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def tracing # property
|
|
@@ -376,6 +376,11 @@ module Playwright
|
|
|
376
376
|
wrap_impl(@impl.pause)
|
|
377
377
|
end
|
|
378
378
|
|
|
379
|
+
# @nodoc
|
|
380
|
+
def enable_debug_console!
|
|
381
|
+
wrap_impl(@impl.enable_debug_console!)
|
|
382
|
+
end
|
|
383
|
+
|
|
379
384
|
# @nodoc
|
|
380
385
|
def browser=(req)
|
|
381
386
|
wrap_impl(@impl.browser=(unwrap_impl(req)))
|
|
@@ -391,9 +396,10 @@ module Playwright
|
|
|
391
396
|
wrap_impl(@impl.options=(unwrap_impl(req)))
|
|
392
397
|
end
|
|
393
398
|
|
|
399
|
+
# -- inherited from EventEmitter --
|
|
394
400
|
# @nodoc
|
|
395
|
-
def
|
|
396
|
-
|
|
401
|
+
def off(event, callback)
|
|
402
|
+
event_emitter_proxy.off(event, callback)
|
|
397
403
|
end
|
|
398
404
|
|
|
399
405
|
# -- inherited from EventEmitter --
|
|
@@ -408,12 +414,6 @@ module Playwright
|
|
|
408
414
|
event_emitter_proxy.on(event, callback)
|
|
409
415
|
end
|
|
410
416
|
|
|
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
|
|
@@ -148,20 +148,20 @@ module Playwright
|
|
|
148
148
|
|
|
149
149
|
# -- inherited from EventEmitter --
|
|
150
150
|
# @nodoc
|
|
151
|
-
def
|
|
152
|
-
event_emitter_proxy.
|
|
151
|
+
def off(event, callback)
|
|
152
|
+
event_emitter_proxy.off(event, callback)
|
|
153
153
|
end
|
|
154
154
|
|
|
155
155
|
# -- inherited from EventEmitter --
|
|
156
156
|
# @nodoc
|
|
157
|
-
def
|
|
158
|
-
event_emitter_proxy.
|
|
157
|
+
def once(event, callback)
|
|
158
|
+
event_emitter_proxy.once(event, callback)
|
|
159
159
|
end
|
|
160
160
|
|
|
161
161
|
# -- inherited from EventEmitter --
|
|
162
162
|
# @nodoc
|
|
163
|
-
def
|
|
164
|
-
event_emitter_proxy.
|
|
163
|
+
def on(event, callback)
|
|
164
|
+
event_emitter_proxy.on(event, callback)
|
|
165
165
|
end
|
|
166
166
|
|
|
167
167
|
private def event_emitter_proxy
|