playwright-ruby-client 0.0.7 → 0.2.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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +38 -3
  3. data/docs/api_coverage.md +89 -84
  4. data/lib/playwright.rb +4 -2
  5. data/lib/playwright/android_input_impl.rb +23 -0
  6. data/lib/playwright/api_implementation.rb +18 -0
  7. data/lib/playwright/channel.rb +7 -0
  8. data/lib/playwright/channel_owner.rb +3 -5
  9. data/lib/playwright/channel_owners/android.rb +1 -1
  10. data/lib/playwright/channel_owners/android_device.rb +83 -13
  11. data/lib/playwright/channel_owners/browser.rb +1 -1
  12. data/lib/playwright/channel_owners/browser_context.rb +10 -2
  13. data/lib/playwright/channel_owners/download.rb +27 -0
  14. data/lib/playwright/channel_owners/element_handle.rb +15 -4
  15. data/lib/playwright/channel_owners/frame.rb +228 -19
  16. data/lib/playwright/channel_owners/js_handle.rb +1 -1
  17. data/lib/playwright/channel_owners/page.rb +350 -27
  18. data/lib/playwright/channel_owners/request.rb +9 -1
  19. data/lib/playwright/errors.rb +1 -1
  20. data/lib/playwright/event_emitter.rb +8 -1
  21. data/lib/playwright/event_emitter_proxy.rb +49 -0
  22. data/lib/playwright/file_chooser_impl.rb +23 -0
  23. data/lib/playwright/http_headers.rb +20 -0
  24. data/lib/playwright/input_files.rb +1 -1
  25. data/lib/playwright/javascript/expression.rb +15 -0
  26. data/lib/playwright/javascript/function.rb +15 -0
  27. data/lib/playwright/javascript/value_parser.rb +1 -1
  28. data/lib/playwright/javascript/value_serializer.rb +1 -1
  29. data/lib/playwright/{input_types/keyboard.rb → keyboard_impl.rb} +5 -1
  30. data/lib/playwright/mouse_impl.rb +7 -0
  31. data/lib/playwright/playwright_api.rb +59 -20
  32. data/lib/playwright/select_option_values.rb +14 -4
  33. data/lib/playwright/timeout_settings.rb +1 -1
  34. data/lib/playwright/touchscreen_impl.rb +7 -0
  35. data/lib/playwright/utils.rb +3 -3
  36. data/lib/playwright/version.rb +1 -1
  37. data/lib/playwright/wait_helper.rb +1 -1
  38. data/lib/playwright_api/android.rb +9 -10
  39. data/lib/playwright_api/android_device.rb +43 -14
  40. data/lib/playwright_api/android_input.rb +25 -0
  41. data/lib/playwright_api/binding_call.rb +10 -6
  42. data/lib/playwright_api/browser.rb +20 -21
  43. data/lib/playwright_api/browser_context.rb +29 -20
  44. data/lib/playwright_api/browser_type.rb +16 -56
  45. data/lib/playwright_api/chromium_browser_context.rb +10 -8
  46. data/lib/playwright_api/console_message.rb +10 -6
  47. data/lib/playwright_api/dialog.rb +5 -1
  48. data/lib/playwright_api/download.rb +28 -11
  49. data/lib/playwright_api/element_handle.rb +107 -96
  50. data/lib/playwright_api/file_chooser.rb +17 -9
  51. data/lib/playwright_api/frame.rb +136 -132
  52. data/lib/playwright_api/js_handle.rb +18 -20
  53. data/lib/playwright_api/keyboard.rb +5 -5
  54. data/lib/playwright_api/page.rb +204 -149
  55. data/lib/playwright_api/playwright.rb +32 -44
  56. data/lib/playwright_api/request.rb +7 -8
  57. data/lib/playwright_api/response.rb +10 -6
  58. data/lib/playwright_api/selectors.rb +13 -9
  59. data/lib/playwright_api/web_socket.rb +10 -1
  60. data/lib/playwright_api/worker.rb +13 -13
  61. metadata +12 -6
  62. data/lib/playwright/input_type.rb +0 -19
  63. data/lib/playwright/input_types/mouse.rb +0 -4
  64. data/lib/playwright/input_types/touchscreen.rb +0 -4
@@ -113,49 +113,13 @@ module Playwright
113
113
  wrap_impl(@impl.devices)
114
114
  end
115
115
 
116
- # Playwright methods might throw errors if they are unable to fulfill a request. For example,
117
- # [`method: Page.waitForSelector`] might fail if the selector doesn't match any nodes during the given timeframe.
118
- #
119
- # For certain types of errors Playwright uses specific error classes. These classes are available via
120
- # [`playwright.errors`](#playwrighterrors).
121
- #
122
- # An example of handling a timeout error:
123
- #
124
- #
125
- # ```js
126
- # try {
127
- # await page.waitForSelector('.foo');
128
- # } catch (e) {
129
- # if (e instanceof playwright.errors.TimeoutError) {
130
- # // Do something if this is a timeout.
131
- # }
132
- # }
133
- # ```
134
- #
135
- # ```python async
136
- # try:
137
- # await page.wait_for_selector(".foo")
138
- # except TimeoutError as e:
139
- # # do something if this is a timeout.
140
- # ```
141
- #
142
- # ```python sync
143
- # try:
144
- # page.wait_for_selector(".foo")
145
- # except TimeoutError as e:
146
- # # do something if this is a timeout.
147
- # ```
148
- def errors # property
149
- raise NotImplementedError.new('errors is not implemented yet.')
150
- end
151
-
152
116
  # This object can be used to launch or connect to Firefox, returning instances of `FirefoxBrowser`.
153
117
  def firefox # property
154
118
  wrap_impl(@impl.firefox)
155
119
  end
156
120
 
157
- # Selectors can be used to install custom selector engines. See
158
- # [Working with selectors](./selectors.md#working-with-selectors) for more information.
121
+ # Selectors can be used to install custom selector engines. See [Working with selectors](./selectors.md) for more
122
+ # information.
159
123
  def selectors # property
160
124
  raise NotImplementedError.new('selectors is not implemented yet.')
161
125
  end
@@ -165,6 +129,26 @@ module Playwright
165
129
  wrap_impl(@impl.webkit)
166
130
  end
167
131
 
132
+ # Terminates this instance of Playwright in case it was created bypassing the Python context manager. This is useful in
133
+ # REPL applications.
134
+ #
135
+ # ```py
136
+ # >>> from playwright.sync_api import sync_playwright
137
+ #
138
+ # >>> playwright = sync_playwright().start()
139
+ #
140
+ # >>> browser = playwright.chromium.launch()
141
+ # >>> page = browser.new_page()
142
+ # >>> page.goto("http://whatsmyuseragent.org/")
143
+ # >>> page.screenshot(path="example.png")
144
+ # >>> browser.close()
145
+ #
146
+ # >>> playwright.stop()
147
+ # ```
148
+ def stop
149
+ raise NotImplementedError.new('stop is not implemented yet.')
150
+ end
151
+
168
152
  # @nodoc
169
153
  def android
170
154
  wrap_impl(@impl.android)
@@ -177,20 +161,24 @@ module Playwright
177
161
 
178
162
  # -- inherited from EventEmitter --
179
163
  # @nodoc
180
- def on(event, callback)
181
- wrap_impl(@impl.on(unwrap_impl(event), unwrap_impl(callback)))
164
+ def once(event, callback)
165
+ event_emitter_proxy.once(event, callback)
182
166
  end
183
167
 
184
168
  # -- inherited from EventEmitter --
185
169
  # @nodoc
186
- def off(event, callback)
187
- wrap_impl(@impl.off(unwrap_impl(event), unwrap_impl(callback)))
170
+ def on(event, callback)
171
+ event_emitter_proxy.on(event, callback)
188
172
  end
189
173
 
190
174
  # -- inherited from EventEmitter --
191
175
  # @nodoc
192
- def once(event, callback)
193
- wrap_impl(@impl.once(unwrap_impl(event), unwrap_impl(callback)))
176
+ def off(event, callback)
177
+ event_emitter_proxy.off(event, callback)
178
+ end
179
+
180
+ private def event_emitter_proxy
181
+ @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
194
182
  end
195
183
  end
196
184
  end
@@ -178,27 +178,26 @@ module Playwright
178
178
  wrap_impl(@impl.url)
179
179
  end
180
180
 
181
+ # -- inherited from EventEmitter --
181
182
  # @nodoc
182
- def after_initialize
183
- wrap_impl(@impl.after_initialize)
183
+ def once(event, callback)
184
+ event_emitter_proxy.once(event, callback)
184
185
  end
185
186
 
186
187
  # -- inherited from EventEmitter --
187
188
  # @nodoc
188
189
  def on(event, callback)
189
- wrap_impl(@impl.on(unwrap_impl(event), unwrap_impl(callback)))
190
+ event_emitter_proxy.on(event, callback)
190
191
  end
191
192
 
192
193
  # -- inherited from EventEmitter --
193
194
  # @nodoc
194
195
  def off(event, callback)
195
- wrap_impl(@impl.off(unwrap_impl(event), unwrap_impl(callback)))
196
+ event_emitter_proxy.off(event, callback)
196
197
  end
197
198
 
198
- # -- inherited from EventEmitter --
199
- # @nodoc
200
- def once(event, callback)
201
- wrap_impl(@impl.once(unwrap_impl(event), unwrap_impl(callback)))
199
+ private def event_emitter_proxy
200
+ @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
202
201
  end
203
202
  end
204
203
  end
@@ -61,20 +61,24 @@ module Playwright
61
61
 
62
62
  # -- inherited from EventEmitter --
63
63
  # @nodoc
64
- def on(event, callback)
65
- wrap_impl(@impl.on(unwrap_impl(event), unwrap_impl(callback)))
64
+ def once(event, callback)
65
+ event_emitter_proxy.once(event, callback)
66
66
  end
67
67
 
68
68
  # -- inherited from EventEmitter --
69
69
  # @nodoc
70
- def off(event, callback)
71
- wrap_impl(@impl.off(unwrap_impl(event), unwrap_impl(callback)))
70
+ def on(event, callback)
71
+ event_emitter_proxy.on(event, callback)
72
72
  end
73
73
 
74
74
  # -- inherited from EventEmitter --
75
75
  # @nodoc
76
- def once(event, callback)
77
- wrap_impl(@impl.once(unwrap_impl(event), unwrap_impl(callback)))
76
+ def off(event, callback)
77
+ event_emitter_proxy.off(event, callback)
78
+ end
79
+
80
+ private def event_emitter_proxy
81
+ @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
78
82
  end
79
83
  end
80
84
  end
@@ -1,6 +1,6 @@
1
1
  module Playwright
2
- # Selectors can be used to install custom selector engines. See
3
- # [Working with selectors](./selectors.md#working-with-selectors) for more information.
2
+ # Selectors can be used to install custom selector engines. See [Working with selectors](./selectors.md) for more
3
+ # information.
4
4
  class Selectors < PlaywrightApi
5
5
 
6
6
  # An example of registering selector engine that queries elements based on a tag name:
@@ -48,26 +48,30 @@ module Playwright
48
48
  # ```python sync
49
49
  # # FIXME: add snippet
50
50
  # ```
51
- def register(name, script, contentScript: nil)
51
+ def register(name, contentScript: nil, path: nil, script: nil)
52
52
  raise NotImplementedError.new('register is not implemented yet.')
53
53
  end
54
54
 
55
55
  # -- inherited from EventEmitter --
56
56
  # @nodoc
57
- def on(event, callback)
58
- wrap_impl(@impl.on(unwrap_impl(event), unwrap_impl(callback)))
57
+ def once(event, callback)
58
+ event_emitter_proxy.once(event, callback)
59
59
  end
60
60
 
61
61
  # -- inherited from EventEmitter --
62
62
  # @nodoc
63
- def off(event, callback)
64
- wrap_impl(@impl.off(unwrap_impl(event), unwrap_impl(callback)))
63
+ def on(event, callback)
64
+ event_emitter_proxy.on(event, callback)
65
65
  end
66
66
 
67
67
  # -- inherited from EventEmitter --
68
68
  # @nodoc
69
- def once(event, callback)
70
- wrap_impl(@impl.once(unwrap_impl(event), unwrap_impl(callback)))
69
+ def off(event, callback)
70
+ event_emitter_proxy.off(event, callback)
71
+ end
72
+
73
+ private def event_emitter_proxy
74
+ @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
71
75
  end
72
76
  end
73
77
  end
@@ -14,8 +14,17 @@ module Playwright
14
14
 
15
15
  # Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
16
16
  # value. Will throw an error if the webSocket is closed before the event is fired. Returns the event data value.
17
- def expect_event(event, optionsOrPredicate: nil)
17
+ def expect_event(event, predicate: nil, timeout: nil)
18
18
  raise NotImplementedError.new('expect_event is not implemented yet.')
19
19
  end
20
+
21
+ # > NOTE: In most cases, you should use [`method: WebSocket.waitForEvent`].
22
+ #
23
+ # Waits for given `event` to fire. If predicate is provided, it passes event's value into the `predicate` function and
24
+ # waits for `predicate(event)` to return a truthy value. Will throw an error if the socket is closed before the `event` is
25
+ # fired.
26
+ def wait_for_event(event, predicate: nil, timeout: nil)
27
+ raise NotImplementedError.new('wait_for_event is not implemented yet.')
28
+ end
20
29
  end
21
30
  end
@@ -28,26 +28,26 @@ module Playwright
28
28
  # ```
29
29
  class Worker < PlaywrightApi
30
30
 
31
- # Returns the return value of `pageFunction`
31
+ # Returns the return value of `expression`.
32
32
  #
33
- # If the function passed to the `worker.evaluate` returns a [Promise], then `worker.evaluate` would wait for the promise
34
- # to resolve and return its value.
33
+ # If the function passed to the [`method: Worker.evaluate`] returns a [Promise], then [`method: Worker.evaluate`] would
34
+ # wait for the promise to resolve and return its value.
35
35
  #
36
- # If the function passed to the `worker.evaluate` returns a non-[Serializable] value, then `worker.evaluate` returns
37
- # `undefined`. DevTools Protocol also supports transferring some additional values that are not serializable by `JSON`:
38
- # `-0`, `NaN`, `Infinity`, `-Infinity`, and bigint literals.
39
- def evaluate(pageFunction, arg: nil)
36
+ # If the function passed to the [`method: Worker.evaluate`] returns a non-[Serializable] value, then
37
+ # [`method: Worker.evaluate`] returns `undefined`. Playwright also supports transferring some additional values that are
38
+ # not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`.
39
+ def evaluate(expression, arg: nil)
40
40
  raise NotImplementedError.new('evaluate is not implemented yet.')
41
41
  end
42
42
 
43
- # Returns the return value of `pageFunction` as in-page object (JSHandle).
43
+ # Returns the return value of `expression` as a `JSHandle`.
44
44
  #
45
- # The only difference between `worker.evaluate` and `worker.evaluateHandle` is that `worker.evaluateHandle` returns
46
- # in-page object (JSHandle).
45
+ # The only difference between [`method: Worker.evaluate`] and [`method: Worker.evaluateHandle`] is that
46
+ # [`method: Worker.evaluateHandle`] returns `JSHandle`.
47
47
  #
48
- # If the function passed to the `worker.evaluateHandle` returns a [Promise], then `worker.evaluateHandle` would wait for
49
- # the promise to resolve and return its value.
50
- def evaluate_handle(pageFunction, arg: nil)
48
+ # If the function passed to the [`method: Worker.evaluateHandle`] returns a [Promise], then
49
+ # [`method: Worker.evaluateHandle`] would wait for the promise to resolve and return its value.
50
+ def evaluate_handle(expression, arg: nil)
51
51
  raise NotImplementedError.new('evaluate_handle is not implemented yet.')
52
52
  end
53
53
 
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: 0.0.7
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - YusukeIwaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-02-07 00:00:00.000000000 Z
11
+ date: 2021-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -181,6 +181,8 @@ files:
181
181
  - bin/setup
182
182
  - docs/api_coverage.md
183
183
  - lib/playwright.rb
184
+ - lib/playwright/android_input_impl.rb
185
+ - lib/playwright/api_implementation.rb
184
186
  - lib/playwright/channel.rb
185
187
  - lib/playwright/channel_owner.rb
186
188
  - lib/playwright/channel_owners/android.rb
@@ -192,6 +194,7 @@ files:
192
194
  - lib/playwright/channel_owners/chromium_browser.rb
193
195
  - lib/playwright/channel_owners/chromium_browser_context.rb
194
196
  - lib/playwright/channel_owners/console_message.rb
197
+ - lib/playwright/channel_owners/download.rb
195
198
  - lib/playwright/channel_owners/electron.rb
196
199
  - lib/playwright/channel_owners/element_handle.rb
197
200
  - lib/playwright/channel_owners/firefox_browser.rb
@@ -206,20 +209,22 @@ files:
206
209
  - lib/playwright/connection.rb
207
210
  - lib/playwright/errors.rb
208
211
  - lib/playwright/event_emitter.rb
212
+ - lib/playwright/event_emitter_proxy.rb
209
213
  - lib/playwright/events.rb
214
+ - lib/playwright/file_chooser_impl.rb
215
+ - lib/playwright/http_headers.rb
210
216
  - lib/playwright/input_files.rb
211
- - lib/playwright/input_type.rb
212
- - lib/playwright/input_types/keyboard.rb
213
- - lib/playwright/input_types/mouse.rb
214
- - lib/playwright/input_types/touchscreen.rb
215
217
  - lib/playwright/javascript.rb
216
218
  - lib/playwright/javascript/expression.rb
217
219
  - lib/playwright/javascript/function.rb
218
220
  - lib/playwright/javascript/value_parser.rb
219
221
  - lib/playwright/javascript/value_serializer.rb
222
+ - lib/playwright/keyboard_impl.rb
223
+ - lib/playwright/mouse_impl.rb
220
224
  - lib/playwright/playwright_api.rb
221
225
  - lib/playwright/select_option_values.rb
222
226
  - lib/playwright/timeout_settings.rb
227
+ - lib/playwright/touchscreen_impl.rb
223
228
  - lib/playwright/transport.rb
224
229
  - lib/playwright/url_matcher.rb
225
230
  - lib/playwright/utils.rb
@@ -228,6 +233,7 @@ files:
228
233
  - lib/playwright_api/accessibility.rb
229
234
  - lib/playwright_api/android.rb
230
235
  - lib/playwright_api/android_device.rb
236
+ - lib/playwright_api/android_input.rb
231
237
  - lib/playwright_api/binding_call.rb
232
238
  - lib/playwright_api/browser.rb
233
239
  - lib/playwright_api/browser_context.rb
@@ -1,19 +0,0 @@
1
- module Playwright
2
- class InputType
3
- def initialize(channel)
4
- @channel = channel
5
- end
6
- end
7
-
8
- # namespace declaration
9
- module InputTypes ; end
10
-
11
- def self.define_input_type(class_name, &block)
12
- klass = Class.new(InputType)
13
- klass.class_eval(&block) if block
14
- InputTypes.const_set(class_name, klass)
15
- end
16
- end
17
-
18
- # load subclasses
19
- Dir[File.join(__dir__, 'input_types', '*.rb')].each { |f| require f }
@@ -1,4 +0,0 @@
1
- module Playwright
2
- define_input_type :Mouse do
3
- end
4
- end
@@ -1,4 +0,0 @@
1
- module Playwright
2
- define_input_type :Touchscreen do
3
- end
4
- end