playwright-ruby-client 1.18.0 → 1.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd0b003cf0d53da6959d90b63c1b925e5d5545b06a96c54f40109fb943bc4d6e
4
- data.tar.gz: 19db226c5ad72e480967e2476b6500607121d1b698396ff66061233eff46eeb1
3
+ metadata.gz: 4743c153d270bd3343d7f59b53e1ef03ebecf65495804c79ef4561e5db1263ac
4
+ data.tar.gz: 2f5db2b025b62ebece498cce6edc8f02f85a07377dee2945fbbcfb60e6718c48
5
5
  SHA512:
6
- metadata.gz: 49ad61dde3eb71a242401225fb16c834dc6ec75f5f5b8baef959f0a162b0fac5960373b6fa2cc091f90e9dfe90bc66c72ec7858af42000c37a543daa6520974d
7
- data.tar.gz: 3492a3ce647a6ee0e44ca38f10948e0b6d6a8c818595ebf4d8f57bed802ebce6065d5f8d507bbc617d2fe8d075556c8f031ede00fab902d39b77dabe1be9ec42
6
+ metadata.gz: 36f2d941a86f2533ad494013346f68a3840e33065bf1d3021ff071f6caec635e890378eb7a88df3d096ffa85a86b037e93dae68535c0d30baacc699cb62292a5
7
+ data.tar.gz: 38757489faccca207351dfc8ff1d5519ee7fe329726a0024fe80fe83eb772abed986dbfcde5ad0b1cd5987a5b79666a4675cb360bb3333b1b29e4065087b2b75
@@ -0,0 +1,7 @@
1
+ ---
2
+ sidebar_position: 10
3
+ ---
4
+
5
+ # APIRequest
6
+
7
+ Not Implemented
@@ -9,51 +9,163 @@ environment or the service to your e2e test. When used on [Page](./page) or a [B
9
9
  the cookies from the corresponding [BrowserContext](./browser_context). This means that if you log in using this API, your e2e test will be
10
10
  logged in and vice versa.
11
11
 
12
- ```python sync title=example_6db210740dd2dcb4551c2207b3204fde7127b24c7850226b273d15c0d6624ba5.py
13
- import os
14
- from playwright.sync_api import sync_playwright
15
-
16
- REPO = "test-repo-1"
17
- USER = "github-username"
18
- API_TOKEN = os.getenv("GITHUB_API_TOKEN")
19
-
20
- with sync_playwright() as p:
21
- # This will launch a new browser, create a context and page. When making HTTP
22
- # requests with the internal APIRequestContext (e.g. `context.request` or `page.request`)
23
- # it will automatically set the cookies to the browser page and vise versa.
24
- browser = playwright.chromium.launch()
25
- context = browser.new_context(base_url="https://api.github.com")
26
- api_request_context = context.request
27
- page = context.new_page()
28
-
29
- # Alternatively you can create a APIRequestContext manually without having a browser context attached:
30
- # api_request_context = playwright.request.new_context(base_url="https://api.github.com")
31
-
32
-
33
- # Create a repository.
34
- response = api_request_context.post(
35
- "/user/repos",
36
- headers={
37
- "Accept": "application/vnd.github.v3+json",
38
- # Add GitHub personal access token.
39
- "Authorization": f"token {API_TOKEN}",
40
- },
41
- data={"name": REPO},
42
- )
43
- assert response.ok
44
- assert response.json()["name"] == REPO
45
-
46
- # Delete a repository.
47
- response = api_request_context.delete(
48
- f"/repos/{USER}/{REPO}",
49
- headers={
50
- "Accept": "application/vnd.github.v3+json",
51
- # Add GitHub personal access token.
52
- "Authorization": f"token {API_TOKEN}",
53
- },
54
- )
55
- assert response.ok
56
- assert await response.body() == '{"status": "ok"}'
12
+ ```ruby
13
+ playwright.chromium.launch do |browser|
14
+ # This will launch a new browser, create a context and page. When making HTTP
15
+ # requests with the internal APIRequestContext (e.g. `context.request` or `page.request`)
16
+ # it will automatically set the cookies to the browser page and vise versa.
17
+ context = browser.new_context(base_url: 'https://api.github,com')
18
+ api_request_context = context.request
57
19
 
20
+
21
+ # Create a repository.
22
+ response = api_request_context.post(
23
+ "/user/repos",
24
+ headers: {
25
+ "Accept": "application/vnd.github.v3+json",
26
+ "Authorization": "Bearer #{API_TOKEN}",
27
+ },
28
+ data: { name: 'test-repo-1' },
29
+ )
30
+ response.ok? # => true
31
+ response.json['name'] # => "tes≈-repo-1"
32
+ end
33
+ ```
34
+
35
+
36
+ ## delete
37
+
38
+ ```
39
+ def delete(
40
+ url,
41
+ data: nil,
42
+ failOnStatusCode: nil,
43
+ form: nil,
44
+ headers: nil,
45
+ ignoreHTTPSErrors: nil,
46
+ multipart: nil,
47
+ params: nil,
48
+ timeout: nil)
49
+ ```
50
+
51
+ Sends HTTP(S) [DELETE](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/DELETE) request and returns its
52
+ response. The method will populate request cookies from the context and update context cookies from the response. The
53
+ method will automatically follow redirects.
54
+
55
+ ## dispose
56
+
57
+ ```
58
+ def dispose
59
+ ```
60
+
61
+ All responses returned by [APIRequestContext#get](./api_request_context#get) and similar methods are stored in the memory, so that you
62
+ can later call [APIResponse#body](./api_response#body). This method discards all stored responses, and makes
63
+ [APIResponse#body](./api_response#body) throw "Response disposed" error.
64
+
65
+ ## fetch
66
+
67
+ ```
68
+ def fetch(
69
+ urlOrRequest,
70
+ data: nil,
71
+ failOnStatusCode: nil,
72
+ form: nil,
73
+ headers: nil,
74
+ ignoreHTTPSErrors: nil,
75
+ method: nil,
76
+ multipart: nil,
77
+ params: nil,
78
+ timeout: nil)
79
+ ```
80
+
81
+ Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update
82
+ context cookies from the response. The method will automatically follow redirects.
83
+
84
+ ## get
85
+
86
+ ```
87
+ def get(
88
+ url,
89
+ failOnStatusCode: nil,
90
+ headers: nil,
91
+ ignoreHTTPSErrors: nil,
92
+ params: nil,
93
+ timeout: nil)
94
+ ```
95
+
96
+ Sends HTTP(S) [GET](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/GET) request and returns its response. The
97
+ method will populate request cookies from the context and update context cookies from the response. The method will
98
+ automatically follow redirects.
99
+
100
+ ## head
101
+
102
+ ```
103
+ def head(
104
+ url,
105
+ failOnStatusCode: nil,
106
+ headers: nil,
107
+ ignoreHTTPSErrors: nil,
108
+ params: nil,
109
+ timeout: nil)
110
+ ```
111
+
112
+ Sends HTTP(S) [HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD) request and returns its response.
113
+ The method will populate request cookies from the context and update context cookies from the response. The method will
114
+ automatically follow redirects.
115
+
116
+ ## patch
117
+
118
+ ```
119
+ def patch(
120
+ url,
121
+ data: nil,
122
+ failOnStatusCode: nil,
123
+ form: nil,
124
+ headers: nil,
125
+ ignoreHTTPSErrors: nil,
126
+ multipart: nil,
127
+ params: nil,
128
+ timeout: nil)
129
+ ```
130
+
131
+ Sends HTTP(S) [PATCH](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH) request and returns its response.
132
+ The method will populate request cookies from the context and update context cookies from the response. The method will
133
+ automatically follow redirects.
134
+
135
+ ## post
136
+
137
+ ```
138
+ def post(
139
+ url,
140
+ data: nil,
141
+ failOnStatusCode: nil,
142
+ form: nil,
143
+ headers: nil,
144
+ ignoreHTTPSErrors: nil,
145
+ multipart: nil,
146
+ params: nil,
147
+ timeout: nil)
148
+ ```
149
+
150
+ Sends HTTP(S) [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST) request and returns its response.
151
+ The method will populate request cookies from the context and update context cookies from the response. The method will
152
+ automatically follow redirects.
153
+
154
+ ## put
155
+
156
+ ```
157
+ def put(
158
+ url,
159
+ data: nil,
160
+ failOnStatusCode: nil,
161
+ form: nil,
162
+ headers: nil,
163
+ ignoreHTTPSErrors: nil,
164
+ multipart: nil,
165
+ params: nil,
166
+ timeout: nil)
58
167
  ```
59
168
 
169
+ Sends HTTP(S) [PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT) request and returns its response. The
170
+ method will populate request cookies from the context and update context cookies from the response. The method will
171
+ automatically follow redirects.
@@ -0,0 +1,104 @@
1
+ ---
2
+ sidebar_position: 10
3
+ ---
4
+
5
+ # APIResponse
6
+
7
+ [APIResponse](./api_response) class represents responses returned by [APIRequestContext#get](./api_request_context#get) and similar methods.
8
+
9
+ ```ruby
10
+ playwright.chromium.launch do |browser|
11
+ context = browser.new_context
12
+ response = context.request.get("https://example.com/user/repos")
13
+
14
+ response.ok? # => true
15
+ response.status # => 200
16
+ response.headers["content-type"] # => "application/json; charset=utf-8"
17
+ response.json # => { "name" => "Foo" }
18
+ response.body # => "{ \"name\" => \"Foo\" }"
19
+ end
20
+ ```
21
+
22
+
23
+ ## body
24
+
25
+ ```
26
+ def body
27
+ ```
28
+
29
+ Returns the buffer with response body.
30
+
31
+ ## dispose
32
+
33
+ ```
34
+ def dispose
35
+ ```
36
+
37
+ Disposes the body of this response. If not called then the body will stay in memory until the context closes.
38
+
39
+ ## headers
40
+
41
+ ```
42
+ def headers
43
+ ```
44
+
45
+ An object with all the response HTTP headers associated with this response.
46
+
47
+ ## headers_array
48
+
49
+ ```
50
+ def headers_array
51
+ ```
52
+
53
+ An array with all the request HTTP headers associated with this response. Header names are not lower-cased. Headers with
54
+ multiple entries, such as `Set-Cookie`, appear in the array multiple times.
55
+
56
+ ## json
57
+
58
+ ```
59
+ def json
60
+ ```
61
+
62
+ Returns the JSON representation of response body.
63
+
64
+ This method will throw if the response body is not parsable via `JSON.parse`.
65
+
66
+ ## ok
67
+
68
+ ```
69
+ def ok
70
+ ```
71
+
72
+ Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
73
+
74
+ ## status
75
+
76
+ ```
77
+ def status
78
+ ```
79
+
80
+ Contains the status code of the response (e.g., 200 for a success).
81
+
82
+ ## status_text
83
+
84
+ ```
85
+ def status_text
86
+ ```
87
+
88
+ Contains the status text of the response (e.g. usually an "OK" for a success).
89
+
90
+ ## text
91
+
92
+ ```
93
+ def text
94
+ ```
95
+
96
+ Returns the text representation of response body.
97
+
98
+ ## url
99
+
100
+ ```
101
+ def url
102
+ ```
103
+
104
+ Contains the URL of the response.
@@ -436,4 +436,8 @@ def expect_page(predicate: nil, timeout: nil)
436
436
  Performs action and waits for a new [Page](./page) to be created in the context. If predicate is provided, it passes [Page](./page) value into the `predicate` and waits for `predicate.call(page)` to return a truthy value. Will throw an error if
437
437
  the context closes before new [Page](./page) is created.
438
438
 
439
+ ## request
440
+
441
+ API testing helper associated with this context. Requests made with this API will use context cookies.
442
+
439
443
  ## tracing
@@ -1597,4 +1597,8 @@ associated with the page.
1597
1597
 
1598
1598
  ## mouse
1599
1599
 
1600
+ ## request
1601
+
1602
+ API testing helper associated with this page. Requests made with this API will use page cookies.
1603
+
1600
1604
  ## touchscreen
@@ -1,17 +1,5 @@
1
1
  # API coverages
2
2
 
3
- ## APIRequestContext
4
-
5
- * ~~delete~~
6
- * ~~dispose~~
7
- * ~~fetch~~
8
- * ~~get~~
9
- * ~~head~~
10
- * ~~patch~~
11
- * ~~post~~
12
- * ~~put~~
13
- * ~~storage_state~~
14
-
15
3
  ## Request
16
4
 
17
5
  * all_headers
@@ -331,7 +319,7 @@
331
319
  * accessibility
332
320
  * keyboard
333
321
  * mouse
334
- * ~~request~~
322
+ * request
335
323
  * touchscreen
336
324
 
337
325
  ## BrowserContext
@@ -362,7 +350,7 @@
362
350
  * expect_event
363
351
  * expect_page
364
352
  * ~~wait_for_event~~
365
- * ~~request~~
353
+ * request
366
354
  * tracing
367
355
 
368
356
  ## CDPSession
@@ -466,6 +454,35 @@
466
454
  ## LocalUtils
467
455
 
468
456
 
457
+ ## APIResponse
458
+
459
+ * body
460
+ * dispose
461
+ * headers
462
+ * headers_array
463
+ * json
464
+ * ok
465
+ * status
466
+ * status_text
467
+ * text
468
+ * url
469
+
470
+ ## APIRequestContext
471
+
472
+ * delete
473
+ * dispose
474
+ * fetch
475
+ * get
476
+ * head
477
+ * patch
478
+ * post
479
+ * put
480
+ * ~~storage_state~~
481
+
482
+ ## ~~APIRequest~~
483
+
484
+ * ~~new_context~~
485
+
469
486
  ## Android
470
487
 
471
488
  * devices
@@ -0,0 +1,73 @@
1
+ module Playwright
2
+ define_api_implementation :APIResponseImpl do
3
+ include Utils::Errors::SafeCloseError
4
+
5
+ # @params context [APIRequestContext]
6
+ # @params initializer [Hash]
7
+ def initialize(context, initializer)
8
+ @request = context
9
+ @initializer = initializer
10
+ @headers = RawHeaders.new(initializer['headers'])
11
+ end
12
+
13
+ def to_s
14
+ "#<APIResponse url=#{url} status=#{status} status_text=#{status_text}>"
15
+ end
16
+
17
+ def url
18
+ @initializer['url']
19
+ end
20
+
21
+ def ok
22
+ (200...300).include?(status)
23
+ end
24
+ alias_method :ok?, :ok
25
+
26
+ def status
27
+ @initializer['status']
28
+ end
29
+
30
+ def status_text
31
+ @initializer['statusText']
32
+ end
33
+
34
+ def headers
35
+ @headers.headers
36
+ end
37
+
38
+ def headers_array
39
+ @headers.headers_array
40
+ end
41
+
42
+ class AlreadyDisposedError < StandardError
43
+ def initialize
44
+ super('Response has been disposed')
45
+ end
46
+ end
47
+
48
+ def body
49
+ binary = @request.channel.send_message_to_server("fetchResponseBody", fetchUid: fetch_uid)
50
+ raise AlreadyDisposedError.new unless binary
51
+ Base64.strict_decode64(binary)
52
+ rescue => err
53
+ if safe_close_error?(err)
54
+ raise AlreadyDisposedError.new
55
+ else
56
+ raise
57
+ end
58
+ end
59
+ alias_method :text, :body
60
+
61
+ def json
62
+ JSON.parse(text)
63
+ end
64
+
65
+ def dispose
66
+ @request.channel.send_message_to_server("disposeAPIResponse", fetchUid: fetch_uid)
67
+ end
68
+
69
+ private def fetch_uid
70
+ @initializer['fetchUid']
71
+ end
72
+ end
73
+ end
@@ -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']) )})
@@ -733,6 +733,10 @@ module Playwright
733
733
  @workers.to_a
734
734
  end
735
735
 
736
+ def request
737
+ @browser_context.request
738
+ end
739
+
736
740
  def pause
737
741
  @browser_context.send(:pause)
738
742
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Playwright
4
- VERSION = '1.18.0'
5
- COMPATIBLE_PLAYWRIGHT_VERSION = '1.18.0'
4
+ VERSION = '1.18.1'
5
+ COMPATIBLE_PLAYWRIGHT_VERSION = '1.18.1'
6
6
  end
@@ -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
- raise NotImplementedError.new('delete is not implemented yet.')
68
+ wrap_impl(@impl.delete(unwrap_impl(url), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
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
- raise NotImplementedError.new('dispose is not implemented yet.')
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
- raise NotImplementedError.new('fetch is not implemented yet.')
91
+ wrap_impl(@impl.fetch(unwrap_impl(urlOrRequest), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), method: unwrap_impl(method), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
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
- raise NotImplementedError.new('get is not implemented yet.')
104
+ wrap_impl(@impl.get(unwrap_impl(url), failOnStatusCode: unwrap_impl(failOnStatusCode), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
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
- raise NotImplementedError.new('head is not implemented yet.')
117
+ wrap_impl(@impl.head(unwrap_impl(url), failOnStatusCode: unwrap_impl(failOnStatusCode), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
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
- raise NotImplementedError.new('patch is not implemented yet.')
133
+ wrap_impl(@impl.patch(unwrap_impl(url), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
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
- raise NotImplementedError.new('post is not implemented yet.')
149
+ wrap_impl(@impl.post(unwrap_impl(url), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
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
- raise NotImplementedError.new('put is not implemented yet.')
165
+ wrap_impl(@impl.put(unwrap_impl(url), data: unwrap_impl(data), failOnStatusCode: unwrap_impl(failOnStatusCode), form: unwrap_impl(form), headers: unwrap_impl(headers), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), multipart: unwrap_impl(multipart), params: unwrap_impl(params), timeout: unwrap_impl(timeout)))
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
@@ -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
@@ -22,7 +22,7 @@ module Playwright
22
22
 
23
23
  # API testing helper associated with this context. Requests made with this API will use context cookies.
24
24
  def request # property
25
- raise NotImplementedError.new('request is not implemented yet.')
25
+ wrap_impl(@impl.request)
26
26
  end
27
27
 
28
28
  def tracing # property
@@ -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,11 +396,6 @@ module Playwright
391
396
  wrap_impl(@impl.options=(unwrap_impl(req)))
392
397
  end
393
398
 
394
- # @nodoc
395
- def enable_debug_console!
396
- wrap_impl(@impl.enable_debug_console!)
397
- end
398
-
399
399
  # -- inherited from EventEmitter --
400
400
  # @nodoc
401
401
  def once(event, callback)
@@ -58,7 +58,7 @@ module Playwright
58
58
 
59
59
  # API testing helper associated with this page. Requests made with this API will use page cookies.
60
60
  def request # property
61
- raise NotImplementedError.new('request is not implemented yet.')
61
+ wrap_impl(@impl.request)
62
62
  end
63
63
 
64
64
  def touchscreen # property
@@ -1391,11 +1391,6 @@ module Playwright
1391
1391
  wrap_impl(@impl.start_js_coverage(resetOnNavigation: unwrap_impl(resetOnNavigation), reportAnonymousScripts: unwrap_impl(reportAnonymousScripts)))
1392
1392
  end
1393
1393
 
1394
- # @nodoc
1395
- def stop_js_coverage
1396
- wrap_impl(@impl.stop_js_coverage)
1397
- end
1398
-
1399
1394
  # @nodoc
1400
1395
  def start_css_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil)
1401
1396
  wrap_impl(@impl.start_css_coverage(resetOnNavigation: unwrap_impl(resetOnNavigation), reportAnonymousScripts: unwrap_impl(reportAnonymousScripts)))
@@ -1406,6 +1401,11 @@ module Playwright
1406
1401
  wrap_impl(@impl.stop_css_coverage)
1407
1402
  end
1408
1403
 
1404
+ # @nodoc
1405
+ def stop_js_coverage
1406
+ wrap_impl(@impl.stop_js_coverage)
1407
+ end
1408
+
1409
1409
  # @nodoc
1410
1410
  def guid
1411
1411
  wrap_impl(@impl.guid)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playwright-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.18.0
4
+ version: 1.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - YusukeIwaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-25 00:00:00.000000000 Z
11
+ date: 2022-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -210,7 +210,9 @@ files:
210
210
  - documentation/README.md
211
211
  - documentation/babel.config.js
212
212
  - documentation/docs/api/accessibility.md
213
+ - documentation/docs/api/api_request.md
213
214
  - documentation/docs/api/api_request_context.md
215
+ - documentation/docs/api/api_response.md
214
216
  - documentation/docs/api/browser.md
215
217
  - documentation/docs/api/browser_context.md
216
218
  - documentation/docs/api/browser_type.md
@@ -275,6 +277,7 @@ files:
275
277
  - lib/playwright/accessibility_impl.rb
276
278
  - lib/playwright/android_input_impl.rb
277
279
  - lib/playwright/api_implementation.rb
280
+ - lib/playwright/api_response_impl.rb
278
281
  - lib/playwright/channel.rb
279
282
  - lib/playwright/channel_owner.rb
280
283
  - lib/playwright/channel_owners/android.rb
@@ -341,7 +344,9 @@ files:
341
344
  - lib/playwright_api/android_input.rb
342
345
  - lib/playwright_api/android_socket.rb
343
346
  - lib/playwright_api/android_web_view.rb
347
+ - lib/playwright_api/api_request.rb
344
348
  - lib/playwright_api/api_request_context.rb
349
+ - lib/playwright_api/api_response.rb
345
350
  - lib/playwright_api/browser.rb
346
351
  - lib/playwright_api/browser_context.rb
347
352
  - lib/playwright_api/browser_type.rb
@@ -391,5 +396,5 @@ requirements: []
391
396
  rubygems_version: 3.3.3
392
397
  signing_key:
393
398
  specification_version: 4
394
- summary: The Ruby binding of playwright driver 1.18.0
399
+ summary: The Ruby binding of playwright driver 1.18.1
395
400
  test_files: []