playwright-ruby-client 1.39.1 → 1.40.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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/docs/api/api_request_context.md +1 -2
  3. data/documentation/docs/api/browser.md +1 -1
  4. data/documentation/docs/api/browser_context.md +1 -1
  5. data/documentation/docs/api/browser_type.md +1 -0
  6. data/documentation/docs/api/download.md +1 -2
  7. data/documentation/docs/api/element_handle.md +4 -1
  8. data/documentation/docs/api/frame.md +4 -1
  9. data/documentation/docs/api/locator.md +4 -1
  10. data/documentation/docs/api/locator_assertions.md +11 -1
  11. data/documentation/docs/api/page.md +6 -3
  12. data/documentation/docs/article/guides/rails_integration.md +80 -51
  13. data/documentation/docs/article/guides/rspec_integration.md +59 -0
  14. data/documentation/docusaurus.config.js +1 -1
  15. data/documentation/package.json +7 -7
  16. data/documentation/yarn.lock +4641 -5023
  17. data/lib/playwright/api_response_impl.rb +2 -2
  18. data/lib/playwright/channel_owners/api_request_context.rb +12 -3
  19. data/lib/playwright/channel_owners/browser.rb +11 -7
  20. data/lib/playwright/channel_owners/browser_context.rb +35 -15
  21. data/lib/playwright/channel_owners/frame.rb +38 -14
  22. data/lib/playwright/channel_owners/page.rb +29 -16
  23. data/lib/playwright/channel_owners/web_socket.rb +8 -13
  24. data/lib/playwright/connection.rb +18 -2
  25. data/lib/playwright/errors.rb +20 -2
  26. data/lib/playwright/input_files.rb +4 -4
  27. data/lib/playwright/locator_assertions_impl.rb +15 -15
  28. data/lib/playwright/test.rb +2 -2
  29. data/lib/playwright/utils.rb +3 -10
  30. data/lib/playwright/version.rb +2 -2
  31. data/lib/playwright/waiter.rb +146 -0
  32. data/lib/playwright.rb +1 -1
  33. data/lib/playwright_api/api_request_context.rb +1 -2
  34. data/lib/playwright_api/browser.rb +2 -2
  35. data/lib/playwright_api/browser_context.rb +3 -3
  36. data/lib/playwright_api/browser_type.rb +2 -1
  37. data/lib/playwright_api/download.rb +1 -2
  38. data/lib/playwright_api/element_handle.rb +4 -1
  39. data/lib/playwright_api/frame.rb +4 -1
  40. data/lib/playwright_api/locator.rb +4 -1
  41. data/lib/playwright_api/locator_assertions.rb +12 -2
  42. data/lib/playwright_api/page.rb +16 -13
  43. data/lib/playwright_api/request.rb +4 -4
  44. data/lib/playwright_api/worker.rb +4 -4
  45. data/sig/playwright.rbs +6 -6
  46. metadata +5 -4
  47. data/lib/playwright/wait_helper.rb +0 -73
@@ -70,17 +70,10 @@ module Playwright
70
70
  end
71
71
 
72
72
  module Errors
73
- module SafeCloseError
73
+ module TargetClosedErrorMethods
74
74
  # @param err [Exception]
75
- private def safe_close_error?(err)
76
- return true if err.is_a?(Transport::AlreadyDisconnectedError)
77
-
78
- [
79
- 'Browser has been closed',
80
- 'Target page, context or browser has been closed',
81
- ].any? do |closed_message|
82
- err.message.end_with?(closed_message)
83
- end
75
+ private def target_closed_error?(err)
76
+ err.is_a?(TargetClosedError)
84
77
  end
85
78
  end
86
79
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Playwright
4
- VERSION = '1.39.1'
5
- COMPATIBLE_PLAYWRIGHT_VERSION = '1.39.0'
4
+ VERSION = '1.40.0'
5
+ COMPATIBLE_PLAYWRIGHT_VERSION = '1.40.1'
6
6
  end
@@ -0,0 +1,146 @@
1
+ require 'securerandom'
2
+
3
+ module Playwright
4
+ # ref: https://github.com/microsoft/playwright-python/blob/v1.40.0/playwright/_impl/_waiter.py
5
+ # ref: https://github.com/microsoft/playwright/blob/v1.40.0/packages/playwright-core/src/client/waiter.ts
6
+ class Waiter
7
+ def initialize(channel_owner, wait_name:)
8
+ @result = Concurrent::Promises.resolvable_future
9
+ @wait_id = SecureRandom.hex(16)
10
+ @event = wait_name
11
+ @channel = channel_owner.channel
12
+ @registered_listeners = Set.new
13
+ @logs = []
14
+ wait_for_event_info_before
15
+ end
16
+
17
+ private def wait_for_event_info_before
18
+ @channel.async_send_message_to_server(
19
+ "waitForEventInfo",
20
+ {
21
+ "info": {
22
+ "waitId": @wait_id,
23
+ "phase": "before",
24
+ "event": @event,
25
+ }
26
+ },
27
+ )
28
+ end
29
+
30
+ private def wait_for_event_info_after(error: nil)
31
+ @channel.async_send_message_to_server(
32
+ "waitForEventInfo",
33
+ {
34
+ "info": {
35
+ "waitId": @wait_id,
36
+ "phase": "after",
37
+ "error": error,
38
+ }.compact,
39
+ },
40
+ )
41
+ end
42
+
43
+ def reject_on_event(emitter, event, error_or_proc, predicate: nil)
44
+ listener = -> (*args) {
45
+ if !predicate || predicate.call(*args)
46
+ if error_or_proc.respond_to?(:call)
47
+ reject(error_or_proc.call)
48
+ else
49
+ reject(error_or_proc)
50
+ end
51
+ end
52
+ }
53
+ emitter.on(event, listener)
54
+ @registered_listeners << [emitter, event, listener]
55
+
56
+ self
57
+ end
58
+
59
+ def reject_on_timeout(timeout_ms, message)
60
+ return if timeout_ms <= 0
61
+
62
+ Concurrent::Promises.schedule(timeout_ms / 1000.0) do
63
+ reject(TimeoutError.new(message: message))
64
+ end.rescue do |err|
65
+ puts err, err.backtrace
66
+ end
67
+
68
+ self
69
+ end
70
+
71
+ private def cleanup
72
+ @registered_listeners.each do |emitter, event, listener|
73
+ emitter.off(event, listener)
74
+ end
75
+ @registered_listeners.clear
76
+ end
77
+
78
+ private def fulfill(result)
79
+ cleanup
80
+ unless @result.resolved?
81
+ @result.fulfill(result)
82
+ end
83
+ wait_for_event_info_after
84
+ end
85
+
86
+ private def reject(error)
87
+ cleanup
88
+ klass = error.is_a?(TimeoutError) ? TimeoutError : Error
89
+ ex = klass.new(message: "#{error.message}#{format_log_recording(@logs)}")
90
+ unless @result.resolved?
91
+ @result.reject(ex)
92
+ end
93
+ wait_for_event_info_after(error: ex)
94
+ end
95
+
96
+ # @param [Playwright::EventEmitter]
97
+ # @param
98
+ def wait_for_event(emitter, event, predicate: nil)
99
+ listener = -> (*args) {
100
+ begin
101
+ if !predicate || predicate.call(*args)
102
+ fulfill(args.first)
103
+ end
104
+ rescue => err
105
+ reject(err)
106
+ end
107
+ }
108
+ emitter.on(event, listener)
109
+ @registered_listeners << [emitter, event, listener]
110
+
111
+ self
112
+ end
113
+
114
+ attr_reader :result
115
+
116
+ def log(message)
117
+ @logs << message
118
+ begin
119
+ @channel.async_send_message_to_server(
120
+ "waitForEventInfo",
121
+ {
122
+ "info": {
123
+ "waitId": @wait_id,
124
+ "phase": "log",
125
+ "message": message,
126
+ },
127
+ },
128
+ )
129
+ rescue => err
130
+ # ignore
131
+ end
132
+ end
133
+
134
+ # @param logs [Array<String>]
135
+ private def format_log_recording(logs)
136
+ return "" if logs.empty?
137
+
138
+ header = " logs "
139
+ header_length = 60
140
+ left_length = ((header_length - header.length) / 2.0).to_i
141
+ right_length = header_length - header.length - left_length
142
+ new_line = "\n"
143
+ "#{new_line}#{'=' * left_length}#{header}#{'=' * right_length}#{new_line}#{logs.join(new_line)}#{new_line}#{'=' * header_length}"
144
+ end
145
+ end
146
+ end
data/lib/playwright.rb CHANGED
@@ -29,7 +29,7 @@ require 'playwright/transport'
29
29
  require 'playwright/url_matcher'
30
30
  require 'playwright/version'
31
31
  require 'playwright/video'
32
- require 'playwright/wait_helper'
32
+ require 'playwright/waiter'
33
33
 
34
34
  require 'playwright/playwright_api'
35
35
  # load generated files
@@ -86,8 +86,7 @@ module Playwright
86
86
  end
87
87
 
88
88
  #
89
- # All responses returned by [`method: APIRequestContext.get`] and similar methods are stored in the memory, so that you can later call [`method: APIResponse.body`]. This method
90
- # discards all stored responses, and makes [`method: APIResponse.body`] throw "Response disposed" error.
89
+ # All responses returned by [`method: APIRequestContext.get`] and similar methods are stored in the memory, so that you can later call [`method: APIResponse.body`].This method discards all its resources, calling any method on disposed `APIRequestContext` will throw an exception.
91
90
  def dispose
92
91
  wrap_impl(@impl.dispose)
93
92
  end
@@ -34,8 +34,8 @@ module Playwright
34
34
  # **NOTE**: This is similar to force quitting the browser. Therefore, you should call [`method: BrowserContext.close`] on any `BrowserContext`'s you explicitly created earlier with [`method: Browser.newContext`] **before** calling [`method: Browser.close`].
35
35
  #
36
36
  # The `Browser` object itself is considered to be disposed and cannot be used anymore.
37
- def close
38
- wrap_impl(@impl.close)
37
+ def close(reason: nil)
38
+ wrap_impl(@impl.close(reason: unwrap_impl(reason)))
39
39
  end
40
40
 
41
41
  #
@@ -105,8 +105,8 @@ module Playwright
105
105
  # Closes the browser context. All the pages that belong to the browser context will be closed.
106
106
  #
107
107
  # **NOTE**: The default browser context cannot be closed.
108
- def close
109
- wrap_impl(@impl.close)
108
+ def close(reason: nil)
109
+ wrap_impl(@impl.close(reason: unwrap_impl(reason)))
110
110
  end
111
111
 
112
112
  #
@@ -135,7 +135,7 @@ module Playwright
135
135
  #
136
136
  # def run(playwright: Playwright):
137
137
  # webkit = playwright.webkit
138
- # browser = webkit.launch(headless=false)
138
+ # browser = webkit.launch(headless=False)
139
139
  # context = browser.new_context()
140
140
  # context.expose_binding("pageURL", lambda source: source["page"].url)
141
141
  # page = context.new_page()
@@ -129,6 +129,7 @@ module Playwright
129
129
  env: nil,
130
130
  executablePath: nil,
131
131
  extraHTTPHeaders: nil,
132
+ firefoxUserPrefs: nil,
132
133
  forcedColors: nil,
133
134
  geolocation: nil,
134
135
  handleSIGHUP: nil,
@@ -164,7 +165,7 @@ module Playwright
164
165
  userAgent: nil,
165
166
  viewport: nil,
166
167
  &block)
167
- wrap_impl(@impl.launch_persistent_context(unwrap_impl(userDataDir), acceptDownloads: unwrap_impl(acceptDownloads), args: unwrap_impl(args), baseURL: unwrap_impl(baseURL), bypassCSP: unwrap_impl(bypassCSP), channel: unwrap_impl(channel), chromiumSandbox: unwrap_impl(chromiumSandbox), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), devtools: unwrap_impl(devtools), downloadsPath: unwrap_impl(downloadsPath), env: unwrap_impl(env), executablePath: unwrap_impl(executablePath), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), forcedColors: unwrap_impl(forcedColors), geolocation: unwrap_impl(geolocation), handleSIGHUP: unwrap_impl(handleSIGHUP), handleSIGINT: unwrap_impl(handleSIGINT), handleSIGTERM: unwrap_impl(handleSIGTERM), hasTouch: unwrap_impl(hasTouch), headless: unwrap_impl(headless), httpCredentials: unwrap_impl(httpCredentials), ignoreDefaultArgs: unwrap_impl(ignoreDefaultArgs), 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_content: unwrap_impl(record_har_content), record_har_mode: unwrap_impl(record_har_mode), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_har_url_filter: unwrap_impl(record_har_url_filter), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), serviceWorkers: unwrap_impl(serviceWorkers), slowMo: unwrap_impl(slowMo), strictSelectors: unwrap_impl(strictSelectors), timeout: unwrap_impl(timeout), timezoneId: unwrap_impl(timezoneId), tracesDir: unwrap_impl(tracesDir), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
168
+ wrap_impl(@impl.launch_persistent_context(unwrap_impl(userDataDir), acceptDownloads: unwrap_impl(acceptDownloads), args: unwrap_impl(args), baseURL: unwrap_impl(baseURL), bypassCSP: unwrap_impl(bypassCSP), channel: unwrap_impl(channel), chromiumSandbox: unwrap_impl(chromiumSandbox), colorScheme: unwrap_impl(colorScheme), deviceScaleFactor: unwrap_impl(deviceScaleFactor), devtools: unwrap_impl(devtools), downloadsPath: unwrap_impl(downloadsPath), env: unwrap_impl(env), executablePath: unwrap_impl(executablePath), extraHTTPHeaders: unwrap_impl(extraHTTPHeaders), firefoxUserPrefs: unwrap_impl(firefoxUserPrefs), forcedColors: unwrap_impl(forcedColors), geolocation: unwrap_impl(geolocation), handleSIGHUP: unwrap_impl(handleSIGHUP), handleSIGINT: unwrap_impl(handleSIGINT), handleSIGTERM: unwrap_impl(handleSIGTERM), hasTouch: unwrap_impl(hasTouch), headless: unwrap_impl(headless), httpCredentials: unwrap_impl(httpCredentials), ignoreDefaultArgs: unwrap_impl(ignoreDefaultArgs), 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_content: unwrap_impl(record_har_content), record_har_mode: unwrap_impl(record_har_mode), record_har_omit_content: unwrap_impl(record_har_omit_content), record_har_path: unwrap_impl(record_har_path), record_har_url_filter: unwrap_impl(record_har_url_filter), record_video_dir: unwrap_impl(record_video_dir), record_video_size: unwrap_impl(record_video_size), reducedMotion: unwrap_impl(reducedMotion), screen: unwrap_impl(screen), serviceWorkers: unwrap_impl(serviceWorkers), slowMo: unwrap_impl(slowMo), strictSelectors: unwrap_impl(strictSelectors), timeout: unwrap_impl(timeout), timezoneId: unwrap_impl(timezoneId), tracesDir: unwrap_impl(tracesDir), userAgent: unwrap_impl(userAgent), viewport: unwrap_impl(viewport), &wrap_block_call(block)))
168
169
  end
169
170
 
170
171
  #
@@ -45,8 +45,7 @@ module Playwright
45
45
  end
46
46
 
47
47
  #
48
- # Returns path to the downloaded file in case of successful download. The method will
49
- # wait for the download to finish if necessary. The method throws when connected remotely.
48
+ # Returns path to the downloaded file for a successful download, or throws for a failed/canceled download. The method will wait for the download to finish if necessary. The method throws when connected remotely.
50
49
  #
51
50
  # Note that the download's file name is a random GUID, use [`method: Download.suggestedFilename`]
52
51
  # to get suggested file name.
@@ -154,13 +154,16 @@ module Playwright
154
154
  #
155
155
  # Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial
156
156
  # properties:
157
+ # - [DeviceMotionEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent)
158
+ # - [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent)
157
159
  # - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
160
+ # - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
158
161
  # - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
159
162
  # - [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
160
163
  # - [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
161
164
  # - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
162
165
  # - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
163
- # - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
166
+ # - [WheelEvent](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent)
164
167
  #
165
168
  # You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
166
169
  #
@@ -149,13 +149,16 @@ module Playwright
149
149
  #
150
150
  # Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial
151
151
  # properties:
152
+ # - [DeviceMotionEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent)
153
+ # - [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent)
152
154
  # - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
155
+ # - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
153
156
  # - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
154
157
  # - [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
155
158
  # - [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
156
159
  # - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
157
160
  # - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
158
- # - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
161
+ # - [WheelEvent](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent)
159
162
  #
160
163
  # You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
161
164
  #
@@ -257,13 +257,16 @@ module Playwright
257
257
  #
258
258
  # Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial
259
259
  # properties:
260
+ # - [DeviceMotionEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent)
261
+ # - [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent)
260
262
  # - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
263
+ # - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
261
264
  # - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
262
265
  # - [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
263
266
  # - [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
264
267
  # - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
265
268
  # - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
266
- # - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
269
+ # - [WheelEvent](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent)
267
270
  #
268
271
  # You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
269
272
  #
@@ -301,6 +301,11 @@ module Playwright
301
301
  #
302
302
  # Ensures the `Locator` points to an element that contains the given text. You can use regular expressions for the value as well.
303
303
  #
304
+ # **Details**
305
+ #
306
+ # When `expected` parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and
307
+ # in the expected string before matching. When regular expression is used, the actual text is matched as is.
308
+ #
304
309
  # **Usage**
305
310
  #
306
311
  # ```python sync
@@ -360,8 +365,8 @@ module Playwright
360
365
  # locator = page.locator("input")
361
366
  # expect(locator).to_have_attribute("type", "text")
362
367
  # ```
363
- def to_have_attribute(name, value, timeout: nil)
364
- wrap_impl(@impl.to_have_attribute(unwrap_impl(name), unwrap_impl(value), timeout: unwrap_impl(timeout)))
368
+ def to_have_attribute(name, value, ignoreCase: nil, timeout: nil)
369
+ wrap_impl(@impl.to_have_attribute(unwrap_impl(name), unwrap_impl(value), ignoreCase: unwrap_impl(ignoreCase), timeout: unwrap_impl(timeout)))
365
370
  end
366
371
 
367
372
  #
@@ -458,6 +463,11 @@ module Playwright
458
463
  #
459
464
  # Ensures the `Locator` points to an element with the given text. You can use regular expressions for the value as well.
460
465
  #
466
+ # **Details**
467
+ #
468
+ # When `expected` parameter is a string, Playwright will normalize whitespaces and line breaks both in the actual text and
469
+ # in the expected string before matching. When regular expression is used, the actual text is matched as is.
470
+ #
461
471
  # **Usage**
462
472
  #
463
473
  # ```python sync
@@ -166,8 +166,8 @@ module Playwright
166
166
  #
167
167
  # **NOTE**: if `runBeforeUnload` is passed as true, a `beforeunload` dialog might be summoned and should be handled
168
168
  # manually via [`event: Page.dialog`] event.
169
- def close(runBeforeUnload: nil)
170
- wrap_impl(@impl.close(runBeforeUnload: unwrap_impl(runBeforeUnload)))
169
+ def close(reason: nil, runBeforeUnload: nil)
170
+ wrap_impl(@impl.close(reason: unwrap_impl(reason), runBeforeUnload: unwrap_impl(runBeforeUnload)))
171
171
  end
172
172
 
173
173
  #
@@ -225,13 +225,16 @@ module Playwright
225
225
  #
226
226
  # Since `eventInit` is event-specific, please refer to the events documentation for the lists of initial
227
227
  # properties:
228
+ # - [DeviceMotionEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceMotionEvent/DeviceMotionEvent)
229
+ # - [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent/DeviceOrientationEvent)
228
230
  # - [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent/DragEvent)
231
+ # - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
229
232
  # - [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/FocusEvent)
230
233
  # - [KeyboardEvent](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/KeyboardEvent)
231
234
  # - [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent)
232
235
  # - [PointerEvent](https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent/PointerEvent)
233
236
  # - [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent/TouchEvent)
234
- # - [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event/Event)
237
+ # - [WheelEvent](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent/WheelEvent)
235
238
  #
236
239
  # You can also specify `JSHandle` as the property value if you want live objects to be passed into the event:
237
240
  #
@@ -442,7 +445,7 @@ module Playwright
442
445
  #
443
446
  # def run(playwright: Playwright):
444
447
  # webkit = playwright.webkit
445
- # browser = webkit.launch(headless=false)
448
+ # browser = webkit.launch(headless=False)
446
449
  # context = browser.new_context()
447
450
  # page = context.new_page()
448
451
  # page.expose_binding("pageURL", lambda source: source["page"].url)
@@ -1671,13 +1674,13 @@ module Playwright
1671
1674
  end
1672
1675
 
1673
1676
  # @nodoc
1674
- def stop_css_coverage
1675
- wrap_impl(@impl.stop_css_coverage)
1677
+ def stop_js_coverage
1678
+ wrap_impl(@impl.stop_js_coverage)
1676
1679
  end
1677
1680
 
1678
1681
  # @nodoc
1679
- def stop_js_coverage
1680
- wrap_impl(@impl.stop_js_coverage)
1682
+ def start_js_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil)
1683
+ wrap_impl(@impl.start_js_coverage(resetOnNavigation: unwrap_impl(resetOnNavigation), reportAnonymousScripts: unwrap_impl(reportAnonymousScripts)))
1681
1684
  end
1682
1685
 
1683
1686
  # @nodoc
@@ -1685,6 +1688,11 @@ module Playwright
1685
1688
  wrap_impl(@impl.start_css_coverage(resetOnNavigation: unwrap_impl(resetOnNavigation), reportAnonymousScripts: unwrap_impl(reportAnonymousScripts)))
1686
1689
  end
1687
1690
 
1691
+ # @nodoc
1692
+ def stop_css_coverage
1693
+ wrap_impl(@impl.stop_css_coverage)
1694
+ end
1695
+
1688
1696
  # @nodoc
1689
1697
  def owned_context=(req)
1690
1698
  wrap_impl(@impl.owned_context=(unwrap_impl(req)))
@@ -1695,11 +1703,6 @@ module Playwright
1695
1703
  wrap_impl(@impl.guid)
1696
1704
  end
1697
1705
 
1698
- # @nodoc
1699
- def start_js_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil)
1700
- wrap_impl(@impl.start_js_coverage(resetOnNavigation: unwrap_impl(resetOnNavigation), reportAnonymousScripts: unwrap_impl(reportAnonymousScripts)))
1701
- end
1702
-
1703
1706
  # -- inherited from EventEmitter --
1704
1707
  # @nodoc
1705
1708
  def off(event, callback)
@@ -196,13 +196,13 @@ module Playwright
196
196
  end
197
197
 
198
198
  # @nodoc
199
- def apply_fallback_overrides(overrides)
200
- wrap_impl(@impl.apply_fallback_overrides(unwrap_impl(overrides)))
199
+ def header_values(name)
200
+ wrap_impl(@impl.header_values(unwrap_impl(name)))
201
201
  end
202
202
 
203
203
  # @nodoc
204
- def header_values(name)
205
- wrap_impl(@impl.header_values(unwrap_impl(name)))
204
+ def apply_fallback_overrides(overrides)
205
+ wrap_impl(@impl.apply_fallback_overrides(unwrap_impl(overrides)))
206
206
  end
207
207
 
208
208
  # -- inherited from EventEmitter --
@@ -47,13 +47,13 @@ module Playwright
47
47
  end
48
48
 
49
49
  # @nodoc
50
- def context=(req)
51
- wrap_impl(@impl.context=(unwrap_impl(req)))
50
+ def page=(req)
51
+ wrap_impl(@impl.page=(unwrap_impl(req)))
52
52
  end
53
53
 
54
54
  # @nodoc
55
- def page=(req)
56
- wrap_impl(@impl.page=(unwrap_impl(req)))
55
+ def context=(req)
56
+ wrap_impl(@impl.context=(unwrap_impl(req)))
57
57
  end
58
58
 
59
59
  # -- inherited from EventEmitter --
data/sig/playwright.rbs CHANGED
@@ -242,7 +242,7 @@ module Playwright
242
242
  def delete: -> void
243
243
  def failure: -> (nil | String)
244
244
  def page: -> Page
245
- def path: -> (nil | (String | File))
245
+ def path: -> (String | File)
246
246
  def save_as: ((String | File) path) -> void
247
247
  def suggested_filename: -> String
248
248
  def url: -> String
@@ -255,7 +255,7 @@ module Playwright
255
255
  def bring_to_front: -> void
256
256
  def check: (String selector, ?force: bool, ?noWaitAfter: bool, ?position: Hash[untyped, untyped], ?strict: bool, ?timeout: Float, ?trial: bool) -> void
257
257
  def click: (String selector, ?button: ("left" | "right" | "middle"), ?clickCount: Integer, ?delay: Float, ?force: bool, ?modifiers: Array[untyped], ?noWaitAfter: bool, ?position: Hash[untyped, untyped], ?strict: bool, ?timeout: Float, ?trial: bool) -> void
258
- def close: (?runBeforeUnload: bool) -> void
258
+ def close: (?reason: String, ?runBeforeUnload: bool) -> void
259
259
  def content: -> String
260
260
  def context: -> BrowserContext
261
261
  def dblclick: (String selector, ?button: ("left" | "right" | "middle"), ?delay: Float, ?force: bool, ?modifiers: Array[untyped], ?noWaitAfter: bool, ?position: Hash[untyped, untyped], ?strict: bool, ?timeout: Float, ?trial: bool) -> void
@@ -361,7 +361,7 @@ module Playwright
361
361
  def browser: -> (nil | Browser)
362
362
  def clear_cookies: -> void
363
363
  def clear_permissions: -> void
364
- def close: -> void
364
+ def close: (?reason: String) -> void
365
365
  def cookies: (?urls: (String | Array[untyped])) -> Array[untyped]
366
366
  def expose_binding: (String name, function callback, ?handle: bool) -> void
367
367
  def expose_function: (String name, function callback) -> void
@@ -399,7 +399,7 @@ module Playwright
399
399
 
400
400
  class Browser
401
401
  def browser_type: -> BrowserType
402
- def close: -> void
402
+ def close: (?reason: String) -> void
403
403
  def contexts: -> Array[untyped]
404
404
  def connected?: -> bool
405
405
  def new_browser_cdp_session: -> CDPSession
@@ -414,7 +414,7 @@ module Playwright
414
414
  def connect_over_cdp: (String endpointURL, ?headers: Hash[untyped, untyped], ?slowMo: Float, ?timeout: Float) ?{ (untyped) -> untyped } -> Browser
415
415
  def executable_path: -> String
416
416
  def launch: (?args: Array[untyped], ?channel: String, ?chromiumSandbox: bool, ?devtools: bool, ?downloadsPath: (String | File), ?env: Hash[untyped, untyped], ?executablePath: (String | File), ?firefoxUserPrefs: Hash[untyped, untyped], ?handleSIGHUP: bool, ?handleSIGINT: bool, ?handleSIGTERM: bool, ?headless: bool, ?ignoreDefaultArgs: (bool | Array[untyped]), ?proxy: Hash[untyped, untyped], ?slowMo: Float, ?timeout: Float, ?tracesDir: (String | File)) ?{ (Browser) -> untyped } -> Browser
417
- def launch_persistent_context: ((String | File) userDataDir, ?acceptDownloads: bool, ?args: Array[untyped], ?baseURL: String, ?bypassCSP: bool, ?channel: String, ?chromiumSandbox: bool, ?colorScheme: ("light" | "dark" | "no-preference" | "null"), ?deviceScaleFactor: Float, ?devtools: bool, ?downloadsPath: (String | File), ?env: Hash[untyped, untyped], ?executablePath: (String | File), ?extraHTTPHeaders: Hash[untyped, untyped], ?forcedColors: ("active" | "none" | "null"), ?geolocation: Hash[untyped, untyped], ?handleSIGHUP: bool, ?handleSIGINT: bool, ?handleSIGTERM: bool, ?hasTouch: bool, ?headless: bool, ?httpCredentials: Hash[untyped, untyped], ?ignoreDefaultArgs: (bool | Array[untyped]), ?ignoreHTTPSErrors: bool, ?isMobile: bool, ?javaScriptEnabled: bool, ?locale: String, ?noViewport: bool, ?offline: bool, ?permissions: Array[untyped], ?proxy: Hash[untyped, untyped], ?record_har_content: ("omit" | "embed" | "attach"), ?record_har_mode: ("full" | "minimal"), ?record_har_omit_content: bool, ?record_har_path: (String | File), ?record_har_url_filter: (String | Regexp), ?record_video_dir: (String | File), ?record_video_size: Hash[untyped, untyped], ?reducedMotion: ("reduce" | "no-preference" | "null"), ?screen: Hash[untyped, untyped], ?serviceWorkers: ("allow" | "block"), ?slowMo: Float, ?strictSelectors: bool, ?timeout: Float, ?timezoneId: String, ?tracesDir: (String | File), ?userAgent: String, ?viewport: (nil | Hash[untyped, untyped])) ?{ (untyped) -> untyped } -> BrowserContext
417
+ def launch_persistent_context: ((String | File) userDataDir, ?acceptDownloads: bool, ?args: Array[untyped], ?baseURL: String, ?bypassCSP: bool, ?channel: String, ?chromiumSandbox: bool, ?colorScheme: ("light" | "dark" | "no-preference" | "null"), ?deviceScaleFactor: Float, ?devtools: bool, ?downloadsPath: (String | File), ?env: Hash[untyped, untyped], ?executablePath: (String | File), ?extraHTTPHeaders: Hash[untyped, untyped], ?firefoxUserPrefs: Hash[untyped, untyped], ?forcedColors: ("active" | "none" | "null"), ?geolocation: Hash[untyped, untyped], ?handleSIGHUP: bool, ?handleSIGINT: bool, ?handleSIGTERM: bool, ?hasTouch: bool, ?headless: bool, ?httpCredentials: Hash[untyped, untyped], ?ignoreDefaultArgs: (bool | Array[untyped]), ?ignoreHTTPSErrors: bool, ?isMobile: bool, ?javaScriptEnabled: bool, ?locale: String, ?noViewport: bool, ?offline: bool, ?permissions: Array[untyped], ?proxy: Hash[untyped, untyped], ?record_har_content: ("omit" | "embed" | "attach"), ?record_har_mode: ("full" | "minimal"), ?record_har_omit_content: bool, ?record_har_path: (String | File), ?record_har_url_filter: (String | Regexp), ?record_video_dir: (String | File), ?record_video_size: Hash[untyped, untyped], ?reducedMotion: ("reduce" | "no-preference" | "null"), ?screen: Hash[untyped, untyped], ?serviceWorkers: ("allow" | "block"), ?slowMo: Float, ?strictSelectors: bool, ?timeout: Float, ?timezoneId: String, ?tracesDir: (String | File), ?userAgent: String, ?viewport: (nil | Hash[untyped, untyped])) ?{ (untyped) -> untyped } -> BrowserContext
418
418
  def name: -> String
419
419
  end
420
420
 
@@ -570,7 +570,7 @@ module Playwright
570
570
  def to_be_in_viewport: (?ratio: Float, ?timeout: Float) -> void
571
571
  def to_be_visible: (?timeout: Float, ?visible: bool) -> void
572
572
  def to_contain_text: ((String | Regexp | Array[untyped] | Array[untyped] | Array[untyped]) expected, ?ignoreCase: bool, ?timeout: Float, ?useInnerText: bool) -> void
573
- def to_have_attribute: (String name, (String | Regexp) value, ?timeout: Float) -> void
573
+ def to_have_attribute: (String name, (String | Regexp) value, ?ignoreCase: bool, ?timeout: Float) -> void
574
574
  def to_have_class: ((String | Regexp | Array[untyped] | Array[untyped] | Array[untyped]) expected, ?timeout: Float) -> void
575
575
  def to_have_count: (Integer count, ?timeout: Float) -> void
576
576
  def to_have_css: (String name, (String | Regexp) value, ?timeout: Float) -> void
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: playwright-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.39.1
4
+ version: 1.40.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - YusukeIwaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-05 00:00:00.000000000 Z
11
+ date: 2023-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -255,6 +255,7 @@ files:
255
255
  - documentation/docs/article/guides/rails_integration.md
256
256
  - documentation/docs/article/guides/rails_integration_with_null_driver.md
257
257
  - documentation/docs/article/guides/recording_video.md
258
+ - documentation/docs/article/guides/rspec_integration.md
258
259
  - documentation/docs/article/guides/semi_automation.md
259
260
  - documentation/docs/article/guides/use_storage_state.md
260
261
  - documentation/docs/include/api_coverage.md
@@ -343,7 +344,7 @@ files:
343
344
  - lib/playwright/utils.rb
344
345
  - lib/playwright/version.rb
345
346
  - lib/playwright/video.rb
346
- - lib/playwright/wait_helper.rb
347
+ - lib/playwright/waiter.rb
347
348
  - lib/playwright/web_socket_client.rb
348
349
  - lib/playwright/web_socket_transport.rb
349
350
  - lib/playwright_api/accessibility.rb
@@ -405,5 +406,5 @@ requirements: []
405
406
  rubygems_version: 3.3.26
406
407
  signing_key:
407
408
  specification_version: 4
408
- summary: The Ruby binding of playwright driver 1.39.0
409
+ summary: The Ruby binding of playwright driver 1.40.1
409
410
  test_files: []
@@ -1,73 +0,0 @@
1
- module Playwright
2
- # ref: https://github.com/microsoft/playwright-python/blob/30946ae3099d51f9b7f355f9ae7e8c04d748ce36/playwright/_impl/_wait_helper.py
3
- # ref: https://github.com/microsoft/playwright/blob/01fb3a6045cbdb4b5bcba0809faed85bd917ab87/src/client/waiter.ts#L21
4
- class WaitHelper
5
- def initialize
6
- @promise = Concurrent::Promises.resolvable_future
7
- @registered_listeners = Set.new
8
- end
9
-
10
- def reject_on_event(emitter, event, error, predicate: nil)
11
- listener = -> (*args) {
12
- if !predicate || predicate.call(*args)
13
- reject(error)
14
- end
15
- }
16
- emitter.on(event, listener)
17
- @registered_listeners << [emitter, event, listener]
18
-
19
- self
20
- end
21
-
22
- def reject_on_timeout(timeout_ms, message)
23
- return if timeout_ms <= 0
24
-
25
- Concurrent::Promises.schedule(timeout_ms / 1000.0) do
26
- reject(TimeoutError.new(message: message))
27
- end
28
-
29
- self
30
- end
31
-
32
- # @param [Playwright::EventEmitter]
33
- # @param
34
- def wait_for_event(emitter, event, predicate: nil)
35
- listener = -> (*args) {
36
- begin
37
- if !predicate || predicate.call(*args)
38
- fulfill(*args)
39
- end
40
- rescue => err
41
- reject(err)
42
- end
43
- }
44
- emitter.on(event, listener)
45
- @registered_listeners << [emitter, event, listener]
46
-
47
- self
48
- end
49
-
50
- attr_reader :promise
51
-
52
- private def cleanup
53
- @registered_listeners.each do |emitter, event, listener|
54
- emitter.off(event, listener)
55
- end
56
- @registered_listeners.clear
57
- end
58
-
59
- private def fulfill(*args)
60
- cleanup
61
- unless @promise.resolved?
62
- @promise.fulfill(args.first)
63
- end
64
- end
65
-
66
- private def reject(error)
67
- cleanup
68
- unless @promise.resolved?
69
- @promise.reject(error)
70
- end
71
- end
72
- end
73
- end