playwright-ruby-client 0.6.0 → 0.6.5
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 +188 -0
- data/documentation/docs/api/browser_context.md +397 -0
- data/documentation/docs/api/browser_type.md +158 -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 +71 -0
- data/documentation/docs/api/element_handle.md +618 -0
- data/documentation/docs/api/experimental/_category_.yml +3 -0
- data/documentation/docs/api/experimental/android.md +26 -0
- data/documentation/docs/api/experimental/android_device.md +92 -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 +50 -0
- data/documentation/docs/api/frame.md +866 -0
- data/documentation/docs/api/js_handle.md +113 -0
- data/documentation/docs/api/keyboard.md +157 -0
- data/documentation/docs/api/mouse.md +69 -0
- data/documentation/docs/api/page.md +1402 -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 +79 -0
- data/documentation/docs/api/selectors.md +23 -0
- data/documentation/docs/api/touchscreen.md +8 -0
- data/documentation/docs/api/tracing.md +47 -0
- data/documentation/docs/api/web_socket.md +7 -0
- data/documentation/docs/api/worker.md +24 -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 +205 -0
- data/documentation/docs/article/guides/recording_video.md +79 -0
- data/{docs → documentation/docs/include}/api_coverage.md +4 -3
- 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 +8785 -0
- data/lib/playwright/channel_owners/binding_call.rb +33 -0
- data/lib/playwright/channel_owners/browser.rb +15 -27
- data/lib/playwright/channel_owners/browser_context.rb +15 -7
- data/lib/playwright/channel_owners/browser_type.rb +23 -8
- 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 +18 -8
- data/lib/playwright/channel_owners/worker.rb +4 -0
- 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/playwright_api.rb +16 -1
- data/lib/playwright/tracing_impl.rb +9 -9
- data/lib/playwright/version.rb +1 -1
- data/lib/playwright_api/accessibility.rb +7 -89
- data/lib/playwright_api/android.rb +10 -66
- data/lib/playwright_api/android_device.rb +10 -9
- data/lib/playwright_api/browser.rb +21 -172
- data/lib/playwright_api/browser_context.rb +54 -617
- data/lib/playwright_api/browser_type.rb +20 -108
- 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 +181 -1647
- data/lib/playwright_api/playwright.rb +14 -117
- data/lib/playwright_api/request.rb +15 -121
- data/lib/playwright_api/response.rb +7 -7
- data/lib/playwright_api/route.rb +8 -105
- data/lib/playwright_api/selectors.rb +6 -97
- data/lib/playwright_api/tracing.rb +7 -73
- data/lib/playwright_api/web_socket.rb +1 -1
- data/lib/playwright_api/worker.rb +28 -42
- metadata +57 -4
- data/lib/playwright/javascript/function.rb +0 -67
@@ -1,58 +1,10 @@
|
|
1
1
|
module Playwright
|
2
2
|
# Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright
|
3
3
|
# to drive automation:
|
4
|
-
#
|
5
4
|
#
|
6
|
-
# ```js
|
7
|
-
# const { chromium, firefox, webkit } = require('playwright');
|
8
|
-
#
|
9
|
-
# (async () => {
|
10
|
-
# const browser = await chromium.launch(); // Or 'firefox' or 'webkit'.
|
11
|
-
# const page = await browser.newPage();
|
12
|
-
# await page.goto('http://example.com');
|
13
|
-
# // other actions...
|
14
|
-
# await browser.close();
|
15
|
-
# })();
|
16
|
-
# ```
|
17
|
-
#
|
18
|
-
# ```java
|
19
|
-
# import com.microsoft.playwright.*;
|
20
|
-
#
|
21
|
-
# public class Example {
|
22
|
-
# public static void main(String[] args) {
|
23
|
-
# try (Playwright playwright = Playwright.create()) {
|
24
|
-
# BrowserType chromium = playwright.chromium();
|
25
|
-
# Browser browser = chromium.launch();
|
26
|
-
# Page page = browser.newPage();
|
27
|
-
# page.navigate("http://example.com");
|
28
|
-
# // other actions...
|
29
|
-
# browser.close();
|
30
|
-
# }
|
31
|
-
# }
|
32
|
-
# }
|
33
|
-
# ```
|
34
|
-
#
|
35
|
-
# ```python async
|
36
|
-
# import asyncio
|
37
|
-
# from playwright.async_api import async_playwright
|
38
|
-
#
|
39
|
-
# async def run(playwright):
|
40
|
-
# chromium = playwright.chromium # or "firefox" or "webkit".
|
41
|
-
# browser = await chromium.launch()
|
42
|
-
# page = await browser.new_page()
|
43
|
-
# await page.goto("http://example.com")
|
44
|
-
# # other actions...
|
45
|
-
# await browser.close()
|
46
|
-
#
|
47
|
-
# async def main():
|
48
|
-
# async with async_playwright() as playwright:
|
49
|
-
# await run(playwright)
|
50
|
-
# asyncio.run(main())
|
51
|
-
# ```
|
52
|
-
#
|
53
5
|
# ```python sync
|
54
6
|
# from playwright.sync_api import sync_playwright
|
55
|
-
#
|
7
|
+
#
|
56
8
|
# def run(playwright):
|
57
9
|
# chromium = playwright.chromium # or "firefox" or "webkit".
|
58
10
|
# browser = chromium.launch()
|
@@ -60,28 +12,10 @@ module Playwright
|
|
60
12
|
# page.goto("http://example.com")
|
61
13
|
# # other actions...
|
62
14
|
# browser.close()
|
63
|
-
#
|
15
|
+
#
|
64
16
|
# with sync_playwright() as playwright:
|
65
17
|
# run(playwright)
|
66
18
|
# ```
|
67
|
-
#
|
68
|
-
# ```csharp
|
69
|
-
# using Microsoft.Playwright;
|
70
|
-
# using System.Threading.Tasks;
|
71
|
-
#
|
72
|
-
# class PlaywrightExample
|
73
|
-
# {
|
74
|
-
# public static async Task Main()
|
75
|
-
# {
|
76
|
-
# using var playwright = await Playwright.CreateAsync();
|
77
|
-
# await using var browser = await playwright.Chromium.LaunchAsync();
|
78
|
-
# var page = await browser.NewPageAsync();
|
79
|
-
#
|
80
|
-
# await page.GotoAsync("https://www.microsoft.com");
|
81
|
-
# // other actions...
|
82
|
-
# }
|
83
|
-
# }
|
84
|
-
# ```
|
85
19
|
class Playwright < PlaywrightApi
|
86
20
|
|
87
21
|
# This object can be used to launch or connect to Chromium, returning instances of `Browser`.
|
@@ -90,47 +24,10 @@ module Playwright
|
|
90
24
|
end
|
91
25
|
|
92
26
|
# Returns a dictionary of devices to be used with [`method: Browser.newContext`] or [`method: Browser.newPage`].
|
93
|
-
#
|
94
27
|
#
|
95
|
-
# ```js
|
96
|
-
# const { webkit, devices } = require('playwright');
|
97
|
-
# const iPhone = devices['iPhone 6'];
|
98
|
-
#
|
99
|
-
# (async () => {
|
100
|
-
# const browser = await webkit.launch();
|
101
|
-
# const context = await browser.newContext({
|
102
|
-
# ...iPhone
|
103
|
-
# });
|
104
|
-
# const page = await context.newPage();
|
105
|
-
# await page.goto('http://example.com');
|
106
|
-
# // other actions...
|
107
|
-
# await browser.close();
|
108
|
-
# })();
|
109
|
-
# ```
|
110
|
-
#
|
111
|
-
# ```python async
|
112
|
-
# import asyncio
|
113
|
-
# from playwright.async_api import async_playwright
|
114
|
-
#
|
115
|
-
# async def run(playwright):
|
116
|
-
# webkit = playwright.webkit
|
117
|
-
# iphone = playwright.devices["iPhone 6"]
|
118
|
-
# browser = await webkit.launch()
|
119
|
-
# context = await browser.new_context(**iphone)
|
120
|
-
# page = await context.new_page()
|
121
|
-
# await page.goto("http://example.com")
|
122
|
-
# # other actions...
|
123
|
-
# await browser.close()
|
124
|
-
#
|
125
|
-
# async def main():
|
126
|
-
# async with async_playwright() as playwright:
|
127
|
-
# await run(playwright)
|
128
|
-
# asyncio.run(main())
|
129
|
-
# ```
|
130
|
-
#
|
131
28
|
# ```python sync
|
132
29
|
# from playwright.sync_api import sync_playwright
|
133
|
-
#
|
30
|
+
#
|
134
31
|
# def run(playwright):
|
135
32
|
# webkit = playwright.webkit
|
136
33
|
# iphone = playwright.devices["iPhone 6"]
|
@@ -140,7 +37,7 @@ module Playwright
|
|
140
37
|
# page.goto("http://example.com")
|
141
38
|
# # other actions...
|
142
39
|
# browser.close()
|
143
|
-
#
|
40
|
+
#
|
144
41
|
# with sync_playwright() as playwright:
|
145
42
|
# run(playwright)
|
146
43
|
# ```
|
@@ -166,18 +63,18 @@ module Playwright
|
|
166
63
|
|
167
64
|
# Terminates this instance of Playwright in case it was created bypassing the Python context manager. This is useful in
|
168
65
|
# REPL applications.
|
169
|
-
#
|
66
|
+
#
|
170
67
|
# ```py
|
171
68
|
# >>> from playwright.sync_api import sync_playwright
|
172
|
-
#
|
69
|
+
#
|
173
70
|
# >>> playwright = sync_playwright().start()
|
174
|
-
#
|
71
|
+
#
|
175
72
|
# >>> browser = playwright.chromium.launch()
|
176
73
|
# >>> page = browser.new_page()
|
177
74
|
# >>> page.goto("http://whatsmyuseragent.org/")
|
178
75
|
# >>> page.screenshot(path="example.png")
|
179
76
|
# >>> browser.close()
|
180
|
-
#
|
77
|
+
#
|
181
78
|
# >>> playwright.stop()
|
182
79
|
# ```
|
183
80
|
def stop
|
@@ -194,12 +91,6 @@ module Playwright
|
|
194
91
|
wrap_impl(@impl.electron)
|
195
92
|
end
|
196
93
|
|
197
|
-
# -- inherited from EventEmitter --
|
198
|
-
# @nodoc
|
199
|
-
def off(event, callback)
|
200
|
-
event_emitter_proxy.off(event, callback)
|
201
|
-
end
|
202
|
-
|
203
94
|
# -- inherited from EventEmitter --
|
204
95
|
# @nodoc
|
205
96
|
def once(event, callback)
|
@@ -212,6 +103,12 @@ module Playwright
|
|
212
103
|
event_emitter_proxy.on(event, callback)
|
213
104
|
end
|
214
105
|
|
106
|
+
# -- inherited from EventEmitter --
|
107
|
+
# @nodoc
|
108
|
+
def off(event, callback)
|
109
|
+
event_emitter_proxy.off(event, callback)
|
110
|
+
end
|
111
|
+
|
215
112
|
private def event_emitter_proxy
|
216
113
|
@event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
|
217
114
|
end
|
@@ -3,44 +3,24 @@ module Playwright
|
|
3
3
|
# - [`event: Page.request`] emitted when the request is issued by the page.
|
4
4
|
# - [`event: Page.response`] emitted when/if the response status and headers are received for the request.
|
5
5
|
# - [`event: Page.requestFinished`] emitted when the response body is downloaded and the request is complete.
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# If request fails at some point, then instead of `'requestfinished'` event (and possibly instead of 'response' event),
|
8
8
|
# the [`event: Page.requestFailed`] event is emitted.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# > NOTE: HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will
|
11
11
|
# complete with `'requestfinished'` event.
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new
|
14
14
|
# request is issued to a redirected url.
|
15
15
|
class Request < PlaywrightApi
|
16
16
|
|
17
17
|
# The method returns `null` unless this request has failed, as reported by `requestfailed` event.
|
18
|
-
#
|
18
|
+
#
|
19
19
|
# Example of logging of all the failed requests:
|
20
|
-
#
|
21
20
|
#
|
22
|
-
# ```js
|
23
|
-
# page.on('requestfailed', request => {
|
24
|
-
# console.log(request.url() + ' ' + request.failure().errorText);
|
25
|
-
# });
|
26
|
-
# ```
|
27
|
-
#
|
28
|
-
# ```java
|
29
|
-
# page.onRequestFailed(request -> {
|
30
|
-
# System.out.println(request.url() + " " + request.failure());
|
31
|
-
# });
|
32
|
-
# ```
|
33
|
-
#
|
34
21
|
# ```py
|
35
22
|
# page.on("requestfailed", lambda request: print(request.url + " " + request.failure))
|
36
23
|
# ```
|
37
|
-
#
|
38
|
-
# ```csharp
|
39
|
-
# page.RequestFailed += (_, request) =>
|
40
|
-
# {
|
41
|
-
# Console.WriteLine(request.Failure);
|
42
|
-
# };
|
43
|
-
# ```
|
44
24
|
def failure
|
45
25
|
wrap_impl(@impl.failure)
|
46
26
|
end
|
@@ -76,7 +56,7 @@ module Playwright
|
|
76
56
|
end
|
77
57
|
|
78
58
|
# Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
|
79
|
-
#
|
59
|
+
#
|
80
60
|
# When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned.
|
81
61
|
# Otherwise it will be parsed as JSON.
|
82
62
|
def post_data_json
|
@@ -84,90 +64,35 @@ module Playwright
|
|
84
64
|
end
|
85
65
|
|
86
66
|
# Request that was redirected by the server to this one, if any.
|
87
|
-
#
|
67
|
+
#
|
88
68
|
# When the server responds with a redirect, Playwright creates a new `Request` object. The two requests are connected by
|
89
69
|
# `redirectedFrom()` and `redirectedTo()` methods. When multiple server redirects has happened, it is possible to
|
90
70
|
# construct the whole redirect chain by repeatedly calling `redirectedFrom()`.
|
91
|
-
#
|
71
|
+
#
|
92
72
|
# For example, if the website `http://example.com` redirects to `https://example.com`:
|
93
|
-
#
|
94
73
|
#
|
95
|
-
# ```js
|
96
|
-
# const response = await page.goto('http://example.com');
|
97
|
-
# console.log(response.request().redirectedFrom().url()); // 'http://example.com'
|
98
|
-
# ```
|
99
|
-
#
|
100
|
-
# ```java
|
101
|
-
# Response response = page.navigate("http://example.com");
|
102
|
-
# System.out.println(response.request().redirectedFrom().url()); // "http://example.com"
|
103
|
-
# ```
|
104
|
-
#
|
105
|
-
# ```python async
|
106
|
-
# response = await page.goto("http://example.com")
|
107
|
-
# print(response.request.redirected_from.url) # "http://example.com"
|
108
|
-
# ```
|
109
|
-
#
|
110
74
|
# ```python sync
|
111
75
|
# response = page.goto("http://example.com")
|
112
76
|
# print(response.request.redirected_from.url) # "http://example.com"
|
113
77
|
# ```
|
114
|
-
#
|
115
|
-
# ```csharp
|
116
|
-
# var response = await page.GotoAsync("http://www.microsoft.com");
|
117
|
-
# Console.WriteLine(response.Request.RedirectedFrom?.Url); // http://www.microsoft.com
|
118
|
-
# ```
|
119
|
-
#
|
78
|
+
#
|
120
79
|
# If the website `https://google.com` has no redirects:
|
121
|
-
#
|
122
80
|
#
|
123
|
-
# ```js
|
124
|
-
# const response = await page.goto('https://google.com');
|
125
|
-
# console.log(response.request().redirectedFrom()); // null
|
126
|
-
# ```
|
127
|
-
#
|
128
|
-
# ```java
|
129
|
-
# Response response = page.navigate("https://google.com");
|
130
|
-
# System.out.println(response.request().redirectedFrom()); // null
|
131
|
-
# ```
|
132
|
-
#
|
133
|
-
# ```python async
|
134
|
-
# response = await page.goto("https://google.com")
|
135
|
-
# print(response.request.redirected_from) # None
|
136
|
-
# ```
|
137
|
-
#
|
138
81
|
# ```python sync
|
139
82
|
# response = page.goto("https://google.com")
|
140
83
|
# print(response.request.redirected_from) # None
|
141
84
|
# ```
|
142
|
-
#
|
143
|
-
# ```csharp
|
144
|
-
# var response = await page.GotoAsync("https://www.google.com");
|
145
|
-
# Console.WriteLine(response.Request.RedirectedFrom?.Url); // null
|
146
|
-
# ```
|
147
85
|
def redirected_from
|
148
86
|
wrap_impl(@impl.redirected_from)
|
149
87
|
end
|
150
88
|
|
151
89
|
# New request issued by the browser if the server responded with redirect.
|
152
|
-
#
|
90
|
+
#
|
153
91
|
# This method is the opposite of [`method: Request.redirectedFrom`]:
|
154
|
-
#
|
155
92
|
#
|
156
|
-
# ```js
|
157
|
-
# console.log(request.redirectedFrom().redirectedTo() === request); // true
|
158
|
-
# ```
|
159
|
-
#
|
160
|
-
# ```java
|
161
|
-
# System.out.println(request.redirectedFrom().redirectedTo() == request); // true
|
162
|
-
# ```
|
163
|
-
#
|
164
93
|
# ```py
|
165
94
|
# assert request.redirected_from.redirected_to == request
|
166
95
|
# ```
|
167
|
-
#
|
168
|
-
# ```csharp
|
169
|
-
# Console.WriteLine(request.RedirectedFrom?.RedirectedTo == request); // True
|
170
|
-
# ```
|
171
96
|
def redirected_to
|
172
97
|
wrap_impl(@impl.redirected_to)
|
173
98
|
end
|
@@ -187,44 +112,13 @@ module Playwright
|
|
187
112
|
# Returns resource timing information for given request. Most of the timing values become available upon the response,
|
188
113
|
# `responseEnd` becomes available when request finishes. Find more information at
|
189
114
|
# [Resource Timing API](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming).
|
190
|
-
#
|
191
115
|
#
|
192
|
-
# ```js
|
193
|
-
# const [request] = await Promise.all([
|
194
|
-
# page.waitForEvent('requestfinished'),
|
195
|
-
# page.goto('http://example.com')
|
196
|
-
# ]);
|
197
|
-
# console.log(request.timing());
|
198
|
-
# ```
|
199
|
-
#
|
200
|
-
# ```java
|
201
|
-
# page.onRequestFinished(request -> {
|
202
|
-
# Timing timing = request.timing();
|
203
|
-
# System.out.println(timing.responseEnd - timing.startTime);
|
204
|
-
# });
|
205
|
-
# page.navigate("http://example.com");
|
206
|
-
# ```
|
207
|
-
#
|
208
|
-
# ```python async
|
209
|
-
# async with page.expect_event("requestfinished") as request_info:
|
210
|
-
# await page.goto("http://example.com")
|
211
|
-
# request = await request_info.value
|
212
|
-
# print(request.timing)
|
213
|
-
# ```
|
214
|
-
#
|
215
116
|
# ```python sync
|
216
117
|
# with page.expect_event("requestfinished") as request_info:
|
217
118
|
# page.goto("http://example.com")
|
218
119
|
# request = request_info.value
|
219
120
|
# print(request.timing)
|
220
121
|
# ```
|
221
|
-
#
|
222
|
-
# ```csharp
|
223
|
-
# var waitForEventTask = page.WaitForEventAsync(PageEvent.RequestFinished);
|
224
|
-
# await page.GotoAsync("https://www.microsoft.com");
|
225
|
-
# var request = await waitForEventTask;
|
226
|
-
# Console.WriteLine(request.Timing.ResponseEnd);
|
227
|
-
# ```
|
228
122
|
def timing
|
229
123
|
wrap_impl(@impl.timing)
|
230
124
|
end
|
@@ -234,12 +128,6 @@ module Playwright
|
|
234
128
|
wrap_impl(@impl.url)
|
235
129
|
end
|
236
130
|
|
237
|
-
# -- inherited from EventEmitter --
|
238
|
-
# @nodoc
|
239
|
-
def off(event, callback)
|
240
|
-
event_emitter_proxy.off(event, callback)
|
241
|
-
end
|
242
|
-
|
243
131
|
# -- inherited from EventEmitter --
|
244
132
|
# @nodoc
|
245
133
|
def once(event, callback)
|
@@ -252,6 +140,12 @@ module Playwright
|
|
252
140
|
event_emitter_proxy.on(event, callback)
|
253
141
|
end
|
254
142
|
|
143
|
+
# -- inherited from EventEmitter --
|
144
|
+
# @nodoc
|
145
|
+
def off(event, callback)
|
146
|
+
event_emitter_proxy.off(event, callback)
|
147
|
+
end
|
148
|
+
|
255
149
|
private def event_emitter_proxy
|
256
150
|
@event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
|
257
151
|
end
|
@@ -23,7 +23,7 @@ module Playwright
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# Returns the JSON representation of response body.
|
26
|
-
#
|
26
|
+
#
|
27
27
|
# This method will throw if the response body is not parsable via `JSON.parse`.
|
28
28
|
def json
|
29
29
|
wrap_impl(@impl.json)
|
@@ -69,12 +69,6 @@ module Playwright
|
|
69
69
|
wrap_impl(@impl.ok?)
|
70
70
|
end
|
71
71
|
|
72
|
-
# -- inherited from EventEmitter --
|
73
|
-
# @nodoc
|
74
|
-
def off(event, callback)
|
75
|
-
event_emitter_proxy.off(event, callback)
|
76
|
-
end
|
77
|
-
|
78
72
|
# -- inherited from EventEmitter --
|
79
73
|
# @nodoc
|
80
74
|
def once(event, callback)
|
@@ -87,6 +81,12 @@ module Playwright
|
|
87
81
|
event_emitter_proxy.on(event, callback)
|
88
82
|
end
|
89
83
|
|
84
|
+
# -- inherited from EventEmitter --
|
85
|
+
# @nodoc
|
86
|
+
def off(event, callback)
|
87
|
+
event_emitter_proxy.off(event, callback)
|
88
|
+
end
|
89
|
+
|
90
90
|
private def event_emitter_proxy
|
91
91
|
@event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
|
92
92
|
end
|
data/lib/playwright_api/route.rb
CHANGED
@@ -9,43 +9,7 @@ module Playwright
|
|
9
9
|
end
|
10
10
|
|
11
11
|
# Continues route's request with optional overrides.
|
12
|
-
#
|
13
12
|
#
|
14
|
-
# ```js
|
15
|
-
# await page.route('**/*', (route, request) => {
|
16
|
-
# // Override headers
|
17
|
-
# const headers = {
|
18
|
-
# ...request.headers(),
|
19
|
-
# foo: 'bar', // set "foo" header
|
20
|
-
# origin: undefined, // remove "origin" header
|
21
|
-
# };
|
22
|
-
# route.continue({headers});
|
23
|
-
# });
|
24
|
-
# ```
|
25
|
-
#
|
26
|
-
# ```java
|
27
|
-
# page.route("**/*", route -> {
|
28
|
-
# // Override headers
|
29
|
-
# Map<String, String> headers = new HashMap<>(route.request().headers());
|
30
|
-
# headers.put("foo", "bar"); // set "foo" header
|
31
|
-
# headers.remove("origin"); // remove "origin" header
|
32
|
-
# route.resume(new Route.ResumeOptions().setHeaders(headers));
|
33
|
-
# });
|
34
|
-
# ```
|
35
|
-
#
|
36
|
-
# ```python async
|
37
|
-
# async def handle(route, request):
|
38
|
-
# # override headers
|
39
|
-
# headers = {
|
40
|
-
# **request.headers,
|
41
|
-
# "foo": "bar" # set "foo" header
|
42
|
-
# "origin": None # remove "origin" header
|
43
|
-
# }
|
44
|
-
# await route.continue_(headers=headers)
|
45
|
-
# }
|
46
|
-
# await page.route("**/*", handle)
|
47
|
-
# ```
|
48
|
-
#
|
49
13
|
# ```python sync
|
50
14
|
# def handle(route, request):
|
51
15
|
# # override headers
|
@@ -58,87 +22,26 @@ module Playwright
|
|
58
22
|
# }
|
59
23
|
# page.route("**/*", handle)
|
60
24
|
# ```
|
61
|
-
#
|
62
|
-
# ```csharp
|
63
|
-
# await page.RouteAsync("**/*", route =>
|
64
|
-
# {
|
65
|
-
# var headers = new Dictionary<string, string>(route.Request.Headers) { { "foo", "bar" } };
|
66
|
-
# headers.Remove("origin");
|
67
|
-
# route.ContinueAsync(headers);
|
68
|
-
# });
|
69
|
-
# ```
|
70
25
|
def continue(headers: nil, method: nil, postData: nil, url: nil)
|
71
26
|
wrap_impl(@impl.continue(headers: unwrap_impl(headers), method: unwrap_impl(method), postData: unwrap_impl(postData), url: unwrap_impl(url)))
|
72
27
|
end
|
73
28
|
|
74
29
|
# Fulfills route's request with given response.
|
75
|
-
#
|
30
|
+
#
|
76
31
|
# An example of fulfilling all requests with 404 responses:
|
77
|
-
#
|
78
32
|
#
|
79
|
-
# ```js
|
80
|
-
# await page.route('**/*', route => {
|
81
|
-
# route.fulfill({
|
82
|
-
# status: 404,
|
83
|
-
# contentType: 'text/plain',
|
84
|
-
# body: 'Not Found!'
|
85
|
-
# });
|
86
|
-
# });
|
87
|
-
# ```
|
88
|
-
#
|
89
|
-
# ```java
|
90
|
-
# page.route("**/*", route -> {
|
91
|
-
# route.fulfill(new Route.FulfillOptions()
|
92
|
-
# .setStatus(404)
|
93
|
-
# .setContentType("text/plain")
|
94
|
-
# .setBody("Not Found!"));
|
95
|
-
# });
|
96
|
-
# ```
|
97
|
-
#
|
98
|
-
# ```python async
|
99
|
-
# await page.route("**/*", lambda route: route.fulfill(
|
100
|
-
# status=404,
|
101
|
-
# content_type="text/plain",
|
102
|
-
# body="not found!"))
|
103
|
-
# ```
|
104
|
-
#
|
105
33
|
# ```python sync
|
106
34
|
# page.route("**/*", lambda route: route.fulfill(
|
107
35
|
# status=404,
|
108
36
|
# content_type="text/plain",
|
109
37
|
# body="not found!"))
|
110
38
|
# ```
|
111
|
-
#
|
112
|
-
# ```csharp
|
113
|
-
# await page.RouteAsync("**/*", route => route.FulfillAsync(
|
114
|
-
# status: 404,
|
115
|
-
# contentType: "text/plain",
|
116
|
-
# body: "Not Found!"));
|
117
|
-
# ```
|
118
|
-
#
|
39
|
+
#
|
119
40
|
# An example of serving static file:
|
120
|
-
#
|
121
41
|
#
|
122
|
-
# ```js
|
123
|
-
# await page.route('**/xhr_endpoint', route => route.fulfill({ path: 'mock_data.json' }));
|
124
|
-
# ```
|
125
|
-
#
|
126
|
-
# ```java
|
127
|
-
# page.route("**/xhr_endpoint", route -> route.fulfill(
|
128
|
-
# new Route.FulfillOptions().setPath(Paths.get("mock_data.json")));
|
129
|
-
# ```
|
130
|
-
#
|
131
|
-
# ```python async
|
132
|
-
# await page.route("**/xhr_endpoint", lambda route: route.fulfill(path="mock_data.json"))
|
133
|
-
# ```
|
134
|
-
#
|
135
42
|
# ```python sync
|
136
43
|
# page.route("**/xhr_endpoint", lambda route: route.fulfill(path="mock_data.json"))
|
137
44
|
# ```
|
138
|
-
#
|
139
|
-
# ```csharp
|
140
|
-
# await page.RouteAsync("**/xhr_endpoint", route => route.FulfillAsync(path: "mock_data.json"));
|
141
|
-
# ```
|
142
45
|
def fulfill(
|
143
46
|
body: nil,
|
144
47
|
contentType: nil,
|
@@ -153,12 +56,6 @@ module Playwright
|
|
153
56
|
wrap_impl(@impl.request)
|
154
57
|
end
|
155
58
|
|
156
|
-
# -- inherited from EventEmitter --
|
157
|
-
# @nodoc
|
158
|
-
def off(event, callback)
|
159
|
-
event_emitter_proxy.off(event, callback)
|
160
|
-
end
|
161
|
-
|
162
59
|
# -- inherited from EventEmitter --
|
163
60
|
# @nodoc
|
164
61
|
def once(event, callback)
|
@@ -171,6 +68,12 @@ module Playwright
|
|
171
68
|
event_emitter_proxy.on(event, callback)
|
172
69
|
end
|
173
70
|
|
71
|
+
# -- inherited from EventEmitter --
|
72
|
+
# @nodoc
|
73
|
+
def off(event, callback)
|
74
|
+
event_emitter_proxy.off(event, callback)
|
75
|
+
end
|
76
|
+
|
174
77
|
private def event_emitter_proxy
|
175
78
|
@event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
|
176
79
|
end
|