playwright-ruby-client 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/README.md +33 -0
  3. data/documentation/babel.config.js +3 -0
  4. data/documentation/docs/api/accessibility.md +7 -0
  5. data/documentation/docs/api/browser.md +185 -0
  6. data/documentation/docs/api/browser_context.md +398 -0
  7. data/documentation/docs/api/browser_type.md +105 -0
  8. data/documentation/docs/api/cdp_session.md +7 -0
  9. data/documentation/docs/api/console_message.md +41 -0
  10. data/documentation/docs/api/dialog.md +74 -0
  11. data/documentation/docs/api/element_handle.md +640 -0
  12. data/documentation/docs/api/experimental/_category_.yml +3 -0
  13. data/documentation/docs/api/experimental/android.md +25 -0
  14. data/documentation/docs/api/experimental/android_device.md +91 -0
  15. data/documentation/docs/api/experimental/android_input.md +38 -0
  16. data/documentation/docs/api/experimental/android_socket.md +7 -0
  17. data/documentation/docs/api/experimental/android_web_view.md +7 -0
  18. data/documentation/docs/api/file_chooser.md +51 -0
  19. data/documentation/docs/api/frame.md +867 -0
  20. data/documentation/docs/api/js_handle.md +116 -0
  21. data/documentation/docs/api/keyboard.md +157 -0
  22. data/documentation/docs/api/mouse.md +69 -0
  23. data/documentation/docs/api/page.md +1469 -0
  24. data/documentation/docs/api/playwright.md +63 -0
  25. data/documentation/docs/api/request.md +188 -0
  26. data/documentation/docs/api/response.md +97 -0
  27. data/documentation/docs/api/route.md +80 -0
  28. data/documentation/docs/api/selectors.md +23 -0
  29. data/documentation/docs/api/touchscreen.md +8 -0
  30. data/documentation/docs/api/tracing.md +54 -0
  31. data/documentation/docs/api/web_socket.md +7 -0
  32. data/documentation/docs/api/worker.md +7 -0
  33. data/documentation/docs/article/api_coverage.mdx +11 -0
  34. data/documentation/docs/article/getting_started.md +152 -0
  35. data/documentation/docs/article/guides/_category_.yml +3 -0
  36. data/documentation/docs/article/guides/download_playwright_driver.md +49 -0
  37. data/documentation/docs/article/guides/launch_browser.md +119 -0
  38. data/documentation/docs/article/guides/rails_integration.md +51 -0
  39. data/{docs → documentation/docs/include}/api_coverage.md +0 -0
  40. data/documentation/docusaurus.config.js +107 -0
  41. data/documentation/package.json +39 -0
  42. data/documentation/sidebars.js +15 -0
  43. data/documentation/src/components/HomepageFeatures.js +61 -0
  44. data/documentation/src/components/HomepageFeatures.module.css +13 -0
  45. data/documentation/src/css/custom.css +44 -0
  46. data/documentation/src/pages/index.js +50 -0
  47. data/documentation/src/pages/index.module.css +41 -0
  48. data/documentation/src/pages/markdown-page.md +7 -0
  49. data/documentation/static/.nojekyll +0 -0
  50. data/documentation/static/img/playwright-logo.svg +9 -0
  51. data/documentation/static/img/undraw_dropdown_menu.svg +1 -0
  52. data/documentation/static/img/undraw_web_development.svg +1 -0
  53. data/documentation/static/img/undraw_windows.svg +1 -0
  54. data/documentation/yarn.lock +8805 -0
  55. data/lib/playwright/channel_owners/binding_call.rb +33 -0
  56. data/lib/playwright/channel_owners/browser_context.rb +2 -2
  57. data/lib/playwright/channel_owners/element_handle.rb +2 -10
  58. data/lib/playwright/channel_owners/frame.rb +6 -28
  59. data/lib/playwright/channel_owners/js_handle.rb +2 -10
  60. data/lib/playwright/channel_owners/page.rb +10 -1
  61. data/lib/playwright/input_files.rb +0 -8
  62. data/lib/playwright/javascript.rb +0 -10
  63. data/lib/playwright/javascript/expression.rb +2 -7
  64. data/lib/playwright/version.rb +1 -1
  65. data/lib/playwright_api/accessibility.rb +7 -89
  66. data/lib/playwright_api/android.rb +7 -64
  67. data/lib/playwright_api/android_device.rb +8 -8
  68. data/lib/playwright_api/browser.rb +15 -169
  69. data/lib/playwright_api/browser_context.rb +47 -609
  70. data/lib/playwright_api/browser_type.rb +13 -103
  71. data/lib/playwright_api/cdp_session.rb +2 -25
  72. data/lib/playwright_api/console_message.rb +6 -6
  73. data/lib/playwright_api/dialog.rb +11 -92
  74. data/lib/playwright_api/element_handle.rb +60 -362
  75. data/lib/playwright_api/file_chooser.rb +0 -28
  76. data/lib/playwright_api/frame.rb +74 -713
  77. data/lib/playwright_api/js_handle.rb +16 -90
  78. data/lib/playwright_api/keyboard.rb +21 -213
  79. data/lib/playwright_api/mouse.rb +1 -45
  80. data/lib/playwright_api/page.rb +155 -1635
  81. data/lib/playwright_api/playwright.rb +14 -117
  82. data/lib/playwright_api/request.rb +15 -121
  83. data/lib/playwright_api/response.rb +9 -9
  84. data/lib/playwright_api/route.rb +8 -105
  85. data/lib/playwright_api/selectors.rb +6 -97
  86. data/lib/playwright_api/tracing.rb +1 -61
  87. data/lib/playwright_api/web_socket.rb +1 -1
  88. data/lib/playwright_api/worker.rb +6 -42
  89. metadata +55 -4
  90. 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,28 +12,10 @@ 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
  # ```
67
- #
68
- # ```csharp
69
- # using Microsoft.Playwright;
70
- # using System.Threading.Tasks;
71
- #
72
- # class PlaywrightExample
73
- # {
74
- # public static async Task Main()
75
- # {
76
- # using var playwright = await Playwright.CreateAsync();
77
- # await using var browser = await playwright.Chromium.LaunchAsync();
78
- # var page = await browser.NewPageAsync();
79
- #
80
- # await page.GotoAsync("https://www.microsoft.com");
81
- # // other actions...
82
- # }
83
- # }
84
- # ```
85
19
  class Playwright < PlaywrightApi
86
20
 
87
21
  # This object can be used to launch or connect to Chromium, returning instances of `Browser`.
@@ -90,47 +24,10 @@ module Playwright
90
24
  end
91
25
 
92
26
  # Returns a dictionary of devices to be used with [`method: Browser.newContext`] or [`method: Browser.newPage`].
93
- #
94
27
  #
95
- # ```js
96
- # const { webkit, devices } = require('playwright');
97
- # const iPhone = devices['iPhone 6'];
98
- #
99
- # (async () => {
100
- # const browser = await webkit.launch();
101
- # const context = await browser.newContext({
102
- # ...iPhone
103
- # });
104
- # const page = await context.newPage();
105
- # await page.goto('http://example.com');
106
- # // other actions...
107
- # await browser.close();
108
- # })();
109
- # ```
110
- #
111
- # ```python async
112
- # import asyncio
113
- # from playwright.async_api import async_playwright
114
- #
115
- # async def run(playwright):
116
- # webkit = playwright.webkit
117
- # iphone = playwright.devices["iPhone 6"]
118
- # browser = await webkit.launch()
119
- # context = await browser.new_context(**iphone)
120
- # page = await context.new_page()
121
- # await page.goto("http://example.com")
122
- # # other actions...
123
- # await browser.close()
124
- #
125
- # async def main():
126
- # async with async_playwright() as playwright:
127
- # await run(playwright)
128
- # asyncio.run(main())
129
- # ```
130
- #
131
28
  # ```python sync
132
29
  # from playwright.sync_api import sync_playwright
133
- #
30
+ #
134
31
  # def run(playwright):
135
32
  # webkit = playwright.webkit
136
33
  # iphone = playwright.devices["iPhone 6"]
@@ -140,7 +37,7 @@ module Playwright
140
37
  # page.goto("http://example.com")
141
38
  # # other actions...
142
39
  # browser.close()
143
- #
40
+ #
144
41
  # with sync_playwright() as playwright:
145
42
  # run(playwright)
146
43
  # ```
@@ -166,18 +63,18 @@ module Playwright
166
63
 
167
64
  # Terminates this instance of Playwright in case it was created bypassing the Python context manager. This is useful in
168
65
  # REPL applications.
169
- #
66
+ #
170
67
  # ```py
171
68
  # >>> from playwright.sync_api import sync_playwright
172
- #
69
+ #
173
70
  # >>> playwright = sync_playwright().start()
174
- #
71
+ #
175
72
  # >>> browser = playwright.chromium.launch()
176
73
  # >>> page = browser.new_page()
177
74
  # >>> page.goto("http://whatsmyuseragent.org/")
178
75
  # >>> page.screenshot(path="example.png")
179
76
  # >>> browser.close()
180
- #
77
+ #
181
78
  # >>> playwright.stop()
182
79
  # ```
183
80
  def stop
@@ -196,20 +93,20 @@ module Playwright
196
93
 
197
94
  # -- inherited from EventEmitter --
198
95
  # @nodoc
199
- def off(event, callback)
200
- event_emitter_proxy.off(event, callback)
96
+ def on(event, callback)
97
+ event_emitter_proxy.on(event, callback)
201
98
  end
202
99
 
203
100
  # -- inherited from EventEmitter --
204
101
  # @nodoc
205
- def once(event, callback)
206
- event_emitter_proxy.once(event, callback)
102
+ def off(event, callback)
103
+ event_emitter_proxy.off(event, callback)
207
104
  end
208
105
 
209
106
  # -- inherited from EventEmitter --
210
107
  # @nodoc
211
- def on(event, callback)
212
- event_emitter_proxy.on(event, callback)
108
+ def once(event, callback)
109
+ event_emitter_proxy.once(event, callback)
213
110
  end
214
111
 
215
112
  private def event_emitter_proxy
@@ -3,44 +3,24 @@ 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
  # ```
37
- #
38
- # ```csharp
39
- # page.RequestFailed += (_, request) =>
40
- # {
41
- # Console.WriteLine(request.Failure);
42
- # };
43
- # ```
44
24
  def failure
45
25
  wrap_impl(@impl.failure)
46
26
  end
@@ -76,7 +56,7 @@ module Playwright
76
56
  end
77
57
 
78
58
  # Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
79
- #
59
+ #
80
60
  # When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned.
81
61
  # Otherwise it will be parsed as JSON.
82
62
  def post_data_json
@@ -84,90 +64,35 @@ module Playwright
84
64
  end
85
65
 
86
66
  # Request that was redirected by the server to this one, if any.
87
- #
67
+ #
88
68
  # When the server responds with a redirect, Playwright creates a new `Request` object. The two requests are connected by
89
69
  # `redirectedFrom()` and `redirectedTo()` methods. When multiple server redirects has happened, it is possible to
90
70
  # construct the whole redirect chain by repeatedly calling `redirectedFrom()`.
91
- #
71
+ #
92
72
  # For example, if the website `http://example.com` redirects to `https://example.com`:
93
- #
94
73
  #
95
- # ```js
96
- # const response = await page.goto('http://example.com');
97
- # console.log(response.request().redirectedFrom().url()); // 'http://example.com'
98
- # ```
99
- #
100
- # ```java
101
- # Response response = page.navigate("http://example.com");
102
- # System.out.println(response.request().redirectedFrom().url()); // "http://example.com"
103
- # ```
104
- #
105
- # ```python async
106
- # response = await page.goto("http://example.com")
107
- # print(response.request.redirected_from.url) # "http://example.com"
108
- # ```
109
- #
110
74
  # ```python sync
111
75
  # response = page.goto("http://example.com")
112
76
  # print(response.request.redirected_from.url) # "http://example.com"
113
77
  # ```
114
- #
115
- # ```csharp
116
- # var response = await page.GotoAsync("http://www.microsoft.com");
117
- # Console.WriteLine(response.Request.RedirectedFrom?.Url); // http://www.microsoft.com
118
- # ```
119
- #
78
+ #
120
79
  # If the website `https://google.com` has no redirects:
121
- #
122
80
  #
123
- # ```js
124
- # const response = await page.goto('https://google.com');
125
- # console.log(response.request().redirectedFrom()); // null
126
- # ```
127
- #
128
- # ```java
129
- # Response response = page.navigate("https://google.com");
130
- # System.out.println(response.request().redirectedFrom()); // null
131
- # ```
132
- #
133
- # ```python async
134
- # response = await page.goto("https://google.com")
135
- # print(response.request.redirected_from) # None
136
- # ```
137
- #
138
81
  # ```python sync
139
82
  # response = page.goto("https://google.com")
140
83
  # print(response.request.redirected_from) # None
141
84
  # ```
142
- #
143
- # ```csharp
144
- # var response = await page.GotoAsync("https://www.google.com");
145
- # Console.WriteLine(response.Request.RedirectedFrom?.Url); // null
146
- # ```
147
85
  def redirected_from
148
86
  wrap_impl(@impl.redirected_from)
149
87
  end
150
88
 
151
89
  # New request issued by the browser if the server responded with redirect.
152
- #
90
+ #
153
91
  # This method is the opposite of [`method: Request.redirectedFrom`]:
154
- #
155
92
  #
156
- # ```js
157
- # console.log(request.redirectedFrom().redirectedTo() === request); // true
158
- # ```
159
- #
160
- # ```java
161
- # System.out.println(request.redirectedFrom().redirectedTo() == request); // true
162
- # ```
163
- #
164
93
  # ```py
165
94
  # assert request.redirected_from.redirected_to == request
166
95
  # ```
167
- #
168
- # ```csharp
169
- # Console.WriteLine(request.RedirectedFrom?.RedirectedTo == request); // True
170
- # ```
171
96
  def redirected_to
172
97
  wrap_impl(@impl.redirected_to)
173
98
  end
@@ -187,44 +112,13 @@ module Playwright
187
112
  # Returns resource timing information for given request. Most of the timing values become available upon the response,
188
113
  # `responseEnd` becomes available when request finishes. Find more information at
189
114
  # [Resource Timing API](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming).
190
- #
191
115
  #
192
- # ```js
193
- # const [request] = await Promise.all([
194
- # page.waitForEvent('requestfinished'),
195
- # page.goto('http://example.com')
196
- # ]);
197
- # console.log(request.timing());
198
- # ```
199
- #
200
- # ```java
201
- # page.onRequestFinished(request -> {
202
- # Timing timing = request.timing();
203
- # System.out.println(timing.responseEnd - timing.startTime);
204
- # });
205
- # page.navigate("http://example.com");
206
- # ```
207
- #
208
- # ```python async
209
- # async with page.expect_event("requestfinished") as request_info:
210
- # await page.goto("http://example.com")
211
- # request = await request_info.value
212
- # print(request.timing)
213
- # ```
214
- #
215
116
  # ```python sync
216
117
  # with page.expect_event("requestfinished") as request_info:
217
118
  # page.goto("http://example.com")
218
119
  # request = request_info.value
219
120
  # print(request.timing)
220
121
  # ```
221
- #
222
- # ```csharp
223
- # var waitForEventTask = page.WaitForEventAsync(PageEvent.RequestFinished);
224
- # await page.GotoAsync("https://www.microsoft.com");
225
- # var request = await waitForEventTask;
226
- # Console.WriteLine(request.Timing.ResponseEnd);
227
- # ```
228
122
  def timing
229
123
  wrap_impl(@impl.timing)
230
124
  end
@@ -236,20 +130,20 @@ module Playwright
236
130
 
237
131
  # -- inherited from EventEmitter --
238
132
  # @nodoc
239
- def off(event, callback)
240
- event_emitter_proxy.off(event, callback)
133
+ def on(event, callback)
134
+ event_emitter_proxy.on(event, callback)
241
135
  end
242
136
 
243
137
  # -- inherited from EventEmitter --
244
138
  # @nodoc
245
- def once(event, callback)
246
- event_emitter_proxy.once(event, callback)
139
+ def off(event, callback)
140
+ event_emitter_proxy.off(event, callback)
247
141
  end
248
142
 
249
143
  # -- inherited from EventEmitter --
250
144
  # @nodoc
251
- def on(event, callback)
252
- event_emitter_proxy.on(event, callback)
145
+ def once(event, callback)
146
+ event_emitter_proxy.once(event, callback)
253
147
  end
254
148
 
255
149
  private def event_emitter_proxy
@@ -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)
@@ -59,14 +59,20 @@ module Playwright
59
59
  wrap_impl(@impl.url)
60
60
  end
61
61
 
62
+ # @nodoc
63
+ def ok?
64
+ wrap_impl(@impl.ok?)
65
+ end
66
+
62
67
  # @nodoc
63
68
  def after_initialize
64
69
  wrap_impl(@impl.after_initialize)
65
70
  end
66
71
 
72
+ # -- inherited from EventEmitter --
67
73
  # @nodoc
68
- def ok?
69
- wrap_impl(@impl.ok?)
74
+ def on(event, callback)
75
+ event_emitter_proxy.on(event, callback)
70
76
  end
71
77
 
72
78
  # -- inherited from EventEmitter --
@@ -81,12 +87,6 @@ module Playwright
81
87
  event_emitter_proxy.once(event, callback)
82
88
  end
83
89
 
84
- # -- inherited from EventEmitter --
85
- # @nodoc
86
- def on(event, callback)
87
- event_emitter_proxy.on(event, callback)
88
- end
89
-
90
90
  private def event_emitter_proxy
91
91
  @event_emitter_proxy ||= EventEmitterProxy.new(self, @impl)
92
92
  end