playwright-ruby-client 0.2.0 → 0.5.4

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 (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +17 -5
  3. data/docs/api_coverage.md +116 -74
  4. data/lib/playwright.rb +48 -9
  5. data/lib/playwright/channel.rb +12 -2
  6. data/lib/playwright/channel_owners/artifact.rb +30 -0
  7. data/lib/playwright/channel_owners/binding_call.rb +3 -0
  8. data/lib/playwright/channel_owners/browser.rb +21 -0
  9. data/lib/playwright/channel_owners/browser_context.rb +154 -3
  10. data/lib/playwright/channel_owners/browser_type.rb +28 -0
  11. data/lib/playwright/channel_owners/dialog.rb +28 -0
  12. data/lib/playwright/channel_owners/element_handle.rb +6 -4
  13. data/lib/playwright/channel_owners/frame.rb +25 -2
  14. data/lib/playwright/channel_owners/js_handle.rb +2 -2
  15. data/lib/playwright/channel_owners/page.rb +141 -25
  16. data/lib/playwright/channel_owners/playwright.rb +24 -27
  17. data/lib/playwright/channel_owners/request.rb +26 -2
  18. data/lib/playwright/channel_owners/response.rb +60 -0
  19. data/lib/playwright/channel_owners/route.rb +78 -0
  20. data/lib/playwright/channel_owners/selectors.rb +19 -1
  21. data/lib/playwright/channel_owners/stream.rb +15 -0
  22. data/lib/playwright/connection.rb +11 -32
  23. data/lib/playwright/download.rb +27 -0
  24. data/lib/playwright/errors.rb +6 -0
  25. data/lib/playwright/events.rb +2 -5
  26. data/lib/playwright/keyboard_impl.rb +1 -1
  27. data/lib/playwright/mouse_impl.rb +41 -0
  28. data/lib/playwright/playwright_api.rb +3 -1
  29. data/lib/playwright/route_handler_entry.rb +28 -0
  30. data/lib/playwright/transport.rb +29 -7
  31. data/lib/playwright/url_matcher.rb +1 -1
  32. data/lib/playwright/utils.rb +9 -0
  33. data/lib/playwright/version.rb +1 -1
  34. data/lib/playwright/video.rb +51 -0
  35. data/lib/playwright/wait_helper.rb +2 -2
  36. data/lib/playwright_api/accessibility.rb +39 -1
  37. data/lib/playwright_api/android.rb +74 -2
  38. data/lib/playwright_api/android_device.rb +141 -23
  39. data/lib/playwright_api/android_input.rb +17 -13
  40. data/lib/playwright_api/android_socket.rb +16 -0
  41. data/lib/playwright_api/android_web_view.rb +21 -0
  42. data/lib/playwright_api/browser.rb +77 -2
  43. data/lib/playwright_api/browser_context.rb +182 -29
  44. data/lib/playwright_api/browser_type.rb +40 -9
  45. data/lib/playwright_api/dialog.rb +54 -7
  46. data/lib/playwright_api/element_handle.rb +105 -31
  47. data/lib/playwright_api/file_chooser.rb +6 -1
  48. data/lib/playwright_api/frame.rb +229 -36
  49. data/lib/playwright_api/js_handle.rb +23 -0
  50. data/lib/playwright_api/keyboard.rb +48 -1
  51. data/lib/playwright_api/mouse.rb +26 -5
  52. data/lib/playwright_api/page.rb +491 -81
  53. data/lib/playwright_api/playwright.rb +21 -4
  54. data/lib/playwright_api/request.rb +30 -2
  55. data/lib/playwright_api/response.rb +21 -11
  56. data/lib/playwright_api/route.rb +51 -5
  57. data/lib/playwright_api/selectors.rb +27 -1
  58. data/lib/playwright_api/touchscreen.rb +1 -1
  59. data/lib/playwright_api/worker.rb +25 -1
  60. data/playwright.gemspec +4 -2
  61. metadata +42 -14
  62. data/lib/playwright/channel_owners/chromium_browser.rb +0 -8
  63. data/lib/playwright/channel_owners/chromium_browser_context.rb +0 -8
  64. data/lib/playwright/channel_owners/download.rb +0 -27
  65. data/lib/playwright/channel_owners/firefox_browser.rb +0 -8
  66. data/lib/playwright/channel_owners/webkit_browser.rb +0 -8
  67. data/lib/playwright_api/binding_call.rb +0 -27
  68. data/lib/playwright_api/chromium_browser_context.rb +0 -59
  69. data/lib/playwright_api/download.rb +0 -95
  70. data/lib/playwright_api/video.rb +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eecde37d8ee0ad9fdb1f0df5a64a5a646f2706915a24a2a2d83a8f176bcc8519
4
- data.tar.gz: cb97a5926b3a25c8c3b2fe8c88946747ec89d3d579f71d36350c7cf2839c83e0
3
+ metadata.gz: 548d69d7e9ada4dcbd8b760c5c993ad48809bc952d889aa96b440e8d2f2e4cc3
4
+ data.tar.gz: d1c634791be5a553240895824b5cd99d17d41d52c0cdfc81993992a8175b4897
5
5
  SHA512:
6
- metadata.gz: 2e1bb8eee779773afd9e3b165a03f3c91bb25ae076ae00d6d1603e34afe8eaf3876f847559841c68403588a79b766f3e4afe680f7056286c64ba16ce5be149bc
7
- data.tar.gz: e55e7895a26b5a579cae82101cd9ae0bf3cebd4f9ecc0c18692b4a18fa5a7e649b4121d9ac5c6029101131cdd56c59af64ba8b65d6c325cfbe7ffe56c8ee632c
6
+ metadata.gz: d61d45ba95f21049bf4e14001c874d659e3a825f1f531ecd91c4ab107dae3d6eee90ee02f1f7dcce4a7fc8d1041da5bf0b09f4cf562baeb5dd0d2d676ee6eec7
7
+ data.tar.gz: 134a10c14a14b716d8be3eff79fffb44fc3f254078a63ac3f00070e5e937ef7523f4b4272b2e838a36357b88862cc643a2d3a5ca9b72295535bdfd1c71cce8f1
data/README.md CHANGED
@@ -9,22 +9,34 @@ Note: Currently, this Gem is just a PoC (Proof of Concept). If you want to devel
9
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**.
10
10
 
11
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
+ ```
12
24
  npm install playwright
13
25
  ./node_modules/.bin/playwright install
14
26
  ```
15
27
 
16
- 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'`
17
29
 
18
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
@@ -19,24 +19,24 @@
19
19
 
20
20
  ## Response
21
21
 
22
- * ~~body~~
23
- * ~~finished~~
24
- * ~~frame~~
25
- * ~~headers~~
26
- * ~~json~~
27
- * ~~ok~~
28
- * ~~request~~
29
- * ~~status~~
30
- * ~~status_text~~
31
- * ~~text~~
32
- * ~~url~~
22
+ * body
23
+ * finished
24
+ * frame
25
+ * headers
26
+ * json
27
+ * ok
28
+ * request
29
+ * status
30
+ * status_text
31
+ * text
32
+ * url
33
33
 
34
- ## ~~Route~~
34
+ ## Route
35
35
 
36
- * ~~abort~~
37
- * ~~continue_~~
38
- * ~~fulfill~~
39
- * ~~request~~
36
+ * abort
37
+ * continue
38
+ * fulfill
39
+ * request
40
40
 
41
41
  ## ~~WebSocket~~
42
42
 
@@ -55,11 +55,11 @@
55
55
 
56
56
  ## Mouse
57
57
 
58
- * ~~click~~
59
- * ~~dblclick~~
60
- * ~~down~~
61
- * ~~move~~
62
- * ~~up~~
58
+ * click
59
+ * dblclick
60
+ * down
61
+ * move
62
+ * up
63
63
 
64
64
  ## Touchscreen
65
65
 
@@ -173,6 +173,7 @@
173
173
  * expect_navigation
174
174
  * wait_for_selector
175
175
  * ~~wait_for_timeout~~
176
+ * wait_for_url
176
177
 
177
178
  ## ~~Worker~~
178
179
 
@@ -182,7 +183,7 @@
182
183
 
183
184
  ## Selectors
184
185
 
185
- * ~~register~~
186
+ * register
186
187
 
187
188
  ## ConsoleMessage
188
189
 
@@ -191,26 +192,13 @@
191
192
  * text
192
193
  * type
193
194
 
194
- ## ~~Dialog~~
195
-
196
- * ~~accept~~
197
- * ~~default_value~~
198
- * ~~dismiss~~
199
- * ~~message~~
200
- * ~~type~~
201
-
202
- ## Download
203
-
204
- * delete
205
- * failure
206
- * path
207
- * save_as
208
- * suggested_filename
209
- * url
210
-
211
- ## ~~Video~~
195
+ ## Dialog
212
196
 
213
- * ~~path~~
197
+ * accept
198
+ * default_value
199
+ * dismiss
200
+ * message
201
+ * type
214
202
 
215
203
  ## Page
216
204
 
@@ -258,7 +246,7 @@
258
246
  * query_selector
259
247
  * query_selector_all
260
248
  * reload
261
- * ~~route~~
249
+ * route
262
250
  * screenshot
263
251
  * select_option
264
252
  * set_content
@@ -272,24 +260,25 @@
272
260
  * title
273
261
  * type
274
262
  * uncheck
275
- * ~~unroute~~
263
+ * unroute
276
264
  * url
277
- * ~~video~~
265
+ * video
278
266
  * viewport_size
267
+ * expect_console_message
268
+ * expect_download
279
269
  * expect_event
270
+ * expect_file_chooser
280
271
  * wait_for_function
281
272
  * wait_for_load_state
282
273
  * expect_navigation
274
+ * expect_popup
283
275
  * expect_request
284
276
  * expect_response
285
277
  * wait_for_selector
286
278
  * ~~wait_for_timeout~~
287
- * ~~workers~~
288
- * ~~expect_download~~
289
- * ~~expect_popup~~
279
+ * wait_for_url
290
280
  * ~~expect_worker~~
291
- * ~~expect_console_message~~
292
- * ~~expect_file_chooser~~
281
+ * ~~workers~~
293
282
  * ~~wait_for_event~~
294
283
  * accessibility
295
284
  * keyboard
@@ -298,28 +287,31 @@
298
287
 
299
288
  ## BrowserContext
300
289
 
301
- * ~~add_cookies~~
302
- * ~~add_init_script~~
303
- * ~~browser~~
304
- * ~~clear_cookies~~
305
- * ~~clear_permissions~~
290
+ * add_cookies
291
+ * add_init_script
292
+ * ~~background_pages~~
293
+ * browser
294
+ * clear_cookies
295
+ * clear_permissions
306
296
  * close
307
- * ~~cookies~~
308
- * ~~expose_binding~~
309
- * ~~expose_function~~
310
- * ~~grant_permissions~~
297
+ * cookies
298
+ * expose_binding
299
+ * expose_function
300
+ * grant_permissions
301
+ * ~~new_cdp_session~~
311
302
  * new_page
312
303
  * pages
313
- * ~~route~~
314
- * ~~set_default_navigation_timeout~~
315
- * ~~set_default_timeout~~
316
- * ~~set_extra_http_headers~~
317
- * ~~set_geolocation~~
318
- * ~~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
319
311
  * ~~storage_state~~
320
- * ~~unroute~~
321
- * ~~expect_event~~
322
- * ~~expect_page~~
312
+ * unroute
313
+ * expect_event
314
+ * expect_page
323
315
  * ~~wait_for_event~~
324
316
 
325
317
  ## ~~CDPSession~~
@@ -327,19 +319,16 @@
327
319
  * ~~detach~~
328
320
  * ~~send_message~~
329
321
 
330
- ## ChromiumBrowserContext
331
-
332
- * ~~background_pages~~
333
- * ~~new_cdp_session~~
334
- * ~~service_workers~~
335
-
336
322
  ## Browser
337
323
 
338
324
  * close
339
325
  * contexts
340
326
  * connected?
327
+ * ~~new_browser_cdp_session~~
341
328
  * new_context
342
329
  * new_page
330
+ * start_tracing
331
+ * stop_tracing
343
332
  * version
344
333
 
345
334
  ## BrowserType
@@ -355,5 +344,58 @@
355
344
  * chromium
356
345
  * devices
357
346
  * firefox
358
- * ~~selectors~~
347
+ * selectors
359
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
@@ -15,8 +15,9 @@ module Playwright
15
15
 
16
16
  # @param method [String]
17
17
  # @param params [Hash]
18
+ # @return [Playwright::ChannelOwner|nil]
18
19
  def send_message_to_server(method, params = {})
19
- result = @connection.send_message_to_server(@guid, method, params)
20
+ result = send_message_to_server_result(method, params)
20
21
  if result.is_a?(Hash)
21
22
  _type, channel_owner = result.first
22
23
  channel_owner
@@ -27,8 +28,17 @@ module Playwright
27
28
 
28
29
  # @param method [String]
29
30
  # @param params [Hash]
30
- def send_no_reply(method, params)
31
+ # @return [Hash]
32
+ def send_message_to_server_result(method, params)
33
+ @connection.send_message_to_server(@guid, method, params)
34
+ end
35
+
36
+ # @param method [String]
37
+ # @param params [Hash]
38
+ # @returns nil
39
+ def async_send_message_to_server(method, params = {})
31
40
  @connection.async_send_message_to_server(@guid, method, params)
41
+
32
42
  nil
33
43
  end
34
44
  end