playwright-ruby-client 0.0.3 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +119 -12
  3. data/docs/api_coverage.md +354 -0
  4. data/lib/playwright.rb +8 -0
  5. data/lib/playwright/channel_owner.rb +16 -2
  6. data/lib/playwright/channel_owners/android.rb +10 -1
  7. data/lib/playwright/channel_owners/android_device.rb +163 -0
  8. data/lib/playwright/channel_owners/browser.rb +22 -29
  9. data/lib/playwright/channel_owners/browser_context.rb +43 -0
  10. data/lib/playwright/channel_owners/console_message.rb +21 -0
  11. data/lib/playwright/channel_owners/element_handle.rb +314 -0
  12. data/lib/playwright/channel_owners/frame.rb +466 -7
  13. data/lib/playwright/channel_owners/js_handle.rb +55 -0
  14. data/lib/playwright/channel_owners/page.rb +353 -5
  15. data/lib/playwright/channel_owners/request.rb +90 -0
  16. data/lib/playwright/channel_owners/webkit_browser.rb +1 -1
  17. data/lib/playwright/connection.rb +15 -14
  18. data/lib/playwright/errors.rb +1 -1
  19. data/lib/playwright/event_emitter.rb +13 -0
  20. data/lib/playwright/input_files.rb +42 -0
  21. data/lib/playwright/input_type.rb +19 -0
  22. data/lib/playwright/input_types/android_input.rb +19 -0
  23. data/lib/playwright/input_types/keyboard.rb +32 -0
  24. data/lib/playwright/input_types/mouse.rb +4 -0
  25. data/lib/playwright/input_types/touchscreen.rb +4 -0
  26. data/lib/playwright/javascript.rb +13 -0
  27. data/lib/playwright/javascript/expression.rb +67 -0
  28. data/lib/playwright/javascript/function.rb +67 -0
  29. data/lib/playwright/javascript/value_parser.rb +75 -0
  30. data/lib/playwright/javascript/value_serializer.rb +54 -0
  31. data/lib/playwright/playwright_api.rb +45 -25
  32. data/lib/playwright/select_option_values.rb +32 -0
  33. data/lib/playwright/timeout_settings.rb +19 -0
  34. data/lib/playwright/url_matcher.rb +19 -0
  35. data/lib/playwright/utils.rb +37 -0
  36. data/lib/playwright/version.rb +1 -1
  37. data/lib/playwright/wait_helper.rb +73 -0
  38. data/lib/playwright_api/accessibility.rb +60 -6
  39. data/lib/playwright_api/android.rb +33 -0
  40. data/lib/playwright_api/android_device.rb +78 -0
  41. data/lib/playwright_api/android_input.rb +25 -0
  42. data/lib/playwright_api/binding_call.rb +18 -0
  43. data/lib/playwright_api/browser.rb +136 -44
  44. data/lib/playwright_api/browser_context.rb +378 -51
  45. data/lib/playwright_api/browser_type.rb +137 -55
  46. data/lib/playwright_api/cdp_session.rb +32 -7
  47. data/lib/playwright_api/chromium_browser_context.rb +31 -0
  48. data/lib/playwright_api/console_message.rb +27 -7
  49. data/lib/playwright_api/dialog.rb +47 -3
  50. data/lib/playwright_api/download.rb +29 -5
  51. data/lib/playwright_api/element_handle.rb +429 -143
  52. data/lib/playwright_api/file_chooser.rb +13 -2
  53. data/lib/playwright_api/frame.rb +633 -179
  54. data/lib/playwright_api/js_handle.rb +97 -17
  55. data/lib/playwright_api/keyboard.rb +152 -24
  56. data/lib/playwright_api/mouse.rb +28 -3
  57. data/lib/playwright_api/page.rb +1183 -317
  58. data/lib/playwright_api/playwright.rb +174 -13
  59. data/lib/playwright_api/request.rb +115 -30
  60. data/lib/playwright_api/response.rb +22 -3
  61. data/lib/playwright_api/route.rb +63 -4
  62. data/lib/playwright_api/selectors.rb +29 -7
  63. data/lib/playwright_api/touchscreen.rb +2 -1
  64. data/lib/playwright_api/video.rb +11 -1
  65. data/lib/playwright_api/web_socket.rb +5 -5
  66. data/lib/playwright_api/worker.rb +29 -5
  67. data/playwright.gemspec +3 -0
  68. metadata +68 -2
@@ -1,5 +1,6 @@
1
1
  module Playwright
2
- # Whenever a network route is set up with `page.route(url, handler)` or `browserContext.route(url, handler)`, the `Route` object allows to handle the route.
2
+ # Whenever a network route is set up with [`method: Page.route`] or [`method: BrowserContext.route`], the `Route` object
3
+ # allows to handle the route.
3
4
  class Route < PlaywrightApi
4
5
 
5
6
  # Aborts the route's request.
@@ -8,6 +9,7 @@ module Playwright
8
9
  end
9
10
 
10
11
  # Continues route's request with optional overrides.
12
+ #
11
13
  #
12
14
  # ```js
13
15
  # await page.route('**/*', (route, request) => {
@@ -20,12 +22,40 @@ module Playwright
20
22
  # route.continue({headers});
21
23
  # });
22
24
  # ```
23
- def continue(overrides: nil)
24
- raise NotImplementedError.new('continue is not implemented yet.')
25
+ #
26
+ # ```python async
27
+ # async def handle(route, request):
28
+ # # override headers
29
+ # headers = {
30
+ # **request.headers,
31
+ # "foo": "bar" # set "foo" header
32
+ # "origin": None # remove "origin" header
33
+ # }
34
+ # await route.continue(headers=headers)
35
+ # }
36
+ # await page.route("**/*", handle)
37
+ # ```
38
+ #
39
+ # ```python sync
40
+ # def handle(route, request):
41
+ # # override headers
42
+ # headers = {
43
+ # **request.headers,
44
+ # "foo": "bar" # set "foo" header
45
+ # "origin": None # remove "origin" header
46
+ # }
47
+ # route.continue(headers=headers)
48
+ # }
49
+ # page.route("**/*", handle)
50
+ # ```
51
+ def continue_(headers: nil, method: nil, postData: nil, url: nil)
52
+ raise NotImplementedError.new('continue_ is not implemented yet.')
25
53
  end
26
54
 
27
55
  # Fulfills route's request with given response.
56
+ #
28
57
  # An example of fulfilling all requests with 404 responses:
58
+ #
29
59
  #
30
60
  # ```js
31
61
  # await page.route('**/*', route => {
@@ -36,12 +66,41 @@ module Playwright
36
66
  # });
37
67
  # });
38
68
  # ```
69
+ #
70
+ # ```python async
71
+ # await page.route("**/*", lambda route: route.fulfill(
72
+ # status=404,
73
+ # content_type="text/plain",
74
+ # body="not found!"))
75
+ # ```
76
+ #
77
+ # ```python sync
78
+ # page.route("**/*", lambda route: route.fulfill(
79
+ # status=404,
80
+ # content_type="text/plain",
81
+ # body="not found!"))
82
+ # ```
83
+ #
39
84
  # An example of serving static file:
85
+ #
40
86
  #
41
87
  # ```js
42
88
  # await page.route('**/xhr_endpoint', route => route.fulfill({ path: 'mock_data.json' }));
43
89
  # ```
44
- def fulfill(response)
90
+ #
91
+ # ```python async
92
+ # await page.route("**/xhr_endpoint", lambda route: route.fulfill(path="mock_data.json"))
93
+ # ```
94
+ #
95
+ # ```python sync
96
+ # page.route("**/xhr_endpoint", lambda route: route.fulfill(path="mock_data.json"))
97
+ # ```
98
+ def fulfill(
99
+ body: nil,
100
+ contentType: nil,
101
+ headers: nil,
102
+ path: nil,
103
+ status: nil)
45
104
  raise NotImplementedError.new('fulfill is not implemented yet.')
46
105
  end
47
106
 
@@ -1,8 +1,10 @@
1
1
  module Playwright
2
- # Selectors can be used to install custom selector engines. See Working with selectors for more information.
2
+ # Selectors can be used to install custom selector engines. See
3
+ # [Working with selectors](./selectors.md#working-with-selectors) for more information.
3
4
  class Selectors < PlaywrightApi
4
5
 
5
6
  # An example of registering selector engine that queries elements based on a tag name:
7
+ #
6
8
  #
7
9
  # ```js
8
10
  # const { selectors, firefox } = require('playwright'); // Or 'chromium' or 'webkit'.
@@ -10,12 +12,6 @@ module Playwright
10
12
  # (async () => {
11
13
  # // Must be a function that evaluates to a selector engine instance.
12
14
  # const createTagNameEngine = () => ({
13
- # // Creates a selector that matches given target when queried at the root.
14
- # // Can return undefined if unable to create one.
15
- # create(root, target) {
16
- # return root.querySelector(target.tagName) === target ? target.tagName : undefined;
17
- # },
18
- #
19
15
  # // Returns the first element matching given selector in the root's subtree.
20
16
  # query(root, selector) {
21
17
  # return root.querySelector(selector);
@@ -44,8 +40,34 @@ module Playwright
44
40
  # await browser.close();
45
41
  # })();
46
42
  # ```
43
+ #
44
+ # ```python async
45
+ # # FIXME: add snippet
46
+ # ```
47
+ #
48
+ # ```python sync
49
+ # # FIXME: add snippet
50
+ # ```
47
51
  def register(name, script, contentScript: nil)
48
52
  raise NotImplementedError.new('register is not implemented yet.')
49
53
  end
54
+
55
+ # -- inherited from EventEmitter --
56
+ # @nodoc
57
+ def on(event, callback)
58
+ wrap_impl(@impl.on(unwrap_impl(event), unwrap_impl(callback)))
59
+ end
60
+
61
+ # -- inherited from EventEmitter --
62
+ # @nodoc
63
+ def off(event, callback)
64
+ wrap_impl(@impl.off(unwrap_impl(event), unwrap_impl(callback)))
65
+ end
66
+
67
+ # -- inherited from EventEmitter --
68
+ # @nodoc
69
+ def once(event, callback)
70
+ wrap_impl(@impl.once(unwrap_impl(event), unwrap_impl(callback)))
71
+ end
50
72
  end
51
73
  end
@@ -1,5 +1,6 @@
1
1
  module Playwright
2
- # The Touchscreen class operates in main-frame CSS pixels relative to the top-left corner of the viewport. Methods on the touchscreen can only be used in browser contexts that have been intialized with `hasTouch` set to true.
2
+ # The Touchscreen class operates in main-frame CSS pixels relative to the top-left corner of the viewport. Methods on the
3
+ # touchscreen can only be used in browser contexts that have been intialized with `hasTouch` set to true.
3
4
  class Touchscreen < PlaywrightApi
4
5
 
5
6
  # Dispatches a `touchstart` and `touchend` event with a single touch at the position (`x`,`y`).
@@ -1,12 +1,22 @@
1
1
  module Playwright
2
2
  # When browser context is created with the `videosPath` option, each page has a video object associated with it.
3
+ #
3
4
  #
4
5
  # ```js
5
6
  # console.log(await page.video().path());
6
7
  # ```
8
+ #
9
+ # ```python async
10
+ # print(await page.video.path())
11
+ # ```
12
+ #
13
+ # ```python sync
14
+ # print(page.video.path())
15
+ # ```
7
16
  class Video < PlaywrightApi
8
17
 
9
- # Returns the file system path this video will be recorded to. The video is guaranteed to be written to the filesystem upon closing the browser context.
18
+ # Returns the file system path this video will be recorded to. The video is guaranteed to be written to the filesystem
19
+ # upon closing the browser context.
10
20
  def path
11
21
  raise NotImplementedError.new('path is not implemented yet.')
12
22
  end
@@ -1,5 +1,5 @@
1
1
  module Playwright
2
- # The WebSocket class represents websocket connections in the page.
2
+ # The `WebSocket` class represents websocket connections in the page.
3
3
  class WebSocket < PlaywrightApi
4
4
 
5
5
  # Indicates that the web socket has been closed.
@@ -12,10 +12,10 @@ module Playwright
12
12
  raise NotImplementedError.new('url is not implemented yet.')
13
13
  end
14
14
 
15
- # Returns the event data value.
16
- # Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy value. Will throw an error if the webSocket is closed before the event is fired.
17
- def wait_for_event(event, optionsOrPredicate: nil)
18
- raise NotImplementedError.new('wait_for_event is not implemented yet.')
15
+ # Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
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)
18
+ raise NotImplementedError.new('expect_event is not implemented yet.')
19
19
  end
20
20
  end
21
21
  end
@@ -1,5 +1,8 @@
1
1
  module Playwright
2
- # The Worker class represents a WebWorker. `worker` event is emitted on the page object to signal a worker creation. `close` event is emitted on the worker object when the worker is gone.
2
+ # The Worker class represents a [WebWorker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API). `worker`
3
+ # event is emitted on the page object to signal a worker creation. `close` event is emitted on the worker object when the
4
+ # worker is gone.
5
+ #
3
6
  #
4
7
  # ```js
5
8
  # page.on('worker', worker => {
@@ -11,18 +14,39 @@ module Playwright
11
14
  # for (const worker of page.workers())
12
15
  # console.log(' ' + worker.url());
13
16
  # ```
17
+ #
18
+ # ```py
19
+ # def handle_worker(worker):
20
+ # print("worker created: " + worker.url)
21
+ # worker.on("close", lambda: print("worker destroyed: " + worker.url))
22
+ #
23
+ # page.on('worker', handle_worker)
24
+ #
25
+ # print("current workers:")
26
+ # for worker in page.workers:
27
+ # print(" " + worker.url)
28
+ # ```
14
29
  class Worker < PlaywrightApi
15
30
 
16
31
  # Returns the return value of `pageFunction`
17
- # If the function passed to the `worker.evaluate` returns a Promise, then `worker.evaluate` would wait for the promise to resolve and return its value.
18
- # If the function passed to the `worker.evaluate` returns a non-Serializable value, then `worker.evaluate` returns `undefined`. DevTools Protocol also supports transferring some additional values that are not serializable by `JSON`: `-0`, `NaN`, `Infinity`, `-Infinity`, and bigint literals.
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.
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.
19
39
  def evaluate(pageFunction, arg: nil)
20
40
  raise NotImplementedError.new('evaluate is not implemented yet.')
21
41
  end
22
42
 
23
43
  # Returns the return value of `pageFunction` as in-page object (JSHandle).
24
- # The only difference between `worker.evaluate` and `worker.evaluateHandle` is that `worker.evaluateHandle` returns in-page object (JSHandle).
25
- # If the function passed to the `worker.evaluateHandle` returns a Promise, then `worker.evaluateHandle` would wait for the promise to resolve and return its value.
44
+ #
45
+ # The only difference between `worker.evaluate` and `worker.evaluateHandle` is that `worker.evaluateHandle` returns
46
+ # in-page object (JSHandle).
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.
26
50
  def evaluate_handle(pageFunction, arg: nil)
27
51
  raise NotImplementedError.new('evaluate_handle is not implemented yet.')
28
52
  end
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'
@@ -32,4 +33,6 @@ Gem::Specification.new do |spec|
32
33
  spec.add_development_dependency 'rspec', '~> 3.10.0 '
33
34
  spec.add_development_dependency 'rubocop', '~> 1.7.0'
34
35
  spec.add_development_dependency 'rubocop-rspec'
36
+ spec.add_development_dependency 'sinatra'
37
+ spec.add_development_dependency 'webrick'
35
38
  end
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.3
4
+ version: 0.0.8
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-11 00:00:00.000000000 Z
11
+ date: 2021-02-11 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
@@ -122,6 +136,34 @@ dependencies:
122
136
  - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: sinatra
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: webrick
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
125
167
  description:
126
168
  email:
127
169
  - q7w8e9w8q7w8e9@yahoo.co.jp
@@ -137,19 +179,24 @@ files:
137
179
  - Rakefile
138
180
  - bin/console
139
181
  - bin/setup
182
+ - docs/api_coverage.md
140
183
  - lib/playwright.rb
141
184
  - lib/playwright/channel.rb
142
185
  - lib/playwright/channel_owner.rb
143
186
  - lib/playwright/channel_owners/android.rb
187
+ - lib/playwright/channel_owners/android_device.rb
144
188
  - lib/playwright/channel_owners/binding_call.rb
145
189
  - lib/playwright/channel_owners/browser.rb
146
190
  - lib/playwright/channel_owners/browser_context.rb
147
191
  - lib/playwright/channel_owners/browser_type.rb
148
192
  - lib/playwright/channel_owners/chromium_browser.rb
149
193
  - lib/playwright/channel_owners/chromium_browser_context.rb
194
+ - lib/playwright/channel_owners/console_message.rb
150
195
  - lib/playwright/channel_owners/electron.rb
196
+ - lib/playwright/channel_owners/element_handle.rb
151
197
  - lib/playwright/channel_owners/firefox_browser.rb
152
198
  - lib/playwright/channel_owners/frame.rb
199
+ - lib/playwright/channel_owners/js_handle.rb
153
200
  - lib/playwright/channel_owners/page.rb
154
201
  - lib/playwright/channel_owners/playwright.rb
155
202
  - lib/playwright/channel_owners/request.rb
@@ -160,10 +207,29 @@ files:
160
207
  - lib/playwright/errors.rb
161
208
  - lib/playwright/event_emitter.rb
162
209
  - lib/playwright/events.rb
210
+ - lib/playwright/input_files.rb
211
+ - lib/playwright/input_type.rb
212
+ - lib/playwright/input_types/android_input.rb
213
+ - lib/playwright/input_types/keyboard.rb
214
+ - lib/playwright/input_types/mouse.rb
215
+ - lib/playwright/input_types/touchscreen.rb
216
+ - lib/playwright/javascript.rb
217
+ - lib/playwright/javascript/expression.rb
218
+ - lib/playwright/javascript/function.rb
219
+ - lib/playwright/javascript/value_parser.rb
220
+ - lib/playwright/javascript/value_serializer.rb
163
221
  - lib/playwright/playwright_api.rb
222
+ - lib/playwright/select_option_values.rb
223
+ - lib/playwright/timeout_settings.rb
164
224
  - lib/playwright/transport.rb
225
+ - lib/playwright/url_matcher.rb
226
+ - lib/playwright/utils.rb
165
227
  - lib/playwright/version.rb
228
+ - lib/playwright/wait_helper.rb
166
229
  - lib/playwright_api/accessibility.rb
230
+ - lib/playwright_api/android.rb
231
+ - lib/playwright_api/android_device.rb
232
+ - lib/playwright_api/android_input.rb
167
233
  - lib/playwright_api/binding_call.rb
168
234
  - lib/playwright_api/browser.rb
169
235
  - lib/playwright_api/browser_context.rb