playwright-ruby-client 0.0.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +117 -5
  3. data/docs/api_coverage.md +359 -0
  4. data/lib/playwright.rb +6 -2
  5. data/lib/playwright/android_input_impl.rb +23 -0
  6. data/lib/playwright/api_implementation.rb +18 -0
  7. data/lib/playwright/channel.rb +7 -0
  8. data/lib/playwright/channel_owner.rb +6 -7
  9. data/lib/playwright/channel_owners/android.rb +10 -1
  10. data/lib/playwright/channel_owners/android_device.rb +163 -0
  11. data/lib/playwright/channel_owners/browser.rb +14 -14
  12. data/lib/playwright/channel_owners/browser_context.rb +10 -2
  13. data/lib/playwright/channel_owners/download.rb +27 -0
  14. data/lib/playwright/channel_owners/element_handle.rb +243 -1
  15. data/lib/playwright/channel_owners/frame.rb +269 -22
  16. data/lib/playwright/channel_owners/js_handle.rb +51 -0
  17. data/lib/playwright/channel_owners/page.rb +379 -34
  18. data/lib/playwright/channel_owners/request.rb +9 -1
  19. data/lib/playwright/channel_owners/webkit_browser.rb +1 -1
  20. data/lib/playwright/connection.rb +9 -6
  21. data/lib/playwright/errors.rb +2 -2
  22. data/lib/playwright/event_emitter.rb +8 -1
  23. data/lib/playwright/event_emitter_proxy.rb +49 -0
  24. data/lib/playwright/file_chooser_impl.rb +23 -0
  25. data/lib/playwright/http_headers.rb +20 -0
  26. data/lib/playwright/input_files.rb +42 -0
  27. data/lib/playwright/javascript/expression.rb +15 -0
  28. data/lib/playwright/javascript/function.rb +15 -0
  29. data/lib/playwright/javascript/value_parser.rb +1 -1
  30. data/lib/playwright/javascript/value_serializer.rb +11 -11
  31. data/lib/playwright/{input_types/keyboard.rb → keyboard_impl.rb} +6 -2
  32. data/lib/playwright/mouse_impl.rb +7 -0
  33. data/lib/playwright/playwright_api.rb +66 -19
  34. data/lib/playwright/select_option_values.rb +42 -0
  35. data/lib/playwright/timeout_settings.rb +1 -1
  36. data/lib/playwright/touchscreen_impl.rb +7 -0
  37. data/lib/playwright/utils.rb +18 -0
  38. data/lib/playwright/version.rb +1 -1
  39. data/lib/playwright/wait_helper.rb +1 -1
  40. data/lib/playwright_api/android.rb +32 -0
  41. data/lib/playwright_api/android_device.rb +77 -0
  42. data/lib/playwright_api/android_input.rb +25 -0
  43. data/lib/playwright_api/binding_call.rb +10 -6
  44. data/lib/playwright_api/browser.rb +22 -22
  45. data/lib/playwright_api/browser_context.rb +31 -22
  46. data/lib/playwright_api/browser_type.rb +16 -56
  47. data/lib/playwright_api/chromium_browser_context.rb +10 -8
  48. data/lib/playwright_api/console_message.rb +9 -10
  49. data/lib/playwright_api/dialog.rb +7 -3
  50. data/lib/playwright_api/download.rb +28 -11
  51. data/lib/playwright_api/element_handle.rb +139 -127
  52. data/lib/playwright_api/file_chooser.rb +17 -9
  53. data/lib/playwright_api/frame.rb +148 -148
  54. data/lib/playwright_api/js_handle.rb +26 -22
  55. data/lib/playwright_api/keyboard.rb +6 -6
  56. data/lib/playwright_api/page.rb +215 -179
  57. data/lib/playwright_api/playwright.rb +34 -46
  58. data/lib/playwright_api/request.rb +7 -8
  59. data/lib/playwright_api/response.rb +10 -6
  60. data/lib/playwright_api/selectors.rb +13 -9
  61. data/lib/playwright_api/web_socket.rb +10 -1
  62. data/lib/playwright_api/worker.rb +13 -13
  63. data/playwright.gemspec +1 -0
  64. metadata +32 -6
  65. data/lib/playwright/input_type.rb +0 -19
  66. data/lib/playwright/input_types/mouse.rb +0 -4
  67. data/lib/playwright/input_types/touchscreen.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 243ef6d83fffde209cb8effe291c49b80fb90f7fd1fab7dacd451a524793f78a
4
- data.tar.gz: 877db73a65179e2409423c73aa1fdf72b0da40ebe2d44bf22bce34533c438c98
3
+ metadata.gz: eecde37d8ee0ad9fdb1f0df5a64a5a646f2706915a24a2a2d83a8f176bcc8519
4
+ data.tar.gz: cb97a5926b3a25c8c3b2fe8c88946747ec89d3d579f71d36350c7cf2839c83e0
5
5
  SHA512:
6
- metadata.gz: 01ea7a14404c07a54acd5112ad3704ce0d00ccd562061cbf46b0ec190c26ff0df850c613cddde6ff2d922de390063d6398a02a33f44fad88dd6d5d6ab1918893
7
- data.tar.gz: 5e965b61082503371431d72a8b243c6212d5d2f3b6a232d62faf6fed2c85a920c041e259ea8f2d646722bf9e14eb4fcefebc9f40e86dca3a8ec2aa931c63d95b
6
+ metadata.gz: 2e1bb8eee779773afd9e3b165a03f3c91bb25ae076ae00d6d1603e34afe8eaf3876f847559841c68403588a79b766f3e4afe680f7056286c64ba16ce5be149bc
7
+ data.tar.gz: e55e7895a26b5a579cae82101cd9ae0bf3cebd4f9ecc0c18692b4a18fa5a7e649b4121d9ac5c6029101131cdd56c59af64ba8b65d6c325cfbe7ffe56c8ee632c
data/README.md CHANGED
@@ -1,14 +1,12 @@
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
3
+ # 🎭 Playwright client for Ruby
4
4
 
5
- A Ruby client for Playwright driver.
6
-
7
- 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)
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
 
9
7
  ## Getting Started
10
8
 
11
- At this point, playwright-ruby-client doesn't include the downloader of playwright driver, so **we have to install [playwright CLI](https://github.com/microsoft/playwright-cli) in advance**.
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
14
12
  npm install playwright
@@ -17,6 +15,8 @@ npm install playwright
17
15
 
18
16
  and then, set `playwright_cli_executable_path: ./node_modules/.bin/playwright` at `Playwright.create`.
19
17
 
18
+ **Prefer playwrighting without Node.js?**
19
+
20
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)
21
21
 
22
22
  ### Capture a site
@@ -35,6 +35,118 @@ end
35
35
 
36
36
  ![image](https://user-images.githubusercontent.com/11763113/104339718-412f9180-553b-11eb-9116-908e1e4b5186.gif)
37
37
 
38
+ ### Simple scraping
39
+
40
+ ```ruby
41
+ require 'playwright'
42
+
43
+ Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
44
+ playwright.chromium.launch(headless: false) do |browser|
45
+ page = browser.new_page
46
+ page.goto('https://github.com/')
47
+
48
+ form = page.query_selector("form.js-site-search-form")
49
+ search_input = form.query_selector("input.header-search-input")
50
+ search_input.click
51
+ page.keyboard.type("playwright")
52
+ page.expect_navigation {
53
+ page.keyboard.press("Enter")
54
+ }
55
+
56
+ list = page.query_selector("ul.repo-list")
57
+ items = list.query_selector_all("div.f4")
58
+ items.each do |item|
59
+ title = item.eval_on_selector("a", "a => a.innerText")
60
+ puts("==> #{title}")
61
+ end
62
+ end
63
+ end
64
+ ```
65
+
66
+ ```sh
67
+ $ bundle exec ruby main.rb
68
+ ==> microsoft/playwright
69
+ ==> microsoft/playwright-python
70
+ ==> microsoft/playwright-cli
71
+ ==> checkly/headless-recorder
72
+ ==> microsoft/playwright-sharp
73
+ ==> playwright-community/jest-playwright
74
+ ==> microsoft/playwright-test
75
+ ==> mxschmitt/playwright-go
76
+ ==> microsoft/playwright-java
77
+ ==> MarketSquare/robotframework-browser
78
+ ```
79
+
80
+ ### Android browser automation
81
+
82
+ ```ruby
83
+ require 'playwright'
84
+
85
+ Playwright.create(playwright_cli_executable_path: './node_modules/.bin/playwright') do |playwright|
86
+ devices = playwright.android.devices
87
+ unless devices.empty?
88
+ device = devices.last
89
+ begin
90
+ puts "Model: #{device.model}"
91
+ puts "Serial: #{device.serial}"
92
+ puts device.shell('ls /system')
93
+
94
+ device.launch_browser do |context|
95
+ page = context.pages.first
96
+ page.goto('https://github.com/YusukeIwaki')
97
+ page.click('header button')
98
+ page.click('input[name="q"]')
99
+ page.keyboard.type('puppeteer')
100
+ page.expect_navigation {
101
+ page.keyboard.press('Enter')
102
+ }
103
+ page.screenshot(path: 'YusukeIwaki.android.png')
104
+ end
105
+ ensure
106
+ device.close
107
+ end
108
+ end
109
+ end
110
+ ```
111
+
112
+ ![android-browser](https://user-images.githubusercontent.com/11763113/106615177-8467a800-65af-11eb-94d9-c56e71487e78.gif)
113
+
114
+ ### Android native automation
115
+
116
+ We have to download android-driver for Playwright in advance.
117
+
118
+ ```
119
+ wget https://github.com/microsoft/playwright/raw/master/bin/android-driver-target.apk -O /path/to/playwright-driver/package/bin/android-driver-target.apk
120
+ wget https://github.com/microsoft/playwright/raw/master/bin/android-driver.apk -O /path/to/playwright-driver/package/bin/android-driver.apk
121
+ ```
122
+
123
+ (If you downloaded Playwright via npm, replace `/path/to/playwright-driver/package/` with `./node_modules/playwright/` above.)
124
+
125
+ ```ruby
126
+ require 'playwright'
127
+
128
+ Playwright.create(playwright_cli_executable_path: ENV['PLAYWRIGHT_CLI_EXECUTABLE_PATH']) do |playwright|
129
+ devices = playwright.android.devices
130
+ unless devices.empty?
131
+ device = devices.last
132
+ begin
133
+ device.shell('input keyevent POWER')
134
+ device.shell('input keyevent POWER')
135
+ device.shell('input keyevent 82')
136
+ sleep 1
137
+ device.shell('cmd statusbar expand-notifications')
138
+
139
+ # pp device.tree
140
+ # pp device.info(res: 'com.android.systemui:id/clock')
141
+ device.tap_on(res: 'com.android.systemui:id/clock')
142
+ ensure
143
+ device.close
144
+ end
145
+ end
146
+ end
147
+
148
+ ```
149
+
38
150
  ## License
39
151
 
40
152
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,359 @@
1
+ # API coverages
2
+
3
+ ## Request
4
+
5
+ * failure
6
+ * frame
7
+ * headers
8
+ * navigation_request?
9
+ * method
10
+ * post_data
11
+ * post_data_buffer
12
+ * post_data_json
13
+ * redirected_from
14
+ * redirected_to
15
+ * resource_type
16
+ * response
17
+ * timing
18
+ * url
19
+
20
+ ## Response
21
+
22
+ * ~~body~~
23
+ * ~~finished~~
24
+ * ~~frame~~
25
+ * ~~headers~~
26
+ * ~~json~~
27
+ * ~~ok~~
28
+ * ~~request~~
29
+ * ~~status~~
30
+ * ~~status_text~~
31
+ * ~~text~~
32
+ * ~~url~~
33
+
34
+ ## ~~Route~~
35
+
36
+ * ~~abort~~
37
+ * ~~continue_~~
38
+ * ~~fulfill~~
39
+ * ~~request~~
40
+
41
+ ## ~~WebSocket~~
42
+
43
+ * ~~closed?~~
44
+ * ~~url~~
45
+ * ~~expect_event~~
46
+ * ~~wait_for_event~~
47
+
48
+ ## Keyboard
49
+
50
+ * down
51
+ * insert_text
52
+ * press
53
+ * type
54
+ * up
55
+
56
+ ## Mouse
57
+
58
+ * ~~click~~
59
+ * ~~dblclick~~
60
+ * ~~down~~
61
+ * ~~move~~
62
+ * ~~up~~
63
+
64
+ ## Touchscreen
65
+
66
+ * ~~tap_point~~
67
+
68
+ ## JSHandle
69
+
70
+ * as_element
71
+ * dispose
72
+ * evaluate
73
+ * evaluate_handle
74
+ * get_properties
75
+ * get_property
76
+ * json_value
77
+
78
+ ## ElementHandle
79
+
80
+ * bounding_box
81
+ * check
82
+ * click
83
+ * content_frame
84
+ * dblclick
85
+ * dispatch_event
86
+ * eval_on_selector
87
+ * eval_on_selector_all
88
+ * fill
89
+ * focus
90
+ * get_attribute
91
+ * hover
92
+ * inner_html
93
+ * inner_text
94
+ * checked?
95
+ * disabled?
96
+ * editable?
97
+ * enabled?
98
+ * hidden?
99
+ * visible?
100
+ * owner_frame
101
+ * press
102
+ * query_selector
103
+ * query_selector_all
104
+ * screenshot
105
+ * scroll_into_view_if_needed
106
+ * select_option
107
+ * select_text
108
+ * set_input_files
109
+ * tap_point
110
+ * text_content
111
+ * type
112
+ * uncheck
113
+ * wait_for_element_state
114
+ * wait_for_selector
115
+
116
+ ## ~~Accessibility~~
117
+
118
+ * ~~snapshot~~
119
+
120
+ ## FileChooser
121
+
122
+ * element
123
+ * multiple?
124
+ * page
125
+ * set_files
126
+
127
+ ## Frame
128
+
129
+ * add_script_tag
130
+ * add_style_tag
131
+ * check
132
+ * child_frames
133
+ * click
134
+ * content
135
+ * dblclick
136
+ * dispatch_event
137
+ * eval_on_selector
138
+ * eval_on_selector_all
139
+ * evaluate
140
+ * evaluate_handle
141
+ * fill
142
+ * focus
143
+ * ~~frame_element~~
144
+ * get_attribute
145
+ * goto
146
+ * hover
147
+ * inner_html
148
+ * inner_text
149
+ * checked?
150
+ * detached?
151
+ * disabled?
152
+ * editable?
153
+ * enabled?
154
+ * hidden?
155
+ * visible?
156
+ * name
157
+ * page
158
+ * parent_frame
159
+ * press
160
+ * query_selector
161
+ * query_selector_all
162
+ * select_option
163
+ * set_content
164
+ * set_input_files
165
+ * tap_point
166
+ * text_content
167
+ * title
168
+ * type
169
+ * uncheck
170
+ * url
171
+ * wait_for_function
172
+ * wait_for_load_state
173
+ * expect_navigation
174
+ * wait_for_selector
175
+ * ~~wait_for_timeout~~
176
+
177
+ ## ~~Worker~~
178
+
179
+ * ~~evaluate~~
180
+ * ~~evaluate_handle~~
181
+ * ~~url~~
182
+
183
+ ## Selectors
184
+
185
+ * ~~register~~
186
+
187
+ ## ConsoleMessage
188
+
189
+ * args
190
+ * location
191
+ * text
192
+ * type
193
+
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~~
212
+
213
+ * ~~path~~
214
+
215
+ ## Page
216
+
217
+ * add_init_script
218
+ * add_script_tag
219
+ * add_style_tag
220
+ * bring_to_front
221
+ * check
222
+ * click
223
+ * close
224
+ * content
225
+ * context
226
+ * dblclick
227
+ * dispatch_event
228
+ * emulate_media
229
+ * eval_on_selector
230
+ * eval_on_selector_all
231
+ * evaluate
232
+ * evaluate_handle
233
+ * expose_binding
234
+ * expose_function
235
+ * fill
236
+ * focus
237
+ * frame
238
+ * frames
239
+ * get_attribute
240
+ * go_back
241
+ * go_forward
242
+ * goto
243
+ * hover
244
+ * inner_html
245
+ * inner_text
246
+ * checked?
247
+ * closed?
248
+ * disabled?
249
+ * editable?
250
+ * enabled?
251
+ * hidden?
252
+ * visible?
253
+ * main_frame
254
+ * opener
255
+ * ~~pause~~
256
+ * pdf
257
+ * press
258
+ * query_selector
259
+ * query_selector_all
260
+ * reload
261
+ * ~~route~~
262
+ * screenshot
263
+ * select_option
264
+ * set_content
265
+ * set_default_navigation_timeout
266
+ * set_default_timeout
267
+ * set_extra_http_headers
268
+ * set_input_files
269
+ * set_viewport_size
270
+ * tap_point
271
+ * text_content
272
+ * title
273
+ * type
274
+ * uncheck
275
+ * ~~unroute~~
276
+ * url
277
+ * ~~video~~
278
+ * viewport_size
279
+ * expect_event
280
+ * wait_for_function
281
+ * wait_for_load_state
282
+ * expect_navigation
283
+ * expect_request
284
+ * expect_response
285
+ * wait_for_selector
286
+ * ~~wait_for_timeout~~
287
+ * ~~workers~~
288
+ * ~~expect_download~~
289
+ * ~~expect_popup~~
290
+ * ~~expect_worker~~
291
+ * ~~expect_console_message~~
292
+ * ~~expect_file_chooser~~
293
+ * ~~wait_for_event~~
294
+ * accessibility
295
+ * keyboard
296
+ * mouse
297
+ * touchscreen
298
+
299
+ ## BrowserContext
300
+
301
+ * ~~add_cookies~~
302
+ * ~~add_init_script~~
303
+ * ~~browser~~
304
+ * ~~clear_cookies~~
305
+ * ~~clear_permissions~~
306
+ * close
307
+ * ~~cookies~~
308
+ * ~~expose_binding~~
309
+ * ~~expose_function~~
310
+ * ~~grant_permissions~~
311
+ * new_page
312
+ * pages
313
+ * ~~route~~
314
+ * ~~set_default_navigation_timeout~~
315
+ * ~~set_default_timeout~~
316
+ * ~~set_extra_http_headers~~
317
+ * ~~set_geolocation~~
318
+ * ~~set_offline~~
319
+ * ~~storage_state~~
320
+ * ~~unroute~~
321
+ * ~~expect_event~~
322
+ * ~~expect_page~~
323
+ * ~~wait_for_event~~
324
+
325
+ ## ~~CDPSession~~
326
+
327
+ * ~~detach~~
328
+ * ~~send_message~~
329
+
330
+ ## ChromiumBrowserContext
331
+
332
+ * ~~background_pages~~
333
+ * ~~new_cdp_session~~
334
+ * ~~service_workers~~
335
+
336
+ ## Browser
337
+
338
+ * close
339
+ * contexts
340
+ * connected?
341
+ * new_context
342
+ * new_page
343
+ * version
344
+
345
+ ## BrowserType
346
+
347
+ * executable_path
348
+ * launch
349
+ * ~~launch_persistent_context~~
350
+ * name
351
+
352
+ ## Playwright
353
+
354
+ * ~~stop~~
355
+ * chromium
356
+ * devices
357
+ * firefox
358
+ * ~~selectors~~
359
+ * webkit