playwright-ruby-client 0.6.0 → 0.6.1
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/README.md +33 -0
- data/documentation/babel.config.js +3 -0
- data/documentation/docs/api/accessibility.md +7 -0
- data/documentation/docs/api/browser.md +185 -0
- data/documentation/docs/api/browser_context.md +398 -0
- data/documentation/docs/api/browser_type.md +105 -0
- data/documentation/docs/api/cdp_session.md +7 -0
- data/documentation/docs/api/console_message.md +41 -0
- data/documentation/docs/api/dialog.md +74 -0
- data/documentation/docs/api/element_handle.md +640 -0
- data/documentation/docs/api/experimental/_category_.yml +3 -0
- data/documentation/docs/api/experimental/android.md +25 -0
- data/documentation/docs/api/experimental/android_device.md +91 -0
- data/documentation/docs/api/experimental/android_input.md +38 -0
- data/documentation/docs/api/experimental/android_socket.md +7 -0
- data/documentation/docs/api/experimental/android_web_view.md +7 -0
- data/documentation/docs/api/file_chooser.md +51 -0
- data/documentation/docs/api/frame.md +867 -0
- data/documentation/docs/api/js_handle.md +116 -0
- data/documentation/docs/api/keyboard.md +157 -0
- data/documentation/docs/api/mouse.md +69 -0
- data/documentation/docs/api/page.md +1469 -0
- data/documentation/docs/api/playwright.md +63 -0
- data/documentation/docs/api/request.md +188 -0
- data/documentation/docs/api/response.md +97 -0
- data/documentation/docs/api/route.md +80 -0
- data/documentation/docs/api/selectors.md +23 -0
- data/documentation/docs/api/touchscreen.md +8 -0
- data/documentation/docs/api/tracing.md +54 -0
- data/documentation/docs/api/web_socket.md +7 -0
- data/documentation/docs/api/worker.md +7 -0
- data/documentation/docs/article/api_coverage.mdx +11 -0
- data/documentation/docs/article/getting_started.md +152 -0
- data/documentation/docs/article/guides/_category_.yml +3 -0
- data/documentation/docs/article/guides/download_playwright_driver.md +49 -0
- data/documentation/docs/article/guides/launch_browser.md +119 -0
- data/documentation/docs/article/guides/rails_integration.md +51 -0
- data/{docs → documentation/docs/include}/api_coverage.md +0 -0
- data/documentation/docusaurus.config.js +107 -0
- data/documentation/package.json +39 -0
- data/documentation/sidebars.js +15 -0
- data/documentation/src/components/HomepageFeatures.js +61 -0
- data/documentation/src/components/HomepageFeatures.module.css +13 -0
- data/documentation/src/css/custom.css +44 -0
- data/documentation/src/pages/index.js +50 -0
- data/documentation/src/pages/index.module.css +41 -0
- data/documentation/src/pages/markdown-page.md +7 -0
- data/documentation/static/.nojekyll +0 -0
- data/documentation/static/img/playwright-logo.svg +9 -0
- data/documentation/static/img/undraw_dropdown_menu.svg +1 -0
- data/documentation/static/img/undraw_web_development.svg +1 -0
- data/documentation/static/img/undraw_windows.svg +1 -0
- data/documentation/yarn.lock +8805 -0
- data/lib/playwright/channel_owners/binding_call.rb +33 -0
- data/lib/playwright/channel_owners/browser_context.rb +2 -2
- data/lib/playwright/channel_owners/element_handle.rb +2 -10
- data/lib/playwright/channel_owners/frame.rb +6 -28
- data/lib/playwright/channel_owners/js_handle.rb +2 -10
- data/lib/playwright/channel_owners/page.rb +10 -1
- data/lib/playwright/input_files.rb +0 -8
- data/lib/playwright/javascript.rb +0 -10
- data/lib/playwright/javascript/expression.rb +2 -7
- data/lib/playwright/version.rb +1 -1
- data/lib/playwright_api/accessibility.rb +7 -89
- data/lib/playwright_api/android.rb +7 -64
- data/lib/playwright_api/android_device.rb +8 -8
- data/lib/playwright_api/browser.rb +15 -169
- data/lib/playwright_api/browser_context.rb +47 -609
- data/lib/playwright_api/browser_type.rb +13 -103
- data/lib/playwright_api/cdp_session.rb +2 -25
- data/lib/playwright_api/console_message.rb +6 -6
- data/lib/playwright_api/dialog.rb +11 -92
- data/lib/playwright_api/element_handle.rb +60 -362
- data/lib/playwright_api/file_chooser.rb +0 -28
- data/lib/playwright_api/frame.rb +74 -713
- data/lib/playwright_api/js_handle.rb +16 -90
- data/lib/playwright_api/keyboard.rb +21 -213
- data/lib/playwright_api/mouse.rb +1 -45
- data/lib/playwright_api/page.rb +155 -1635
- data/lib/playwright_api/playwright.rb +14 -117
- data/lib/playwright_api/request.rb +15 -121
- data/lib/playwright_api/response.rb +9 -9
- data/lib/playwright_api/route.rb +8 -105
- data/lib/playwright_api/selectors.rb +6 -97
- data/lib/playwright_api/tracing.rb +1 -61
- data/lib/playwright_api/web_socket.rb +1 -1
- data/lib/playwright_api/worker.rb +6 -42
- metadata +55 -4
- data/lib/playwright/javascript/function.rb +0 -67
@@ -3,5 +3,38 @@ module Playwright
|
|
3
3
|
def name
|
4
4
|
@initializer['name']
|
5
5
|
end
|
6
|
+
|
7
|
+
def call_async(callback)
|
8
|
+
Thread.new(callback) { call(callback) }
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param callback [Proc]
|
12
|
+
def call(callback)
|
13
|
+
frame = ChannelOwners::Frame.from(@initializer['frame'])
|
14
|
+
# It is not desired to use PlaywrightApi.wrap directly.
|
15
|
+
# However it is a little difficult to define wrapper for `source` parameter in generate_api.
|
16
|
+
# Just a workaround...
|
17
|
+
source = {
|
18
|
+
context: PlaywrightApi.wrap(frame.page.context),
|
19
|
+
page: PlaywrightApi.wrap(frame.page),
|
20
|
+
frame: PlaywrightApi.wrap(frame),
|
21
|
+
}
|
22
|
+
args =
|
23
|
+
if @initializer['handle']
|
24
|
+
handle = ChannelOwners::ElementHandle.from(@initializer['handle'])
|
25
|
+
[handle]
|
26
|
+
else
|
27
|
+
@initializer['args'].map do |arg|
|
28
|
+
JavaScript::ValueParser.new(arg).parse
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
begin
|
33
|
+
result = callback.call(source, *args)
|
34
|
+
@channel.send_message_to_server('resolve', result: JavaScript::ValueSerializer.new(result).serialize)
|
35
|
+
rescue => err
|
36
|
+
@channel.send_message_to_server('reject', error: { error: { message: err.message, name: 'Error' }})
|
37
|
+
end
|
38
|
+
end
|
6
39
|
end
|
7
40
|
end
|
@@ -301,19 +301,11 @@ module Playwright
|
|
301
301
|
end
|
302
302
|
|
303
303
|
def eval_on_selector(selector, pageFunction, arg: nil)
|
304
|
-
|
305
|
-
JavaScript::Function.new(pageFunction, arg).eval_on_selector(@channel, selector)
|
306
|
-
else
|
307
|
-
JavaScript::Expression.new(pageFunction).eval_on_selector(@channel, selector)
|
308
|
-
end
|
304
|
+
JavaScript::Expression.new(pageFunction, arg).eval_on_selector(@channel, selector)
|
309
305
|
end
|
310
306
|
|
311
307
|
def eval_on_selector_all(selector, pageFunction, arg: nil)
|
312
|
-
|
313
|
-
JavaScript::Function.new(pageFunction, arg).eval_on_selector_all(@channel, selector)
|
314
|
-
else
|
315
|
-
JavaScript::Expression.new(pageFunction).eval_on_selector_all(@channel, selector)
|
316
|
-
end
|
308
|
+
JavaScript::Expression.new(pageFunction, arg).eval_on_selector_all(@channel, selector)
|
317
309
|
end
|
318
310
|
|
319
311
|
def wait_for_element_state(state, timeout: nil)
|
@@ -132,19 +132,11 @@ module Playwright
|
|
132
132
|
end
|
133
133
|
|
134
134
|
def evaluate(pageFunction, arg: nil)
|
135
|
-
|
136
|
-
JavaScript::Function.new(pageFunction, arg).evaluate(@channel)
|
137
|
-
else
|
138
|
-
JavaScript::Expression.new(pageFunction).evaluate(@channel)
|
139
|
-
end
|
135
|
+
JavaScript::Expression.new(pageFunction, arg).evaluate(@channel)
|
140
136
|
end
|
141
137
|
|
142
138
|
def evaluate_handle(pageFunction, arg: nil)
|
143
|
-
|
144
|
-
JavaScript::Function.new(pageFunction, arg).evaluate_handle(@channel)
|
145
|
-
else
|
146
|
-
JavaScript::Expression.new(pageFunction).evaluate_handle(@channel)
|
147
|
-
end
|
139
|
+
JavaScript::Expression.new(pageFunction, arg).evaluate_handle(@channel)
|
148
140
|
end
|
149
141
|
|
150
142
|
def query_selector(selector)
|
@@ -208,19 +200,11 @@ module Playwright
|
|
208
200
|
end
|
209
201
|
|
210
202
|
def eval_on_selector(selector, pageFunction, arg: nil)
|
211
|
-
|
212
|
-
JavaScript::Function.new(pageFunction, arg).eval_on_selector(@channel, selector)
|
213
|
-
else
|
214
|
-
JavaScript::Expression.new(pageFunction).eval_on_selector(@channel, selector)
|
215
|
-
end
|
203
|
+
JavaScript::Expression.new(pageFunction, arg).eval_on_selector(@channel, selector)
|
216
204
|
end
|
217
205
|
|
218
206
|
def eval_on_selector_all(selector, pageFunction, arg: nil)
|
219
|
-
|
220
|
-
JavaScript::Function.new(pageFunction, arg).eval_on_selector_all(@channel, selector)
|
221
|
-
else
|
222
|
-
JavaScript::Expression.new(pageFunction).eval_on_selector_all(@channel, selector)
|
223
|
-
end
|
207
|
+
JavaScript::Expression.new(pageFunction, arg).eval_on_selector_all(@channel, selector)
|
224
208
|
end
|
225
209
|
|
226
210
|
def content
|
@@ -531,14 +515,8 @@ module Playwright
|
|
531
515
|
raise ArgumentError.new("Unknown polling option: #{polling}")
|
532
516
|
end
|
533
517
|
|
534
|
-
|
535
|
-
|
536
|
-
JavaScript::Function.new(pageFunction, arg)
|
537
|
-
else
|
538
|
-
JavaScript::Expression.new(pageFunction)
|
539
|
-
end
|
540
|
-
|
541
|
-
function_or_expression.wait_for_function(@channel, polling: polling, timeout: timeout)
|
518
|
+
expression = JavaScript::Expression.new(pageFunction, arg)
|
519
|
+
expression.wait_for_function(@channel, polling: polling, timeout: timeout)
|
542
520
|
end
|
543
521
|
|
544
522
|
def title
|
@@ -14,19 +14,11 @@ module Playwright
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def evaluate(pageFunction, arg: nil)
|
17
|
-
|
18
|
-
JavaScript::Function.new(pageFunction, arg).evaluate(@channel)
|
19
|
-
else
|
20
|
-
JavaScript::Expression.new(pageFunction).evaluate(@channel)
|
21
|
-
end
|
17
|
+
JavaScript::Expression.new(pageFunction, arg).evaluate(@channel)
|
22
18
|
end
|
23
19
|
|
24
20
|
def evaluate_handle(pageFunction, arg: nil)
|
25
|
-
|
26
|
-
JavaScript::Function.new(pageFunction, arg).evaluate_handle(@channel)
|
27
|
-
else
|
28
|
-
JavaScript::Expression.new(pageFunction).evaluate_handle(@channel)
|
29
|
-
end
|
21
|
+
JavaScript::Expression.new(pageFunction, arg).evaluate_handle(@channel)
|
30
22
|
end
|
31
23
|
|
32
24
|
def get_properties
|
@@ -30,6 +30,7 @@ module Playwright
|
|
30
30
|
@frames << @main_frame
|
31
31
|
@opener = ChannelOwners::Page.from_nullable(@initializer['opener'])
|
32
32
|
|
33
|
+
@channel.on('bindingCall', ->(params) { on_binding(ChannelOwners::BindingCall.from(params['binding'])) })
|
33
34
|
@channel.once('close', ->(_) { on_close })
|
34
35
|
@channel.on('console', ->(params) {
|
35
36
|
console_message = ChannelOwners::ConsoleMessage.from(params['message'])
|
@@ -100,6 +101,14 @@ module Playwright
|
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
104
|
+
private def on_binding(binding_call)
|
105
|
+
func = @bindings[binding_call.name]
|
106
|
+
if func
|
107
|
+
binding_call.call_async(func)
|
108
|
+
end
|
109
|
+
@browser_context.send(:on_binding, binding_call)
|
110
|
+
end
|
111
|
+
|
103
112
|
private def on_close
|
104
113
|
@closed = true
|
105
114
|
@browser_context.send(:remove_page, self)
|
@@ -306,7 +315,7 @@ module Playwright
|
|
306
315
|
timeout: timeout,
|
307
316
|
waitUntil: waitUntil,
|
308
317
|
}.compact
|
309
|
-
resp = @channel.send_message_to_server('
|
318
|
+
resp = @channel.send_message_to_server('reload', params)
|
310
319
|
ChannelOwners::Response.from_nullable(resp)
|
311
320
|
end
|
312
321
|
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'base64'
|
2
|
-
require 'mime/types'
|
3
2
|
|
4
3
|
module Playwright
|
5
4
|
class InputFiles
|
@@ -19,13 +18,11 @@ module Playwright
|
|
19
18
|
when String
|
20
19
|
{
|
21
20
|
name: File.basename(file),
|
22
|
-
mimeType: mime_type_for(file),
|
23
21
|
buffer: Base64.strict_encode64(File.read(file)),
|
24
22
|
}
|
25
23
|
when File
|
26
24
|
{
|
27
25
|
name: File.basename(file.path),
|
28
|
-
mimeType: mime_type_for(file.path),
|
29
26
|
buffer: Base64.strict_encode64(file.read),
|
30
27
|
}
|
31
28
|
else
|
@@ -33,10 +30,5 @@ module Playwright
|
|
33
30
|
end
|
34
31
|
end
|
35
32
|
end
|
36
|
-
|
37
|
-
private def mime_type_for(filepath)
|
38
|
-
mime_types = MIME::Types.type_for(filepath)
|
39
|
-
mime_types.first.to_s || 'application/octet-stream'
|
40
|
-
end
|
41
33
|
end
|
42
34
|
end
|
@@ -1,13 +1,3 @@
|
|
1
1
|
require_relative './javascript/expression'
|
2
|
-
require_relative './javascript/function'
|
3
2
|
require_relative './javascript/value_parser'
|
4
3
|
require_relative './javascript/value_serializer'
|
5
|
-
|
6
|
-
module Playwright
|
7
|
-
module JavaScript
|
8
|
-
# Detect if str is likely to be a function
|
9
|
-
module_function def function?(str)
|
10
|
-
['async', 'function'].any? { |key| str.strip.start_with?(key) } || str.include?('=>')
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,16 +1,15 @@
|
|
1
1
|
module Playwright
|
2
2
|
module JavaScript
|
3
3
|
class Expression
|
4
|
-
def initialize(expression)
|
4
|
+
def initialize(expression, arg)
|
5
5
|
@expression = expression
|
6
|
-
@serialized_arg = ValueSerializer.new(
|
6
|
+
@serialized_arg = ValueSerializer.new(arg).serialize
|
7
7
|
end
|
8
8
|
|
9
9
|
def evaluate(channel)
|
10
10
|
value = channel.send_message_to_server(
|
11
11
|
'evaluateExpression',
|
12
12
|
expression: @expression,
|
13
|
-
isFunction: false,
|
14
13
|
arg: @serialized_arg,
|
15
14
|
)
|
16
15
|
ValueParser.new(value).parse
|
@@ -20,7 +19,6 @@ module Playwright
|
|
20
19
|
resp = channel.send_message_to_server(
|
21
20
|
'evaluateExpressionHandle',
|
22
21
|
expression: @expression,
|
23
|
-
isFunction: false,
|
24
22
|
arg: @serialized_arg,
|
25
23
|
)
|
26
24
|
::Playwright::ChannelOwner.from(resp)
|
@@ -31,7 +29,6 @@ module Playwright
|
|
31
29
|
'evalOnSelector',
|
32
30
|
selector: selector,
|
33
31
|
expression: @expression,
|
34
|
-
isFunction: false,
|
35
32
|
arg: @serialized_arg,
|
36
33
|
)
|
37
34
|
ValueParser.new(value).parse
|
@@ -42,7 +39,6 @@ module Playwright
|
|
42
39
|
'evalOnSelectorAll',
|
43
40
|
selector: selector,
|
44
41
|
expression: @expression,
|
45
|
-
isFunction: false,
|
46
42
|
arg: @serialized_arg,
|
47
43
|
)
|
48
44
|
ValueParser.new(value).parse
|
@@ -51,7 +47,6 @@ module Playwright
|
|
51
47
|
def wait_for_function(channel, polling:, timeout:)
|
52
48
|
params = {
|
53
49
|
expression: @expression,
|
54
|
-
isFunction: false,
|
55
50
|
arg: @serialized_arg,
|
56
51
|
polling: polling,
|
57
52
|
timeout: timeout,
|
data/lib/playwright/version.rb
CHANGED
@@ -2,13 +2,13 @@ module Playwright
|
|
2
2
|
# The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by
|
3
3
|
# assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or
|
4
4
|
# [switches](https://en.wikipedia.org/wiki/Switch_access).
|
5
|
-
#
|
5
|
+
#
|
6
6
|
# Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that might
|
7
7
|
# have wildly different output.
|
8
|
-
#
|
8
|
+
#
|
9
9
|
# Rendering engines of Chromium, Firefox and WebKit have a concept of "accessibility tree", which is then translated into
|
10
10
|
# different platform-specific APIs. Accessibility namespace gives access to this Accessibility Tree.
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# Most of the accessibility tree gets filtered out when converting from internal browser AX Tree to Platform-specific
|
13
13
|
# AX-Tree or by assistive technologies themselves. By default, Playwright tries to approximate this filtering, exposing
|
14
14
|
# only the "interesting" nodes of the tree.
|
@@ -16,101 +16,19 @@ module Playwright
|
|
16
16
|
|
17
17
|
# Captures the current state of the accessibility tree. The returned object represents the root accessible node of the
|
18
18
|
# page.
|
19
|
-
#
|
19
|
+
#
|
20
20
|
# > NOTE: The Chromium accessibility tree contains nodes that go unused on most platforms and by most screen readers.
|
21
21
|
# Playwright will discard them as well for an easier to process tree, unless `interestingOnly` is set to `false`.
|
22
|
-
#
|
22
|
+
#
|
23
23
|
# An example of dumping the entire accessibility tree:
|
24
|
-
#
|
25
24
|
#
|
26
|
-
# ```js
|
27
|
-
# const snapshot = await page.accessibility.snapshot();
|
28
|
-
# console.log(snapshot);
|
29
|
-
# ```
|
30
|
-
#
|
31
|
-
# ```java
|
32
|
-
# String snapshot = page.accessibility().snapshot();
|
33
|
-
# System.out.println(snapshot);
|
34
|
-
# ```
|
35
|
-
#
|
36
|
-
# ```python async
|
37
|
-
# snapshot = await page.accessibility.snapshot()
|
38
|
-
# print(snapshot)
|
39
|
-
# ```
|
40
|
-
#
|
41
25
|
# ```python sync
|
42
26
|
# snapshot = page.accessibility.snapshot()
|
43
27
|
# print(snapshot)
|
44
28
|
# ```
|
45
|
-
#
|
46
|
-
# ```csharp
|
47
|
-
# var accessibilitySnapshot = await page.Accessibility.SnapshotAsync();
|
48
|
-
# Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(accessibilitySnapshot));
|
49
|
-
# ```
|
50
|
-
#
|
29
|
+
#
|
51
30
|
# An example of logging the focused node's name:
|
52
|
-
#
|
53
31
|
#
|
54
|
-
# ```js
|
55
|
-
# const snapshot = await page.accessibility.snapshot();
|
56
|
-
# const node = findFocusedNode(snapshot);
|
57
|
-
# console.log(node && node.name);
|
58
|
-
#
|
59
|
-
# function findFocusedNode(node) {
|
60
|
-
# if (node.focused)
|
61
|
-
# return node;
|
62
|
-
# for (const child of node.children || []) {
|
63
|
-
# const foundNode = findFocusedNode(child);
|
64
|
-
# return foundNode;
|
65
|
-
# }
|
66
|
-
# return null;
|
67
|
-
# }
|
68
|
-
# ```
|
69
|
-
#
|
70
|
-
# ```csharp
|
71
|
-
# static AccessibilitySnapshotResult findFocusedNode(AccessibilitySnapshotResult root)
|
72
|
-
# {
|
73
|
-
# var nodes = new Stack<AccessibilitySnapshotResult>(new[] { root });
|
74
|
-
# while (nodes.Count > 0)
|
75
|
-
# {
|
76
|
-
# var node = nodes.Pop();
|
77
|
-
# if (node.Focused) return node;
|
78
|
-
# foreach (var innerNode in node.Children)
|
79
|
-
# {
|
80
|
-
# nodes.Push(innerNode);
|
81
|
-
# }
|
82
|
-
# }
|
83
|
-
#
|
84
|
-
# return null;
|
85
|
-
# }
|
86
|
-
#
|
87
|
-
# var accessibilitySnapshot = await page.Accessibility.SnapshotAsync();
|
88
|
-
# Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(accessibilitySnapshot));
|
89
|
-
# var focusedNode = findFocusedNode(accessibilitySnapshot);
|
90
|
-
# if (focusedNode != null)
|
91
|
-
# Console.WriteLine(focusedNode.Name);
|
92
|
-
# ```
|
93
|
-
#
|
94
|
-
# ```java
|
95
|
-
# // FIXME
|
96
|
-
# String snapshot = page.accessibility().snapshot();
|
97
|
-
# ```
|
98
|
-
#
|
99
|
-
# ```python async
|
100
|
-
# def find_focused_node(node):
|
101
|
-
# if (node.get("focused"))
|
102
|
-
# return node
|
103
|
-
# for child in (node.get("children") or []):
|
104
|
-
# found_node = find_focused_node(child)
|
105
|
-
# return found_node
|
106
|
-
# return None
|
107
|
-
#
|
108
|
-
# snapshot = await page.accessibility.snapshot()
|
109
|
-
# node = find_focused_node(snapshot)
|
110
|
-
# if node:
|
111
|
-
# print(node["name"])
|
112
|
-
# ```
|
113
|
-
#
|
114
32
|
# ```python sync
|
115
33
|
# def find_focused_node(node):
|
116
34
|
# if (node.get("focused"))
|
@@ -119,7 +37,7 @@ module Playwright
|
|
119
37
|
# found_node = find_focused_node(child)
|
120
38
|
# return found_node
|
121
39
|
# return None
|
122
|
-
#
|
40
|
+
#
|
123
41
|
# snapshot = page.accessibility.snapshot()
|
124
42
|
# node = find_focused_node(snapshot)
|
125
43
|
# if node:
|
@@ -1,68 +1,11 @@
|
|
1
1
|
module Playwright
|
2
2
|
# Playwright has **experimental** support for Android automation. You can access android namespace via:
|
3
|
-
#
|
4
3
|
#
|
5
|
-
# ```js
|
6
|
-
# const { _android: android } = require('playwright');
|
7
|
-
# ```
|
8
|
-
#
|
9
4
|
# An example of the Android automation script would be:
|
10
|
-
#
|
11
5
|
#
|
12
|
-
# ```js
|
13
|
-
# const { _android: android } = require('playwright');
|
14
|
-
#
|
15
|
-
# (async () => {
|
16
|
-
# // Connect to the device.
|
17
|
-
# const [device] = await android.devices();
|
18
|
-
# console.log(`Model: ${device.model()}`);
|
19
|
-
# console.log(`Serial: ${device.serial()}`);
|
20
|
-
# // Take screenshot of the whole device.
|
21
|
-
# await device.screenshot({ path: 'device.png' });
|
22
|
-
#
|
23
|
-
# {
|
24
|
-
# // --------------------- WebView -----------------------
|
25
|
-
#
|
26
|
-
# // Launch an application with WebView.
|
27
|
-
# await device.shell('am force-stop org.chromium.webview_shell');
|
28
|
-
# await device.shell('am start org.chromium.webview_shell/.WebViewBrowserActivity');
|
29
|
-
# // Get the WebView.
|
30
|
-
# const webview = await device.webView({ pkg: 'org.chromium.webview_shell' });
|
31
|
-
#
|
32
|
-
# // Fill the input box.
|
33
|
-
# await device.fill({ res: 'org.chromium.webview_shell:id/url_field' }, 'github.com/microsoft/playwright');
|
34
|
-
# await device.press({ res: 'org.chromium.webview_shell:id/url_field' }, 'Enter');
|
35
|
-
#
|
36
|
-
# // Work with WebView's page as usual.
|
37
|
-
# const page = await webview.page();
|
38
|
-
# await page.waitForNavigation({ url: /.*microsoft\/playwright.*/ });
|
39
|
-
# console.log(await page.title());
|
40
|
-
# }
|
41
|
-
#
|
42
|
-
# {
|
43
|
-
# // --------------------- Browser -----------------------
|
44
|
-
#
|
45
|
-
# // Launch Chrome browser.
|
46
|
-
# await device.shell('am force-stop com.android.chrome');
|
47
|
-
# const context = await device.launchBrowser();
|
48
|
-
#
|
49
|
-
# // Use BrowserContext as usual.
|
50
|
-
# const page = await context.newPage();
|
51
|
-
# await page.goto('https://webkit.org/');
|
52
|
-
# console.log(await page.evaluate(() => window.location.href));
|
53
|
-
# await page.screenshot({ path: 'page.png' });
|
54
|
-
#
|
55
|
-
# await context.close();
|
56
|
-
# }
|
57
|
-
#
|
58
|
-
# // Close the device.
|
59
|
-
# await device.close();
|
60
|
-
# })();
|
61
|
-
# ```
|
62
|
-
#
|
63
6
|
# Note that since you don't need Playwright to install web browsers when testing Android, you can omit browser download
|
64
7
|
# via setting the following environment variable when installing Playwright:
|
65
|
-
#
|
8
|
+
#
|
66
9
|
# ```sh js
|
67
10
|
# PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm i -D playwright
|
68
11
|
# ```
|
@@ -81,20 +24,20 @@ module Playwright
|
|
81
24
|
|
82
25
|
# -- inherited from EventEmitter --
|
83
26
|
# @nodoc
|
84
|
-
def
|
85
|
-
event_emitter_proxy.
|
27
|
+
def on(event, callback)
|
28
|
+
event_emitter_proxy.on(event, callback)
|
86
29
|
end
|
87
30
|
|
88
31
|
# -- inherited from EventEmitter --
|
89
32
|
# @nodoc
|
90
|
-
def
|
91
|
-
event_emitter_proxy.
|
33
|
+
def off(event, callback)
|
34
|
+
event_emitter_proxy.off(event, callback)
|
92
35
|
end
|
93
36
|
|
94
37
|
# -- inherited from EventEmitter --
|
95
38
|
# @nodoc
|
96
|
-
def
|
97
|
-
event_emitter_proxy.
|
39
|
+
def once(event, callback)
|
40
|
+
event_emitter_proxy.once(event, callback)
|
98
41
|
end
|
99
42
|
|
100
43
|
private def event_emitter_proxy
|