playwright-ruby-client 0.0.6 → 0.2.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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +117 -5
  3. data/docs/api_coverage.md +359 -0
  4. data/lib/playwright.rb +6 -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 +6 -7
  9. data/lib/playwright/channel_owners/android.rb +10 -1
  10. data/lib/playwright/channel_owners/android_device.rb +163 -0
  11. data/lib/playwright/channel_owners/browser.rb +14 -14
  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 +243 -1
  15. data/lib/playwright/channel_owners/frame.rb +269 -22
  16. data/lib/playwright/channel_owners/js_handle.rb +51 -0
  17. data/lib/playwright/channel_owners/page.rb +379 -34
  18. data/lib/playwright/channel_owners/request.rb +9 -1
  19. data/lib/playwright/channel_owners/webkit_browser.rb +1 -1
  20. data/lib/playwright/connection.rb +9 -6
  21. data/lib/playwright/errors.rb +2 -2
  22. data/lib/playwright/event_emitter.rb +8 -1
  23. data/lib/playwright/event_emitter_proxy.rb +49 -0
  24. data/lib/playwright/file_chooser_impl.rb +23 -0
  25. data/lib/playwright/http_headers.rb +20 -0
  26. data/lib/playwright/input_files.rb +42 -0
  27. data/lib/playwright/javascript/expression.rb +15 -0
  28. data/lib/playwright/javascript/function.rb +15 -0
  29. data/lib/playwright/javascript/value_parser.rb +1 -1
  30. data/lib/playwright/javascript/value_serializer.rb +11 -11
  31. data/lib/playwright/{input_types/keyboard.rb → keyboard_impl.rb} +6 -2
  32. data/lib/playwright/mouse_impl.rb +7 -0
  33. data/lib/playwright/playwright_api.rb +66 -19
  34. data/lib/playwright/select_option_values.rb +42 -0
  35. data/lib/playwright/timeout_settings.rb +1 -1
  36. data/lib/playwright/touchscreen_impl.rb +7 -0
  37. data/lib/playwright/utils.rb +18 -0
  38. data/lib/playwright/version.rb +1 -1
  39. data/lib/playwright/wait_helper.rb +1 -1
  40. data/lib/playwright_api/android.rb +32 -0
  41. data/lib/playwright_api/android_device.rb +77 -0
  42. data/lib/playwright_api/android_input.rb +25 -0
  43. data/lib/playwright_api/binding_call.rb +10 -6
  44. data/lib/playwright_api/browser.rb +22 -22
  45. data/lib/playwright_api/browser_context.rb +31 -22
  46. data/lib/playwright_api/browser_type.rb +16 -56
  47. data/lib/playwright_api/chromium_browser_context.rb +10 -8
  48. data/lib/playwright_api/console_message.rb +9 -10
  49. data/lib/playwright_api/dialog.rb +7 -3
  50. data/lib/playwright_api/download.rb +28 -11
  51. data/lib/playwright_api/element_handle.rb +139 -127
  52. data/lib/playwright_api/file_chooser.rb +17 -9
  53. data/lib/playwright_api/frame.rb +148 -148
  54. data/lib/playwright_api/js_handle.rb +26 -22
  55. data/lib/playwright_api/keyboard.rb +6 -6
  56. data/lib/playwright_api/page.rb +215 -179
  57. data/lib/playwright_api/playwright.rb +34 -46
  58. data/lib/playwright_api/request.rb +7 -8
  59. data/lib/playwright_api/response.rb +10 -6
  60. data/lib/playwright_api/selectors.rb +13 -9
  61. data/lib/playwright_api/web_socket.rb +10 -1
  62. data/lib/playwright_api/worker.rb +13 -13
  63. data/playwright.gemspec +1 -0
  64. metadata +32 -6
  65. data/lib/playwright/input_type.rb +0 -19
  66. data/lib/playwright/input_types/mouse.rb +0 -4
  67. 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,32 +129,56 @@ 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
+
152
+ # @nodoc
153
+ def android
154
+ wrap_impl(@impl.android)
155
+ end
156
+
168
157
  # @nodoc
169
158
  def electron
170
159
  wrap_impl(@impl.electron)
171
160
  end
172
161
 
162
+ # -- inherited from EventEmitter --
173
163
  # @nodoc
174
- def android
175
- wrap_impl(@impl.android)
164
+ def once(event, callback)
165
+ event_emitter_proxy.once(event, callback)
176
166
  end
177
167
 
178
168
  # -- inherited from EventEmitter --
179
169
  # @nodoc
180
170
  def on(event, callback)
181
- wrap_impl(@impl.on(event, callback))
171
+ event_emitter_proxy.on(event, callback)
182
172
  end
183
173
 
184
174
  # -- inherited from EventEmitter --
185
175
  # @nodoc
186
176
  def off(event, callback)
187
- wrap_impl(@impl.off(event, callback))
177
+ event_emitter_proxy.off(event, callback)
188
178
  end
189
179
 
190
- # -- inherited from EventEmitter --
191
- # @nodoc
192
- def once(event, callback)
193
- wrap_impl(@impl.once(event, callback))
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(event, 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(event, 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(event, 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(event, 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(event, 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(event, 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(event, 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(event, 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(event, 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
 
data/playwright.gemspec CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.require_paths = ['lib']
26
26
 
27
27
  spec.add_dependency 'concurrent-ruby'
28
+ spec.add_dependency 'mime-types', '>= 3.0'
28
29
  spec.add_development_dependency 'bundler', '~> 2.2.3'
29
30
  spec.add_development_dependency 'dry-inflector'
30
31
  spec.add_development_dependency 'pry-byebug'
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.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - YusukeIwaki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-26 00:00:00.000000000 Z
11
+ date: 2021-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mime-types
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -165,10 +179,14 @@ files:
165
179
  - Rakefile
166
180
  - bin/console
167
181
  - bin/setup
182
+ - docs/api_coverage.md
168
183
  - lib/playwright.rb
184
+ - lib/playwright/android_input_impl.rb
185
+ - lib/playwright/api_implementation.rb
169
186
  - lib/playwright/channel.rb
170
187
  - lib/playwright/channel_owner.rb
171
188
  - lib/playwright/channel_owners/android.rb
189
+ - lib/playwright/channel_owners/android_device.rb
172
190
  - lib/playwright/channel_owners/binding_call.rb
173
191
  - lib/playwright/channel_owners/browser.rb
174
192
  - lib/playwright/channel_owners/browser_context.rb
@@ -176,6 +194,7 @@ files:
176
194
  - lib/playwright/channel_owners/chromium_browser.rb
177
195
  - lib/playwright/channel_owners/chromium_browser_context.rb
178
196
  - lib/playwright/channel_owners/console_message.rb
197
+ - lib/playwright/channel_owners/download.rb
179
198
  - lib/playwright/channel_owners/electron.rb
180
199
  - lib/playwright/channel_owners/element_handle.rb
181
200
  - lib/playwright/channel_owners/firefox_browser.rb
@@ -190,24 +209,31 @@ files:
190
209
  - lib/playwright/connection.rb
191
210
  - lib/playwright/errors.rb
192
211
  - lib/playwright/event_emitter.rb
212
+ - lib/playwright/event_emitter_proxy.rb
193
213
  - lib/playwright/events.rb
194
- - lib/playwright/input_type.rb
195
- - lib/playwright/input_types/keyboard.rb
196
- - lib/playwright/input_types/mouse.rb
197
- - lib/playwright/input_types/touchscreen.rb
214
+ - lib/playwright/file_chooser_impl.rb
215
+ - lib/playwright/http_headers.rb
216
+ - lib/playwright/input_files.rb
198
217
  - lib/playwright/javascript.rb
199
218
  - lib/playwright/javascript/expression.rb
200
219
  - lib/playwright/javascript/function.rb
201
220
  - lib/playwright/javascript/value_parser.rb
202
221
  - lib/playwright/javascript/value_serializer.rb
222
+ - lib/playwright/keyboard_impl.rb
223
+ - lib/playwright/mouse_impl.rb
203
224
  - lib/playwright/playwright_api.rb
225
+ - lib/playwright/select_option_values.rb
204
226
  - lib/playwright/timeout_settings.rb
227
+ - lib/playwright/touchscreen_impl.rb
205
228
  - lib/playwright/transport.rb
206
229
  - lib/playwright/url_matcher.rb
207
230
  - lib/playwright/utils.rb
208
231
  - lib/playwright/version.rb
209
232
  - lib/playwright/wait_helper.rb
210
233
  - lib/playwright_api/accessibility.rb
234
+ - lib/playwright_api/android.rb
235
+ - lib/playwright_api/android_device.rb
236
+ - lib/playwright_api/android_input.rb
211
237
  - lib/playwright_api/binding_call.rb
212
238
  - lib/playwright_api/browser.rb
213
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