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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/docs/api/api_request.md +7 -0
  3. data/documentation/docs/api/api_request_context.md +157 -45
  4. data/documentation/docs/api/api_response.md +104 -0
  5. data/documentation/docs/api/browser_context.md +4 -0
  6. data/documentation/docs/api/page.md +4 -0
  7. data/documentation/docs/include/api_coverage.md +31 -14
  8. data/lib/playwright/api_response_impl.rb +73 -0
  9. data/lib/playwright/channel_owners/api_request_context.rb +232 -0
  10. data/lib/playwright/channel_owners/browser_context.rb +3 -1
  11. data/lib/playwright/channel_owners/page.rb +4 -0
  12. data/lib/playwright/transport.rb +14 -1
  13. data/lib/playwright/version.rb +2 -2
  14. data/lib/playwright_api/android.rb +6 -6
  15. data/lib/playwright_api/android_device.rb +6 -6
  16. data/lib/playwright_api/api_request.rb +20 -0
  17. data/lib/playwright_api/api_request_context.rb +14 -14
  18. data/lib/playwright_api/api_response.rb +81 -0
  19. data/lib/playwright_api/browser.rb +6 -6
  20. data/lib/playwright_api/browser_context.rb +9 -9
  21. data/lib/playwright_api/browser_type.rb +6 -6
  22. data/lib/playwright_api/cdp_session.rb +6 -6
  23. data/lib/playwright_api/console_message.rb +6 -6
  24. data/lib/playwright_api/dialog.rb +6 -6
  25. data/lib/playwright_api/element_handle.rb +6 -6
  26. data/lib/playwright_api/frame.rb +6 -6
  27. data/lib/playwright_api/js_handle.rb +6 -6
  28. data/lib/playwright_api/page.rb +11 -11
  29. data/lib/playwright_api/playwright.rb +6 -6
  30. data/lib/playwright_api/request.rb +6 -6
  31. data/lib/playwright_api/response.rb +6 -6
  32. data/lib/playwright_api/route.rb +6 -6
  33. data/lib/playwright_api/selectors.rb +6 -6
  34. data/lib/playwright_api/web_socket.rb +6 -6
  35. data/lib/playwright_api/worker.rb +6 -6
  36. metadata +9 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd0b003cf0d53da6959d90b63c1b925e5d5545b06a96c54f40109fb943bc4d6e
4
- data.tar.gz: 19db226c5ad72e480967e2476b6500607121d1b698396ff66061233eff46eeb1
3
+ metadata.gz: 61c1d2ea0171ac16b6687a7e48411d1c8ec0f61e40794628c1ac4e248fdce06a
4
+ data.tar.gz: 0ebea8c18299effd7f13ab1f7f8f96b043bb0ef2c215481943a8ba4df96abb7c
5
5
  SHA512:
6
- metadata.gz: 49ad61dde3eb71a242401225fb16c834dc6ec75f5f5b8baef959f0a162b0fac5960373b6fa2cc091f90e9dfe90bc66c72ec7858af42000c37a543daa6520974d
7
- data.tar.gz: 3492a3ce647a6ee0e44ca38f10948e0b6d6a8c818595ebf4d8f57bed802ebce6065d5f8d507bbc617d2fe8d075556c8f031ede00fab902d39b77dabe1be9ec42
6
+ metadata.gz: 11c4ee9385a617b09ac668f9659193062b77b6d273c24c7ee73038f5a0279a811420fd2a13f1bee86d83f5e2ddbbf9720ad362ca6514ba445d3b4a1e5c77c372
7
+ data.tar.gz: cb0ddd6cad0c1d289014c0fddf2b2336885c46410c3501444d80fbee9947603f46b8d6e72a9e0244d1a8adf4550f25c0297d0263508cb8e918d93ded9063827e
@@ -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