playwright-ruby-client 0.0.3 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +119 -12
- data/docs/api_coverage.md +354 -0
- data/lib/playwright.rb +8 -0
- data/lib/playwright/channel_owner.rb +16 -2
- data/lib/playwright/channel_owners/android.rb +10 -1
- data/lib/playwright/channel_owners/android_device.rb +163 -0
- data/lib/playwright/channel_owners/browser.rb +22 -29
- data/lib/playwright/channel_owners/browser_context.rb +43 -0
- data/lib/playwright/channel_owners/console_message.rb +21 -0
- data/lib/playwright/channel_owners/element_handle.rb +314 -0
- data/lib/playwright/channel_owners/frame.rb +466 -7
- data/lib/playwright/channel_owners/js_handle.rb +55 -0
- data/lib/playwright/channel_owners/page.rb +353 -5
- data/lib/playwright/channel_owners/request.rb +90 -0
- data/lib/playwright/channel_owners/webkit_browser.rb +1 -1
- data/lib/playwright/connection.rb +15 -14
- data/lib/playwright/errors.rb +1 -1
- data/lib/playwright/event_emitter.rb +13 -0
- data/lib/playwright/input_files.rb +42 -0
- data/lib/playwright/input_type.rb +19 -0
- data/lib/playwright/input_types/android_input.rb +19 -0
- data/lib/playwright/input_types/keyboard.rb +32 -0
- data/lib/playwright/input_types/mouse.rb +4 -0
- data/lib/playwright/input_types/touchscreen.rb +4 -0
- data/lib/playwright/javascript.rb +13 -0
- data/lib/playwright/javascript/expression.rb +67 -0
- data/lib/playwright/javascript/function.rb +67 -0
- data/lib/playwright/javascript/value_parser.rb +75 -0
- data/lib/playwright/javascript/value_serializer.rb +54 -0
- data/lib/playwright/playwright_api.rb +45 -25
- data/lib/playwright/select_option_values.rb +32 -0
- data/lib/playwright/timeout_settings.rb +19 -0
- data/lib/playwright/url_matcher.rb +19 -0
- data/lib/playwright/utils.rb +37 -0
- data/lib/playwright/version.rb +1 -1
- data/lib/playwright/wait_helper.rb +73 -0
- data/lib/playwright_api/accessibility.rb +60 -6
- data/lib/playwright_api/android.rb +33 -0
- data/lib/playwright_api/android_device.rb +78 -0
- data/lib/playwright_api/android_input.rb +25 -0
- data/lib/playwright_api/binding_call.rb +18 -0
- data/lib/playwright_api/browser.rb +136 -44
- data/lib/playwright_api/browser_context.rb +378 -51
- data/lib/playwright_api/browser_type.rb +137 -55
- data/lib/playwright_api/cdp_session.rb +32 -7
- data/lib/playwright_api/chromium_browser_context.rb +31 -0
- data/lib/playwright_api/console_message.rb +27 -7
- data/lib/playwright_api/dialog.rb +47 -3
- data/lib/playwright_api/download.rb +29 -5
- data/lib/playwright_api/element_handle.rb +429 -143
- data/lib/playwright_api/file_chooser.rb +13 -2
- data/lib/playwright_api/frame.rb +633 -179
- data/lib/playwright_api/js_handle.rb +97 -17
- data/lib/playwright_api/keyboard.rb +152 -24
- data/lib/playwright_api/mouse.rb +28 -3
- data/lib/playwright_api/page.rb +1183 -317
- data/lib/playwright_api/playwright.rb +174 -13
- data/lib/playwright_api/request.rb +115 -30
- data/lib/playwright_api/response.rb +22 -3
- data/lib/playwright_api/route.rb +63 -4
- data/lib/playwright_api/selectors.rb +29 -7
- data/lib/playwright_api/touchscreen.rb +2 -1
- data/lib/playwright_api/video.rb +11 -1
- data/lib/playwright_api/web_socket.rb +5 -5
- data/lib/playwright_api/worker.rb +29 -5
- data/playwright.gemspec +3 -0
- metadata +68 -2
@@ -1,5 +1,7 @@
|
|
1
1
|
module Playwright
|
2
|
-
# BrowserType provides methods to launch a specific browser instance or connect to an existing one. The following is a
|
2
|
+
# BrowserType provides methods to launch a specific browser instance or connect to an existing one. The following is a
|
3
|
+
# typical example of using Playwright to drive automation:
|
4
|
+
#
|
3
5
|
#
|
4
6
|
# ```js
|
5
7
|
# const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
|
@@ -12,6 +14,39 @@ module Playwright
|
|
12
14
|
# await browser.close();
|
13
15
|
# })();
|
14
16
|
# ```
|
17
|
+
#
|
18
|
+
# ```python async
|
19
|
+
# import asyncio
|
20
|
+
# from playwright.async_api import async_playwright
|
21
|
+
#
|
22
|
+
# async def run(playwright):
|
23
|
+
# chromium = playwright.chromium
|
24
|
+
# browser = await chromium.launch()
|
25
|
+
# page = await browser.new_page()
|
26
|
+
# await page.goto("https://example.com")
|
27
|
+
# # other actions...
|
28
|
+
# await browser.close()
|
29
|
+
#
|
30
|
+
# async def main():
|
31
|
+
# async with async_playwright() as playwright:
|
32
|
+
# await run(playwright)
|
33
|
+
# asyncio.run(main())
|
34
|
+
# ```
|
35
|
+
#
|
36
|
+
# ```python sync
|
37
|
+
# from playwright.sync_api import sync_playwright
|
38
|
+
#
|
39
|
+
# def run(playwright):
|
40
|
+
# chromium = playwright.chromium
|
41
|
+
# browser = chromium.launch()
|
42
|
+
# page = browser.new_page()
|
43
|
+
# page.goto("https://example.com")
|
44
|
+
# # other actions...
|
45
|
+
# browser.close()
|
46
|
+
#
|
47
|
+
# with sync_playwright() as playwright:
|
48
|
+
# run(playwright)
|
49
|
+
# ```
|
15
50
|
class BrowserType < PlaywrightApi
|
16
51
|
|
17
52
|
# This methods attaches Playwright to an existing browser instance.
|
@@ -21,11 +56,13 @@ module Playwright
|
|
21
56
|
|
22
57
|
# A path where Playwright expects to find a bundled browser executable.
|
23
58
|
def executable_path
|
24
|
-
|
59
|
+
wrap_impl(@impl.executable_path)
|
25
60
|
end
|
26
61
|
|
27
62
|
# Returns the browser instance.
|
63
|
+
#
|
28
64
|
# You can use `ignoreDefaultArgs` to filter out `--mute-audio` from default arguments:
|
65
|
+
#
|
29
66
|
#
|
30
67
|
# ```js
|
31
68
|
# const browser = await chromium.launch({ // Or 'firefox' or 'webkit'.
|
@@ -33,76 +70,103 @@ module Playwright
|
|
33
70
|
# });
|
34
71
|
# ```
|
35
72
|
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
73
|
+
# ```python async
|
74
|
+
# browser = await playwright.chromium.launch( # or "firefox" or "webkit".
|
75
|
+
# ignore_default_args=["--mute-audio"]
|
76
|
+
# )
|
77
|
+
# ```
|
78
|
+
#
|
79
|
+
# ```python sync
|
80
|
+
# browser = playwright.chromium.launch( # or "firefox" or "webkit".
|
81
|
+
# ignore_default_args=["--mute-audio"]
|
82
|
+
# )
|
83
|
+
# ```
|
84
|
+
#
|
85
|
+
# > **Chromium-only** Playwright can also be used to control the Chrome browser, but it works best with the version of
|
86
|
+
# Chromium it is bundled with. There is no guarantee it will work with any other version. Use `executablePath` option with
|
87
|
+
# extreme caution.
|
88
|
+
# >
|
89
|
+
# > If Google Chrome (rather than Chromium) is preferred, a
|
90
|
+
# [Chrome Canary](https://www.google.com/chrome/browser/canary.html) or
|
91
|
+
# [Dev Channel](https://www.chromium.org/getting-involved/dev-channel) build is suggested.
|
92
|
+
# >
|
93
|
+
# > In [`method: BrowserType.launch`] above, any mention of Chromium also applies to Chrome.
|
94
|
+
# >
|
95
|
+
# > See [`this article`](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for
|
96
|
+
# a description of the differences between Chromium and Chrome.
|
97
|
+
# [`This article`](https://chromium.googlesource.com/chromium/src/+/lkgr/docs/chromium_browser_vs_google_chrome.md)
|
98
|
+
# describes some differences for Linux users.
|
40
99
|
def launch(
|
41
|
-
headless: nil,
|
42
|
-
executablePath: nil,
|
43
100
|
args: nil,
|
44
|
-
ignoreDefaultArgs: nil,
|
45
|
-
proxy: nil,
|
46
|
-
downloadsPath: nil,
|
47
101
|
chromiumSandbox: nil,
|
102
|
+
devtools: nil,
|
103
|
+
downloadsPath: nil,
|
104
|
+
env: nil,
|
105
|
+
executablePath: nil,
|
48
106
|
firefoxUserPrefs: nil,
|
107
|
+
handleSIGHUP: nil,
|
49
108
|
handleSIGINT: nil,
|
50
109
|
handleSIGTERM: nil,
|
51
|
-
|
110
|
+
headless: nil,
|
111
|
+
ignoreDefaultArgs: nil,
|
52
112
|
logger: nil,
|
53
|
-
|
54
|
-
env: nil,
|
55
|
-
devtools: nil,
|
113
|
+
proxy: nil,
|
56
114
|
slowMo: nil,
|
115
|
+
timeout: nil,
|
57
116
|
&block)
|
58
|
-
|
117
|
+
wrap_impl(@impl.launch(args: unwrap_impl(args), chromiumSandbox: unwrap_impl(chromiumSandbox), devtools: unwrap_impl(devtools), downloadsPath: unwrap_impl(downloadsPath), env: unwrap_impl(env), executablePath: unwrap_impl(executablePath), firefoxUserPrefs: unwrap_impl(firefoxUserPrefs), handleSIGHUP: unwrap_impl(handleSIGHUP), handleSIGINT: unwrap_impl(handleSIGINT), handleSIGTERM: unwrap_impl(handleSIGTERM), headless: unwrap_impl(headless), ignoreDefaultArgs: unwrap_impl(ignoreDefaultArgs), logger: unwrap_impl(logger), proxy: unwrap_impl(proxy), slowMo: unwrap_impl(slowMo), timeout: unwrap_impl(timeout), &wrap_block_call(block)))
|
59
118
|
end
|
60
119
|
|
61
120
|
# Returns the persistent browser context instance.
|
62
|
-
#
|
121
|
+
#
|
122
|
+
# Launches browser that uses persistent storage located at `userDataDir` and returns the only context. Closing this
|
123
|
+
# context will automatically close the browser.
|
63
124
|
def launch_persistent_context(
|
64
125
|
userDataDir,
|
65
|
-
|
66
|
-
executablePath: nil,
|
126
|
+
acceptDownloads: nil,
|
67
127
|
args: nil,
|
68
|
-
|
69
|
-
proxy: nil,
|
70
|
-
downloadsPath: nil,
|
128
|
+
bypassCSP: nil,
|
71
129
|
chromiumSandbox: nil,
|
130
|
+
colorScheme: nil,
|
131
|
+
deviceScaleFactor: nil,
|
132
|
+
devtools: nil,
|
133
|
+
downloadsPath: nil,
|
134
|
+
env: nil,
|
135
|
+
executablePath: nil,
|
136
|
+
extraHTTPHeaders: nil,
|
137
|
+
geolocation: nil,
|
138
|
+
handleSIGHUP: nil,
|
72
139
|
handleSIGINT: nil,
|
73
140
|
handleSIGTERM: nil,
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
slowMo: nil,
|
79
|
-
acceptDownloads: nil,
|
141
|
+
hasTouch: nil,
|
142
|
+
headless: nil,
|
143
|
+
httpCredentials: nil,
|
144
|
+
ignoreDefaultArgs: nil,
|
80
145
|
ignoreHTTPSErrors: nil,
|
81
|
-
bypassCSP: nil,
|
82
|
-
viewport: nil,
|
83
|
-
userAgent: nil,
|
84
|
-
deviceScaleFactor: nil,
|
85
146
|
isMobile: nil,
|
86
|
-
hasTouch: nil,
|
87
147
|
javaScriptEnabled: nil,
|
88
|
-
timezoneId: nil,
|
89
|
-
geolocation: nil,
|
90
148
|
locale: nil,
|
91
|
-
permissions: nil,
|
92
|
-
extraHTTPHeaders: nil,
|
93
|
-
offline: nil,
|
94
|
-
httpCredentials: nil,
|
95
|
-
colorScheme: nil,
|
96
149
|
logger: nil,
|
97
|
-
|
98
|
-
|
150
|
+
offline: nil,
|
151
|
+
permissions: nil,
|
152
|
+
proxy: nil,
|
99
153
|
recordHar: nil,
|
100
|
-
recordVideo: nil
|
154
|
+
recordVideo: nil,
|
155
|
+
slowMo: nil,
|
156
|
+
timeout: nil,
|
157
|
+
timezoneId: nil,
|
158
|
+
userAgent: nil,
|
159
|
+
videoSize: nil,
|
160
|
+
videosPath: nil,
|
161
|
+
viewport: nil)
|
101
162
|
raise NotImplementedError.new('launch_persistent_context is not implemented yet.')
|
102
163
|
end
|
103
164
|
|
104
165
|
# Returns the browser app instance.
|
105
|
-
#
|
166
|
+
#
|
167
|
+
# Launches browser server that client can connect to. An example of launching a browser executable and connecting to it
|
168
|
+
# later:
|
169
|
+
#
|
106
170
|
#
|
107
171
|
# ```js
|
108
172
|
# const { chromium } = require('playwright'); // Or 'webkit' or 'firefox'.
|
@@ -117,28 +181,46 @@ module Playwright
|
|
117
181
|
# })();
|
118
182
|
# ```
|
119
183
|
def launch_server(
|
120
|
-
headless: nil,
|
121
|
-
port: nil,
|
122
|
-
executablePath: nil,
|
123
184
|
args: nil,
|
124
|
-
ignoreDefaultArgs: nil,
|
125
|
-
proxy: nil,
|
126
|
-
downloadsPath: nil,
|
127
185
|
chromiumSandbox: nil,
|
186
|
+
devtools: nil,
|
187
|
+
downloadsPath: nil,
|
188
|
+
env: nil,
|
189
|
+
executablePath: nil,
|
128
190
|
firefoxUserPrefs: nil,
|
191
|
+
handleSIGHUP: nil,
|
129
192
|
handleSIGINT: nil,
|
130
193
|
handleSIGTERM: nil,
|
131
|
-
|
194
|
+
headless: nil,
|
195
|
+
ignoreDefaultArgs: nil,
|
132
196
|
logger: nil,
|
133
|
-
|
134
|
-
|
135
|
-
|
197
|
+
port: nil,
|
198
|
+
proxy: nil,
|
199
|
+
timeout: nil)
|
136
200
|
raise NotImplementedError.new('launch_server is not implemented yet.')
|
137
201
|
end
|
138
202
|
|
139
203
|
# Returns browser name. For example: `'chromium'`, `'webkit'` or `'firefox'`.
|
140
204
|
def name
|
141
|
-
|
205
|
+
wrap_impl(@impl.name)
|
206
|
+
end
|
207
|
+
|
208
|
+
# -- inherited from EventEmitter --
|
209
|
+
# @nodoc
|
210
|
+
def on(event, callback)
|
211
|
+
wrap_impl(@impl.on(unwrap_impl(event), unwrap_impl(callback)))
|
212
|
+
end
|
213
|
+
|
214
|
+
# -- inherited from EventEmitter --
|
215
|
+
# @nodoc
|
216
|
+
def off(event, callback)
|
217
|
+
wrap_impl(@impl.off(unwrap_impl(event), unwrap_impl(callback)))
|
218
|
+
end
|
219
|
+
|
220
|
+
# -- inherited from EventEmitter --
|
221
|
+
# @nodoc
|
222
|
+
def once(event, callback)
|
223
|
+
wrap_impl(@impl.once(unwrap_impl(event), unwrap_impl(callback)))
|
142
224
|
end
|
143
225
|
end
|
144
226
|
end
|
@@ -1,13 +1,15 @@
|
|
1
1
|
module Playwright
|
2
|
-
#
|
2
|
+
# - extends: [EventEmitter]
|
3
3
|
#
|
4
|
-
#
|
5
|
-
# protocol
|
4
|
+
# The `CDPSession` instances are used to talk raw Chrome Devtools Protocol:
|
5
|
+
# - protocol methods can be called with `session.send` method.
|
6
|
+
# - protocol events can be subscribed to with `session.on` method.
|
6
7
|
#
|
7
8
|
# Useful links:
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# Getting Started with DevTools Protocol:
|
9
|
+
# - Documentation on DevTools Protocol can be found here:
|
10
|
+
# [DevTools Protocol Viewer](https://chromedevtools.github.io/devtools-protocol/).
|
11
|
+
# - Getting Started with DevTools Protocol:
|
12
|
+
# https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md
|
11
13
|
#
|
12
14
|
#
|
13
15
|
# ```js
|
@@ -20,9 +22,32 @@ module Playwright
|
|
20
22
|
# playbackRate: response.playbackRate / 2
|
21
23
|
# });
|
22
24
|
# ```
|
25
|
+
#
|
26
|
+
# ```python async
|
27
|
+
# client = await page.context().new_cdp_session(page)
|
28
|
+
# await client.send("animation.enable")
|
29
|
+
# client.on("animation.animation_created", lambda: print("animation created!"))
|
30
|
+
# response = await client.send("animation.get_playback_rate")
|
31
|
+
# print("playback rate is " + response["playback_rate"])
|
32
|
+
# await client.send("animation.set_playback_rate", {
|
33
|
+
# playback_rate: response["playback_rate"] / 2
|
34
|
+
# })
|
35
|
+
# ```
|
36
|
+
#
|
37
|
+
# ```python sync
|
38
|
+
# client = page.context().new_cdp_session(page)
|
39
|
+
# client.send("animation.enable")
|
40
|
+
# client.on("animation.animation_created", lambda: print("animation created!"))
|
41
|
+
# response = client.send("animation.get_playback_rate")
|
42
|
+
# print("playback rate is " + response["playback_rate"])
|
43
|
+
# client.send("animation.set_playback_rate", {
|
44
|
+
# playback_rate: response["playback_rate"] / 2
|
45
|
+
# })
|
46
|
+
# ```
|
23
47
|
class CDPSession < PlaywrightApi
|
24
48
|
|
25
|
-
# Detaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be used to
|
49
|
+
# Detaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be used to
|
50
|
+
# send messages.
|
26
51
|
def detach
|
27
52
|
raise NotImplementedError.new('detach is not implemented yet.')
|
28
53
|
end
|
@@ -1,11 +1,24 @@
|
|
1
1
|
require_relative './browser_context.rb'
|
2
2
|
|
3
3
|
module Playwright
|
4
|
+
# - extends: `BrowserContext`
|
5
|
+
#
|
4
6
|
# Chromium-specific features including background pages, service worker support, etc.
|
7
|
+
#
|
5
8
|
#
|
6
9
|
# ```js
|
7
10
|
# const backgroundPage = await context.waitForEvent('backgroundpage');
|
8
11
|
# ```
|
12
|
+
#
|
13
|
+
# ```python async
|
14
|
+
# # FIXME
|
15
|
+
# background_page = await context.wait_for_event("backgroundpage")
|
16
|
+
# ```
|
17
|
+
#
|
18
|
+
# ```python sync
|
19
|
+
# # FIXME
|
20
|
+
# background_page = context.wait_for_event("backgroundpage")
|
21
|
+
# ```
|
9
22
|
class ChromiumBrowserContext < BrowserContext
|
10
23
|
|
11
24
|
# All existing background pages in the context.
|
@@ -22,5 +35,23 @@ module Playwright
|
|
22
35
|
def service_workers
|
23
36
|
raise NotImplementedError.new('service_workers is not implemented yet.')
|
24
37
|
end
|
38
|
+
|
39
|
+
# -- inherited from EventEmitter --
|
40
|
+
# @nodoc
|
41
|
+
def on(event, callback)
|
42
|
+
wrap_impl(@impl.on(unwrap_impl(event), unwrap_impl(callback)))
|
43
|
+
end
|
44
|
+
|
45
|
+
# -- inherited from EventEmitter --
|
46
|
+
# @nodoc
|
47
|
+
def off(event, callback)
|
48
|
+
wrap_impl(@impl.off(unwrap_impl(event), unwrap_impl(callback)))
|
49
|
+
end
|
50
|
+
|
51
|
+
# -- inherited from EventEmitter --
|
52
|
+
# @nodoc
|
53
|
+
def once(event, callback)
|
54
|
+
wrap_impl(@impl.once(unwrap_impl(event), unwrap_impl(callback)))
|
55
|
+
end
|
25
56
|
end
|
26
57
|
end
|
@@ -1,22 +1,42 @@
|
|
1
1
|
module Playwright
|
2
|
-
# ConsoleMessage objects are dispatched by page via the
|
2
|
+
# `ConsoleMessage` objects are dispatched by page via the [`event: Page.console`] event.
|
3
3
|
class ConsoleMessage < PlaywrightApi
|
4
4
|
|
5
5
|
def args
|
6
|
-
|
6
|
+
wrap_impl(@impl.args)
|
7
7
|
end
|
8
8
|
|
9
9
|
def location
|
10
|
-
|
10
|
+
wrap_impl(@impl.location)
|
11
11
|
end
|
12
12
|
|
13
13
|
def text
|
14
|
-
|
14
|
+
wrap_impl(@impl.text)
|
15
15
|
end
|
16
16
|
|
17
|
-
# One of the following values: `'log'`, `'debug'`, `'info'`, `'error'`, `'warning'`, `'dir'`, `'dirxml'`, `'table'`,
|
18
|
-
|
19
|
-
|
17
|
+
# One of the following values: `'log'`, `'debug'`, `'info'`, `'error'`, `'warning'`, `'dir'`, `'dirxml'`, `'table'`,
|
18
|
+
# `'trace'`, `'clear'`, `'startGroup'`, `'startGroupCollapsed'`, `'endGroup'`, `'assert'`, `'profile'`, `'profileEnd'`,
|
19
|
+
# `'count'`, `'timeEnd'`.
|
20
|
+
def type
|
21
|
+
wrap_impl(@impl.type)
|
22
|
+
end
|
23
|
+
|
24
|
+
# -- inherited from EventEmitter --
|
25
|
+
# @nodoc
|
26
|
+
def on(event, callback)
|
27
|
+
wrap_impl(@impl.on(unwrap_impl(event), unwrap_impl(callback)))
|
28
|
+
end
|
29
|
+
|
30
|
+
# -- inherited from EventEmitter --
|
31
|
+
# @nodoc
|
32
|
+
def off(event, callback)
|
33
|
+
wrap_impl(@impl.off(unwrap_impl(event), unwrap_impl(callback)))
|
34
|
+
end
|
35
|
+
|
36
|
+
# -- inherited from EventEmitter --
|
37
|
+
# @nodoc
|
38
|
+
def once(event, callback)
|
39
|
+
wrap_impl(@impl.once(unwrap_impl(event), unwrap_impl(callback)))
|
20
40
|
end
|
21
41
|
end
|
22
42
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Playwright
|
2
|
-
# Dialog objects are dispatched by page via the
|
2
|
+
# `Dialog` objects are dispatched by page via the [`event: Page.dialog`] event.
|
3
|
+
#
|
3
4
|
# An example of using `Dialog` class:
|
5
|
+
#
|
4
6
|
#
|
5
7
|
# ```js
|
6
8
|
# const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
|
@@ -16,6 +18,48 @@ module Playwright
|
|
16
18
|
# page.evaluate(() => alert('1'));
|
17
19
|
# })();
|
18
20
|
# ```
|
21
|
+
#
|
22
|
+
# ```python async
|
23
|
+
# import asyncio
|
24
|
+
# from playwright.async_api import async_playwright
|
25
|
+
#
|
26
|
+
# async def handle_dialog(dialog):
|
27
|
+
# print(dialog.message)
|
28
|
+
# await dialog.dismiss()
|
29
|
+
#
|
30
|
+
# async def run(playwright):
|
31
|
+
# chromium = playwright.chromium
|
32
|
+
# browser = await chromium.launch()
|
33
|
+
# page = await browser.new_page()
|
34
|
+
# page.on("dialog", handle_dialog)
|
35
|
+
# page.evaluate("alert('1')")
|
36
|
+
# await browser.close()
|
37
|
+
#
|
38
|
+
# async def main():
|
39
|
+
# async with async_playwright() as playwright:
|
40
|
+
# await run(playwright)
|
41
|
+
# asyncio.run(main())
|
42
|
+
# ```
|
43
|
+
#
|
44
|
+
# ```python sync
|
45
|
+
# # FIXME
|
46
|
+
# from playwright.sync_api import sync_playwright
|
47
|
+
#
|
48
|
+
# def handle_dialog(dialog):
|
49
|
+
# print(dialog.message)
|
50
|
+
# dialog.dismiss()
|
51
|
+
#
|
52
|
+
# def run(playwright):
|
53
|
+
# chromium = playwright.chromium
|
54
|
+
# browser = chromium.launch()
|
55
|
+
# page = browser.new_page()
|
56
|
+
# page.on("dialog", handle_dialog)
|
57
|
+
# page.evaluate("alert('1')")
|
58
|
+
# browser.close()
|
59
|
+
#
|
60
|
+
# with sync_playwright() as playwright:
|
61
|
+
# run(playwright)
|
62
|
+
# ```
|
19
63
|
class Dialog < PlaywrightApi
|
20
64
|
|
21
65
|
# Returns when the dialog has been accepted.
|
@@ -39,8 +83,8 @@ module Playwright
|
|
39
83
|
end
|
40
84
|
|
41
85
|
# Returns dialog's type, can be one of `alert`, `beforeunload`, `confirm` or `prompt`.
|
42
|
-
def
|
43
|
-
raise NotImplementedError.new('
|
86
|
+
def type
|
87
|
+
raise NotImplementedError.new('type is not implemented yet.')
|
44
88
|
end
|
45
89
|
end
|
46
90
|
end
|