playwright-ruby-client 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/documentation/README.md +33 -0
- data/documentation/babel.config.js +3 -0
- data/documentation/docs/api/accessibility.md +7 -0
- data/documentation/docs/api/browser.md +185 -0
- data/documentation/docs/api/browser_context.md +398 -0
- data/documentation/docs/api/browser_type.md +105 -0
- data/documentation/docs/api/cdp_session.md +7 -0
- data/documentation/docs/api/console_message.md +41 -0
- data/documentation/docs/api/dialog.md +74 -0
- data/documentation/docs/api/element_handle.md +640 -0
- data/documentation/docs/api/experimental/_category_.yml +3 -0
- data/documentation/docs/api/experimental/android.md +25 -0
- data/documentation/docs/api/experimental/android_device.md +91 -0
- data/documentation/docs/api/experimental/android_input.md +38 -0
- data/documentation/docs/api/experimental/android_socket.md +7 -0
- data/documentation/docs/api/experimental/android_web_view.md +7 -0
- data/documentation/docs/api/file_chooser.md +51 -0
- data/documentation/docs/api/frame.md +867 -0
- data/documentation/docs/api/js_handle.md +116 -0
- data/documentation/docs/api/keyboard.md +157 -0
- data/documentation/docs/api/mouse.md +69 -0
- data/documentation/docs/api/page.md +1469 -0
- data/documentation/docs/api/playwright.md +63 -0
- data/documentation/docs/api/request.md +188 -0
- data/documentation/docs/api/response.md +97 -0
- data/documentation/docs/api/route.md +80 -0
- data/documentation/docs/api/selectors.md +23 -0
- data/documentation/docs/api/touchscreen.md +8 -0
- data/documentation/docs/api/tracing.md +54 -0
- data/documentation/docs/api/web_socket.md +7 -0
- data/documentation/docs/api/worker.md +7 -0
- data/documentation/docs/article/api_coverage.mdx +11 -0
- data/documentation/docs/article/getting_started.md +152 -0
- data/documentation/docs/article/guides/_category_.yml +3 -0
- data/documentation/docs/article/guides/download_playwright_driver.md +49 -0
- data/documentation/docs/article/guides/launch_browser.md +119 -0
- data/documentation/docs/article/guides/rails_integration.md +51 -0
- data/{docs → documentation/docs/include}/api_coverage.md +0 -0
- data/documentation/docusaurus.config.js +107 -0
- data/documentation/package.json +39 -0
- data/documentation/sidebars.js +15 -0
- data/documentation/src/components/HomepageFeatures.js +61 -0
- data/documentation/src/components/HomepageFeatures.module.css +13 -0
- data/documentation/src/css/custom.css +44 -0
- data/documentation/src/pages/index.js +50 -0
- data/documentation/src/pages/index.module.css +41 -0
- data/documentation/src/pages/markdown-page.md +7 -0
- data/documentation/static/.nojekyll +0 -0
- data/documentation/static/img/playwright-logo.svg +9 -0
- data/documentation/static/img/undraw_dropdown_menu.svg +1 -0
- data/documentation/static/img/undraw_web_development.svg +1 -0
- data/documentation/static/img/undraw_windows.svg +1 -0
- data/documentation/yarn.lock +8805 -0
- data/lib/playwright/channel_owners/binding_call.rb +33 -0
- data/lib/playwright/channel_owners/browser_context.rb +2 -2
- data/lib/playwright/channel_owners/element_handle.rb +2 -10
- data/lib/playwright/channel_owners/frame.rb +6 -28
- data/lib/playwright/channel_owners/js_handle.rb +2 -10
- data/lib/playwright/channel_owners/page.rb +10 -1
- data/lib/playwright/input_files.rb +0 -8
- data/lib/playwright/javascript.rb +0 -10
- data/lib/playwright/javascript/expression.rb +2 -7
- data/lib/playwright/version.rb +1 -1
- data/lib/playwright_api/accessibility.rb +7 -89
- data/lib/playwright_api/android.rb +7 -64
- data/lib/playwright_api/android_device.rb +8 -8
- data/lib/playwright_api/browser.rb +15 -169
- data/lib/playwright_api/browser_context.rb +47 -609
- data/lib/playwright_api/browser_type.rb +13 -103
- data/lib/playwright_api/cdp_session.rb +2 -25
- data/lib/playwright_api/console_message.rb +6 -6
- data/lib/playwright_api/dialog.rb +11 -92
- data/lib/playwright_api/element_handle.rb +60 -362
- data/lib/playwright_api/file_chooser.rb +0 -28
- data/lib/playwright_api/frame.rb +74 -713
- data/lib/playwright_api/js_handle.rb +16 -90
- data/lib/playwright_api/keyboard.rb +21 -213
- data/lib/playwright_api/mouse.rb +1 -45
- data/lib/playwright_api/page.rb +155 -1635
- data/lib/playwright_api/playwright.rb +14 -117
- data/lib/playwright_api/request.rb +15 -121
- data/lib/playwright_api/response.rb +9 -9
- data/lib/playwright_api/route.rb +8 -105
- data/lib/playwright_api/selectors.rb +6 -97
- data/lib/playwright_api/tracing.rb +1 -61
- data/lib/playwright_api/web_socket.rb +1 -1
- data/lib/playwright_api/worker.rb +6 -42
- metadata +55 -4
- data/lib/playwright/javascript/function.rb +0 -67
@@ -0,0 +1,63 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 10
|
3
|
+
---
|
4
|
+
|
5
|
+
# Playwright
|
6
|
+
|
7
|
+
Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright
|
8
|
+
to drive automation:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
require 'playwright'
|
12
|
+
|
13
|
+
Playwright.create(playwright_cli_executable_path: 'npx playwright') do |playwright|
|
14
|
+
chromium = playwright.chromium # or "firefox" or "webkit".
|
15
|
+
chromium.launch do |browser|
|
16
|
+
page = browser.new_page
|
17
|
+
page.goto('https://example.com/')
|
18
|
+
|
19
|
+
# other actions
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
## chromium
|
28
|
+
|
29
|
+
This object can be used to launch or connect to Chromium, returning instances of [Browser](./browser).
|
30
|
+
|
31
|
+
## devices
|
32
|
+
|
33
|
+
Returns a dictionary of devices to be used with [Browser#new_context](./browser#new_context) or [Browser#new_page](./browser#new_page).
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require 'playwright'
|
37
|
+
|
38
|
+
Playwright.create(playwright_cli_executable_path: 'npx playwright') do |playwright|
|
39
|
+
iphone = playwright.devices["iPhone 6"]
|
40
|
+
playwright.webkit.launch do |browser|
|
41
|
+
context = browser.new_context(**iphone)
|
42
|
+
page = context.new_page
|
43
|
+
page.goto('https://example.com/')
|
44
|
+
|
45
|
+
# other actions
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
|
52
|
+
## firefox
|
53
|
+
|
54
|
+
This object can be used to launch or connect to Firefox, returning instances of [Browser](./browser).
|
55
|
+
|
56
|
+
## selectors
|
57
|
+
|
58
|
+
Selectors can be used to install custom selector engines. See [Working with selectors](https://playwright.dev/python/docs/selectors) for more
|
59
|
+
information.
|
60
|
+
|
61
|
+
## webkit
|
62
|
+
|
63
|
+
This object can be used to launch or connect to WebKit, returning instances of [Browser](./browser).
|
@@ -0,0 +1,188 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 10
|
3
|
+
---
|
4
|
+
|
5
|
+
# Request
|
6
|
+
|
7
|
+
Whenever the page sends a request for a network resource the following sequence of events are emitted by [Page](./page):
|
8
|
+
- [`event: Page.request`] emitted when the request is issued by the page.
|
9
|
+
- [`event: Page.response`] emitted when/if the response status and headers are received for the request.
|
10
|
+
- [`event: Page.requestFinished`] emitted when the response body is downloaded and the request is complete.
|
11
|
+
|
12
|
+
If request fails at some point, then instead of `'requestfinished'` event (and possibly instead of 'response' event),
|
13
|
+
the [`event: Page.requestFailed`] event is emitted.
|
14
|
+
|
15
|
+
> NOTE: HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will
|
16
|
+
complete with `'requestfinished'` event.
|
17
|
+
|
18
|
+
If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new
|
19
|
+
request is issued to a redirected url.
|
20
|
+
|
21
|
+
## failure
|
22
|
+
|
23
|
+
```
|
24
|
+
def failure
|
25
|
+
```
|
26
|
+
|
27
|
+
The method returns `null` unless this request has failed, as reported by `requestfailed` event.
|
28
|
+
|
29
|
+
Example of logging of all the failed requests:
|
30
|
+
|
31
|
+
```py title=example_5f3f4534ab17f584cfd41ca38448ce7de9490b6588e29e73116ede3cb15a25a5.py
|
32
|
+
page.on("requestfailed", lambda request: print(request.url + " " + request.failure))
|
33
|
+
|
34
|
+
```
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
## frame
|
39
|
+
|
40
|
+
```
|
41
|
+
def frame
|
42
|
+
```
|
43
|
+
|
44
|
+
Returns the [Frame](./frame) that initiated this request.
|
45
|
+
|
46
|
+
## headers
|
47
|
+
|
48
|
+
```
|
49
|
+
def headers
|
50
|
+
```
|
51
|
+
|
52
|
+
An object with HTTP headers associated with the request. All header names are lower-case.
|
53
|
+
|
54
|
+
## navigation_request?
|
55
|
+
|
56
|
+
```
|
57
|
+
def navigation_request?
|
58
|
+
```
|
59
|
+
|
60
|
+
Whether this request is driving frame's navigation.
|
61
|
+
|
62
|
+
## method
|
63
|
+
|
64
|
+
```
|
65
|
+
def method
|
66
|
+
```
|
67
|
+
|
68
|
+
Request's method (GET, POST, etc.)
|
69
|
+
|
70
|
+
## post_data
|
71
|
+
|
72
|
+
```
|
73
|
+
def post_data
|
74
|
+
```
|
75
|
+
|
76
|
+
Request's post body, if any.
|
77
|
+
|
78
|
+
## post_data_buffer
|
79
|
+
|
80
|
+
```
|
81
|
+
def post_data_buffer
|
82
|
+
```
|
83
|
+
|
84
|
+
Request's post body in a binary form, if any.
|
85
|
+
|
86
|
+
## post_data_json
|
87
|
+
|
88
|
+
```
|
89
|
+
def post_data_json
|
90
|
+
```
|
91
|
+
|
92
|
+
Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
|
93
|
+
|
94
|
+
When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned.
|
95
|
+
Otherwise it will be parsed as JSON.
|
96
|
+
|
97
|
+
## redirected_from
|
98
|
+
|
99
|
+
```
|
100
|
+
def redirected_from
|
101
|
+
```
|
102
|
+
|
103
|
+
Request that was redirected by the server to this one, if any.
|
104
|
+
|
105
|
+
When the server responds with a redirect, Playwright creates a new [Request](./request) object. The two requests are connected by
|
106
|
+
`redirectedFrom()` and `redirectedTo()` methods. When multiple server redirects has happened, it is possible to
|
107
|
+
construct the whole redirect chain by repeatedly calling `redirectedFrom()`.
|
108
|
+
|
109
|
+
For example, if the website `http://example.com` redirects to `https://example.com`:
|
110
|
+
|
111
|
+
```python sync title=example_89568fc86bf623eef37b68c6659b1a8524647c8365bb32a7a8af63bd86111075.py
|
112
|
+
response = page.goto("http://example.com")
|
113
|
+
print(response.request.redirected_from.url) # "http://example.com"
|
114
|
+
|
115
|
+
```
|
116
|
+
|
117
|
+
If the website `https://google.com` has no redirects:
|
118
|
+
|
119
|
+
```python sync title=example_6d7b3fbf8d69dbe639b71fedc5a8977777fca29dfb16d38012bb07c496342472.py
|
120
|
+
response = page.goto("https://google.com")
|
121
|
+
print(response.request.redirected_from) # None
|
122
|
+
|
123
|
+
```
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
## redirected_to
|
128
|
+
|
129
|
+
```
|
130
|
+
def redirected_to
|
131
|
+
```
|
132
|
+
|
133
|
+
New request issued by the browser if the server responded with redirect.
|
134
|
+
|
135
|
+
This method is the opposite of [Request#redirected_from](./request#redirected_from):
|
136
|
+
|
137
|
+
```py title=example_922623f4033e7ec2158787e54a8554655f7e1e20a024e4bf4f69337f781ab88a.py
|
138
|
+
assert request.redirected_from.redirected_to == request
|
139
|
+
|
140
|
+
```
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
## resource_type
|
145
|
+
|
146
|
+
```
|
147
|
+
def resource_type
|
148
|
+
```
|
149
|
+
|
150
|
+
Contains the request's resource type as it was perceived by the rendering engine. ResourceType will be one of the
|
151
|
+
following: `document`, `stylesheet`, `image`, `media`, `font`, `script`, `texttrack`, `xhr`, `fetch`, `eventsource`,
|
152
|
+
`websocket`, `manifest`, `other`.
|
153
|
+
|
154
|
+
## response
|
155
|
+
|
156
|
+
```
|
157
|
+
def response
|
158
|
+
```
|
159
|
+
|
160
|
+
Returns the matching [Response](./response) object, or `null` if the response was not received due to error.
|
161
|
+
|
162
|
+
## timing
|
163
|
+
|
164
|
+
```
|
165
|
+
def timing
|
166
|
+
```
|
167
|
+
|
168
|
+
Returns resource timing information for given request. Most of the timing values become available upon the response,
|
169
|
+
`responseEnd` becomes available when request finishes. Find more information at
|
170
|
+
[Resource Timing API](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming).
|
171
|
+
|
172
|
+
```python sync title=example_e2a297fe95fd0699b6a856c3be2f28106daa2615c0f4d6084f5012682a619d20.py
|
173
|
+
with page.expect_event("requestfinished") as request_info:
|
174
|
+
page.goto("http://example.com")
|
175
|
+
request = request_info.value
|
176
|
+
print(request.timing)
|
177
|
+
|
178
|
+
```
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
## url
|
183
|
+
|
184
|
+
```
|
185
|
+
def url
|
186
|
+
```
|
187
|
+
|
188
|
+
URL of the request.
|
@@ -0,0 +1,97 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 10
|
3
|
+
---
|
4
|
+
|
5
|
+
# Response
|
6
|
+
|
7
|
+
[Response](./response) class represents responses which are received by page.
|
8
|
+
|
9
|
+
## body
|
10
|
+
|
11
|
+
```
|
12
|
+
def body
|
13
|
+
```
|
14
|
+
|
15
|
+
Returns the buffer with response body.
|
16
|
+
|
17
|
+
## finished
|
18
|
+
|
19
|
+
```
|
20
|
+
def finished
|
21
|
+
```
|
22
|
+
|
23
|
+
Waits for this response to finish, returns failure error if request failed.
|
24
|
+
|
25
|
+
## frame
|
26
|
+
|
27
|
+
```
|
28
|
+
def frame
|
29
|
+
```
|
30
|
+
|
31
|
+
Returns the [Frame](./frame) that initiated this response.
|
32
|
+
|
33
|
+
## headers
|
34
|
+
|
35
|
+
```
|
36
|
+
def headers
|
37
|
+
```
|
38
|
+
|
39
|
+
Returns the object with HTTP headers associated with the response. All header names are lower-case.
|
40
|
+
|
41
|
+
## json
|
42
|
+
|
43
|
+
```
|
44
|
+
def json
|
45
|
+
```
|
46
|
+
|
47
|
+
Returns the JSON representation of response body.
|
48
|
+
|
49
|
+
This method will throw if the response body is not parsable via `JSON.parse`.
|
50
|
+
|
51
|
+
## ok
|
52
|
+
|
53
|
+
```
|
54
|
+
def ok
|
55
|
+
```
|
56
|
+
|
57
|
+
Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
|
58
|
+
|
59
|
+
## request
|
60
|
+
|
61
|
+
```
|
62
|
+
def request
|
63
|
+
```
|
64
|
+
|
65
|
+
Returns the matching [Request](./request) object.
|
66
|
+
|
67
|
+
## status
|
68
|
+
|
69
|
+
```
|
70
|
+
def status
|
71
|
+
```
|
72
|
+
|
73
|
+
Contains the status code of the response (e.g., 200 for a success).
|
74
|
+
|
75
|
+
## status_text
|
76
|
+
|
77
|
+
```
|
78
|
+
def status_text
|
79
|
+
```
|
80
|
+
|
81
|
+
Contains the status text of the response (e.g. usually an "OK" for a success).
|
82
|
+
|
83
|
+
## text
|
84
|
+
|
85
|
+
```
|
86
|
+
def text
|
87
|
+
```
|
88
|
+
|
89
|
+
Returns the text representation of response body.
|
90
|
+
|
91
|
+
## url
|
92
|
+
|
93
|
+
```
|
94
|
+
def url
|
95
|
+
```
|
96
|
+
|
97
|
+
Contains the URL of the response.
|
@@ -0,0 +1,80 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 10
|
3
|
+
---
|
4
|
+
|
5
|
+
# Route
|
6
|
+
|
7
|
+
Whenever a network route is set up with [Page#route](./page#route) or [BrowserContext#route](./browser_context#route), the [Route](./route) object
|
8
|
+
allows to handle the route.
|
9
|
+
|
10
|
+
## abort
|
11
|
+
|
12
|
+
```
|
13
|
+
def abort(errorCode: nil)
|
14
|
+
```
|
15
|
+
|
16
|
+
Aborts the route's request.
|
17
|
+
|
18
|
+
## continue
|
19
|
+
|
20
|
+
```
|
21
|
+
def continue(headers: nil, method: nil, postData: nil, url: nil)
|
22
|
+
```
|
23
|
+
|
24
|
+
Continues route's request with optional overrides.
|
25
|
+
|
26
|
+
```python sync title=example_1960aabd58c9553683368e29429d39c1209d35e6e3625bbef1280a1fa022a9ee.py
|
27
|
+
def handle(route, request):
|
28
|
+
# override headers
|
29
|
+
headers = {
|
30
|
+
**request.headers,
|
31
|
+
"foo": "bar" # set "foo" header
|
32
|
+
"origin": None # remove "origin" header
|
33
|
+
}
|
34
|
+
route.continue_(headers=headers)
|
35
|
+
}
|
36
|
+
page.route("**/*", handle)
|
37
|
+
|
38
|
+
```
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
## fulfill
|
43
|
+
|
44
|
+
```
|
45
|
+
def fulfill(
|
46
|
+
body: nil,
|
47
|
+
contentType: nil,
|
48
|
+
headers: nil,
|
49
|
+
path: nil,
|
50
|
+
status: nil)
|
51
|
+
```
|
52
|
+
|
53
|
+
Fulfills route's request with given response.
|
54
|
+
|
55
|
+
An example of fulfilling all requests with 404 responses:
|
56
|
+
|
57
|
+
```python sync title=example_6d2dfd4bb5c8360f8d80bb91c563b0bd9b99aa24595063cf85e5a6e1b105f89c.py
|
58
|
+
page.route("**/*", lambda route: route.fulfill(
|
59
|
+
status=404,
|
60
|
+
content_type="text/plain",
|
61
|
+
body="not found!"))
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
An example of serving static file:
|
66
|
+
|
67
|
+
```python sync title=example_c77fd0986d0b74c905cd9417756c76775e612cc86410f9a5aabc5b46d233d150.py
|
68
|
+
page.route("**/xhr_endpoint", lambda route: route.fulfill(path="mock_data.json"))
|
69
|
+
|
70
|
+
```
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
## request
|
75
|
+
|
76
|
+
```
|
77
|
+
def request
|
78
|
+
```
|
79
|
+
|
80
|
+
A request to be routed.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
sidebar_position: 10
|
3
|
+
---
|
4
|
+
|
5
|
+
# Selectors
|
6
|
+
|
7
|
+
Selectors can be used to install custom selector engines. See [Working with selectors](https://playwright.dev/python/docs/selectors) for more
|
8
|
+
information.
|
9
|
+
|
10
|
+
## register
|
11
|
+
|
12
|
+
```
|
13
|
+
def register(name, contentScript: nil, path: nil, script: nil)
|
14
|
+
```
|
15
|
+
|
16
|
+
An example of registering selector engine that queries elements based on a tag name:
|
17
|
+
|
18
|
+
```python sync title=example_49f0cb9b5a21d0d5fe2b180c847bdb21068b335b4c2f42d5c05eb1957297899f.py
|
19
|
+
# FIXME: add snippet
|
20
|
+
|
21
|
+
```
|
22
|
+
|
23
|
+
|