playwright-ruby-client 0.0.8 → 1.58.1.alpha1
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/AGENTS.md +4 -0
- data/CLAUDE/api_generation.md +28 -0
- data/CLAUDE/ci_expectations.md +23 -0
- data/CLAUDE/gem_release_flow.md +39 -0
- data/CLAUDE/past_upgrade_pr_patterns.md +42 -0
- data/CLAUDE/playwright_upgrade_workflow.md +35 -0
- data/CLAUDE/rspec_debugging.md +30 -0
- data/CLAUDE/unimplemented_examples.md +18 -0
- data/CLAUDE.md +32 -0
- data/CONTRIBUTING.md +5 -0
- data/README.md +60 -16
- data/documentation/README.md +33 -0
- data/documentation/babel.config.js +3 -0
- data/documentation/docs/api/api_request.md +7 -0
- data/documentation/docs/api/api_request_context.md +298 -0
- data/documentation/docs/api/api_response.md +114 -0
- data/documentation/docs/api/browser.md +237 -0
- data/documentation/docs/api/browser_context.md +503 -0
- data/documentation/docs/api/browser_type.md +184 -0
- data/documentation/docs/api/cdp_session.md +44 -0
- data/documentation/docs/api/clock.md +154 -0
- data/documentation/docs/api/console_message.md +85 -0
- data/documentation/docs/api/dialog.md +84 -0
- data/documentation/docs/api/download.md +111 -0
- data/documentation/docs/api/element_handle.md +694 -0
- data/documentation/docs/api/experimental/_category_.yml +3 -0
- data/documentation/docs/api/experimental/android.md +42 -0
- data/documentation/docs/api/experimental/android_device.md +109 -0
- data/documentation/docs/api/experimental/android_input.md +43 -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 +53 -0
- data/documentation/docs/api/frame.md +1218 -0
- data/documentation/docs/api/frame_locator.md +348 -0
- data/documentation/docs/api/js_handle.md +121 -0
- data/documentation/docs/api/keyboard.md +170 -0
- data/documentation/docs/api/locator.md +1495 -0
- data/documentation/docs/api/locator_assertions.md +827 -0
- data/documentation/docs/api/mouse.md +86 -0
- data/documentation/docs/api/page.md +1946 -0
- data/documentation/docs/api/page_assertions.md +65 -0
- data/documentation/docs/api/playwright.md +66 -0
- data/documentation/docs/api/request.md +255 -0
- data/documentation/docs/api/response.md +176 -0
- data/documentation/docs/api/route.md +205 -0
- data/documentation/docs/api/selectors.md +63 -0
- data/documentation/docs/api/touchscreen.md +22 -0
- data/documentation/docs/api/tracing.md +129 -0
- data/documentation/docs/api/web_socket.md +51 -0
- data/documentation/docs/api/worker.md +83 -0
- data/documentation/docs/article/api_coverage.mdx +11 -0
- data/documentation/docs/article/getting_started.md +161 -0
- data/documentation/docs/article/guides/_category_.yml +3 -0
- data/documentation/docs/article/guides/download_playwright_driver.md +55 -0
- data/documentation/docs/article/guides/inspector.md +31 -0
- data/documentation/docs/article/guides/launch_browser.md +121 -0
- data/documentation/docs/article/guides/playwright_on_alpine_linux.md +112 -0
- data/documentation/docs/article/guides/rails_integration.md +278 -0
- data/documentation/docs/article/guides/rails_integration_with_null_driver.md +145 -0
- data/documentation/docs/article/guides/recording_video.md +79 -0
- data/documentation/docs/article/guides/rspec_integration.md +59 -0
- data/documentation/docs/article/guides/semi_automation.md +71 -0
- data/documentation/docs/article/guides/use_storage_state.md +78 -0
- data/documentation/docs/include/api_coverage.md +671 -0
- data/documentation/docusaurus.config.js +114 -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 +49 -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/playwright-ruby-client.png +0 -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 +9005 -0
- data/lib/playwright/{input_types/android_input.rb → android_input_impl.rb} +5 -1
- data/lib/playwright/api_implementation.rb +18 -0
- data/lib/playwright/api_response_impl.rb +77 -0
- data/lib/playwright/channel.rb +62 -1
- data/lib/playwright/channel_owner.rb +70 -7
- data/lib/playwright/channel_owners/android.rb +16 -3
- data/lib/playwright/channel_owners/android_device.rb +22 -66
- data/lib/playwright/channel_owners/api_request_context.rb +247 -0
- data/lib/playwright/channel_owners/artifact.rb +40 -0
- data/lib/playwright/channel_owners/binding_call.rb +70 -0
- data/lib/playwright/channel_owners/browser.rb +114 -22
- data/lib/playwright/channel_owners/browser_context.rb +589 -15
- data/lib/playwright/channel_owners/browser_type.rb +90 -1
- data/lib/playwright/channel_owners/cdp_session.rb +19 -0
- data/lib/playwright/channel_owners/dialog.rb +32 -0
- data/lib/playwright/channel_owners/element_handle.rb +107 -43
- data/lib/playwright/channel_owners/fetch_request.rb +8 -0
- data/lib/playwright/channel_owners/frame.rb +334 -104
- data/lib/playwright/channel_owners/js_handle.rb +9 -13
- data/lib/playwright/channel_owners/local_utils.rb +82 -0
- data/lib/playwright/channel_owners/page.rb +778 -95
- data/lib/playwright/channel_owners/playwright.rb +25 -30
- data/lib/playwright/channel_owners/request.rb +120 -18
- data/lib/playwright/channel_owners/response.rb +113 -0
- data/lib/playwright/channel_owners/route.rb +181 -0
- data/lib/playwright/channel_owners/stream.rb +30 -0
- data/lib/playwright/channel_owners/tracing.rb +117 -0
- data/lib/playwright/channel_owners/web_socket.rb +96 -0
- data/lib/playwright/channel_owners/worker.rb +46 -0
- data/lib/playwright/channel_owners/writable_stream.rb +14 -0
- data/lib/playwright/clock_impl.rb +67 -0
- data/lib/playwright/connection.rb +111 -63
- data/lib/playwright/console_message_impl.rb +29 -0
- data/lib/playwright/download_impl.rb +32 -0
- data/lib/playwright/errors.rb +42 -5
- data/lib/playwright/event_emitter.rb +17 -3
- data/lib/playwright/event_emitter_proxy.rb +49 -0
- data/lib/playwright/events.rb +10 -5
- data/lib/playwright/file_chooser_impl.rb +24 -0
- data/lib/playwright/frame_locator_impl.rb +66 -0
- data/lib/playwright/har_router.rb +89 -0
- data/lib/playwright/http_headers.rb +14 -0
- data/lib/playwright/input_files.rb +102 -15
- data/lib/playwright/javascript/expression.rb +7 -11
- data/lib/playwright/javascript/regex.rb +23 -0
- data/lib/playwright/javascript/source_url.rb +16 -0
- data/lib/playwright/javascript/value_parser.rb +108 -19
- data/lib/playwright/javascript/value_serializer.rb +47 -8
- data/lib/playwright/javascript/visitor_info.rb +26 -0
- data/lib/playwright/javascript.rb +2 -10
- data/lib/playwright/{input_types/keyboard.rb → keyboard_impl.rb} +6 -2
- data/lib/playwright/locator_assertions_impl.rb +571 -0
- data/lib/playwright/locator_impl.rb +544 -0
- data/lib/playwright/locator_utils.rb +136 -0
- data/lib/playwright/mouse_impl.rb +57 -0
- data/lib/playwright/page_assertions_impl.rb +154 -0
- data/lib/playwright/playwright_api.rb +102 -30
- data/lib/playwright/raw_headers.rb +61 -0
- data/lib/playwright/route_handler.rb +78 -0
- data/lib/playwright/select_option_values.rb +34 -13
- data/lib/playwright/selectors_impl.rb +45 -0
- data/lib/playwright/test.rb +102 -0
- data/lib/playwright/timeout_settings.rb +9 -4
- data/lib/playwright/touchscreen_impl.rb +14 -0
- data/lib/playwright/transport.rb +61 -10
- data/lib/playwright/url_matcher.rb +24 -2
- data/lib/playwright/utils.rb +48 -13
- data/lib/playwright/version.rb +2 -1
- data/lib/playwright/video.rb +54 -0
- data/lib/playwright/waiter.rb +166 -0
- data/lib/playwright/web_socket_client.rb +167 -0
- data/lib/playwright/web_socket_transport.rb +116 -0
- data/lib/playwright.rb +188 -11
- data/lib/playwright_api/android.rb +46 -11
- data/lib/playwright_api/android_device.rb +182 -31
- data/lib/playwright_api/android_input.rb +22 -13
- data/lib/playwright_api/android_socket.rb +18 -0
- data/lib/playwright_api/android_web_view.rb +24 -0
- data/lib/playwright_api/api_request.rb +26 -0
- data/lib/playwright_api/api_request_context.rb +311 -0
- data/lib/playwright_api/api_response.rb +92 -0
- data/lib/playwright_api/browser.rb +116 -103
- data/lib/playwright_api/browser_context.rb +290 -389
- data/lib/playwright_api/browser_type.rb +96 -118
- data/lib/playwright_api/cdp_session.rb +36 -39
- data/lib/playwright_api/clock.rb +121 -0
- data/lib/playwright_api/console_message.rb +35 -19
- data/lib/playwright_api/dialog.rb +53 -50
- data/lib/playwright_api/download.rb +49 -43
- data/lib/playwright_api/element_handle.rb +354 -402
- data/lib/playwright_api/file_chooser.rb +15 -18
- data/lib/playwright_api/frame.rb +703 -603
- data/lib/playwright_api/frame_locator.rb +285 -0
- data/lib/playwright_api/js_handle.rb +50 -76
- data/lib/playwright_api/keyboard.rb +67 -146
- data/lib/playwright_api/locator.rb +1304 -0
- data/lib/playwright_api/locator_assertions.rb +704 -0
- data/lib/playwright_api/mouse.rb +23 -29
- data/lib/playwright_api/page.rb +1196 -1176
- data/lib/playwright_api/page_assertions.rb +60 -0
- data/lib/playwright_api/playwright.rb +54 -122
- data/lib/playwright_api/request.rb +112 -74
- data/lib/playwright_api/response.rb +92 -20
- data/lib/playwright_api/route.rb +152 -62
- data/lib/playwright_api/selectors.rb +47 -61
- data/lib/playwright_api/touchscreen.rb +8 -2
- data/lib/playwright_api/tracing.rb +128 -0
- data/lib/playwright_api/web_socket.rb +43 -5
- data/lib/playwright_api/worker.rb +74 -34
- data/playwright.gemspec +14 -9
- data/sig/playwright.rbs +658 -0
- metadata +216 -50
- data/docs/api_coverage.md +0 -354
- data/lib/playwright/channel_owners/chromium_browser.rb +0 -8
- data/lib/playwright/channel_owners/chromium_browser_context.rb +0 -8
- data/lib/playwright/channel_owners/console_message.rb +0 -21
- data/lib/playwright/channel_owners/firefox_browser.rb +0 -8
- data/lib/playwright/channel_owners/selectors.rb +0 -4
- data/lib/playwright/channel_owners/webkit_browser.rb +0 -8
- data/lib/playwright/input_type.rb +0 -19
- data/lib/playwright/input_types/mouse.rb +0 -4
- data/lib/playwright/input_types/touchscreen.rb +0 -4
- data/lib/playwright/javascript/function.rb +0 -67
- data/lib/playwright/wait_helper.rb +0 -73
- data/lib/playwright_api/accessibility.rb +0 -93
- data/lib/playwright_api/binding_call.rb +0 -23
- data/lib/playwright_api/chromium_browser_context.rb +0 -57
- data/lib/playwright_api/video.rb +0 -24
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 10
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# CDPSession
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
The [CDPSession](./cdp_session) instances are used to talk raw Chrome Devtools Protocol:
|
|
9
|
+
- protocol methods can be called with `session.send_message` method.
|
|
10
|
+
- protocol events can be subscribed to with `session.on` method.
|
|
11
|
+
|
|
12
|
+
Useful links:
|
|
13
|
+
- Documentation on DevTools Protocol can be found here: [DevTools Protocol Viewer](https://chromedevtools.github.io/devtools-protocol/).
|
|
14
|
+
- Getting Started with DevTools Protocol: https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
client = page.context.new_cdp_session(page)
|
|
18
|
+
client.send_message('Animation.enable')
|
|
19
|
+
client.on('Animation.animationCreated', -> (_) { puts 'Animation Created' })
|
|
20
|
+
response = client.send_message('Animation.getPlaybackRate')
|
|
21
|
+
puts "Playback rate is #{response['playbackRate']}"
|
|
22
|
+
client.send_message(
|
|
23
|
+
'Animation.setPlaybackRate',
|
|
24
|
+
params: { playbackRate: response['playbackRate'] / 2.0 },
|
|
25
|
+
)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## detach
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
def detach
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
Detaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be used to
|
|
36
|
+
send messages.
|
|
37
|
+
|
|
38
|
+
## send_message
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
def send_message(method, params: nil)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 10
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Clock
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Accurately simulating time-dependent behavior is essential for verifying the correctness of applications. Learn more about [clock emulation](https://playwright.dev/python/docs/clock).
|
|
9
|
+
|
|
10
|
+
Note that clock is installed for the entire [BrowserContext](./browser_context), so the time
|
|
11
|
+
in all the pages and iframes is controlled by the same clock.
|
|
12
|
+
|
|
13
|
+
## fast_forward
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
def fast_forward(ticks)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
Advance the clock by jumping forward in time. Only fires due timers at most once. This is equivalent to user closing the laptop lid for a while and
|
|
21
|
+
reopening it later, after given time.
|
|
22
|
+
|
|
23
|
+
**Usage**
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
page.clock.fast_forward(1000)
|
|
27
|
+
page.clock.fast_forward("30:00")
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## install
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
def install(time: nil)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
Install fake implementations for the following time-related functions:
|
|
38
|
+
- `Date`
|
|
39
|
+
- `setTimeout`
|
|
40
|
+
- `clearTimeout`
|
|
41
|
+
- `setInterval`
|
|
42
|
+
- `clearInterval`
|
|
43
|
+
- `requestAnimationFrame`
|
|
44
|
+
- `cancelAnimationFrame`
|
|
45
|
+
- `requestIdleCallback`
|
|
46
|
+
- `cancelIdleCallback`
|
|
47
|
+
- `performance`
|
|
48
|
+
|
|
49
|
+
Fake timers are used to manually control the flow of time in tests. They allow you to advance time, fire timers, and control the behavior of time-dependent functions. See [Clock#run_for](./clock#run_for) and [Clock#fast_forward](./clock#fast_forward) for more information.
|
|
50
|
+
|
|
51
|
+
## run_for
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
def run_for(ticks)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
Advance the clock, firing all the time-related callbacks.
|
|
59
|
+
|
|
60
|
+
**Usage**
|
|
61
|
+
|
|
62
|
+
```ruby
|
|
63
|
+
page.clock.run_for(1000)
|
|
64
|
+
page.clock.run_for("30:00")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## pause_at
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
def pause_at(time)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
Advance the clock by jumping forward in time and pause the time. Once this method is called, no timers
|
|
75
|
+
are fired unless [Clock#run_for](./clock#run_for), [Clock#fast_forward](./clock#fast_forward), [Clock#pause_at](./clock#pause_at) or [Clock#resume](./clock#resume) is called.
|
|
76
|
+
|
|
77
|
+
Only fires due timers at most once.
|
|
78
|
+
This is equivalent to user closing the laptop lid for a while and reopening it at the specified time and
|
|
79
|
+
pausing.
|
|
80
|
+
|
|
81
|
+
**Usage**
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
page.clock.pause_at(Time.parse("2020-02-02"))
|
|
85
|
+
page.clock.pause_at("2020-02-02")
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
For best results, install the clock before navigating the page and set it to a time slightly before the intended test time. This ensures that all timers run normally during page loading, preventing the page from getting stuck. Once the page has fully loaded, you can safely use [Clock#pause_at](./clock#pause_at) to pause the clock.
|
|
89
|
+
|
|
90
|
+
```ruby
|
|
91
|
+
# Initialize clock with some time before the test time and let the page load
|
|
92
|
+
# naturally. `Date.now` will progress as the timers fire.
|
|
93
|
+
page.clock.install(Time.parse("2024-12-10T08:00:00Z"))
|
|
94
|
+
page.goto("http://localhost:3333")
|
|
95
|
+
page.clock.pause_at(Time.parse("2024-12-10T10:00:00Z"))
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## resume
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
def resume
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
Resumes timers. Once this method is called, time resumes flowing, timers are fired as usual.
|
|
106
|
+
|
|
107
|
+
## set_fixed_time
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
def set_fixed_time(time)
|
|
111
|
+
```
|
|
112
|
+
alias: `fixed_time=`
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
Makes `Date.now` and `new Date()` return fixed fake time at all times,
|
|
116
|
+
keeps all the timers running.
|
|
117
|
+
|
|
118
|
+
Use this method for simple scenarios where you only need to test with a predefined time. For more advanced scenarios, use [Clock#install](./clock#install) instead. Read docs on [clock emulation](https://playwright.dev/python/docs/clock) to learn more.
|
|
119
|
+
|
|
120
|
+
**Usage**
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
page.clock.set_fixed_time(Time.now)
|
|
124
|
+
page.clock.set_fixed_time(Time.parse("2020-02-02"))
|
|
125
|
+
page.clock.set_fixed_time("2020-02-02")
|
|
126
|
+
|
|
127
|
+
# or we can use the alias
|
|
128
|
+
page.clock.fixed_time = Time.now
|
|
129
|
+
page.clock.fixed_time = Time.parse("2020-02-02")
|
|
130
|
+
page.clock.fixed_time = "2020-02-02"
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## set_system_time
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
def set_system_time(time)
|
|
137
|
+
```
|
|
138
|
+
alias: `system_time=`
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
Sets system time, but does not trigger any timers. Use this to test how the web page reacts to a time shift, for example switching from summer to winter time, or changing time zones.
|
|
142
|
+
|
|
143
|
+
**Usage**
|
|
144
|
+
|
|
145
|
+
```ruby
|
|
146
|
+
page.clock.set_system_time(Time.now)
|
|
147
|
+
page.clock.set_system_time(Time.parse("2020-02-02"))
|
|
148
|
+
page.clock.set_system_time("2020-02-02")
|
|
149
|
+
|
|
150
|
+
# or we can use the alias
|
|
151
|
+
page.clock.system_time = Time.now
|
|
152
|
+
page.clock.system_time = Time.parse("2020-02-02")
|
|
153
|
+
page.clock.system_time = "2020-02-02"
|
|
154
|
+
```
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 10
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# ConsoleMessage
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
[ConsoleMessage](./console_message) objects are dispatched by page via the [`event: Page.console`] event.
|
|
9
|
+
For each console message logged in the page there will be corresponding event in the Playwright
|
|
10
|
+
context.
|
|
11
|
+
|
|
12
|
+
```ruby
|
|
13
|
+
# Listen for all console logs
|
|
14
|
+
page.on("console", ->(msg) { puts msg.text })
|
|
15
|
+
|
|
16
|
+
# Listen for all console events and handle errors
|
|
17
|
+
page.on("console", ->(msg) {
|
|
18
|
+
if msg.type == 'error'
|
|
19
|
+
puts "error: #{msg.text}"
|
|
20
|
+
end
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
# Get the next console log
|
|
24
|
+
msg = page.expect_console_message do
|
|
25
|
+
# Issue console.log inside the page
|
|
26
|
+
page.evaluate("console.error('hello', 42, { foo: 'bar' })")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Deconstruct print arguments
|
|
30
|
+
msg.args[0].json_value # => 'hello'
|
|
31
|
+
msg.args[1].json_value # => 42
|
|
32
|
+
msg.args[2].json_value # => { 'foo' => 'bar' }
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## args
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
def args
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
List of arguments passed to a `console` function call. See also [`event: Page.console`].
|
|
43
|
+
|
|
44
|
+
## location
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
def location
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## page
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
def page
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
The page that produced this console message, if any.
|
|
60
|
+
|
|
61
|
+
## text
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
def text
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
The text of the console message.
|
|
69
|
+
|
|
70
|
+
## type
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
def type
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
## worker
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
def worker
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
The web worker or service worker that produced this console message, if any. Note that console messages from web workers also have non-null [ConsoleMessage#page](./console_message#page).
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 10
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Dialog
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
[Dialog](./dialog) objects are dispatched by page via the [`event: Page.dialog`] event.
|
|
9
|
+
|
|
10
|
+
An example of using [Dialog](./dialog) class:
|
|
11
|
+
|
|
12
|
+
```ruby
|
|
13
|
+
def handle_dialog(dialog)
|
|
14
|
+
puts "[#{dialog.type}] #{dialog.message}"
|
|
15
|
+
if dialog.message =~ /foo/
|
|
16
|
+
dialog.accept
|
|
17
|
+
else
|
|
18
|
+
dialog.dismiss
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
page.on("dialog", method(:handle_dialog))
|
|
23
|
+
page.evaluate("confirm('foo')") # will be accepted
|
|
24
|
+
# => [confirm] foo
|
|
25
|
+
page.evaluate("alert('bar')") # will be dismissed
|
|
26
|
+
# => [alert] bar
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**NOTE**: Dialogs are dismissed automatically, unless there is a [`event: Page.dialog`] listener.
|
|
30
|
+
When listener is present, it **must** either [Dialog#accept](./dialog#accept) or [Dialog#dismiss](./dialog#dismiss) the dialog - otherwise the page will [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and actions like click will never finish.
|
|
31
|
+
|
|
32
|
+
## accept
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
def accept(promptText: nil)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
Returns when the dialog has been accepted.
|
|
40
|
+
|
|
41
|
+
## default_value
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
def default_value
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
If dialog is prompt, returns default prompt value. Otherwise, returns empty string.
|
|
49
|
+
|
|
50
|
+
## dismiss
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
def dismiss
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
Returns when the dialog has been dismissed.
|
|
58
|
+
|
|
59
|
+
## message
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
def message
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
A message displayed in the dialog.
|
|
67
|
+
|
|
68
|
+
## page
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
def page
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
The page that initiated this dialog, if available.
|
|
76
|
+
|
|
77
|
+
## type
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
def type
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
Returns dialog's type, can be one of `alert`, `beforeunload`, `confirm` or `prompt`.
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 10
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Download
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
[Download](./download) objects are dispatched by page via the [`event: Page.download`] event.
|
|
9
|
+
|
|
10
|
+
All the downloaded files belonging to the browser context are deleted when the
|
|
11
|
+
browser context is closed.
|
|
12
|
+
|
|
13
|
+
Download event is emitted once the download starts. Download path becomes available once download completes.
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
download = page.expect_download do
|
|
17
|
+
page.get_by_text("Download file").click
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Wait for the download process to complete and save the downloaded file somewhere
|
|
21
|
+
path = File.join(download_dir, download.suggested_filename)
|
|
22
|
+
download.save_as(path)
|
|
23
|
+
|
|
24
|
+
path
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## cancel
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
def cancel
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
Cancels a download. Will not fail if the download is already finished or canceled.
|
|
35
|
+
Upon successful cancellations, `download.failure()` would resolve to `'canceled'`.
|
|
36
|
+
|
|
37
|
+
## delete
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
def delete
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
Deletes the downloaded file. Will wait for the download to finish if necessary.
|
|
45
|
+
|
|
46
|
+
## failure
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
def failure
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
Returns download error if any. Will wait for the download to finish if necessary.
|
|
54
|
+
|
|
55
|
+
## page
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
def page
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
Get the page that the download belongs to.
|
|
63
|
+
|
|
64
|
+
## path
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
def path
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
Returns path to the downloaded file for a successful download, or throws for a failed/canceled download. The method will wait for the download to finish if necessary. The method throws when connected remotely.
|
|
72
|
+
|
|
73
|
+
Note that the download's file name is a random GUID, use [Download#suggested_filename](./download#suggested_filename)
|
|
74
|
+
to get suggested file name.
|
|
75
|
+
|
|
76
|
+
## save_as
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
def save_as(path)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
Copy the download to a user-specified path. It is safe to call this method while the download
|
|
84
|
+
is still in progress. Will wait for the download to finish if necessary.
|
|
85
|
+
|
|
86
|
+
**Usage**
|
|
87
|
+
|
|
88
|
+
```ruby
|
|
89
|
+
download.save_as(File.join(download_dir, download.suggested_filename))
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## suggested_filename
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
def suggested_filename
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
Returns suggested filename for this download. It is typically computed by the browser from the
|
|
100
|
+
[`Content-Disposition`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition) response header
|
|
101
|
+
or the `download` attribute. See the spec on [whatwg](https://html.spec.whatwg.org/#downloading-resources). Different
|
|
102
|
+
browsers can use different logic for computing it.
|
|
103
|
+
|
|
104
|
+
## url
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
def url
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
Returns downloaded url.
|