playwright-ruby-client 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -15
  3. data/lib/playwright/channel_owners/browser.rb +2 -2
  4. data/lib/playwright/channel_owners/console_message.rb +25 -0
  5. data/lib/playwright/channel_owners/element_handle.rb +8 -0
  6. data/lib/playwright/channel_owners/js_handle.rb +4 -0
  7. data/lib/playwright/channel_owners/page.rb +14 -1
  8. data/lib/playwright/version.rb +1 -1
  9. data/lib/playwright_api/accessibility.rb +20 -6
  10. data/lib/playwright_api/browser.rb +52 -39
  11. data/lib/playwright_api/browser_context.rb +94 -44
  12. data/lib/playwright_api/browser_type.rb +72 -53
  13. data/lib/playwright_api/cdp_session.rb +10 -7
  14. data/lib/playwright_api/chromium_browser_context.rb +3 -0
  15. data/lib/playwright_api/console_message.rb +12 -5
  16. data/lib/playwright_api/dialog.rb +3 -1
  17. data/lib/playwright_api/download.rb +13 -4
  18. data/lib/playwright_api/element_handle.rb +226 -113
  19. data/lib/playwright_api/file_chooser.rb +4 -2
  20. data/lib/playwright_api/frame.rb +276 -128
  21. data/lib/playwright_api/js_handle.rb +30 -10
  22. data/lib/playwright_api/keyboard.rb +56 -18
  23. data/lib/playwright_api/mouse.rb +6 -3
  24. data/lib/playwright_api/page.rb +452 -237
  25. data/lib/playwright_api/playwright.rb +80 -16
  26. data/lib/playwright_api/request.rb +35 -15
  27. data/lib/playwright_api/response.rb +4 -3
  28. data/lib/playwright_api/route.rb +15 -4
  29. data/lib/playwright_api/selectors.rb +3 -7
  30. data/lib/playwright_api/touchscreen.rb +2 -1
  31. data/lib/playwright_api/video.rb +3 -1
  32. data/lib/playwright_api/web_socket.rb +4 -2
  33. data/lib/playwright_api/worker.rb +17 -5
  34. metadata +5 -2
@@ -1,35 +1,99 @@
1
1
  module Playwright
2
- # @nodoc
2
+ # Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright
3
+ # to drive automation:
4
+ #
5
+ #
6
+ # ```js
7
+ # const { chromium, firefox, webkit } = require('playwright');
8
+ #
9
+ # (async () => {
10
+ # const browser = await chromium.launch(); // Or 'firefox' or 'webkit'.
11
+ # const page = await browser.newPage();
12
+ # await page.goto('http://example.com');
13
+ # // other actions...
14
+ # await browser.close();
15
+ # })();
16
+ # ```
17
+ #
18
+ # By default, the `playwright` NPM package automatically downloads browser executables during installation. The
19
+ # `playwright-core` NPM package can be used to skip automatic downloads.
3
20
  class Playwright < PlaywrightApi
4
21
 
5
- # @nodoc
6
- def android
7
- wrap_channel_owner(@channel_owner.android)
22
+ # This object can be used to launch or connect to Chromium, returning instances of `ChromiumBrowser`.
23
+ def chromium # property
24
+ wrap_channel_owner(@channel_owner.chromium)
8
25
  end
9
26
 
10
- # @nodoc
11
- def chromium
12
- wrap_channel_owner(@channel_owner.chromium)
27
+ # Returns a list of devices to be used with [`method: Browser.newContext`] or [`method: Browser.newPage`]. Actual list of
28
+ # devices can be found in
29
+ # [src/server/deviceDescriptors.ts](https://github.com/Microsoft/playwright/blob/master/src/server/deviceDescriptors.ts).
30
+ #
31
+ #
32
+ # ```js
33
+ # const { webkit, devices } = require('playwright');
34
+ # const iPhone = devices['iPhone 6'];
35
+ #
36
+ # (async () => {
37
+ # const browser = await webkit.launch();
38
+ # const context = await browser.newContext({
39
+ # ...iPhone
40
+ # });
41
+ # const page = await context.newPage();
42
+ # await page.goto('http://example.com');
43
+ # // other actions...
44
+ # await browser.close();
45
+ # })();
46
+ # ```
47
+ def devices # property
48
+ wrap_channel_owner(@channel_owner.devices)
13
49
  end
14
50
 
15
- # @nodoc
16
- def electron
17
- wrap_channel_owner(@channel_owner.electron)
51
+ # Playwright methods might throw errors if they are unable to fulfill a request. For example,
52
+ # [`method: Page.waitForSelector`] might fail if the selector doesn't match any nodes during the given timeframe.
53
+ #
54
+ # For certain types of errors Playwright uses specific error classes. These classes are available via
55
+ # [`playwright.errors`](#playwrighterrors).
56
+ #
57
+ # An example of handling a timeout error:
58
+ #
59
+ #
60
+ # ```js
61
+ # try {
62
+ # await page.waitForSelector('.foo');
63
+ # } catch (e) {
64
+ # if (e instanceof playwright.errors.TimeoutError) {
65
+ # // Do something if this is a timeout.
66
+ # }
67
+ # }
68
+ # ```
69
+ def errors # property
70
+ raise NotImplementedError.new('errors is not implemented yet.')
18
71
  end
19
72
 
20
- # @nodoc
21
- def firefox
73
+ # This object can be used to launch or connect to Firefox, returning instances of `FirefoxBrowser`.
74
+ def firefox # property
22
75
  wrap_channel_owner(@channel_owner.firefox)
23
76
  end
24
77
 
78
+ # Selectors can be used to install custom selector engines. See
79
+ # [Working with selectors](./selectors.md#working-with-selectors) for more information.
80
+ def selectors # property
81
+ raise NotImplementedError.new('selectors is not implemented yet.')
82
+ end
83
+
84
+ # This object can be used to launch or connect to WebKit, returning instances of `WebKitBrowser`.
85
+ def webkit # property
86
+ wrap_channel_owner(@channel_owner.webkit)
87
+ end
88
+
25
89
  # @nodoc
26
- def devices
27
- wrap_channel_owner(@channel_owner.devices)
90
+ def android
91
+ wrap_channel_owner(@channel_owner.android)
28
92
  end
29
93
 
30
94
  # @nodoc
31
- def webkit
32
- wrap_channel_owner(@channel_owner.webkit)
95
+ def electron
96
+ wrap_channel_owner(@channel_owner.electron)
33
97
  end
34
98
  end
35
99
  end
@@ -1,19 +1,23 @@
1
1
  module Playwright
2
- # Whenever the page sends a request for a network resource the following sequence of events are emitted by Page:
2
+ # Whenever the page sends a request for a network resource the following sequence of events are emitted by `Page`:
3
+ # - [`event: Page.request`] emitted when the request is issued by the page.
4
+ # - [`event: Page.response`] emitted when/if the response status and headers are received for the request.
5
+ # - [`event: Page.requestfinished`] emitted when the response body is downloaded and the request is complete.
3
6
  #
4
- # page.on('request') emitted when the request is issued by the page.
5
- # page.on('response') emitted when/if the response status and headers are received for the request.
6
- # page.on('requestfinished') emitted when the response body is downloaded and the request is complete.
7
+ # If request fails at some point, then instead of `'requestfinished'` event (and possibly instead of 'response' event),
8
+ # the [`event: Page.requestfailed`] event is emitted.
7
9
  #
8
- # If request fails at some point, then instead of `'requestfinished'` event (and possibly instead of 'response' event), the page.on('requestfailed') event is emitted.
10
+ # > **NOTE** HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request
11
+ # will complete with `'requestfinished'` event.
9
12
  #
10
- # **NOTE** HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will complete with `'requestfinished'` event.
11
- #
12
- # If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new request is issued to a redirected url.
13
+ # If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new
14
+ # request is issued to a redirected url.
13
15
  class Request < PlaywrightApi
14
16
 
15
17
  # The method returns `null` unless this request has failed, as reported by `requestfailed` event.
18
+ #
16
19
  # Example of logging of all the failed requests:
20
+ #
17
21
  #
18
22
  # ```js
19
23
  # page.on('requestfailed', request => {
@@ -24,7 +28,7 @@ module Playwright
24
28
  raise NotImplementedError.new('failure is not implemented yet.')
25
29
  end
26
30
 
27
- # Returns the Frame that initiated this request.
31
+ # Returns the `Frame` that initiated this request.
28
32
  def frame
29
33
  raise NotImplementedError.new('frame is not implemented yet.')
30
34
  end
@@ -55,20 +59,29 @@ module Playwright
55
59
  end
56
60
 
57
61
  # Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
58
- # When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned. Otherwise it will be parsed as JSON.
62
+ #
63
+ # When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned.
64
+ # Otherwise it will be parsed as JSON.
59
65
  def post_data_json
60
66
  raise NotImplementedError.new('post_data_json is not implemented yet.')
61
67
  end
62
68
 
63
69
  # Request that was redirected by the server to this one, if any.
64
- # When the server responds with a redirect, Playwright creates a new Request object. The two requests are connected by `redirectedFrom()` and `redirectedTo()` methods. When multiple server redirects has happened, it is possible to construct the whole redirect chain by repeatedly calling `redirectedFrom()`.
70
+ #
71
+ # When the server responds with a redirect, Playwright creates a new `Request` object. The two requests are connected by
72
+ # `redirectedFrom()` and `redirectedTo()` methods. When multiple server redirects has happened, it is possible to
73
+ # construct the whole redirect chain by repeatedly calling `redirectedFrom()`.
74
+ #
65
75
  # For example, if the website `http://example.com` redirects to `https://example.com`:
76
+ #
66
77
  #
67
78
  # ```js
68
79
  # const response = await page.goto('http://example.com');
69
80
  # console.log(response.request().redirectedFrom().url()); // 'http://example.com'
70
81
  # ```
82
+ #
71
83
  # If the website `https://google.com` has no redirects:
84
+ #
72
85
  #
73
86
  # ```js
74
87
  # const response = await page.goto('https://google.com');
@@ -79,7 +92,9 @@ module Playwright
79
92
  end
80
93
 
81
94
  # New request issued by the browser if the server responded with redirect.
82
- # This method is the opposite of `request.redirectedFrom()`:
95
+ #
96
+ # This method is the opposite of [`method: Request.redirectedFrom`]:
97
+ #
83
98
  #
84
99
  # ```js
85
100
  # console.log(request.redirectedFrom().redirectedTo() === request); // true
@@ -88,17 +103,22 @@ module Playwright
88
103
  raise NotImplementedError.new('redirected_to is not implemented yet.')
89
104
  end
90
105
 
91
- # Contains the request's resource type as it was perceived by the rendering engine. ResourceType will be one of the following: `document`, `stylesheet`, `image`, `media`, `font`, `script`, `texttrack`, `xhr`, `fetch`, `eventsource`, `websocket`, `manifest`, `other`.
106
+ # Contains the request's resource type as it was perceived by the rendering engine. ResourceType will be one of the
107
+ # following: `document`, `stylesheet`, `image`, `media`, `font`, `script`, `texttrack`, `xhr`, `fetch`, `eventsource`,
108
+ # `websocket`, `manifest`, `other`.
92
109
  def resource_type
93
110
  raise NotImplementedError.new('resource_type is not implemented yet.')
94
111
  end
95
112
 
96
- # Returns the matching Response object, or `null` if the response was not received due to error.
113
+ # Returns the matching `Response` object, or `null` if the response was not received due to error.
97
114
  def response
98
115
  raise NotImplementedError.new('response is not implemented yet.')
99
116
  end
100
117
 
101
- # Returns resource timing information for given request. Most of the timing values become available upon the response, `responseEnd` becomes available when request finishes. Find more information at Resource Timing API.
118
+ # Returns resource timing information for given request. Most of the timing values become available upon the response,
119
+ # `responseEnd` becomes available when request finishes. Find more information at
120
+ # [Resource Timing API](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming).
121
+ #
102
122
  #
103
123
  # ```js
104
124
  # const [request] = await Promise.all([
@@ -1,5 +1,5 @@
1
1
  module Playwright
2
- # Response class represents responses which are received by page.
2
+ # `Response` class represents responses which are received by page.
3
3
  class Response < PlaywrightApi
4
4
 
5
5
  # Returns the buffer with response body.
@@ -12,7 +12,7 @@ module Playwright
12
12
  raise NotImplementedError.new('finished is not implemented yet.')
13
13
  end
14
14
 
15
- # Returns the Frame that initiated this response.
15
+ # Returns the `Frame` that initiated this response.
16
16
  def frame
17
17
  raise NotImplementedError.new('frame is not implemented yet.')
18
18
  end
@@ -23,6 +23,7 @@ module Playwright
23
23
  end
24
24
 
25
25
  # Returns the JSON representation of response body.
26
+ #
26
27
  # This method will throw if the response body is not parsable via `JSON.parse`.
27
28
  def json
28
29
  raise NotImplementedError.new('json is not implemented yet.')
@@ -33,7 +34,7 @@ module Playwright
33
34
  raise NotImplementedError.new('ok is not implemented yet.')
34
35
  end
35
36
 
36
- # Returns the matching Request object.
37
+ # Returns the matching `Request` object.
37
38
  def request
38
39
  raise NotImplementedError.new('request is not implemented yet.')
39
40
  end
@@ -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,14 @@ 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
+ def continue_(headers: nil, method: nil, postData: nil, url: nil)
26
+ raise NotImplementedError.new('continue_ is not implemented yet.')
25
27
  end
26
28
 
27
29
  # Fulfills route's request with given response.
30
+ #
28
31
  # An example of fulfilling all requests with 404 responses:
32
+ #
29
33
  #
30
34
  # ```js
31
35
  # await page.route('**/*', route => {
@@ -36,12 +40,19 @@ module Playwright
36
40
  # });
37
41
  # });
38
42
  # ```
43
+ #
39
44
  # An example of serving static file:
45
+ #
40
46
  #
41
47
  # ```js
42
48
  # await page.route('**/xhr_endpoint', route => route.fulfill({ path: 'mock_data.json' }));
43
49
  # ```
44
- def fulfill(response)
50
+ def fulfill(
51
+ body: nil,
52
+ contentType: nil,
53
+ headers: nil,
54
+ path: nil,
55
+ status: nil)
45
56
  raise NotImplementedError.new('fulfill is not implemented yet.')
46
57
  end
47
58
 
@@ -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);
@@ -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,14 @@
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
  # ```
7
8
  class Video < PlaywrightApi
8
9
 
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.
10
+ # Returns the file system path this video will be recorded to. The video is guaranteed to be written to the filesystem
11
+ # upon closing the browser context.
10
12
  def path
11
13
  raise NotImplementedError.new('path is not implemented yet.')
12
14
  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.
@@ -13,7 +13,9 @@ module Playwright
13
13
  end
14
14
 
15
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.
16
+ #
17
+ # Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
18
+ # value. Will throw an error if the webSocket is closed before the event is fired.
17
19
  def wait_for_event(event, optionsOrPredicate: nil)
18
20
  raise NotImplementedError.new('wait_for_event is not implemented yet.')
19
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 => {
@@ -14,15 +17,24 @@ module Playwright
14
17
  class Worker < PlaywrightApi
15
18
 
16
19
  # 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.
20
+ #
21
+ # If the function passed to the `worker.evaluate` returns a [Promise], then `worker.evaluate` would wait for the promise
22
+ # to resolve and return its value.
23
+ #
24
+ # If the function passed to the `worker.evaluate` returns a non-[Serializable] value, then `worker.evaluate` returns
25
+ # `undefined`. DevTools Protocol also supports transferring some additional values that are not serializable by `JSON`:
26
+ # `-0`, `NaN`, `Infinity`, `-Infinity`, and bigint literals.
19
27
  def evaluate(pageFunction, arg: nil)
20
28
  raise NotImplementedError.new('evaluate is not implemented yet.')
21
29
  end
22
30
 
23
31
  # 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.
32
+ #
33
+ # The only difference between `worker.evaluate` and `worker.evaluateHandle` is that `worker.evaluateHandle` returns
34
+ # in-page object (JSHandle).
35
+ #
36
+ # If the function passed to the `worker.evaluateHandle` returns a [Promise], then `worker.evaluateHandle` would wait for
37
+ # the promise to resolve and return its value.
26
38
  def evaluate_handle(pageFunction, arg: nil)
27
39
  raise NotImplementedError.new('evaluate_handle is not implemented yet.')
28
40
  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.4
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-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -147,9 +147,12 @@ files:
147
147
  - lib/playwright/channel_owners/browser_type.rb
148
148
  - lib/playwright/channel_owners/chromium_browser.rb
149
149
  - lib/playwright/channel_owners/chromium_browser_context.rb
150
+ - lib/playwright/channel_owners/console_message.rb
150
151
  - lib/playwright/channel_owners/electron.rb
152
+ - lib/playwright/channel_owners/element_handle.rb
151
153
  - lib/playwright/channel_owners/firefox_browser.rb
152
154
  - lib/playwright/channel_owners/frame.rb
155
+ - lib/playwright/channel_owners/js_handle.rb
153
156
  - lib/playwright/channel_owners/page.rb
154
157
  - lib/playwright/channel_owners/playwright.rb
155
158
  - lib/playwright/channel_owners/request.rb