playwright-ruby-client 0.1.0 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -8
  3. data/docs/api_coverage.md +123 -73
  4. data/lib/playwright.rb +48 -9
  5. data/lib/playwright/channel.rb +12 -2
  6. data/lib/playwright/channel_owner.rb +3 -5
  7. data/lib/playwright/channel_owners/android.rb +1 -1
  8. data/lib/playwright/channel_owners/android_device.rb +11 -11
  9. data/lib/playwright/channel_owners/artifact.rb +30 -0
  10. data/lib/playwright/channel_owners/binding_call.rb +3 -0
  11. data/lib/playwright/channel_owners/browser.rb +22 -1
  12. data/lib/playwright/channel_owners/browser_context.rb +155 -4
  13. data/lib/playwright/channel_owners/browser_type.rb +28 -0
  14. data/lib/playwright/channel_owners/dialog.rb +28 -0
  15. data/lib/playwright/channel_owners/element_handle.rb +18 -5
  16. data/lib/playwright/channel_owners/frame.rb +40 -5
  17. data/lib/playwright/channel_owners/js_handle.rb +3 -3
  18. data/lib/playwright/channel_owners/page.rb +172 -51
  19. data/lib/playwright/channel_owners/playwright.rb +24 -27
  20. data/lib/playwright/channel_owners/request.rb +27 -3
  21. data/lib/playwright/channel_owners/response.rb +60 -0
  22. data/lib/playwright/channel_owners/route.rb +78 -0
  23. data/lib/playwright/channel_owners/selectors.rb +19 -1
  24. data/lib/playwright/channel_owners/stream.rb +15 -0
  25. data/lib/playwright/connection.rb +11 -32
  26. data/lib/playwright/download.rb +27 -0
  27. data/lib/playwright/errors.rb +6 -0
  28. data/lib/playwright/events.rb +2 -5
  29. data/lib/playwright/keyboard_impl.rb +1 -1
  30. data/lib/playwright/mouse_impl.rb +41 -0
  31. data/lib/playwright/playwright_api.rb +3 -1
  32. data/lib/playwright/route_handler_entry.rb +28 -0
  33. data/lib/playwright/select_option_values.rb +14 -4
  34. data/lib/playwright/transport.rb +28 -7
  35. data/lib/playwright/url_matcher.rb +1 -1
  36. data/lib/playwright/utils.rb +11 -2
  37. data/lib/playwright/version.rb +1 -1
  38. data/lib/playwright/video.rb +51 -0
  39. data/lib/playwright/wait_helper.rb +2 -2
  40. data/lib/playwright_api/accessibility.rb +39 -1
  41. data/lib/playwright_api/android.rb +72 -5
  42. data/lib/playwright_api/android_device.rb +139 -26
  43. data/lib/playwright_api/android_input.rb +17 -13
  44. data/lib/playwright_api/android_socket.rb +16 -0
  45. data/lib/playwright_api/android_web_view.rb +21 -0
  46. data/lib/playwright_api/browser.rb +87 -19
  47. data/lib/playwright_api/browser_context.rb +216 -32
  48. data/lib/playwright_api/browser_type.rb +45 -58
  49. data/lib/playwright_api/dialog.rb +54 -7
  50. data/lib/playwright_api/element_handle.rb +113 -33
  51. data/lib/playwright_api/file_chooser.rb +6 -1
  52. data/lib/playwright_api/frame.rb +238 -43
  53. data/lib/playwright_api/js_handle.rb +20 -2
  54. data/lib/playwright_api/keyboard.rb +48 -1
  55. data/lib/playwright_api/mouse.rb +26 -5
  56. data/lib/playwright_api/page.rb +534 -63
  57. data/lib/playwright_api/playwright.rb +43 -47
  58. data/lib/playwright_api/request.rb +38 -12
  59. data/lib/playwright_api/response.rb +27 -10
  60. data/lib/playwright_api/route.rb +51 -6
  61. data/lib/playwright_api/selectors.rb +28 -2
  62. data/lib/playwright_api/touchscreen.rb +1 -1
  63. data/lib/playwright_api/web_socket.rb +15 -0
  64. data/lib/playwright_api/worker.rb +25 -1
  65. data/playwright.gemspec +4 -2
  66. metadata +42 -14
  67. data/lib/playwright/channel_owners/chromium_browser.rb +0 -8
  68. data/lib/playwright/channel_owners/chromium_browser_context.rb +0 -8
  69. data/lib/playwright/channel_owners/download.rb +0 -27
  70. data/lib/playwright/channel_owners/firefox_browser.rb +0 -8
  71. data/lib/playwright/channel_owners/webkit_browser.rb +0 -8
  72. data/lib/playwright_api/binding_call.rb +0 -27
  73. data/lib/playwright_api/chromium_browser_context.rb +0 -59
  74. data/lib/playwright_api/download.rb +0 -100
  75. data/lib/playwright_api/video.rb +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8e526e28e95751a08697bc93b14ec33f4f82e827b8adf4dc45aed4bf44dd1d2
4
- data.tar.gz: 647596db5628a1014a7816bb43d2ca41a21eeb6cf8c7263dea701d8f9a6ba4e7
3
+ metadata.gz: 81be247e4fe8a3bf351cf8ead156c490657547f89a1ae5f8a1536ad72a1c30e4
4
+ data.tar.gz: '0398932fd2d3eae453668624bad5271990bc426168caa56e71be773e87e9504a'
5
5
  SHA512:
6
- metadata.gz: 0051320ee1e574680ebc6be4d5cf359a28bd8ada9a737fc60d734f017c43142b6f267553f15d0e1ac0ed368f12d57dac5a887a39695f59a11f774344405dcfd1
7
- data.tar.gz: 14f97b51a9462a8bfb587c5752eb13b3db0c132d0d56d7bdaab829389f2cb7c17bb879b171773e1e21259bb6b352f6020a5b7165be577bb147b22b5b0155c28e
6
+ metadata.gz: b77d93002b1395839dc4f9cf2c62bb40e9abaca0008aaf2a52c83498b811018782144686c7a83acdc8ae2b9bc3287b21e2808fcb996d6b270deb7fdf04c2dddb
7
+ data.tar.gz: 72c787d2dc63a2b78e09ae5660d1774a390e65ceb322529807965a0da95f27ca5f6ffd23dbcf1b81fb8ac4bb44f17ac58e508075c5cae959b1d1e233ed7c09e1
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/playwright-ruby-client.svg)](https://badge.fury.io/rb/playwright-ruby-client)
2
2
 
3
- # playwright-ruby-client
4
-
5
- A Ruby client for Playwright driver.
3
+ # 🎭 Playwright client for Ruby
6
4
 
7
5
  Note: Currently, this Gem is just a PoC (Proof of Concept). If you want to develop browser-automation for Chrome with Ruby, consider using [puppeteer-ruby](https://github.com/YusukeIwaki/puppeteer-ruby). The list of the available APIs of playwright-ruby-client is [here](./docs/api_coverage.md)
8
6
 
@@ -11,20 +9,34 @@ Note: Currently, this Gem is just a PoC (Proof of Concept). If you want to devel
11
9
  At this point, playwright-ruby-client doesn't include the downloader of playwright driver, so **we have to install [playwright](https://github.com/microsoft/playwright) in advance**.
12
10
 
13
11
  ```sh
12
+ npx playwright install
13
+ ```
14
+
15
+ and then, set `playwright_cli_executable_path: "npx playwright"` at `Playwright.create`.
16
+
17
+ **Prefer npm install instead of npx?**
18
+
19
+ Actually `npx playwright` is a bit slow. We can also use `npm install` to setup.
20
+
21
+ Instead of `npx playwright install`:
22
+
23
+ ```
14
24
  npm install playwright
15
25
  ./node_modules/.bin/playwright install
16
26
  ```
17
27
 
18
- and then, set `playwright_cli_executable_path: ./node_modules/.bin/playwright` at `Playwright.create`.
28
+ And set `playwright_cli_executable_path: './node_modules/.bin/playwright'`
29
+
30
+ **Prefer playwrighting without Node.js?**
19
31
 
20
- Instead of npm install, you can also directly download playwright driver from playwright.azureedge.net/builds/. The URL can be easily detected from [here](https://github.com/microsoft/playwright-python/blob/79f6ce0a6a69c480573372706df84af5ef99c4a4/setup.py#L56-L61)
32
+ Instead of npm, you can also directly download playwright driver from playwright.azureedge.net/builds/. The URL can be easily detected from [here](https://github.com/microsoft/playwright-python/blob/79f6ce0a6a69c480573372706df84af5ef99c4a4/setup.py#L56-L61)
21
33
 
22
34
  ### Capture a site
23
35
 
24
36
  ```ruby
25
37
  require 'playwright'
26
38
 
27
- Playwright.create(playwright_cli_executable_path: '/path/to/playwright') do |playwright|
39
+ Playwright.create(playwright_cli_executable_path: 'npx playwright') do |playwright|
28
40
  playwright.chromium.launch(headless: false) do |browser|
29
41
  page = browser.new_page
30
42
  page.goto('https://github.com/YusukeIwaki')
@@ -40,7 +52,7 @@ end
40
52
  ```ruby
41
53
  require 'playwright'
42
54
 
43
- Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
55
+ Playwright.create(playwright_cli_executable_path: 'npx playwright') do |playwright|
44
56
  playwright.chromium.launch(headless: false) do |browser|
45
57
  page = browser.new_page
46
58
  page.goto('https://github.com/')
@@ -82,7 +94,7 @@ $ bundle exec ruby main.rb
82
94
  ```ruby
83
95
  require 'playwright'
84
96
 
85
- Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
97
+ Playwright.create(playwright_cli_executable_path: 'npx playwright') do |playwright|
86
98
  devices = playwright.android.devices
87
99
  unless devices.empty?
88
100
  device = devices.last
data/docs/api_coverage.md CHANGED
@@ -9,6 +9,7 @@
9
9
  * method
10
10
  * post_data
11
11
  * post_data_buffer
12
+ * post_data_json
12
13
  * redirected_from
13
14
  * redirected_to
14
15
  * resource_type
@@ -18,28 +19,31 @@
18
19
 
19
20
  ## Response
20
21
 
21
- * ~~body~~
22
- * ~~finished~~
23
- * ~~frame~~
24
- * ~~headers~~
25
- * ~~ok~~
26
- * ~~request~~
27
- * ~~status~~
28
- * ~~status_text~~
29
- * ~~text~~
30
- * ~~url~~
22
+ * body
23
+ * finished
24
+ * frame
25
+ * headers
26
+ * json
27
+ * ok
28
+ * request
29
+ * status
30
+ * status_text
31
+ * text
32
+ * url
31
33
 
32
- ## ~~Route~~
34
+ ## Route
33
35
 
34
- * ~~abort~~
35
- * ~~continue_~~
36
- * ~~fulfill~~
37
- * ~~request~~
36
+ * abort
37
+ * continue
38
+ * fulfill
39
+ * request
38
40
 
39
41
  ## ~~WebSocket~~
40
42
 
41
43
  * ~~closed?~~
42
44
  * ~~url~~
45
+ * ~~expect_event~~
46
+ * ~~wait_for_event~~
43
47
 
44
48
  ## Keyboard
45
49
 
@@ -51,11 +55,11 @@
51
55
 
52
56
  ## Mouse
53
57
 
54
- * ~~click~~
55
- * ~~dblclick~~
56
- * ~~down~~
57
- * ~~move~~
58
- * ~~up~~
58
+ * click
59
+ * dblclick
60
+ * down
61
+ * move
62
+ * up
59
63
 
60
64
  ## Touchscreen
61
65
 
@@ -169,6 +173,7 @@
169
173
  * expect_navigation
170
174
  * wait_for_selector
171
175
  * ~~wait_for_timeout~~
176
+ * wait_for_url
172
177
 
173
178
  ## ~~Worker~~
174
179
 
@@ -178,7 +183,7 @@
178
183
 
179
184
  ## Selectors
180
185
 
181
- * ~~register~~
186
+ * register
182
187
 
183
188
  ## ConsoleMessage
184
189
 
@@ -187,27 +192,13 @@
187
192
  * text
188
193
  * type
189
194
 
190
- ## ~~Dialog~~
191
-
192
- * ~~accept~~
193
- * ~~default_value~~
194
- * ~~dismiss~~
195
- * ~~message~~
196
- * ~~type~~
197
-
198
- ## Download
199
-
200
- * ~~create_read_stream~~
201
- * delete
202
- * failure
203
- * path
204
- * save_as
205
- * suggested_filename
206
- * url
207
-
208
- ## ~~Video~~
195
+ ## Dialog
209
196
 
210
- * ~~path~~
197
+ * accept
198
+ * default_value
199
+ * dismiss
200
+ * message
201
+ * type
211
202
 
212
203
  ## Page
213
204
 
@@ -255,7 +246,7 @@
255
246
  * query_selector
256
247
  * query_selector_all
257
248
  * reload
258
- * ~~route~~
249
+ * route
259
250
  * screenshot
260
251
  * select_option
261
252
  * set_content
@@ -269,83 +260,142 @@
269
260
  * title
270
261
  * type
271
262
  * uncheck
272
- * ~~unroute~~
263
+ * unroute
273
264
  * url
274
- * ~~video~~
265
+ * video
275
266
  * viewport_size
267
+ * expect_console_message
268
+ * expect_download
269
+ * expect_event
270
+ * expect_file_chooser
276
271
  * wait_for_function
277
272
  * wait_for_load_state
278
273
  * expect_navigation
274
+ * expect_popup
279
275
  * expect_request
280
276
  * expect_response
281
277
  * wait_for_selector
282
278
  * ~~wait_for_timeout~~
279
+ * wait_for_url
280
+ * ~~expect_worker~~
283
281
  * ~~workers~~
282
+ * ~~wait_for_event~~
284
283
  * accessibility
285
- * ~~coverage~~
286
284
  * keyboard
287
285
  * mouse
288
286
  * touchscreen
289
287
 
290
288
  ## BrowserContext
291
289
 
292
- * ~~add_cookies~~
293
- * ~~add_init_script~~
294
- * ~~browser~~
295
- * ~~clear_cookies~~
296
- * ~~clear_permissions~~
290
+ * add_cookies
291
+ * add_init_script
292
+ * ~~background_pages~~
293
+ * browser
294
+ * clear_cookies
295
+ * clear_permissions
297
296
  * close
298
- * ~~cookies~~
299
- * ~~expose_binding~~
300
- * ~~expose_function~~
301
- * ~~grant_permissions~~
297
+ * cookies
298
+ * expose_binding
299
+ * expose_function
300
+ * grant_permissions
301
+ * ~~new_cdp_session~~
302
302
  * new_page
303
303
  * pages
304
- * ~~route~~
305
- * ~~set_default_navigation_timeout~~
306
- * ~~set_default_timeout~~
307
- * ~~set_extra_http_headers~~
308
- * ~~set_geolocation~~
309
- * ~~set_http_credentials~~
310
- * ~~set_offline~~
304
+ * route
305
+ * ~~service_workers~~
306
+ * set_default_navigation_timeout
307
+ * set_default_timeout
308
+ * set_extra_http_headers
309
+ * set_geolocation
310
+ * set_offline
311
311
  * ~~storage_state~~
312
- * ~~unroute~~
312
+ * unroute
313
+ * expect_event
314
+ * expect_page
315
+ * ~~wait_for_event~~
313
316
 
314
317
  ## ~~CDPSession~~
315
318
 
316
319
  * ~~detach~~
317
320
  * ~~send_message~~
318
321
 
319
- ## ChromiumBrowserContext
320
-
321
- * ~~background_pages~~
322
- * ~~new_cdp_session~~
323
- * ~~service_workers~~
324
-
325
322
  ## Browser
326
323
 
327
324
  * close
328
325
  * contexts
329
326
  * connected?
327
+ * ~~new_browser_cdp_session~~
330
328
  * new_context
331
329
  * new_page
330
+ * start_tracing
331
+ * stop_tracing
332
332
  * version
333
333
 
334
334
  ## BrowserType
335
335
 
336
- * ~~connect~~
337
336
  * executable_path
338
337
  * launch
339
338
  * ~~launch_persistent_context~~
340
- * ~~launch_server~~
341
339
  * name
342
340
 
343
341
  ## Playwright
344
342
 
345
- * ~~close~~
343
+ * ~~stop~~
346
344
  * chromium
347
345
  * devices
348
- * ~~errors~~
349
346
  * firefox
350
- * ~~selectors~~
347
+ * selectors
351
348
  * webkit
349
+
350
+ ## Android
351
+
352
+ * devices
353
+ * ~~set_default_timeout~~
354
+
355
+ ## AndroidDevice
356
+
357
+ * close
358
+ * ~~drag~~
359
+ * ~~fill~~
360
+ * ~~fling~~
361
+ * info
362
+ * ~~install_apk~~
363
+ * launch_browser
364
+ * ~~long_tap~~
365
+ * model
366
+ * ~~open~~
367
+ * ~~pinch_close~~
368
+ * ~~pinch_open~~
369
+ * ~~press~~
370
+ * ~~push~~
371
+ * screenshot
372
+ * ~~scroll~~
373
+ * serial
374
+ * ~~set_default_timeout~~
375
+ * shell
376
+ * ~~swipe~~
377
+ * ~~tap_point~~
378
+ * ~~wait~~
379
+ * ~~wait_for_event~~
380
+ * ~~web_view~~
381
+ * ~~web_views~~
382
+ * input
383
+
384
+ ## AndroidInput
385
+
386
+ * drag
387
+ * press
388
+ * ~~swipe~~
389
+ * tap_point
390
+ * type
391
+
392
+ ## ~~AndroidSocket~~
393
+
394
+ * ~~close~~
395
+ * ~~write~~
396
+
397
+ ## ~~AndroidWebView~~
398
+
399
+ * ~~page~~
400
+ * ~~pid~~
401
+ * ~~pkg~~
data/lib/playwright.rb CHANGED
@@ -17,14 +17,17 @@ require 'playwright/utils'
17
17
  require 'playwright/api_implementation'
18
18
  require 'playwright/channel'
19
19
  require 'playwright/channel_owner'
20
+ require 'playwright/download'
20
21
  require 'playwright/http_headers'
21
22
  require 'playwright/input_files'
22
23
  require 'playwright/connection'
24
+ require 'playwright/route_handler_entry'
23
25
  require 'playwright/select_option_values'
24
26
  require 'playwright/timeout_settings'
25
27
  require 'playwright/transport'
26
28
  require 'playwright/url_matcher'
27
29
  require 'playwright/version'
30
+ require 'playwright/video'
28
31
  require 'playwright/wait_helper'
29
32
 
30
33
  require 'playwright/playwright_api'
@@ -32,18 +35,54 @@ require 'playwright/playwright_api'
32
35
  Dir[File.join(__dir__, 'playwright_api', '*.rb')].each { |f| require f }
33
36
 
34
37
  module Playwright
35
- module_function def create(playwright_cli_executable_path:, &block)
36
- raise ArgumentError.new("block must be provided") unless block
38
+ class Execution
39
+ def initialize(connection, playwright)
40
+ @connection = connection
41
+ @playwright = playwright
42
+ end
43
+
44
+ def stop
45
+ @connection.stop
46
+ end
47
+
48
+ attr_reader :playwright
49
+ end
37
50
 
51
+ # Recommended to call this method with block.
52
+ #
53
+ # Playwright.create(...) do |playwright|
54
+ # browser = playwright.chromium.launch
55
+ # ...
56
+ # end
57
+ #
58
+ # When we use this method without block, an instance of Puppeteer::Execution is returned
59
+ # and we *must* call execution.stop on the end.
60
+ # The instance of playwright is available by calling execution.playwright
61
+ module_function def create(playwright_cli_executable_path:, &block)
38
62
  connection = Connection.new(playwright_cli_executable_path: playwright_cli_executable_path)
63
+ connection.async_run
64
+
65
+ execution =
66
+ begin
67
+ playwright = connection.wait_for_object_with_known_name('Playwright')
68
+ Execution.new(connection, PlaywrightApi.wrap(playwright))
69
+ rescue
70
+ connection.stop
71
+ raise
72
+ end
39
73
 
40
- playwright_promise = connection.async_wait_for_object_with_known_name('Playwright')
41
- Thread.new { connection.run }
42
- playwright = PlaywrightApi.wrap(playwright_promise.value!)
43
- begin
44
- block.call(playwright)
45
- ensure
46
- connection.stop
74
+ if block
75
+ begin
76
+ block.call(execution.playwright)
77
+ ensure
78
+ execution.stop
79
+ end
80
+ else
81
+ execution
47
82
  end
48
83
  end
84
+
85
+ module_function def instance
86
+ @playwright_instance
87
+ end
49
88
  end