playwright-ruby-client 1.51.0 → 1.56.0
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/CONTRIBUTING.md +5 -0
- data/README.md +4 -0
- data/documentation/docs/api/browser_context.md +7 -3
- data/documentation/docs/api/console_message.md +0 -3
- data/documentation/docs/api/experimental/android.md +10 -0
- data/documentation/docs/api/frame.md +1 -0
- data/documentation/docs/api/frame_locator.md +1 -0
- data/documentation/docs/api/locator.md +24 -0
- data/documentation/docs/api/locator_assertions.md +47 -1
- data/documentation/docs/api/mouse.md +2 -0
- data/documentation/docs/api/page.md +34 -2
- data/documentation/docs/api/route.md +2 -0
- data/documentation/docs/api/selectors.md +10 -0
- data/documentation/docs/api/tracing.md +8 -0
- data/documentation/docs/article/guides/inspector.md +1 -1
- data/documentation/docs/article/guides/playwright_on_alpine_linux.md +9 -69
- data/documentation/docs/include/api_coverage.md +8 -2
- data/documentation/package.json +3 -3
- data/documentation/yarn.lock +12372 -8623
- data/lib/playwright/channel.rb +6 -3
- data/lib/playwright/channel_owners/android.rb +12 -0
- data/lib/playwright/channel_owners/android_device.rb +6 -5
- data/lib/playwright/channel_owners/api_request_context.rb +6 -1
- data/lib/playwright/channel_owners/browser.rb +37 -6
- data/lib/playwright/channel_owners/browser_context.rb +47 -38
- data/lib/playwright/channel_owners/browser_type.rb +43 -14
- data/lib/playwright/channel_owners/element_handle.rb +22 -17
- data/lib/playwright/channel_owners/frame.rb +65 -34
- data/lib/playwright/channel_owners/page.rb +39 -9
- data/lib/playwright/channel_owners/playwright.rb +10 -4
- data/lib/playwright/channel_owners/web_socket.rb +1 -1
- data/lib/playwright/connection.rb +3 -0
- data/lib/playwright/console_message_impl.rb +3 -2
- data/lib/playwright/file_chooser_impl.rb +3 -2
- data/lib/playwright/frame_locator_impl.rb +5 -8
- data/lib/playwright/javascript/value_parser.rb +54 -2
- data/lib/playwright/locator_assertions_impl.rb +100 -34
- data/lib/playwright/locator_impl.rb +26 -36
- data/lib/playwright/page_assertions_impl.rb +16 -11
- data/lib/playwright/selectors_impl.rb +45 -0
- data/lib/playwright/test.rb +21 -3
- data/lib/playwright/timeout_settings.rb +5 -0
- data/lib/playwright/transport.rb +1 -1
- data/lib/playwright/utils.rb +0 -33
- data/lib/playwright/version.rb +2 -2
- data/lib/playwright/web_socket_client.rb +4 -1
- data/lib/playwright/web_socket_transport.rb +3 -1
- data/lib/playwright.rb +14 -14
- data/lib/playwright_api/android.rb +12 -7
- data/lib/playwright_api/android_device.rb +8 -8
- data/lib/playwright_api/api_request.rb +1 -0
- data/lib/playwright_api/api_request_context.rb +6 -6
- data/lib/playwright_api/browser.rb +6 -6
- data/lib/playwright_api/browser_context.rb +17 -17
- data/lib/playwright_api/browser_type.rb +6 -6
- data/lib/playwright_api/cdp_session.rb +6 -6
- data/lib/playwright_api/console_message.rb +0 -4
- data/lib/playwright_api/dialog.rb +6 -6
- data/lib/playwright_api/element_handle.rb +6 -6
- data/lib/playwright_api/frame.rb +12 -6
- data/lib/playwright_api/frame_locator.rb +1 -0
- data/lib/playwright_api/js_handle.rb +6 -6
- data/lib/playwright_api/locator.rb +30 -3
- data/lib/playwright_api/locator_assertions.rb +47 -3
- data/lib/playwright_api/mouse.rb +2 -0
- data/lib/playwright_api/page.rb +41 -13
- data/lib/playwright_api/playwright.rb +6 -6
- data/lib/playwright_api/request.rb +6 -6
- data/lib/playwright_api/response.rb +6 -6
- data/lib/playwright_api/route.rb +8 -6
- data/lib/playwright_api/selectors.rb +1 -28
- data/lib/playwright_api/tracing.rb +14 -6
- data/lib/playwright_api/web_socket.rb +6 -6
- data/lib/playwright_api/worker.rb +8 -8
- data/sig/playwright.rbs +15 -1
- metadata +6 -5
- data/lib/playwright/channel_owners/selectors.rb +0 -26
data/lib/playwright/channel.rb
CHANGED
|
@@ -29,9 +29,9 @@ module Playwright
|
|
|
29
29
|
# @param method [String]
|
|
30
30
|
# @param params [Hash]
|
|
31
31
|
# @return [Hash]
|
|
32
|
-
def send_message_to_server_result(method, params)
|
|
32
|
+
def send_message_to_server_result(title = nil, method, params)
|
|
33
33
|
check_not_collected
|
|
34
|
-
with_logging do |metadata|
|
|
34
|
+
with_logging(title) do |metadata|
|
|
35
35
|
@connection.send_message_to_server(@guid, method, params, metadata: metadata)
|
|
36
36
|
end
|
|
37
37
|
end
|
|
@@ -46,7 +46,7 @@ module Playwright
|
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
private def with_logging(&block)
|
|
49
|
+
private def with_logging(title = nil, &block)
|
|
50
50
|
locations = caller_locations
|
|
51
51
|
first_api_call_location_idx = locations.index { |loc| loc.absolute_path&.include?('playwright_api') }
|
|
52
52
|
unless first_api_call_location_idx
|
|
@@ -64,6 +64,9 @@ module Playwright
|
|
|
64
64
|
stacks = locations
|
|
65
65
|
|
|
66
66
|
metadata = build_metadata_payload_from(api_name, stacks)
|
|
67
|
+
if title
|
|
68
|
+
metadata[:title] = title
|
|
69
|
+
end
|
|
67
70
|
block.call(metadata)
|
|
68
71
|
end
|
|
69
72
|
|
|
@@ -4,6 +4,18 @@ module Playwright
|
|
|
4
4
|
@timeout_settings = TimeoutSettings.new
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
+
def set_default_navigation_timeout(timeout)
|
|
8
|
+
@timeout_settings.default_navigation_timeout = timeout
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def set_default_timeout(timeout)
|
|
12
|
+
@timeout_settings.default_timeout = timeout
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private def _timeout_settings
|
|
16
|
+
@timeout_settings
|
|
17
|
+
end
|
|
18
|
+
|
|
7
19
|
def devices(host: nil, omitDriverInstall: nil, port: nil)
|
|
8
20
|
params = { host: host, port: port, omitDriverInstall: omitDriverInstall }.compact
|
|
9
21
|
resp = @channel.send_message_to_server('devices', params)
|
|
@@ -5,6 +5,7 @@ module Playwright
|
|
|
5
5
|
private def after_initialize
|
|
6
6
|
@input = AndroidInputImpl.new(@channel)
|
|
7
7
|
@should_close_connection_on_close = false
|
|
8
|
+
@timeout_settings = @parent.send(:_timeout_settings)
|
|
8
9
|
end
|
|
9
10
|
|
|
10
11
|
def should_close_connection_on_close!
|
|
@@ -46,9 +47,9 @@ module Playwright
|
|
|
46
47
|
enabled: selector[:enabled],
|
|
47
48
|
focusable: selector[:focusable],
|
|
48
49
|
focused: selector[:focused],
|
|
49
|
-
hasChild: selector[:hasChild] ? {
|
|
50
|
+
hasChild: selector[:hasChild] ? { androidSelector: to_selector_channel(selector[:hasChild][:selector]) } : nil,
|
|
50
51
|
hasDescendant: selector[:hasDescendant] ? {
|
|
51
|
-
|
|
52
|
+
androidSelector: to_selector_channel(selector[:hasDescendant][:selector]),
|
|
52
53
|
maxDepth: selector[:hasDescendant][:maxDepth],
|
|
53
54
|
} : nil,
|
|
54
55
|
longClickable: selector[:longClickable],
|
|
@@ -59,15 +60,15 @@ module Playwright
|
|
|
59
60
|
|
|
60
61
|
def tap_on(selector, duration: nil, timeout: nil)
|
|
61
62
|
params = {
|
|
62
|
-
|
|
63
|
+
androidSelector: to_selector_channel(selector),
|
|
63
64
|
duration: duration,
|
|
64
|
-
timeout: timeout,
|
|
65
|
+
timeout: @timeout_settings.timeout(timeout),
|
|
65
66
|
}.compact
|
|
66
67
|
@channel.send_message_to_server('tap', params)
|
|
67
68
|
end
|
|
68
69
|
|
|
69
70
|
def info(selector)
|
|
70
|
-
@channel.send_message_to_server('info',
|
|
71
|
+
@channel.send_message_to_server('info', androidSelector: to_selector_channel(selector))
|
|
71
72
|
end
|
|
72
73
|
|
|
73
74
|
def screenshot(path: nil)
|
|
@@ -5,6 +5,11 @@ module Playwright
|
|
|
5
5
|
define_channel_owner :APIRequestContext do
|
|
6
6
|
private def after_initialize
|
|
7
7
|
@tracing = ChannelOwners::Tracing.from(@initializer['tracing'])
|
|
8
|
+
@timeout_settings = TimeoutSettings.new
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private def _update_timeout_settings(timeout_settings)
|
|
12
|
+
@timeout_settings = timeout_settings
|
|
8
13
|
end
|
|
9
14
|
|
|
10
15
|
def dispose(reason: nil)
|
|
@@ -156,7 +161,7 @@ module Playwright
|
|
|
156
161
|
fetch_params[:jsonData] = json_data
|
|
157
162
|
fetch_params[:formData] = form_data
|
|
158
163
|
fetch_params[:multipartData] = multipart_data
|
|
159
|
-
fetch_params[:timeout] = timeout
|
|
164
|
+
fetch_params[:timeout] = @timeout_settings.timeout(timeout)
|
|
160
165
|
fetch_params[:failOnStatusCode] = failOnStatusCode
|
|
161
166
|
fetch_params[:ignoreHTTPSErrors] = ignoreHTTPSErrors
|
|
162
167
|
fetch_params[:maxRedirects] = maxRedirects
|
|
@@ -7,11 +7,11 @@ module Playwright
|
|
|
7
7
|
include Utils::PrepareBrowserContextOptions
|
|
8
8
|
|
|
9
9
|
private def after_initialize
|
|
10
|
-
@browser_type = @parent
|
|
11
10
|
@connected = true
|
|
12
11
|
@should_close_connection_on_close = false
|
|
13
12
|
|
|
14
13
|
@contexts = Set.new
|
|
14
|
+
@channel.on('context', ->(params) { did_create_context(ChannelOwners::BrowserContext.from(params['context'])) })
|
|
15
15
|
@channel.on('close', method(:on_close))
|
|
16
16
|
@close_reason = nil
|
|
17
17
|
end
|
|
@@ -34,10 +34,18 @@ module Playwright
|
|
|
34
34
|
|
|
35
35
|
def new_context(**options, &block)
|
|
36
36
|
params = options.dup
|
|
37
|
+
@browser_type.send(:update_with_playwright_selectors_options, params)
|
|
37
38
|
prepare_browser_context_options(params)
|
|
38
39
|
|
|
39
40
|
resp = @channel.send_message_to_server('newContext', params.compact)
|
|
40
41
|
context = ChannelOwners::BrowserContext.from(resp)
|
|
42
|
+
context.send(:initialize_har_from_options,
|
|
43
|
+
record_har_content: params[:record_har_content],
|
|
44
|
+
record_har_mode: params[:record_har_mode],
|
|
45
|
+
record_har_omit_content: params[:record_har_omit_content],
|
|
46
|
+
record_har_path: params[:record_har_path],
|
|
47
|
+
record_har_url_filter: params[:record_har_url_filter],
|
|
48
|
+
)
|
|
41
49
|
@browser_type.send(:did_create_context, context, params)
|
|
42
50
|
return context unless block
|
|
43
51
|
|
|
@@ -63,10 +71,6 @@ module Playwright
|
|
|
63
71
|
end
|
|
64
72
|
end
|
|
65
73
|
|
|
66
|
-
private def update_browser_type(browser_type)
|
|
67
|
-
@browser_type = browser_type
|
|
68
|
-
end
|
|
69
|
-
|
|
70
74
|
def close(reason: nil)
|
|
71
75
|
@close_reason = reason
|
|
72
76
|
if @should_close_connection_on_close
|
|
@@ -111,13 +115,40 @@ module Playwright
|
|
|
111
115
|
data
|
|
112
116
|
end
|
|
113
117
|
|
|
118
|
+
# called from BrowserType
|
|
119
|
+
private def connect_to_browser_type(browser_type, traces_dir)
|
|
120
|
+
# Note: when using connect(), `browserType` is different from `this.parent`.
|
|
121
|
+
# This is why browser type is not wired up in the constructor, and instead this separate method is called later on.
|
|
122
|
+
@browser_type = browser_type
|
|
123
|
+
@traces_dir = traces_dir
|
|
124
|
+
@contexts.each do |context|
|
|
125
|
+
setup_browser_context(context)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
private def did_create_context(context)
|
|
130
|
+
context.browser = self
|
|
131
|
+
@contexts << context
|
|
132
|
+
|
|
133
|
+
# Note: when connecting to a browser, initial contexts arrive before `_browserType` is set,
|
|
134
|
+
# and will be configured later in `ConnectToBrowserType`.
|
|
135
|
+
if @browser_type
|
|
136
|
+
setup_browser_context(context)
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
private def setup_browser_context(context)
|
|
141
|
+
context.tracing.send(:update_traces_dir, @traces_dir)
|
|
142
|
+
@browser_type.send(:playwright_selectors_browser_contexts) << context
|
|
143
|
+
end
|
|
144
|
+
|
|
114
145
|
private def on_close(_ = {})
|
|
115
146
|
@connected = false
|
|
116
147
|
emit(Events::Browser::Disconnected, self)
|
|
117
148
|
@closed_or_closing = true
|
|
118
149
|
end
|
|
119
150
|
|
|
120
|
-
# called from BrowserContext#initialize
|
|
151
|
+
# called from BrowserContext#initialize
|
|
121
152
|
private def add_context(context)
|
|
122
153
|
@contexts << context
|
|
123
154
|
end
|
|
@@ -8,20 +8,17 @@ module Playwright
|
|
|
8
8
|
attr_reader :clock, :tracing, :request
|
|
9
9
|
|
|
10
10
|
private def after_initialize
|
|
11
|
-
|
|
12
|
-
@browser = @parent
|
|
13
|
-
@browser.send(:add_context, self)
|
|
14
|
-
end
|
|
11
|
+
@options = @initializer['options']
|
|
15
12
|
@pages = Set.new
|
|
16
13
|
@routes = []
|
|
17
14
|
@bindings = {}
|
|
18
15
|
@timeout_settings = TimeoutSettings.new
|
|
19
16
|
@service_workers = Set.new
|
|
20
|
-
@background_pages = Set.new
|
|
21
17
|
@owner_page = nil
|
|
22
18
|
|
|
23
19
|
@tracing = ChannelOwners::Tracing.from(@initializer['tracing'])
|
|
24
20
|
@request = ChannelOwners::APIRequestContext.from(@initializer['requestContext'])
|
|
21
|
+
@request.send(:_update_timeout_settings, @timeout_settings)
|
|
25
22
|
@clock = ClockImpl.new(self)
|
|
26
23
|
@har_recorders = {}
|
|
27
24
|
|
|
@@ -29,14 +26,11 @@ module Playwright
|
|
|
29
26
|
@channel.once('close', ->(_) { on_close })
|
|
30
27
|
@channel.on('page', ->(params) { on_page(ChannelOwners::Page.from(params['page']) )})
|
|
31
28
|
@channel.on('route', ->(params) { on_route(ChannelOwners::Route.from(params['route'])) })
|
|
32
|
-
@channel.on('backgroundPage', ->(params) {
|
|
33
|
-
on_background_page(ChannelOwners::Page.from(params['page']))
|
|
34
|
-
})
|
|
35
29
|
@channel.on('serviceWorker', ->(params) {
|
|
36
30
|
on_service_worker(ChannelOwners::Worker.from(params['worker']))
|
|
37
31
|
})
|
|
38
32
|
@channel.on('console', ->(params) {
|
|
39
|
-
on_console_message(ConsoleMessageImpl.new(params))
|
|
33
|
+
on_console_message(ConsoleMessageImpl.new(params, ChannelOwners::Page.from_nullable(params['page'])))
|
|
40
34
|
})
|
|
41
35
|
@channel.on('pageError', ->(params) {
|
|
42
36
|
on_page_error(
|
|
@@ -83,14 +77,20 @@ module Playwright
|
|
|
83
77
|
@close_was_called = false
|
|
84
78
|
end
|
|
85
79
|
|
|
80
|
+
private def initialize_har_from_options(record_har_path:, record_har_content:, record_har_omit_content:, record_har_url_filter:, record_har_mode:)
|
|
81
|
+
return unless record_har_path
|
|
82
|
+
|
|
83
|
+
default_policy = record_har_path.end_with?('.zip') ? 'attach' : 'embed'
|
|
84
|
+
content_policy = record_har_content || (record_har_omit_content ? 'omit' : default_policy)
|
|
85
|
+
record_into_har(record_har_path, nil,
|
|
86
|
+
url: record_har_url_filter,
|
|
87
|
+
update_content: content_policy,
|
|
88
|
+
update_mode: record_har_mode || 'full',
|
|
89
|
+
)
|
|
90
|
+
end
|
|
91
|
+
|
|
86
92
|
private def update_options(context_options:, browser_options:)
|
|
87
93
|
@options = context_options
|
|
88
|
-
if @options[:recordHar]
|
|
89
|
-
@har_recorders[''] = {
|
|
90
|
-
path: @options[:recordHar][:path],
|
|
91
|
-
content: @options[:recordHar][:content]
|
|
92
|
-
}
|
|
93
|
-
end
|
|
94
94
|
@tracing.send(:update_traces_dir, browser_options[:tracesDir])
|
|
95
95
|
end
|
|
96
96
|
|
|
@@ -100,11 +100,6 @@ module Playwright
|
|
|
100
100
|
page.send(:emit_popup_event_from_browser_context)
|
|
101
101
|
end
|
|
102
102
|
|
|
103
|
-
private def on_background_page(page)
|
|
104
|
-
@background_pages << page
|
|
105
|
-
emit(Events::BrowserContext::BackgroundPage, page)
|
|
106
|
-
end
|
|
107
|
-
|
|
108
103
|
private def on_route(route)
|
|
109
104
|
route.send(:update_context, self)
|
|
110
105
|
|
|
@@ -212,7 +207,8 @@ module Playwright
|
|
|
212
207
|
end
|
|
213
208
|
|
|
214
209
|
def background_pages
|
|
215
|
-
|
|
210
|
+
puts '[WARNING] BrowserContext#background_pages is deprecated. Returns an empty list.'
|
|
211
|
+
[]
|
|
216
212
|
end
|
|
217
213
|
|
|
218
214
|
def service_workers
|
|
@@ -226,12 +222,10 @@ module Playwright
|
|
|
226
222
|
|
|
227
223
|
def set_default_navigation_timeout(timeout)
|
|
228
224
|
@timeout_settings.default_navigation_timeout = timeout
|
|
229
|
-
@channel.send_message_to_server('setDefaultNavigationTimeoutNoReply', timeout: timeout)
|
|
230
225
|
end
|
|
231
226
|
|
|
232
227
|
def set_default_timeout(timeout)
|
|
233
228
|
@timeout_settings.default_timeout = timeout
|
|
234
|
-
@channel.send_message_to_server('setDefaultTimeoutNoReply', timeout: timeout)
|
|
235
229
|
end
|
|
236
230
|
|
|
237
231
|
def pages
|
|
@@ -377,25 +371,32 @@ module Playwright
|
|
|
377
371
|
update_interception_patterns
|
|
378
372
|
end
|
|
379
373
|
|
|
380
|
-
private def record_into_har(har, page,
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
record_har_content: updateContent || 'attach',
|
|
385
|
-
record_har_mode: updateMode || 'minimal',
|
|
386
|
-
record_har_url_filter: url,
|
|
387
|
-
)
|
|
374
|
+
private def record_into_har(har, page, url:, update_content:, update_mode:)
|
|
375
|
+
options = {
|
|
376
|
+
zip: har.end_with?('.zip'),
|
|
377
|
+
content: update_content || 'attach',
|
|
388
378
|
}
|
|
379
|
+
|
|
380
|
+
if url.is_a?(Regexp)
|
|
381
|
+
regex = ::Playwright::JavaScript::Regex.new(url)
|
|
382
|
+
options[:urlRegexSource] = regex.source
|
|
383
|
+
options[:urlRegexFlags] = regex.flag
|
|
384
|
+
elsif url.is_a?(String)
|
|
385
|
+
options[:urlGlob] = url
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
params = { options: options }
|
|
389
389
|
if page
|
|
390
390
|
params[:page] = page.channel
|
|
391
391
|
end
|
|
392
|
+
|
|
392
393
|
har_id = @channel.send_message_to_server('harStart', params)
|
|
393
|
-
@har_recorders[har_id] = { path: har, content: 'attach' }
|
|
394
|
+
@har_recorders[har_id] = { path: har, content: update_content || 'attach' }
|
|
394
395
|
end
|
|
395
396
|
|
|
396
397
|
def route_from_har(har, notFound: nil, update: nil, updateContent: nil, updateMode: nil, url: nil)
|
|
397
398
|
if update
|
|
398
|
-
record_into_har(har, nil,
|
|
399
|
+
record_into_har(har, nil, url: url, update_content: updateContent, update_mode: updateMode)
|
|
399
400
|
return
|
|
400
401
|
end
|
|
401
402
|
|
|
@@ -433,7 +434,10 @@ module Playwright
|
|
|
433
434
|
end
|
|
434
435
|
|
|
435
436
|
private def on_close
|
|
436
|
-
@browser
|
|
437
|
+
if @browser
|
|
438
|
+
@browser.send(:remove_context, self)
|
|
439
|
+
@browser.browser_type.send(:playwright_selectors_browser_contexts).delete(self)
|
|
440
|
+
end
|
|
437
441
|
emit(Events::BrowserContext::Close)
|
|
438
442
|
@closed_promise.fulfill(true)
|
|
439
443
|
end
|
|
@@ -531,10 +535,6 @@ module Playwright
|
|
|
531
535
|
@pages.delete(page)
|
|
532
536
|
end
|
|
533
537
|
|
|
534
|
-
private def remove_background_page(page)
|
|
535
|
-
@background_pages.delete(page)
|
|
536
|
-
end
|
|
537
|
-
|
|
538
538
|
private def remove_service_worker(worker)
|
|
539
539
|
@service_workers.delete(worker)
|
|
540
540
|
end
|
|
@@ -614,5 +614,14 @@ module Playwright
|
|
|
614
614
|
private def clock_set_system_time(time_params)
|
|
615
615
|
@channel.send_message_to_server('clockSetSystemTime', time_params)
|
|
616
616
|
end
|
|
617
|
+
|
|
618
|
+
private def register_selector_engine(selector_engine)
|
|
619
|
+
@channel.send_message_to_server('registerSelectorEngine', { selectorEngine: selector_engine })
|
|
620
|
+
end
|
|
621
|
+
|
|
622
|
+
private def set_test_id_attribute_name(test_id_attribute_name)
|
|
623
|
+
@channel.send_message_to_server('setTestIdAttributeName', { testIdAttributeName: test_id_attribute_name })
|
|
624
|
+
::Playwright::LocatorUtils.instance_variable_set(:@test_id_attribute_name, test_id_attribute_name)
|
|
625
|
+
end
|
|
617
626
|
end
|
|
618
627
|
end
|
|
@@ -2,6 +2,14 @@ module Playwright
|
|
|
2
2
|
define_channel_owner :BrowserType do
|
|
3
3
|
include Utils::PrepareBrowserContextOptions
|
|
4
4
|
|
|
5
|
+
private def after_initialize
|
|
6
|
+
@timeout_settings = TimeoutSettings.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
private def update_playwright(playwright)
|
|
10
|
+
@playwright = playwright
|
|
11
|
+
end
|
|
12
|
+
|
|
5
13
|
def name
|
|
6
14
|
@initializer['name']
|
|
7
15
|
end
|
|
@@ -11,9 +19,11 @@ module Playwright
|
|
|
11
19
|
end
|
|
12
20
|
|
|
13
21
|
def launch(options, &block)
|
|
14
|
-
|
|
22
|
+
params = options.dup
|
|
23
|
+
params[:timeout] ||= @timeout_settings.launch_timeout
|
|
24
|
+
resp = @channel.send_message_to_server('launch', params.compact)
|
|
15
25
|
browser = ChannelOwners::Browser.from(resp)
|
|
16
|
-
|
|
26
|
+
browser.send(:connect_to_browser_type, self, params[:tracesDir])
|
|
17
27
|
return browser unless block
|
|
18
28
|
|
|
19
29
|
begin
|
|
@@ -27,10 +37,20 @@ module Playwright
|
|
|
27
37
|
params = options.dup
|
|
28
38
|
prepare_browser_context_options(params)
|
|
29
39
|
params['userDataDir'] = userDataDir
|
|
40
|
+
params[:timeout] ||= @timeout_settings.launch_timeout
|
|
41
|
+
|
|
42
|
+
result = @channel.send_message_to_server_result('launchPersistentContext', params.compact)
|
|
43
|
+
browser = ChannelOwners::Browser.from(result['browser'])
|
|
44
|
+
browser.send(:connect_to_browser_type, self, params[:tracesDir])
|
|
45
|
+
context = ChannelOwners::BrowserContext.from(result['context'])
|
|
46
|
+
context.send(:initialize_har_from_options,
|
|
47
|
+
record_har_content: params[:record_har_content],
|
|
48
|
+
record_har_mode: params[:record_har_mode],
|
|
49
|
+
record_har_omit_content: params[:record_har_omit_content],
|
|
50
|
+
record_har_path: params[:record_har_path],
|
|
51
|
+
record_har_url_filter: params[:record_har_url_filter],
|
|
52
|
+
)
|
|
30
53
|
|
|
31
|
-
resp = @channel.send_message_to_server('launchPersistentContext', params.compact)
|
|
32
|
-
context = ChannelOwners::Browser.from(resp)
|
|
33
|
-
did_create_context(context, params, params)
|
|
34
54
|
return context unless block
|
|
35
55
|
|
|
36
56
|
begin
|
|
@@ -47,7 +67,7 @@ module Playwright
|
|
|
47
67
|
endpointURL: endpointURL,
|
|
48
68
|
headers: headers,
|
|
49
69
|
slowMo: slowMo,
|
|
50
|
-
timeout: timeout,
|
|
70
|
+
timeout: @timeout_settings.timeout(timeout),
|
|
51
71
|
}.compact
|
|
52
72
|
|
|
53
73
|
if headers
|
|
@@ -56,12 +76,7 @@ module Playwright
|
|
|
56
76
|
|
|
57
77
|
result = @channel.send_message_to_server_result('connectOverCDP', params)
|
|
58
78
|
browser = ChannelOwners::Browser.from(result['browser'])
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if result['defaultContext']
|
|
62
|
-
default_context = ChannelOwners::BrowserContext.from(result['defaultContext'])
|
|
63
|
-
did_create_context(default_context)
|
|
64
|
-
end
|
|
79
|
+
browser.send(:connect_to_browser_type, self, nil)
|
|
65
80
|
|
|
66
81
|
if block
|
|
67
82
|
begin
|
|
@@ -78,8 +93,22 @@ module Playwright
|
|
|
78
93
|
context.send(:update_options, context_options: context_options, browser_options: browser_options)
|
|
79
94
|
end
|
|
80
95
|
|
|
81
|
-
private def
|
|
82
|
-
|
|
96
|
+
private def update_with_playwright_selectors_options(options)
|
|
97
|
+
selectors = @playwright&.selectors
|
|
98
|
+
if selectors
|
|
99
|
+
selectors.send(:update_with_selector_options, options)
|
|
100
|
+
else
|
|
101
|
+
options
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
private def playwright_selectors_browser_contexts
|
|
106
|
+
selectors = @playwright&.selectors
|
|
107
|
+
if selectors
|
|
108
|
+
selectors.send(:contexts_for_selectors)
|
|
109
|
+
else
|
|
110
|
+
[]
|
|
111
|
+
end
|
|
83
112
|
end
|
|
84
113
|
end
|
|
85
114
|
end
|
|
@@ -3,6 +3,11 @@ require_relative './js_handle'
|
|
|
3
3
|
module Playwright
|
|
4
4
|
module ChannelOwners
|
|
5
5
|
class ElementHandle < JSHandle
|
|
6
|
+
private def _timeout(timeout)
|
|
7
|
+
# @parent is Frame
|
|
8
|
+
@parent.send(:_timeout, timeout)
|
|
9
|
+
end
|
|
10
|
+
|
|
6
11
|
def as_element
|
|
7
12
|
self
|
|
8
13
|
end
|
|
@@ -69,7 +74,7 @@ module Playwright
|
|
|
69
74
|
|
|
70
75
|
def scroll_into_view_if_needed(timeout: nil)
|
|
71
76
|
params = {
|
|
72
|
-
timeout: timeout,
|
|
77
|
+
timeout: _timeout(timeout),
|
|
73
78
|
}.compact
|
|
74
79
|
@channel.send_message_to_server('scrollIntoViewIfNeeded', params)
|
|
75
80
|
|
|
@@ -88,7 +93,7 @@ module Playwright
|
|
|
88
93
|
modifiers: modifiers,
|
|
89
94
|
noWaitAfter: noWaitAfter,
|
|
90
95
|
position: position,
|
|
91
|
-
timeout: timeout,
|
|
96
|
+
timeout: _timeout(timeout),
|
|
92
97
|
trial: trial,
|
|
93
98
|
}.compact
|
|
94
99
|
@channel.send_message_to_server('hover', params)
|
|
@@ -115,7 +120,7 @@ module Playwright
|
|
|
115
120
|
modifiers: modifiers,
|
|
116
121
|
noWaitAfter: noWaitAfter,
|
|
117
122
|
position: position,
|
|
118
|
-
timeout: timeout,
|
|
123
|
+
timeout: _timeout(timeout),
|
|
119
124
|
trial: trial,
|
|
120
125
|
}.compact
|
|
121
126
|
@channel.send_message_to_server('click', params)
|
|
@@ -140,7 +145,7 @@ module Playwright
|
|
|
140
145
|
modifiers: modifiers,
|
|
141
146
|
noWaitAfter: noWaitAfter,
|
|
142
147
|
position: position,
|
|
143
|
-
timeout: timeout,
|
|
148
|
+
timeout: _timeout(timeout),
|
|
144
149
|
trial: trial,
|
|
145
150
|
}.compact
|
|
146
151
|
@channel.send_message_to_server('dblclick', params)
|
|
@@ -162,7 +167,7 @@ module Playwright
|
|
|
162
167
|
value: value,
|
|
163
168
|
label: label,
|
|
164
169
|
).as_params
|
|
165
|
-
params = base_params.merge({ force: force, noWaitAfter: noWaitAfter, timeout: timeout }.compact)
|
|
170
|
+
params = base_params.merge({ force: force, noWaitAfter: noWaitAfter, timeout: _timeout(timeout) }.compact)
|
|
166
171
|
@channel.send_message_to_server('selectOption', params)
|
|
167
172
|
end
|
|
168
173
|
|
|
@@ -179,7 +184,7 @@ module Playwright
|
|
|
179
184
|
modifiers: modifiers,
|
|
180
185
|
noWaitAfter: noWaitAfter,
|
|
181
186
|
position: position,
|
|
182
|
-
timeout: timeout,
|
|
187
|
+
timeout: _timeout(timeout),
|
|
183
188
|
trial: trial,
|
|
184
189
|
}.compact
|
|
185
190
|
@channel.send_message_to_server('tap', params)
|
|
@@ -192,7 +197,7 @@ module Playwright
|
|
|
192
197
|
value: value,
|
|
193
198
|
force: force,
|
|
194
199
|
noWaitAfter: noWaitAfter,
|
|
195
|
-
timeout: timeout,
|
|
200
|
+
timeout: _timeout(timeout),
|
|
196
201
|
}.compact
|
|
197
202
|
@channel.send_message_to_server('fill', params)
|
|
198
203
|
|
|
@@ -200,14 +205,14 @@ module Playwright
|
|
|
200
205
|
end
|
|
201
206
|
|
|
202
207
|
def select_text(force: nil, timeout: nil)
|
|
203
|
-
params = { force: force, timeout: timeout }.compact
|
|
208
|
+
params = { force: force, timeout: _timeout(timeout) }.compact
|
|
204
209
|
@channel.send_message_to_server('selectText', params)
|
|
205
210
|
|
|
206
211
|
nil
|
|
207
212
|
end
|
|
208
213
|
|
|
209
214
|
def input_value(timeout: nil)
|
|
210
|
-
params = { timeout: timeout }.compact
|
|
215
|
+
params = { timeout: _timeout(timeout) }.compact
|
|
211
216
|
@channel.send_message_to_server('inputValue', params)
|
|
212
217
|
end
|
|
213
218
|
|
|
@@ -218,7 +223,7 @@ module Playwright
|
|
|
218
223
|
end
|
|
219
224
|
|
|
220
225
|
method_name, params = InputFiles.new(frame.page.context, files).as_method_and_params
|
|
221
|
-
params.merge!({ noWaitAfter: noWaitAfter, timeout: timeout }.compact)
|
|
226
|
+
params.merge!({ noWaitAfter: noWaitAfter, timeout: _timeout(timeout) }.compact)
|
|
222
227
|
@channel.send_message_to_server(method_name, params)
|
|
223
228
|
|
|
224
229
|
nil
|
|
@@ -235,7 +240,7 @@ module Playwright
|
|
|
235
240
|
text: text,
|
|
236
241
|
delay: delay,
|
|
237
242
|
noWaitAfter: noWaitAfter,
|
|
238
|
-
timeout: timeout,
|
|
243
|
+
timeout: _timeout(timeout),
|
|
239
244
|
}.compact
|
|
240
245
|
@channel.send_message_to_server('type', params)
|
|
241
246
|
|
|
@@ -247,7 +252,7 @@ module Playwright
|
|
|
247
252
|
key: key,
|
|
248
253
|
delay: delay,
|
|
249
254
|
noWaitAfter: noWaitAfter,
|
|
250
|
-
timeout: timeout,
|
|
255
|
+
timeout: _timeout(timeout),
|
|
251
256
|
}.compact
|
|
252
257
|
@channel.send_message_to_server('press', params)
|
|
253
258
|
|
|
@@ -259,7 +264,7 @@ module Playwright
|
|
|
259
264
|
force: force,
|
|
260
265
|
noWaitAfter: noWaitAfter,
|
|
261
266
|
position: position,
|
|
262
|
-
timeout: timeout,
|
|
267
|
+
timeout: _timeout(timeout),
|
|
263
268
|
trial: trial,
|
|
264
269
|
}.compact
|
|
265
270
|
@channel.send_message_to_server('check', params)
|
|
@@ -272,7 +277,7 @@ module Playwright
|
|
|
272
277
|
force: force,
|
|
273
278
|
noWaitAfter: noWaitAfter,
|
|
274
279
|
position: position,
|
|
275
|
-
timeout: timeout,
|
|
280
|
+
timeout: _timeout(timeout),
|
|
276
281
|
trial: trial,
|
|
277
282
|
}.compact
|
|
278
283
|
@channel.send_message_to_server('uncheck', params)
|
|
@@ -314,7 +319,7 @@ module Playwright
|
|
|
314
319
|
quality: quality,
|
|
315
320
|
scale: scale,
|
|
316
321
|
style: style,
|
|
317
|
-
timeout: timeout,
|
|
322
|
+
timeout: _timeout(timeout),
|
|
318
323
|
type: type,
|
|
319
324
|
}.compact
|
|
320
325
|
if mask.is_a?(Enumerable)
|
|
@@ -352,14 +357,14 @@ module Playwright
|
|
|
352
357
|
end
|
|
353
358
|
|
|
354
359
|
def wait_for_element_state(state, timeout: nil)
|
|
355
|
-
params = { state: state, timeout: timeout }.compact
|
|
360
|
+
params = { state: state, timeout: _timeout(timeout) }.compact
|
|
356
361
|
@channel.send_message_to_server('waitForElementState', params)
|
|
357
362
|
|
|
358
363
|
nil
|
|
359
364
|
end
|
|
360
365
|
|
|
361
366
|
def wait_for_selector(selector, state: nil, strict: nil, timeout: nil)
|
|
362
|
-
params = { selector: selector, state: state, strict: strict, timeout: timeout }.compact
|
|
367
|
+
params = { selector: selector, state: state, strict: strict, timeout: _timeout(timeout) }.compact
|
|
363
368
|
resp = @channel.send_message_to_server('waitForSelector', params)
|
|
364
369
|
|
|
365
370
|
ChannelOwners::ElementHandle.from_nullable(resp)
|