playwright-ruby-client 1.52.0 → 1.53.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/documentation/docs/api/experimental/android.md +10 -0
- data/documentation/docs/api/locator.md +24 -1
- data/documentation/docs/api/locator_assertions.md +4 -7
- data/documentation/docs/api/page.md +1 -1
- data/documentation/docs/api/selectors.md +10 -0
- data/documentation/docs/api/tracing.md +8 -0
- data/documentation/docs/include/api_coverage.md +3 -2
- 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 +44 -23
- data/lib/playwright/channel_owners/browser_type.rb +45 -12
- data/lib/playwright/channel_owners/element_handle.rb +22 -17
- data/lib/playwright/channel_owners/frame.rb +40 -33
- data/lib/playwright/channel_owners/page.rb +19 -8
- 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/file_chooser_impl.rb +3 -2
- data/lib/playwright/frame_locator_impl.rb +5 -8
- data/lib/playwright/locator_assertions_impl.rb +64 -34
- data/lib/playwright/locator_impl.rb +31 -20
- data/lib/playwright/page_assertions_impl.rb +10 -8
- 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/utils.rb +0 -33
- data/lib/playwright/version.rb +2 -2
- data/lib/playwright_api/android.rb +12 -7
- data/lib/playwright_api/android_device.rb +8 -8
- 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 +10 -10
- data/lib/playwright_api/browser_type.rb +6 -6
- data/lib/playwright_api/cdp_session.rb +6 -6
- data/lib/playwright_api/dialog.rb +6 -6
- data/lib/playwright_api/element_handle.rb +6 -6
- data/lib/playwright_api/frame.rb +6 -6
- data/lib/playwright_api/js_handle.rb +6 -6
- data/lib/playwright_api/locator.rb +30 -4
- data/lib/playwright_api/locator_assertions.rb +3 -3
- data/lib/playwright_api/page.rb +13 -8
- data/lib/playwright_api/playwright.rb +6 -6
- data/lib/playwright_api/request.rb +8 -8
- data/lib/playwright_api/response.rb +6 -6
- data/lib/playwright_api/route.rb +6 -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 +6 -1
- metadata +4 -4
- data/lib/playwright/channel_owners/selectors.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22ec489327d6ba1f70552c2ff0d73b41e4a4ba6c02a898aa608dfe86cfdb3b14
|
4
|
+
data.tar.gz: e41e3084aae362754ad8980bde6ef20e178edc87db72d4e845844802af02d77d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3232bcc3f42fc1ab80c1027f1b2af825d21903c9024c8253015d5892dc1f5022a2ef31a9689350e33a4a9e6ce9425a31e55dc38ed75e0142e674c66135ca82f8
|
7
|
+
data.tar.gz: 29497adfd1e1bbcbef55eda2cdbc496e9a270d4500a082a071024afd519f01a9976bae5cc06c63a9c2f1825ca5afe86ed618017356add5015a5e0f15128bc72d
|
@@ -30,3 +30,13 @@ def devices(host: nil, omitDriverInstall: nil, port: nil)
|
|
30
30
|
|
31
31
|
|
32
32
|
Returns the list of detected Android devices.
|
33
|
+
|
34
|
+
## set_default_timeout
|
35
|
+
|
36
|
+
```
|
37
|
+
def set_default_timeout(timeout)
|
38
|
+
```
|
39
|
+
alias: `default_timeout=`
|
40
|
+
|
41
|
+
|
42
|
+
This setting will change the default maximum time for all the methods accepting `timeout` option.
|
@@ -87,7 +87,7 @@ button = page.get_by_role("button").and(page.get_by_title("Subscribe"))
|
|
87
87
|
## aria_snapshot
|
88
88
|
|
89
89
|
```
|
90
|
-
def aria_snapshot(
|
90
|
+
def aria_snapshot(timeout: nil)
|
91
91
|
```
|
92
92
|
|
93
93
|
|
@@ -317,6 +317,23 @@ When all steps combined have not finished during the specified `timeout`, this m
|
|
317
317
|
|
318
318
|
**NOTE**: `element.dblclick()` dispatches two `click` events and a single `dblclick` event.
|
319
319
|
|
320
|
+
## describe
|
321
|
+
|
322
|
+
```
|
323
|
+
def describe(description)
|
324
|
+
```
|
325
|
+
|
326
|
+
|
327
|
+
Describes the locator, description is used in the trace viewer and reports.
|
328
|
+
Returns the locator pointing to the same element.
|
329
|
+
|
330
|
+
**Usage**
|
331
|
+
|
332
|
+
```ruby
|
333
|
+
button = page.get_by_test_id("btn-sub").describe("Subscribe button")
|
334
|
+
button.click
|
335
|
+
```
|
336
|
+
|
320
337
|
## dispatch_event
|
321
338
|
|
322
339
|
```
|
@@ -458,6 +475,12 @@ If `expression` throws or rejects, this method throws.
|
|
458
475
|
|
459
476
|
**Usage**
|
460
477
|
|
478
|
+
Passing argument to `expression`:
|
479
|
+
|
480
|
+
```ruby
|
481
|
+
page.get_by_test_id("myId").evaluate("(element, [x, y]) => element.textContent + ' ' + x * y", arg: [7, 8]) # => "myId text 56"
|
482
|
+
```
|
483
|
+
|
461
484
|
## evaluate_all
|
462
485
|
|
463
486
|
```
|
@@ -470,7 +470,7 @@ expect(locator).to contain_class("row middle")
|
|
470
470
|
When an array is passed, the method asserts that the list of elements located matches the corresponding list of expected class lists. Each element's class attribute is matched against the corresponding class in the array:
|
471
471
|
|
472
472
|
```html
|
473
|
-
<div class='list'
|
473
|
+
<div class='list'>
|
474
474
|
<div class='component inactive'></div>
|
475
475
|
<div class='component active'></div>
|
476
476
|
<div class='component inactive'></div>
|
@@ -615,13 +615,10 @@ Ensures the [Locator](./locator) points to an element with given CSS classes. Wh
|
|
615
615
|
<div class='middle selected row' id='component'></div>
|
616
616
|
```
|
617
617
|
|
618
|
-
```
|
619
|
-
from playwright.sync_api import expect
|
620
|
-
|
618
|
+
```ruby
|
621
619
|
locator = page.locator("#component")
|
622
|
-
expect(locator).
|
623
|
-
expect(locator).
|
624
|
-
|
620
|
+
expect(locator).to have_class(/(^|\s)selected(\s|$)/)
|
621
|
+
expect(locator).to have_class("middle selected row")
|
625
622
|
```
|
626
623
|
|
627
624
|
When an array is passed, the method asserts that the list of elements located matches the corresponding list of expected class values. Each element's class attribute is matched against the corresponding string or regular expression in the array:
|
@@ -1820,7 +1820,7 @@ function will throw.
|
|
1820
1820
|
This method works across navigations:
|
1821
1821
|
|
1822
1822
|
```ruby
|
1823
|
-
%w[https://
|
1823
|
+
%w[https://playwright.dev/ https://playwright-ruby-client.vercel.app/].each do |current_url|
|
1824
1824
|
page.goto(current_url, waitUntil: "domcontentloaded")
|
1825
1825
|
element = page.wait_for_selector("img")
|
1826
1826
|
puts "Loaded image: #{element["src"]}"
|
@@ -51,3 +51,13 @@ playwright.chromium.launch do |browser|
|
|
51
51
|
button_count # => 1
|
52
52
|
end
|
53
53
|
```
|
54
|
+
|
55
|
+
## set_test_id_attribute
|
56
|
+
|
57
|
+
```
|
58
|
+
def set_test_id_attribute(attributeName)
|
59
|
+
```
|
60
|
+
alias: `test_id_attribute=`
|
61
|
+
|
62
|
+
|
63
|
+
Defines custom attribute name to be used in [Page#get_by_test_id](./page#get_by_test_id). `data-testid` is used by default.
|
@@ -7,6 +7,10 @@ sidebar_position: 10
|
|
7
7
|
|
8
8
|
API for collecting and saving Playwright traces. Playwright traces can be opened in [Trace Viewer](https://playwright.dev/python/docs/trace-viewer) after Playwright script runs.
|
9
9
|
|
10
|
+
**NOTE**: You probably want to [enable tracing in your config file](https://playwright.dev/docs/api/class-testoptions#test-options-trace) instead of using `context.tracing`.
|
11
|
+
|
12
|
+
The `context.tracing` API captures browser operations and network activity, but it doesn't record test assertions (like `expect` calls). We recommend [enabling tracing through Playwright Test configuration](https://playwright.dev/docs/api/class-testoptions#test-options-trace), which includes those assertions and provides a more complete trace for debugging test failures.
|
13
|
+
|
10
14
|
Start recording a trace before performing actions. At the end, stop tracing and save it to a file.
|
11
15
|
|
12
16
|
```ruby
|
@@ -32,6 +36,10 @@ def start(
|
|
32
36
|
|
33
37
|
Start tracing.
|
34
38
|
|
39
|
+
**NOTE**: You probably want to [enable tracing in your config file](https://playwright.dev/docs/api/class-testoptions#test-options-trace) instead of using `Tracing.start`.
|
40
|
+
|
41
|
+
The `context.tracing` API captures browser operations and network activity, but it doesn't record test assertions (like `expect` calls). We recommend [enabling tracing through Playwright Test configuration](https://playwright.dev/docs/api/class-testoptions#test-options-trace), which includes those assertions and provides a more complete trace for debugging test failures.
|
42
|
+
|
35
43
|
**Usage**
|
36
44
|
|
37
45
|
```ruby
|
@@ -212,7 +212,7 @@
|
|
212
212
|
## Selectors
|
213
213
|
|
214
214
|
* register
|
215
|
-
*
|
215
|
+
* set_test_id_attribute
|
216
216
|
|
217
217
|
## Clock
|
218
218
|
|
@@ -455,6 +455,7 @@
|
|
455
455
|
* click
|
456
456
|
* count
|
457
457
|
* dblclick
|
458
|
+
* describe
|
458
459
|
* dispatch_event
|
459
460
|
* drag_to
|
460
461
|
* element_handle
|
@@ -617,7 +618,7 @@
|
|
617
618
|
|
618
619
|
* ~~connect~~
|
619
620
|
* devices
|
620
|
-
*
|
621
|
+
* set_default_timeout
|
621
622
|
|
622
623
|
## AndroidDevice
|
623
624
|
|
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,10 +8,7 @@ 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 = {}
|
@@ -22,6 +19,7 @@ module Playwright
|
|
22
19
|
|
23
20
|
@tracing = ChannelOwners::Tracing.from(@initializer['tracing'])
|
24
21
|
@request = ChannelOwners::APIRequestContext.from(@initializer['requestContext'])
|
22
|
+
@request.send(:_update_timeout_settings, @timeout_settings)
|
25
23
|
@clock = ClockImpl.new(self)
|
26
24
|
@har_recorders = {}
|
27
25
|
|
@@ -83,14 +81,20 @@ module Playwright
|
|
83
81
|
@close_was_called = false
|
84
82
|
end
|
85
83
|
|
84
|
+
private def initialize_har_from_options(record_har_path:, record_har_content:, record_har_omit_content:, record_har_url_filter:, record_har_mode:)
|
85
|
+
return unless record_har_path
|
86
|
+
|
87
|
+
default_policy = record_har_path.end_with?('.zip') ? 'attach' : 'embed'
|
88
|
+
content_policy = record_har_content || (record_har_omit_content ? 'omit' : default_policy)
|
89
|
+
record_into_har(record_har_path, nil,
|
90
|
+
url: record_har_url_filter,
|
91
|
+
update_content: content_policy,
|
92
|
+
update_mode: record_har_mode || 'full',
|
93
|
+
)
|
94
|
+
end
|
95
|
+
|
86
96
|
private def update_options(context_options:, browser_options:)
|
87
97
|
@options = context_options
|
88
|
-
if @options[:recordHar]
|
89
|
-
@har_recorders[''] = {
|
90
|
-
path: @options[:recordHar][:path],
|
91
|
-
content: @options[:recordHar][:content]
|
92
|
-
}
|
93
|
-
end
|
94
98
|
@tracing.send(:update_traces_dir, browser_options[:tracesDir])
|
95
99
|
end
|
96
100
|
|
@@ -226,12 +230,10 @@ module Playwright
|
|
226
230
|
|
227
231
|
def set_default_navigation_timeout(timeout)
|
228
232
|
@timeout_settings.default_navigation_timeout = timeout
|
229
|
-
@channel.send_message_to_server('setDefaultNavigationTimeoutNoReply', timeout: timeout)
|
230
233
|
end
|
231
234
|
|
232
235
|
def set_default_timeout(timeout)
|
233
236
|
@timeout_settings.default_timeout = timeout
|
234
|
-
@channel.send_message_to_server('setDefaultTimeoutNoReply', timeout: timeout)
|
235
237
|
end
|
236
238
|
|
237
239
|
def pages
|
@@ -377,25 +379,32 @@ module Playwright
|
|
377
379
|
update_interception_patterns
|
378
380
|
end
|
379
381
|
|
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
|
-
)
|
382
|
+
private def record_into_har(har, page, url:, update_content:, update_mode:)
|
383
|
+
options = {
|
384
|
+
zip: har.end_with?('.zip'),
|
385
|
+
content: update_content || 'attach',
|
388
386
|
}
|
387
|
+
|
388
|
+
if url.is_a?(Regexp)
|
389
|
+
regex = ::Playwright::JavaScript::Regex.new(url)
|
390
|
+
options[:urlRegexSource] = regex.source
|
391
|
+
options[:urlRegexFlags] = regex.flag
|
392
|
+
elsif url.is_a?(String)
|
393
|
+
options[:urlGlob] = url
|
394
|
+
end
|
395
|
+
|
396
|
+
params = { options: options }
|
389
397
|
if page
|
390
398
|
params[:page] = page.channel
|
391
399
|
end
|
400
|
+
|
392
401
|
har_id = @channel.send_message_to_server('harStart', params)
|
393
|
-
@har_recorders[har_id] = { path: har, content: 'attach' }
|
402
|
+
@har_recorders[har_id] = { path: har, content: update_content || 'attach' }
|
394
403
|
end
|
395
404
|
|
396
405
|
def route_from_har(har, notFound: nil, update: nil, updateContent: nil, updateMode: nil, url: nil)
|
397
406
|
if update
|
398
|
-
record_into_har(har, nil,
|
407
|
+
record_into_har(har, nil, url: url, update_content: updateContent, update_mode: updateMode)
|
399
408
|
return
|
400
409
|
end
|
401
410
|
|
@@ -433,7 +442,10 @@ module Playwright
|
|
433
442
|
end
|
434
443
|
|
435
444
|
private def on_close
|
436
|
-
@browser
|
445
|
+
if @browser
|
446
|
+
@browser.send(:remove_context, self)
|
447
|
+
@browser.browser_type.send(:playwright_selectors_browser_contexts).delete(self)
|
448
|
+
end
|
437
449
|
emit(Events::BrowserContext::Close)
|
438
450
|
@closed_promise.fulfill(true)
|
439
451
|
end
|
@@ -614,5 +626,14 @@ module Playwright
|
|
614
626
|
private def clock_set_system_time(time_params)
|
615
627
|
@channel.send_message_to_server('clockSetSystemTime', time_params)
|
616
628
|
end
|
629
|
+
|
630
|
+
private def register_selector_engine(selector_engine)
|
631
|
+
@channel.send_message_to_server('registerSelectorEngine', { selectorEngine: selector_engine })
|
632
|
+
end
|
633
|
+
|
634
|
+
private def set_test_id_attribute_name(test_id_attribute_name)
|
635
|
+
@channel.send_message_to_server('setTestIdAttributeName', { testIdAttributeName: test_id_attribute_name })
|
636
|
+
::Playwright::LocatorUtils.instance_variable_set(:@test_id_attribute_name, test_id_attribute_name)
|
637
|
+
end
|
617
638
|
end
|
618
639
|
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
|
@@ -81,5 +96,23 @@ module Playwright
|
|
81
96
|
private def did_launch_browser(browser)
|
82
97
|
browser.send(:update_browser_type, self)
|
83
98
|
end
|
99
|
+
|
100
|
+
private def update_with_playwright_selectors_options(options)
|
101
|
+
selectors = @playwright&.selectors
|
102
|
+
if selectors
|
103
|
+
selectors.send(:update_with_selector_options, options)
|
104
|
+
else
|
105
|
+
options
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
private def playwright_selectors_browser_contexts
|
110
|
+
selectors = @playwright&.selectors
|
111
|
+
if selectors
|
112
|
+
selectors.send(:contexts_for_selectors)
|
113
|
+
else
|
114
|
+
[]
|
115
|
+
end
|
116
|
+
end
|
84
117
|
end
|
85
118
|
end
|