playwright-ruby-client 0.6.0 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/README.md +33 -0
  3. data/documentation/babel.config.js +3 -0
  4. data/documentation/docs/api/accessibility.md +7 -0
  5. data/documentation/docs/api/browser.md +188 -0
  6. data/documentation/docs/api/browser_context.md +397 -0
  7. data/documentation/docs/api/browser_type.md +158 -0
  8. data/documentation/docs/api/cdp_session.md +7 -0
  9. data/documentation/docs/api/console_message.md +41 -0
  10. data/documentation/docs/api/dialog.md +71 -0
  11. data/documentation/docs/api/element_handle.md +618 -0
  12. data/documentation/docs/api/experimental/_category_.yml +3 -0
  13. data/documentation/docs/api/experimental/android.md +26 -0
  14. data/documentation/docs/api/experimental/android_device.md +92 -0
  15. data/documentation/docs/api/experimental/android_input.md +38 -0
  16. data/documentation/docs/api/experimental/android_socket.md +7 -0
  17. data/documentation/docs/api/experimental/android_web_view.md +7 -0
  18. data/documentation/docs/api/file_chooser.md +50 -0
  19. data/documentation/docs/api/frame.md +866 -0
  20. data/documentation/docs/api/js_handle.md +113 -0
  21. data/documentation/docs/api/keyboard.md +157 -0
  22. data/documentation/docs/api/mouse.md +69 -0
  23. data/documentation/docs/api/page.md +1402 -0
  24. data/documentation/docs/api/playwright.md +63 -0
  25. data/documentation/docs/api/request.md +188 -0
  26. data/documentation/docs/api/response.md +97 -0
  27. data/documentation/docs/api/route.md +79 -0
  28. data/documentation/docs/api/selectors.md +23 -0
  29. data/documentation/docs/api/touchscreen.md +8 -0
  30. data/documentation/docs/api/tracing.md +47 -0
  31. data/documentation/docs/api/web_socket.md +7 -0
  32. data/documentation/docs/api/worker.md +24 -0
  33. data/documentation/docs/article/api_coverage.mdx +11 -0
  34. data/documentation/docs/article/getting_started.md +152 -0
  35. data/documentation/docs/article/guides/_category_.yml +3 -0
  36. data/documentation/docs/article/guides/download_playwright_driver.md +49 -0
  37. data/documentation/docs/article/guides/launch_browser.md +119 -0
  38. data/documentation/docs/article/guides/rails_integration.md +205 -0
  39. data/documentation/docs/article/guides/recording_video.md +79 -0
  40. data/{docs → documentation/docs/include}/api_coverage.md +4 -3
  41. data/documentation/docusaurus.config.js +107 -0
  42. data/documentation/package.json +39 -0
  43. data/documentation/sidebars.js +15 -0
  44. data/documentation/src/components/HomepageFeatures.js +61 -0
  45. data/documentation/src/components/HomepageFeatures.module.css +13 -0
  46. data/documentation/src/css/custom.css +44 -0
  47. data/documentation/src/pages/index.js +50 -0
  48. data/documentation/src/pages/index.module.css +41 -0
  49. data/documentation/src/pages/markdown-page.md +7 -0
  50. data/documentation/static/.nojekyll +0 -0
  51. data/documentation/static/img/playwright-logo.svg +9 -0
  52. data/documentation/static/img/undraw_dropdown_menu.svg +1 -0
  53. data/documentation/static/img/undraw_web_development.svg +1 -0
  54. data/documentation/static/img/undraw_windows.svg +1 -0
  55. data/documentation/yarn.lock +8785 -0
  56. data/lib/playwright/channel_owners/binding_call.rb +33 -0
  57. data/lib/playwright/channel_owners/browser.rb +15 -27
  58. data/lib/playwright/channel_owners/browser_context.rb +15 -7
  59. data/lib/playwright/channel_owners/browser_type.rb +23 -8
  60. data/lib/playwright/channel_owners/element_handle.rb +2 -10
  61. data/lib/playwright/channel_owners/frame.rb +6 -28
  62. data/lib/playwright/channel_owners/js_handle.rb +2 -10
  63. data/lib/playwright/channel_owners/page.rb +18 -8
  64. data/lib/playwright/channel_owners/worker.rb +4 -0
  65. data/lib/playwright/input_files.rb +0 -8
  66. data/lib/playwright/javascript.rb +0 -10
  67. data/lib/playwright/javascript/expression.rb +2 -7
  68. data/lib/playwright/playwright_api.rb +16 -1
  69. data/lib/playwright/tracing_impl.rb +9 -9
  70. data/lib/playwright/version.rb +1 -1
  71. data/lib/playwright_api/accessibility.rb +7 -89
  72. data/lib/playwright_api/android.rb +10 -66
  73. data/lib/playwright_api/android_device.rb +10 -9
  74. data/lib/playwright_api/browser.rb +21 -172
  75. data/lib/playwright_api/browser_context.rb +54 -617
  76. data/lib/playwright_api/browser_type.rb +20 -108
  77. data/lib/playwright_api/cdp_session.rb +2 -25
  78. data/lib/playwright_api/console_message.rb +6 -6
  79. data/lib/playwright_api/dialog.rb +11 -92
  80. data/lib/playwright_api/element_handle.rb +60 -362
  81. data/lib/playwright_api/file_chooser.rb +0 -28
  82. data/lib/playwright_api/frame.rb +74 -713
  83. data/lib/playwright_api/js_handle.rb +16 -90
  84. data/lib/playwright_api/keyboard.rb +21 -213
  85. data/lib/playwright_api/mouse.rb +1 -45
  86. data/lib/playwright_api/page.rb +181 -1647
  87. data/lib/playwright_api/playwright.rb +14 -117
  88. data/lib/playwright_api/request.rb +15 -121
  89. data/lib/playwright_api/response.rb +7 -7
  90. data/lib/playwright_api/route.rb +8 -105
  91. data/lib/playwright_api/selectors.rb +6 -97
  92. data/lib/playwright_api/tracing.rb +7 -73
  93. data/lib/playwright_api/web_socket.rb +1 -1
  94. data/lib/playwright_api/worker.rb +28 -42
  95. metadata +57 -4
  96. data/lib/playwright/javascript/function.rb +0 -67
@@ -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(nil).serialize
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,
@@ -18,6 +18,17 @@ module Playwright
18
18
  end
19
19
  end
20
20
 
21
+ # Unwrap ChannelOwner / ApiImplementation.
22
+ # @note Intended for internal use only.
23
+ def self.unwrap(api)
24
+ case api
25
+ when PlaywrightApi
26
+ api.instance_variable_get(:@impl)
27
+ else
28
+ api
29
+ end
30
+ end
31
+
21
32
  class ChannelOwnerWrapper
22
33
  def initialize(impl)
23
34
  impl_class_name = impl.class.name
@@ -114,6 +125,8 @@ module Playwright
114
125
  private def wrap_impl(object)
115
126
  if object.is_a?(Array)
116
127
  object.map { |obj| wrap_impl(obj) }
128
+ elsif object.is_a?(Hash)
129
+ object.map { |key, obj| [key, wrap_impl(obj)] }.to_h
117
130
  else
118
131
  ::Playwright::PlaywrightApi.wrap(object)
119
132
  end
@@ -122,8 +135,10 @@ module Playwright
122
135
  private def unwrap_impl(object)
123
136
  if object.is_a?(Array)
124
137
  object.map { |obj| unwrap_impl(obj) }
138
+ elsif object.is_a?(Hash)
139
+ object.map { |key, obj| [key, unwrap_impl(obj)] }.to_h
125
140
  elsif object.is_a?(PlaywrightApi)
126
- object.instance_variable_get(:@impl)
141
+ ::Playwright::PlaywrightApi.unwrap(object)
127
142
  else
128
143
  object
129
144
  end
@@ -15,17 +15,17 @@ module Playwright
15
15
  end
16
16
 
17
17
  # Stop tracing.
18
- def stop
18
+ def stop(path: nil)
19
19
  @channel.send_message_to_server('tracingStop')
20
- end
21
20
 
22
- def export(path)
23
- resp = @channel.send_message_to_server('tracingExport')
24
- artifact = ChannelOwners::Artifact.from(resp)
25
- # if self._context._browser:
26
- # artifact._is_remote = self._context._browser._is_remote
27
- artifact.save_as(path)
28
- artifact.delete
21
+ if path
22
+ resp = @channel.send_message_to_server('tracingExport')
23
+ artifact = ChannelOwners::Artifact.from(resp)
24
+ # if self._context._browser:
25
+ # artifact._is_remote = self._context._browser._is_remote
26
+ artifact.save_as(path)
27
+ artifact.delete
28
+ end
29
29
  end
30
30
  end
31
31
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Playwright
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.5'
5
5
  COMPATIBLE_PLAYWRIGHT_VERSION = '1.12.0'
6
6
  end
@@ -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,69 +1,13 @@
1
1
  module Playwright
2
- # Playwright has **experimental** support for Android automation. You can access android namespace via:
3
- #
2
+ # Playwright has **experimental** support for Android automation. See [here](./mobile.md) for more information. You can
3
+ # access android namespace via:
4
4
  #
5
- # ```js
6
- # const { _android: android } = require('playwright');
7
- # ```
8
- #
9
5
  # An example of the Android automation script would be:
10
- #
11
6
  #
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
7
  # Note that since you don't need Playwright to install web browsers when testing Android, you can omit browser download
64
8
  # via setting the following environment variable when installing Playwright:
65
- #
66
- # ```sh js
9
+ #
10
+ # ```bash js
67
11
  # PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 npm i -D playwright
68
12
  # ```
69
13
  class Android < PlaywrightApi
@@ -79,12 +23,6 @@ module Playwright
79
23
  end
80
24
  alias_method :default_timeout=, :set_default_timeout
81
25
 
82
- # -- inherited from EventEmitter --
83
- # @nodoc
84
- def off(event, callback)
85
- event_emitter_proxy.off(event, callback)
86
- end
87
-
88
26
  # -- inherited from EventEmitter --
89
27
  # @nodoc
90
28
  def once(event, callback)
@@ -97,6 +35,12 @@ module Playwright
97
35
  event_emitter_proxy.on(event, callback)
98
36
  end
99
37
 
38
+ # -- inherited from EventEmitter --
39
+ # @nodoc
40
+ def off(event, callback)
41
+ event_emitter_proxy.off(event, callback)
42
+ end
43
+
100
44
  private def event_emitter_proxy
101
45
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
102
46
  end
@@ -59,12 +59,13 @@ module Playwright
59
59
  record_har_path: nil,
60
60
  record_video_dir: nil,
61
61
  record_video_size: nil,
62
+ reducedMotion: nil,
62
63
  screen: nil,
63
64
  timezoneId: nil,
64
65
  userAgent: nil,
65
66
  viewport: nil,
66
67
  &block)
67
- wrap_impl(@impl.launch_browser(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), command: unwrap_impl(command), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), screen: unwrap_impl(screen), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
68
+ wrap_impl(@impl.launch_browser(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), command: unwrap_impl(command), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
68
69
  end
69
70
 
70
71
  # Performs a long tap on the widget defined by `selector`.
@@ -160,20 +161,14 @@ module Playwright
160
161
  raise NotImplementedError.new('web_views is not implemented yet.')
161
162
  end
162
163
 
163
- # @nodoc
164
- def tap_on(selector, duration: nil, timeout: nil)
165
- wrap_impl(@impl.tap_on(unwrap_impl(selector), duration: unwrap_impl(duration), timeout: unwrap_impl(timeout)))
166
- end
167
-
168
164
  # @nodoc
169
165
  def tree
170
166
  wrap_impl(@impl.tree)
171
167
  end
172
168
 
173
- # -- inherited from EventEmitter --
174
169
  # @nodoc
175
- def off(event, callback)
176
- event_emitter_proxy.off(event, callback)
170
+ def tap_on(selector, duration: nil, timeout: nil)
171
+ wrap_impl(@impl.tap_on(unwrap_impl(selector), duration: unwrap_impl(duration), timeout: unwrap_impl(timeout)))
177
172
  end
178
173
 
179
174
  # -- inherited from EventEmitter --
@@ -188,6 +183,12 @@ module Playwright
188
183
  event_emitter_proxy.on(event, callback)
189
184
  end
190
185
 
186
+ # -- inherited from EventEmitter --
187
+ # @nodoc
188
+ def off(event, callback)
189
+ event_emitter_proxy.off(event, callback)
190
+ end
191
+
191
192
  private def event_emitter_proxy
192
193
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
193
194
  end
@@ -1,136 +1,42 @@
1
1
  module Playwright
2
2
  # - extends: [EventEmitter]
3
- #
3
+ #
4
4
  # A Browser is created via [`method: BrowserType.launch`]. An example of using a `Browser` to create a `Page`:
5
- #
6
5
  #
7
- # ```js
8
- # const { firefox } = require('playwright'); // Or 'chromium' or 'webkit'.
9
- #
10
- # (async () => {
11
- # const browser = await firefox.launch();
12
- # const page = await browser.newPage();
13
- # await page.goto('https://example.com');
14
- # await browser.close();
15
- # })();
16
- # ```
17
- #
18
- # ```java
19
- # import com.microsoft.playwright.*;
20
- #
21
- # public class Example {
22
- # public static void main(String[] args) {
23
- # try (Playwright playwright = Playwright.create()) {
24
- # BrowserType firefox = playwright.firefox()
25
- # Browser browser = firefox.launch();
26
- # Page page = browser.newPage();
27
- # page.navigate('https://example.com');
28
- # browser.close();
29
- # }
30
- # }
31
- # }
32
- # ```
33
- #
34
- # ```python async
35
- # import asyncio
36
- # from playwright.async_api import async_playwright
37
- #
38
- # async def run(playwright):
39
- # firefox = playwright.firefox
40
- # browser = await firefox.launch()
41
- # page = await browser.new_page()
42
- # await page.goto("https://example.com")
43
- # await browser.close()
44
- #
45
- # async def main():
46
- # async with async_playwright() as playwright:
47
- # await run(playwright)
48
- # asyncio.run(main())
49
- # ```
50
- #
51
6
  # ```python sync
52
7
  # from playwright.sync_api import sync_playwright
53
- #
8
+ #
54
9
  # def run(playwright):
55
10
  # firefox = playwright.firefox
56
11
  # browser = firefox.launch()
57
12
  # page = browser.new_page()
58
13
  # page.goto("https://example.com")
59
14
  # browser.close()
60
- #
15
+ #
61
16
  # with sync_playwright() as playwright:
62
17
  # run(playwright)
63
18
  # ```
64
- #
65
- # ```csharp
66
- # using Microsoft.Playwright;
67
- # using System.Threading.Tasks;
68
- #
69
- # class BrowserExamples
70
- # {
71
- # public static async Task Main()
72
- # {
73
- # using var playwright = await Playwright.CreateAsync();
74
- # var firefox = playwright.Firefox;
75
- # var browser = await firefox.LaunchAsync(headless: false);
76
- # var page = await browser.NewPageAsync();
77
- # await page.GotoAsync("https://www.bing.com");
78
- # await browser.CloseAsync();
79
- # }
80
- # }
81
- # ```
82
19
  class Browser < PlaywrightApi
83
20
 
84
21
  # In case this browser is obtained using [`method: BrowserType.launch`], closes the browser and all of its pages (if any
85
22
  # were opened).
86
- #
23
+ #
87
24
  # In case this browser is connected to, clears all created contexts belonging to this browser and disconnects from the
88
25
  # browser server.
89
- #
26
+ #
90
27
  # The `Browser` object itself is considered to be disposed and cannot be used anymore.
91
28
  def close
92
29
  wrap_impl(@impl.close)
93
30
  end
94
31
 
95
32
  # Returns an array of all open browser contexts. In a newly created browser, this will return zero browser contexts.
96
- #
97
33
  #
98
- # ```js
99
- # const browser = await pw.webkit.launch();
100
- # console.log(browser.contexts().length); // prints `0`
101
- #
102
- # const context = await browser.newContext();
103
- # console.log(browser.contexts().length); // prints `1`
104
- # ```
105
- #
106
- # ```java
107
- # Browser browser = pw.webkit().launch();
108
- # System.out.println(browser.contexts().size()); // prints "0"
109
- # BrowserContext context = browser.newContext();
110
- # System.out.println(browser.contexts().size()); // prints "1"
111
- # ```
112
- #
113
- # ```python async
114
- # browser = await pw.webkit.launch()
115
- # print(len(browser.contexts())) # prints `0`
116
- # context = await browser.new_context()
117
- # print(len(browser.contexts())) # prints `1`
118
- # ```
119
- #
120
34
  # ```python sync
121
35
  # browser = pw.webkit.launch()
122
36
  # print(len(browser.contexts())) # prints `0`
123
37
  # context = browser.new_context()
124
38
  # print(len(browser.contexts())) # prints `1`
125
39
  # ```
126
- #
127
- # ```csharp
128
- # using var playwright = await Playwright.CreateAsync();
129
- # var browser = await playwright.Webkit.LaunchAsync();
130
- # System.Console.WriteLine(browser.Contexts.Count); // prints "0"
131
- # var context = await browser.NewContextAsync();
132
- # System.Console.WriteLine(browser.Contexts.Count); // prints "1"
133
- # ```
134
40
  def contexts
135
41
  wrap_impl(@impl.contexts)
136
42
  end
@@ -141,44 +47,14 @@ module Playwright
141
47
  end
142
48
 
143
49
  # > NOTE: CDP Sessions are only supported on Chromium-based browsers.
144
- #
50
+ #
145
51
  # Returns the newly created browser session.
146
52
  def new_browser_cdp_session
147
53
  raise NotImplementedError.new('new_browser_cdp_session is not implemented yet.')
148
54
  end
149
55
 
150
56
  # Creates a new browser context. It won't share cookies/cache with other browser contexts.
151
- #
152
57
  #
153
- # ```js
154
- # (async () => {
155
- # const browser = await playwright.firefox.launch(); // Or 'chromium' or 'webkit'.
156
- # // Create a new incognito browser context.
157
- # const context = await browser.newContext();
158
- # // Create a new page in a pristine context.
159
- # const page = await context.newPage();
160
- # await page.goto('https://example.com');
161
- # })();
162
- # ```
163
- #
164
- # ```java
165
- # Browser browser = playwright.firefox().launch(); // Or 'chromium' or 'webkit'.
166
- # // Create a new incognito browser context.
167
- # BrowserContext context = browser.newContext();
168
- # // Create a new page in a pristine context.
169
- # Page page = context.newPage();
170
- # page.navigate('https://example.com');
171
- # ```
172
- #
173
- # ```python async
174
- # browser = await playwright.firefox.launch() # or "chromium" or "webkit".
175
- # # create a new incognito browser context.
176
- # context = await browser.new_context()
177
- # # create a new page in a pristine context.
178
- # page = await context.new_page()
179
- # await page.goto("https://example.com")
180
- # ```
181
- #
182
58
  # ```python sync
183
59
  # browser = playwright.firefox.launch() # or "chromium" or "webkit".
184
60
  # # create a new incognito browser context.
@@ -187,16 +63,6 @@ module Playwright
187
63
  # page = context.new_page()
188
64
  # page.goto("https://example.com")
189
65
  # ```
190
- #
191
- # ```csharp
192
- # using var playwright = await Playwright.CreateAsync();
193
- # var browser = await playwright.Firefox.LaunchAsync();
194
- # // Create a new incognito browser context.
195
- # var context = await browser.NewContextAsync();
196
- # // Create a new page in a pristine context.
197
- # var page = await context.NewPageAsync(); ;
198
- # await page.GotoAsync("https://www.bing.com");
199
- # ```
200
66
  def new_context(
201
67
  acceptDownloads: nil,
202
68
  bypassCSP: nil,
@@ -218,17 +84,18 @@ module Playwright
218
84
  record_har_path: nil,
219
85
  record_video_dir: nil,
220
86
  record_video_size: nil,
87
+ reducedMotion: nil,
221
88
  screen: nil,
222
89
  storageState: nil,
223
90
  timezoneId: nil,
224
91
  userAgent: nil,
225
92
  viewport: nil,
226
93
  &block)
227
- wrap_impl(@impl.new_context(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), screen: unwrap_impl(screen), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
94
+ wrap_impl(@impl.new_context(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
228
95
  end
229
96
 
230
97
  # Creates a new page in a new browser context. Closing this page will close the context as well.
231
- #
98
+ #
232
99
  # This is a convenience API that should only be used for the single-page scenarios and short snippets. Production code and
233
100
  # testing frameworks should explicitly create [`method: Browser.newContext`] followed by the
234
101
  # [`method: BrowserContext.newPage`] to control their exact life times.
@@ -253,39 +120,21 @@ module Playwright
253
120
  record_har_path: nil,
254
121
  record_video_dir: nil,
255
122
  record_video_size: nil,
123
+ reducedMotion: nil,
256
124
  screen: nil,
257
125
  storageState: nil,
258
126
  timezoneId: nil,
259
127
  userAgent: nil,
260
- viewport: nil)
261
- wrap_impl(@impl.new_page(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), screen: unwrap_impl(screen), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport)))
128
+ viewport: nil,
129
+ &block)
130
+ wrap_impl(@impl.new_page(acceptDownloads: unwrap_impl(acceptDownloads), bypassCSP: unwrap_impl(bypassCSP), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), geolocation: unwrap_impl(geolocation), hasTouch: unwrap_impl(hasTouch), httpCredentials: unwrap_impl(httpCredentials), ignoreHTTPSErrors: unwrap_impl(ignoreHTTPSErrors), isMobile: unwrap_impl(isMobile), javaScriptEnabled: unwrap_impl(javaScriptEnabled), locale: unwrap_impl(locale), noViewport: unwrap_impl(noViewport), offline: unwrap_impl(offline), permissions: unwrap_impl(permissions), proxy: unwrap_impl(proxy), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), storageState: unwrap_impl(storageState), timezoneId: unwrap_impl(timezoneId), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
262
131
  end
263
132
 
264
133
  # > NOTE: Tracing is only supported on Chromium-based browsers.
265
- #
134
+ #
266
135
  # You can use [`method: Browser.startTracing`] and [`method: Browser.stopTracing`] to create a trace file that can be
267
136
  # opened in Chrome DevTools performance panel.
268
- #
269
137
  #
270
- # ```js
271
- # await browser.startTracing(page, {path: 'trace.json'});
272
- # await page.goto('https://www.google.com');
273
- # await browser.stopTracing();
274
- # ```
275
- #
276
- # ```java
277
- # browser.startTracing(page, new Browser.StartTracingOptions()
278
- # .setPath(Paths.get("trace.json")));
279
- # page.goto('https://www.google.com');
280
- # browser.stopTracing();
281
- # ```
282
- #
283
- # ```python async
284
- # await browser.start_tracing(page, path="trace.json")
285
- # await page.goto("https://www.google.com")
286
- # await browser.stop_tracing()
287
- # ```
288
- #
289
138
  # ```python sync
290
139
  # browser.start_tracing(page, path="trace.json")
291
140
  # page.goto("https://www.google.com")
@@ -296,7 +145,7 @@ module Playwright
296
145
  end
297
146
 
298
147
  # > NOTE: Tracing is only supported on Chromium-based browsers.
299
- #
148
+ #
300
149
  # Returns the buffer with trace data.
301
150
  def stop_tracing
302
151
  wrap_impl(@impl.stop_tracing)
@@ -307,12 +156,6 @@ module Playwright
307
156
  wrap_impl(@impl.version)
308
157
  end
309
158
 
310
- # -- inherited from EventEmitter --
311
- # @nodoc
312
- def off(event, callback)
313
- event_emitter_proxy.off(event, callback)
314
- end
315
-
316
159
  # -- inherited from EventEmitter --
317
160
  # @nodoc
318
161
  def once(event, callback)
@@ -325,6 +168,12 @@ module Playwright
325
168
  event_emitter_proxy.on(event, callback)
326
169
  end
327
170
 
171
+ # -- inherited from EventEmitter --
172
+ # @nodoc
173
+ def off(event, callback)
174
+ event_emitter_proxy.off(event, callback)
175
+ end
176
+
328
177
  private def event_emitter_proxy
329
178
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
330
179
  end