playwright-ruby-client 0.5.8 → 0.6.2

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 (99) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/documentation/README.md +33 -0
  4. data/documentation/babel.config.js +3 -0
  5. data/documentation/docs/api/accessibility.md +7 -0
  6. data/documentation/docs/api/browser.md +187 -0
  7. data/documentation/docs/api/browser_context.md +397 -0
  8. data/documentation/docs/api/browser_type.md +105 -0
  9. data/documentation/docs/api/cdp_session.md +7 -0
  10. data/documentation/docs/api/console_message.md +41 -0
  11. data/documentation/docs/api/dialog.md +71 -0
  12. data/documentation/docs/api/element_handle.md +618 -0
  13. data/documentation/docs/api/experimental/_category_.yml +3 -0
  14. data/documentation/docs/api/experimental/android.md +25 -0
  15. data/documentation/docs/api/experimental/android_device.md +92 -0
  16. data/documentation/docs/api/experimental/android_input.md +38 -0
  17. data/documentation/docs/api/experimental/android_socket.md +7 -0
  18. data/documentation/docs/api/experimental/android_web_view.md +7 -0
  19. data/documentation/docs/api/file_chooser.md +50 -0
  20. data/documentation/docs/api/frame.md +866 -0
  21. data/documentation/docs/api/js_handle.md +113 -0
  22. data/documentation/docs/api/keyboard.md +157 -0
  23. data/documentation/docs/api/mouse.md +69 -0
  24. data/documentation/docs/api/page.md +1402 -0
  25. data/documentation/docs/api/playwright.md +63 -0
  26. data/documentation/docs/api/request.md +188 -0
  27. data/documentation/docs/api/response.md +97 -0
  28. data/documentation/docs/api/route.md +80 -0
  29. data/documentation/docs/api/selectors.md +23 -0
  30. data/documentation/docs/api/touchscreen.md +8 -0
  31. data/documentation/docs/api/tracing.md +54 -0
  32. data/documentation/docs/api/web_socket.md +7 -0
  33. data/documentation/docs/api/worker.md +24 -0
  34. data/documentation/docs/article/api_coverage.mdx +11 -0
  35. data/documentation/docs/article/getting_started.md +152 -0
  36. data/documentation/docs/article/guides/_category_.yml +3 -0
  37. data/documentation/docs/article/guides/download_playwright_driver.md +49 -0
  38. data/documentation/docs/article/guides/launch_browser.md +119 -0
  39. data/documentation/docs/article/guides/rails_integration.md +51 -0
  40. data/{docs → documentation/docs/include}/api_coverage.md +13 -2
  41. data/documentation/docusaurus.config.js +107 -0
  42. data/documentation/package.json +39 -0
  43. data/documentation/sidebars.js +15 -0
  44. data/documentation/src/components/HomepageFeatures.js +61 -0
  45. data/documentation/src/components/HomepageFeatures.module.css +13 -0
  46. data/documentation/src/css/custom.css +44 -0
  47. data/documentation/src/pages/index.js +50 -0
  48. data/documentation/src/pages/index.module.css +41 -0
  49. data/documentation/src/pages/markdown-page.md +7 -0
  50. data/documentation/static/.nojekyll +0 -0
  51. data/documentation/static/img/playwright-logo.svg +9 -0
  52. data/documentation/static/img/undraw_dropdown_menu.svg +1 -0
  53. data/documentation/static/img/undraw_web_development.svg +1 -0
  54. data/documentation/static/img/undraw_windows.svg +1 -0
  55. data/documentation/yarn.lock +8805 -0
  56. data/lib/playwright/channel_owners/binding_call.rb +33 -0
  57. data/lib/playwright/channel_owners/browser.rb +27 -2
  58. data/lib/playwright/channel_owners/browser_context.rb +54 -3
  59. data/lib/playwright/channel_owners/browser_type.rb +8 -1
  60. data/lib/playwright/channel_owners/element_handle.rb +17 -16
  61. data/lib/playwright/channel_owners/frame.rb +29 -34
  62. data/lib/playwright/channel_owners/js_handle.rb +2 -10
  63. data/lib/playwright/channel_owners/page.rb +35 -51
  64. data/lib/playwright/channel_owners/worker.rb +4 -0
  65. data/lib/playwright/download.rb +3 -2
  66. data/lib/playwright/events.rb +4 -0
  67. data/lib/playwright/input_files.rb +0 -8
  68. data/lib/playwright/javascript.rb +0 -10
  69. data/lib/playwright/javascript/expression.rb +2 -7
  70. data/lib/playwright/playwright_api.rb +16 -1
  71. data/lib/playwright/tracing_impl.rb +31 -0
  72. data/lib/playwright/version.rb +2 -1
  73. data/lib/playwright_api/accessibility.rb +7 -88
  74. data/lib/playwright_api/android.rb +2 -59
  75. data/lib/playwright_api/android_device.rb +6 -5
  76. data/lib/playwright_api/browser.rb +13 -122
  77. data/lib/playwright_api/browser_context.rb +66 -433
  78. data/lib/playwright_api/browser_type.rb +28 -78
  79. data/lib/playwright_api/cdp_session.rb +2 -25
  80. data/lib/playwright_api/console_message.rb +2 -0
  81. data/lib/playwright_api/dialog.rb +5 -63
  82. data/lib/playwright_api/element_handle.rb +96 -294
  83. data/lib/playwright_api/file_chooser.rb +0 -21
  84. data/lib/playwright_api/frame.rb +99 -565
  85. data/lib/playwright_api/js_handle.rb +10 -67
  86. data/lib/playwright_api/keyboard.rb +22 -166
  87. data/lib/playwright_api/mouse.rb +1 -45
  88. data/lib/playwright_api/page.rb +222 -1223
  89. data/lib/playwright_api/playwright.rb +8 -93
  90. data/lib/playwright_api/request.rb +9 -87
  91. data/lib/playwright_api/response.rb +1 -1
  92. data/lib/playwright_api/route.rb +3 -80
  93. data/lib/playwright_api/selectors.rb +0 -66
  94. data/lib/playwright_api/tracing.rb +39 -0
  95. data/lib/playwright_api/web_socket.rb +1 -1
  96. data/lib/playwright_api/worker.rb +28 -42
  97. data/playwright.gemspec +2 -2
  98. metadata +60 -20
  99. data/lib/playwright/javascript/function.rb +0 -67
@@ -1,58 +1,10 @@
1
1
  module Playwright
2
2
  # Playwright module provides a method to launch a browser instance. The following is a typical example of using Playwright
3
3
  # to drive automation:
4
- #
5
4
  #
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
- # ```java
19
- # import com.microsoft.playwright.*;
20
- #
21
- # public class Example {
22
- # public static void main(String[] args) {
23
- # try (Playwright playwright = Playwright.create()) {
24
- # BrowserType chromium = playwright.chromium();
25
- # Browser browser = chromium.launch();
26
- # Page page = browser.newPage();
27
- # page.navigate("http://example.com");
28
- # // other actions...
29
- # browser.close();
30
- # }
31
- # }
32
- # }
33
- # ```
34
- #
35
- # ```python async
36
- # import asyncio
37
- # from playwright.async_api import async_playwright
38
- #
39
- # async def run(playwright):
40
- # chromium = playwright.chromium # or "firefox" or "webkit".
41
- # browser = await chromium.launch()
42
- # page = await browser.new_page()
43
- # await page.goto("http://example.com")
44
- # # other actions...
45
- # await browser.close()
46
- #
47
- # async def main():
48
- # async with async_playwright() as playwright:
49
- # await run(playwright)
50
- # asyncio.run(main())
51
- # ```
52
- #
53
5
  # ```python sync
54
6
  # from playwright.sync_api import sync_playwright
55
- #
7
+ #
56
8
  # def run(playwright):
57
9
  # chromium = playwright.chromium # or "firefox" or "webkit".
58
10
  # browser = chromium.launch()
@@ -60,7 +12,7 @@ module Playwright
60
12
  # page.goto("http://example.com")
61
13
  # # other actions...
62
14
  # browser.close()
63
- #
15
+ #
64
16
  # with sync_playwright() as playwright:
65
17
  # run(playwright)
66
18
  # ```
@@ -72,47 +24,10 @@ module Playwright
72
24
  end
73
25
 
74
26
  # Returns a dictionary of devices to be used with [`method: Browser.newContext`] or [`method: Browser.newPage`].
75
- #
76
27
  #
77
- # ```js
78
- # const { webkit, devices } = require('playwright');
79
- # const iPhone = devices['iPhone 6'];
80
- #
81
- # (async () => {
82
- # const browser = await webkit.launch();
83
- # const context = await browser.newContext({
84
- # ...iPhone
85
- # });
86
- # const page = await context.newPage();
87
- # await page.goto('http://example.com');
88
- # // other actions...
89
- # await browser.close();
90
- # })();
91
- # ```
92
- #
93
- # ```python async
94
- # import asyncio
95
- # from playwright.async_api import async_playwright
96
- #
97
- # async def run(playwright):
98
- # webkit = playwright.webkit
99
- # iphone = playwright.devices["iPhone 6"]
100
- # browser = await webkit.launch()
101
- # context = await browser.new_context(**iphone)
102
- # page = await context.new_page()
103
- # await page.goto("http://example.com")
104
- # # other actions...
105
- # await browser.close()
106
- #
107
- # async def main():
108
- # async with async_playwright() as playwright:
109
- # await run(playwright)
110
- # asyncio.run(main())
111
- # ```
112
- #
113
28
  # ```python sync
114
29
  # from playwright.sync_api import sync_playwright
115
- #
30
+ #
116
31
  # def run(playwright):
117
32
  # webkit = playwright.webkit
118
33
  # iphone = playwright.devices["iPhone 6"]
@@ -122,7 +37,7 @@ module Playwright
122
37
  # page.goto("http://example.com")
123
38
  # # other actions...
124
39
  # browser.close()
125
- #
40
+ #
126
41
  # with sync_playwright() as playwright:
127
42
  # run(playwright)
128
43
  # ```
@@ -148,18 +63,18 @@ module Playwright
148
63
 
149
64
  # Terminates this instance of Playwright in case it was created bypassing the Python context manager. This is useful in
150
65
  # REPL applications.
151
- #
66
+ #
152
67
  # ```py
153
68
  # >>> from playwright.sync_api import sync_playwright
154
- #
69
+ #
155
70
  # >>> playwright = sync_playwright().start()
156
- #
71
+ #
157
72
  # >>> browser = playwright.chromium.launch()
158
73
  # >>> page = browser.new_page()
159
74
  # >>> page.goto("http://whatsmyuseragent.org/")
160
75
  # >>> page.screenshot(path="example.png")
161
76
  # >>> browser.close()
162
- #
77
+ #
163
78
  # >>> playwright.stop()
164
79
  # ```
165
80
  def stop
@@ -3,34 +3,21 @@ module Playwright
3
3
  # - [`event: Page.request`] emitted when the request is issued by the page.
4
4
  # - [`event: Page.response`] emitted when/if the response status and headers are received for the request.
5
5
  # - [`event: Page.requestFinished`] emitted when the response body is downloaded and the request is complete.
6
- #
6
+ #
7
7
  # If request fails at some point, then instead of `'requestfinished'` event (and possibly instead of 'response' event),
8
8
  # the [`event: Page.requestFailed`] event is emitted.
9
- #
9
+ #
10
10
  # > NOTE: HTTP Error responses, such as 404 or 503, are still successful responses from HTTP standpoint, so request will
11
11
  # complete with `'requestfinished'` event.
12
- #
12
+ #
13
13
  # If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new
14
14
  # request is issued to a redirected url.
15
15
  class Request < PlaywrightApi
16
16
 
17
17
  # The method returns `null` unless this request has failed, as reported by `requestfailed` event.
18
- #
18
+ #
19
19
  # Example of logging of all the failed requests:
20
- #
21
20
  #
22
- # ```js
23
- # page.on('requestfailed', request => {
24
- # console.log(request.url() + ' ' + request.failure().errorText);
25
- # });
26
- # ```
27
- #
28
- # ```java
29
- # page.onRequestFailed(request -> {
30
- # System.out.println(request.url() + " " + request.failure());
31
- # });
32
- # ```
33
- #
34
21
  # ```py
35
22
  # page.on("requestfailed", lambda request: print(request.url + " " + request.failure))
36
23
  # ```
@@ -69,7 +56,7 @@ module Playwright
69
56
  end
70
57
 
71
58
  # Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
72
- #
59
+ #
73
60
  # When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned.
74
61
  # Otherwise it will be parsed as JSON.
75
62
  def post_data_json
@@ -77,52 +64,20 @@ module Playwright
77
64
  end
78
65
 
79
66
  # Request that was redirected by the server to this one, if any.
80
- #
67
+ #
81
68
  # When the server responds with a redirect, Playwright creates a new `Request` object. The two requests are connected by
82
69
  # `redirectedFrom()` and `redirectedTo()` methods. When multiple server redirects has happened, it is possible to
83
70
  # construct the whole redirect chain by repeatedly calling `redirectedFrom()`.
84
- #
71
+ #
85
72
  # For example, if the website `http://example.com` redirects to `https://example.com`:
86
- #
87
73
  #
88
- # ```js
89
- # const response = await page.goto('http://example.com');
90
- # console.log(response.request().redirectedFrom().url()); // 'http://example.com'
91
- # ```
92
- #
93
- # ```java
94
- # Response response = page.navigate("http://example.com");
95
- # System.out.println(response.request().redirectedFrom().url()); // "http://example.com"
96
- # ```
97
- #
98
- # ```python async
99
- # response = await page.goto("http://example.com")
100
- # print(response.request.redirected_from.url) # "http://example.com"
101
- # ```
102
- #
103
74
  # ```python sync
104
75
  # response = page.goto("http://example.com")
105
76
  # print(response.request.redirected_from.url) # "http://example.com"
106
77
  # ```
107
- #
78
+ #
108
79
  # If the website `https://google.com` has no redirects:
109
- #
110
80
  #
111
- # ```js
112
- # const response = await page.goto('https://google.com');
113
- # console.log(response.request().redirectedFrom()); // null
114
- # ```
115
- #
116
- # ```java
117
- # Response response = page.navigate("https://google.com");
118
- # System.out.println(response.request().redirectedFrom()); // null
119
- # ```
120
- #
121
- # ```python async
122
- # response = await page.goto("https://google.com")
123
- # print(response.request.redirected_from) # None
124
- # ```
125
- #
126
81
  # ```python sync
127
82
  # response = page.goto("https://google.com")
128
83
  # print(response.request.redirected_from) # None
@@ -132,18 +87,9 @@ module Playwright
132
87
  end
133
88
 
134
89
  # New request issued by the browser if the server responded with redirect.
135
- #
90
+ #
136
91
  # This method is the opposite of [`method: Request.redirectedFrom`]:
137
- #
138
92
  #
139
- # ```js
140
- # console.log(request.redirectedFrom().redirectedTo() === request); // true
141
- # ```
142
- #
143
- # ```java
144
- # System.out.println(request.redirectedFrom().redirectedTo() == request); // true
145
- # ```
146
- #
147
93
  # ```py
148
94
  # assert request.redirected_from.redirected_to == request
149
95
  # ```
@@ -166,31 +112,7 @@ module Playwright
166
112
  # Returns resource timing information for given request. Most of the timing values become available upon the response,
167
113
  # `responseEnd` becomes available when request finishes. Find more information at
168
114
  # [Resource Timing API](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming).
169
- #
170
115
  #
171
- # ```js
172
- # const [request] = await Promise.all([
173
- # page.waitForEvent('requestfinished'),
174
- # page.goto('http://example.com')
175
- # ]);
176
- # console.log(request.timing());
177
- # ```
178
- #
179
- # ```java
180
- # page.onRequestFinished(request -> {
181
- # Timing timing = request.timing();
182
- # System.out.println(timing.responseEnd - timing.startTime);
183
- # });
184
- # page.navigate("http://example.com");
185
- # ```
186
- #
187
- # ```python async
188
- # async with page.expect_event("requestfinished") as request_info:
189
- # await page.goto("http://example.com")
190
- # request = await request_info.value
191
- # print(request.timing)
192
- # ```
193
- #
194
116
  # ```python sync
195
117
  # with page.expect_event("requestfinished") as request_info:
196
118
  # page.goto("http://example.com")
@@ -23,7 +23,7 @@ module Playwright
23
23
  end
24
24
 
25
25
  # Returns the JSON representation of response body.
26
- #
26
+ #
27
27
  # This method will throw if the response body is not parsable via `JSON.parse`.
28
28
  def json
29
29
  wrap_impl(@impl.json)
@@ -9,43 +9,7 @@ module Playwright
9
9
  end
10
10
 
11
11
  # Continues route's request with optional overrides.
12
- #
13
12
  #
14
- # ```js
15
- # await page.route('**/*', (route, request) => {
16
- # // Override headers
17
- # const headers = {
18
- # ...request.headers(),
19
- # foo: 'bar', // set "foo" header
20
- # origin: undefined, // remove "origin" header
21
- # };
22
- # route.continue({headers});
23
- # });
24
- # ```
25
- #
26
- # ```java
27
- # page.route("**/*", route -> {
28
- # // Override headers
29
- # Map<String, String> headers = new HashMap<>(route.request().headers());
30
- # headers.put("foo", "bar"); // set "foo" header
31
- # headers.remove("origin"); // remove "origin" header
32
- # route.resume(new Route.ResumeOptions().setHeaders(headers));
33
- # });
34
- # ```
35
- #
36
- # ```python async
37
- # async def handle(route, request):
38
- # # override headers
39
- # headers = {
40
- # **request.headers,
41
- # "foo": "bar" # set "foo" header
42
- # "origin": None # remove "origin" header
43
- # }
44
- # await route.continue(headers=headers)
45
- # }
46
- # await page.route("**/*", handle)
47
- # ```
48
- #
49
13
  # ```python sync
50
14
  # def handle(route, request):
51
15
  # # override headers
@@ -54,7 +18,7 @@ module Playwright
54
18
  # "foo": "bar" # set "foo" header
55
19
  # "origin": None # remove "origin" header
56
20
  # }
57
- # route.continue(headers=headers)
21
+ # route.continue_(headers=headers)
58
22
  # }
59
23
  # page.route("**/*", handle)
60
24
  # ```
@@ -63,59 +27,18 @@ module Playwright
63
27
  end
64
28
 
65
29
  # Fulfills route's request with given response.
66
- #
30
+ #
67
31
  # An example of fulfilling all requests with 404 responses:
68
- #
69
32
  #
70
- # ```js
71
- # await page.route('**/*', route => {
72
- # route.fulfill({
73
- # status: 404,
74
- # contentType: 'text/plain',
75
- # body: 'Not Found!'
76
- # });
77
- # });
78
- # ```
79
- #
80
- # ```java
81
- # page.route("**/*", route -> {
82
- # route.fulfill(new Route.FulfillOptions()
83
- # .setStatus(404)
84
- # .setContentType("text/plain")
85
- # .setBody("Not Found!"));
86
- # });
87
- # ```
88
- #
89
- # ```python async
90
- # await page.route("**/*", lambda route: route.fulfill(
91
- # status=404,
92
- # content_type="text/plain",
93
- # body="not found!"))
94
- # ```
95
- #
96
33
  # ```python sync
97
34
  # page.route("**/*", lambda route: route.fulfill(
98
35
  # status=404,
99
36
  # content_type="text/plain",
100
37
  # body="not found!"))
101
38
  # ```
102
- #
39
+ #
103
40
  # An example of serving static file:
104
- #
105
41
  #
106
- # ```js
107
- # await page.route('**/xhr_endpoint', route => route.fulfill({ path: 'mock_data.json' }));
108
- # ```
109
- #
110
- # ```java
111
- # page.route("**/xhr_endpoint", route -> route.fulfill(
112
- # new Route.FulfillOptions().setPath(Paths.get("mock_data.json")));
113
- # ```
114
- #
115
- # ```python async
116
- # await page.route("**/xhr_endpoint", lambda route: route.fulfill(path="mock_data.json"))
117
- # ```
118
- #
119
42
  # ```python sync
120
43
  # page.route("**/xhr_endpoint", lambda route: route.fulfill(path="mock_data.json"))
121
44
  # ```
@@ -4,73 +4,7 @@ module Playwright
4
4
  class Selectors < PlaywrightApi
5
5
 
6
6
  # An example of registering selector engine that queries elements based on a tag name:
7
- #
8
7
  #
9
- # ```js
10
- # const { selectors, firefox } = require('playwright'); // Or 'chromium' or 'webkit'.
11
- #
12
- # (async () => {
13
- # // Must be a function that evaluates to a selector engine instance.
14
- # const createTagNameEngine = () => ({
15
- # // Returns the first element matching given selector in the root's subtree.
16
- # query(root, selector) {
17
- # return root.querySelector(selector);
18
- # },
19
- #
20
- # // Returns all elements matching given selector in the root's subtree.
21
- # queryAll(root, selector) {
22
- # return Array.from(root.querySelectorAll(selector));
23
- # }
24
- # });
25
- #
26
- # // Register the engine. Selectors will be prefixed with "tag=".
27
- # await selectors.register('tag', createTagNameEngine);
28
- #
29
- # const browser = await firefox.launch();
30
- # const page = await browser.newPage();
31
- # await page.setContent(`<div><button>Click me</button></div>`);
32
- #
33
- # // Use the selector prefixed with its name.
34
- # const button = await page.$('tag=button');
35
- # // Combine it with other selector engines.
36
- # await page.click('tag=div >> text="Click me"');
37
- # // Can use it in any methods supporting selectors.
38
- # const buttonCount = await page.$$eval('tag=button', buttons => buttons.length);
39
- #
40
- # await browser.close();
41
- # })();
42
- # ```
43
- #
44
- # ```java
45
- # // Script that evaluates to a selector engine instance.
46
- # String createTagNameEngine = "{\n" +
47
- # " // Returns the first element matching given selector in the root's subtree.\n" +
48
- # " query(root, selector) {\n" +
49
- # " return root.querySelector(selector);\n" +
50
- # " },\n" +
51
- # " // Returns all elements matching given selector in the root's subtree.\n" +
52
- # " queryAll(root, selector) {\n" +
53
- # " return Array.from(root.querySelectorAll(selector));\n" +
54
- # " }\n" +
55
- # "}";
56
- # // Register the engine. Selectors will be prefixed with "tag=".
57
- # playwright.selectors().register("tag", createTagNameEngine);
58
- # Browser browser = playwright.firefox().launch();
59
- # Page page = browser.newPage();
60
- # page.setContent("<div><button>Click me</button></div>");
61
- # // Use the selector prefixed with its name.
62
- # ElementHandle button = page.querySelector("tag=button");
63
- # // Combine it with other selector engines.
64
- # page.click("tag=div >> text=\"Click me\"");
65
- # // Can use it in any methods supporting selectors.
66
- # int buttonCount = (int) page.evalOnSelectorAll("tag=button", "buttons => buttons.length");
67
- # browser.close();
68
- # ```
69
- #
70
- # ```python async
71
- # # FIXME: add snippet
72
- # ```
73
- #
74
8
  # ```python sync
75
9
  # # FIXME: add snippet
76
10
  # ```