playwright-ruby-client 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +114 -2
  3. data/docs/api_coverage.md +351 -0
  4. data/lib/playwright.rb +7 -1
  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 +3 -2
  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 +13 -13
  12. data/lib/playwright/channel_owners/browser_context.rb +9 -1
  13. data/lib/playwright/channel_owners/download.rb +27 -0
  14. data/lib/playwright/channel_owners/element_handle.rb +306 -0
  15. data/lib/playwright/channel_owners/frame.rb +371 -19
  16. data/lib/playwright/channel_owners/js_handle.rb +51 -0
  17. data/lib/playwright/channel_owners/page.rb +416 -19
  18. data/lib/playwright/channel_owners/request.rb +98 -0
  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 +37 -0
  28. data/lib/playwright/javascript/function.rb +37 -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/keyboard_impl.rb +36 -0
  32. data/lib/playwright/mouse_impl.rb +7 -0
  33. data/lib/playwright/playwright_api.rb +84 -29
  34. data/lib/playwright/select_option_values.rb +32 -0
  35. data/lib/playwright/timeout_settings.rb +2 -2
  36. data/lib/playwright/touchscreen_impl.rb +7 -0
  37. data/lib/playwright/url_matcher.rb +19 -0
  38. data/lib/playwright/utils.rb +18 -0
  39. data/lib/playwright/version.rb +1 -1
  40. data/lib/playwright/wait_helper.rb +1 -1
  41. data/lib/playwright_api/accessibility.rb +46 -6
  42. data/lib/playwright_api/android.rb +37 -0
  43. data/lib/playwright_api/android_device.rb +82 -0
  44. data/lib/playwright_api/android_input.rb +25 -0
  45. data/lib/playwright_api/binding_call.rb +10 -6
  46. data/lib/playwright_api/browser.rb +85 -18
  47. data/lib/playwright_api/browser_context.rb +269 -37
  48. data/lib/playwright_api/browser_type.rb +60 -11
  49. data/lib/playwright_api/cdp_session.rb +23 -1
  50. data/lib/playwright_api/chromium_browser_context.rb +18 -6
  51. data/lib/playwright_api/console_message.rb +14 -15
  52. data/lib/playwright_api/dialog.rb +48 -2
  53. data/lib/playwright_api/download.rb +47 -10
  54. data/lib/playwright_api/element_handle.rb +269 -110
  55. data/lib/playwright_api/file_chooser.rb +23 -7
  56. data/lib/playwright_api/frame.rb +439 -154
  57. data/lib/playwright_api/js_handle.rb +69 -24
  58. data/lib/playwright_api/keyboard.rb +99 -9
  59. data/lib/playwright_api/mouse.rb +22 -0
  60. data/lib/playwright_api/page.rb +856 -229
  61. data/lib/playwright_api/playwright.rb +108 -20
  62. data/lib/playwright_api/request.rb +77 -29
  63. data/lib/playwright_api/response.rb +10 -13
  64. data/lib/playwright_api/route.rb +49 -0
  65. data/lib/playwright_api/selectors.rb +20 -8
  66. data/lib/playwright_api/video.rb +8 -0
  67. data/lib/playwright_api/web_socket.rb +0 -8
  68. data/lib/playwright_api/worker.rb +25 -13
  69. data/playwright.gemspec +1 -0
  70. metadata +33 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c54a8690be4b1b2e33cecb6cda92071cd1d6867647fe939b004bf0434c31c74e
4
- data.tar.gz: 1c2c784a5970c7a89bffc6bdb12cf7c8e1353a676881a99862bb9bbe30dd3dea
3
+ metadata.gz: a8e526e28e95751a08697bc93b14ec33f4f82e827b8adf4dc45aed4bf44dd1d2
4
+ data.tar.gz: 647596db5628a1014a7816bb43d2ca41a21eeb6cf8c7263dea701d8f9a6ba4e7
5
5
  SHA512:
6
- metadata.gz: e9ca66a5edc3d168e16b552f3c84e4b4a939a7e8610da439fdea8350a87fed0656a9b5c715e4ac384d23b1d089ab23fa61ccd06288b1f11045aa83a3351a4f94
7
- data.tar.gz: cad563aa4e2f81a026f08a04a7fd3caf1295f6419b01f1601d324583243dd839bb4b7f3aec73967555c4dbb6b8ffb8b65e7607836ec2c11231512c6e45fbf526
6
+ metadata.gz: 0051320ee1e574680ebc6be4d5cf359a28bd8ada9a737fc60d734f017c43142b6f267553f15d0e1ac0ed368f12d57dac5a887a39695f59a11f774344405dcfd1
7
+ data.tar.gz: 14f97b51a9462a8bfb587c5752eb13b3db0c132d0d56d7bdaab829389f2cb7c17bb879b171773e1e21259bb6b352f6020a5b7165be577bb147b22b5b0155c28e
data/README.md CHANGED
@@ -4,11 +4,11 @@
4
4
 
5
5
  A Ruby client for Playwright driver.
6
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)
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). The list of the available APIs of playwright-ruby-client is [here](./docs/api_coverage.md)
8
8
 
9
9
  ## Getting Started
10
10
 
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**.
11
+ 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
12
 
13
13
  ```sh
14
14
  npm install playwright
@@ -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,351 @@
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
+ * redirected_from
13
+ * redirected_to
14
+ * resource_type
15
+ * response
16
+ * timing
17
+ * url
18
+
19
+ ## Response
20
+
21
+ * ~~body~~
22
+ * ~~finished~~
23
+ * ~~frame~~
24
+ * ~~headers~~
25
+ * ~~ok~~
26
+ * ~~request~~
27
+ * ~~status~~
28
+ * ~~status_text~~
29
+ * ~~text~~
30
+ * ~~url~~
31
+
32
+ ## ~~Route~~
33
+
34
+ * ~~abort~~
35
+ * ~~continue_~~
36
+ * ~~fulfill~~
37
+ * ~~request~~
38
+
39
+ ## ~~WebSocket~~
40
+
41
+ * ~~closed?~~
42
+ * ~~url~~
43
+
44
+ ## Keyboard
45
+
46
+ * down
47
+ * insert_text
48
+ * press
49
+ * type
50
+ * up
51
+
52
+ ## Mouse
53
+
54
+ * ~~click~~
55
+ * ~~dblclick~~
56
+ * ~~down~~
57
+ * ~~move~~
58
+ * ~~up~~
59
+
60
+ ## Touchscreen
61
+
62
+ * ~~tap_point~~
63
+
64
+ ## JSHandle
65
+
66
+ * as_element
67
+ * dispose
68
+ * evaluate
69
+ * evaluate_handle
70
+ * get_properties
71
+ * get_property
72
+ * json_value
73
+
74
+ ## ElementHandle
75
+
76
+ * bounding_box
77
+ * check
78
+ * click
79
+ * content_frame
80
+ * dblclick
81
+ * dispatch_event
82
+ * eval_on_selector
83
+ * eval_on_selector_all
84
+ * fill
85
+ * focus
86
+ * get_attribute
87
+ * hover
88
+ * inner_html
89
+ * inner_text
90
+ * checked?
91
+ * disabled?
92
+ * editable?
93
+ * enabled?
94
+ * hidden?
95
+ * visible?
96
+ * owner_frame
97
+ * press
98
+ * query_selector
99
+ * query_selector_all
100
+ * screenshot
101
+ * scroll_into_view_if_needed
102
+ * select_option
103
+ * select_text
104
+ * set_input_files
105
+ * tap_point
106
+ * text_content
107
+ * type
108
+ * uncheck
109
+ * wait_for_element_state
110
+ * wait_for_selector
111
+
112
+ ## ~~Accessibility~~
113
+
114
+ * ~~snapshot~~
115
+
116
+ ## FileChooser
117
+
118
+ * element
119
+ * multiple?
120
+ * page
121
+ * set_files
122
+
123
+ ## Frame
124
+
125
+ * add_script_tag
126
+ * add_style_tag
127
+ * check
128
+ * child_frames
129
+ * click
130
+ * content
131
+ * dblclick
132
+ * dispatch_event
133
+ * eval_on_selector
134
+ * eval_on_selector_all
135
+ * evaluate
136
+ * evaluate_handle
137
+ * fill
138
+ * focus
139
+ * ~~frame_element~~
140
+ * get_attribute
141
+ * goto
142
+ * hover
143
+ * inner_html
144
+ * inner_text
145
+ * checked?
146
+ * detached?
147
+ * disabled?
148
+ * editable?
149
+ * enabled?
150
+ * hidden?
151
+ * visible?
152
+ * name
153
+ * page
154
+ * parent_frame
155
+ * press
156
+ * query_selector
157
+ * query_selector_all
158
+ * select_option
159
+ * set_content
160
+ * set_input_files
161
+ * tap_point
162
+ * text_content
163
+ * title
164
+ * type
165
+ * uncheck
166
+ * url
167
+ * wait_for_function
168
+ * wait_for_load_state
169
+ * expect_navigation
170
+ * wait_for_selector
171
+ * ~~wait_for_timeout~~
172
+
173
+ ## ~~Worker~~
174
+
175
+ * ~~evaluate~~
176
+ * ~~evaluate_handle~~
177
+ * ~~url~~
178
+
179
+ ## Selectors
180
+
181
+ * ~~register~~
182
+
183
+ ## ConsoleMessage
184
+
185
+ * args
186
+ * location
187
+ * text
188
+ * type
189
+
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~~
209
+
210
+ * ~~path~~
211
+
212
+ ## Page
213
+
214
+ * add_init_script
215
+ * add_script_tag
216
+ * add_style_tag
217
+ * bring_to_front
218
+ * check
219
+ * click
220
+ * close
221
+ * content
222
+ * context
223
+ * dblclick
224
+ * dispatch_event
225
+ * emulate_media
226
+ * eval_on_selector
227
+ * eval_on_selector_all
228
+ * evaluate
229
+ * evaluate_handle
230
+ * expose_binding
231
+ * expose_function
232
+ * fill
233
+ * focus
234
+ * frame
235
+ * frames
236
+ * get_attribute
237
+ * go_back
238
+ * go_forward
239
+ * goto
240
+ * hover
241
+ * inner_html
242
+ * inner_text
243
+ * checked?
244
+ * closed?
245
+ * disabled?
246
+ * editable?
247
+ * enabled?
248
+ * hidden?
249
+ * visible?
250
+ * main_frame
251
+ * opener
252
+ * ~~pause~~
253
+ * pdf
254
+ * press
255
+ * query_selector
256
+ * query_selector_all
257
+ * reload
258
+ * ~~route~~
259
+ * screenshot
260
+ * select_option
261
+ * set_content
262
+ * set_default_navigation_timeout
263
+ * set_default_timeout
264
+ * set_extra_http_headers
265
+ * set_input_files
266
+ * set_viewport_size
267
+ * tap_point
268
+ * text_content
269
+ * title
270
+ * type
271
+ * uncheck
272
+ * ~~unroute~~
273
+ * url
274
+ * ~~video~~
275
+ * viewport_size
276
+ * wait_for_function
277
+ * wait_for_load_state
278
+ * expect_navigation
279
+ * expect_request
280
+ * expect_response
281
+ * wait_for_selector
282
+ * ~~wait_for_timeout~~
283
+ * ~~workers~~
284
+ * accessibility
285
+ * ~~coverage~~
286
+ * keyboard
287
+ * mouse
288
+ * touchscreen
289
+
290
+ ## BrowserContext
291
+
292
+ * ~~add_cookies~~
293
+ * ~~add_init_script~~
294
+ * ~~browser~~
295
+ * ~~clear_cookies~~
296
+ * ~~clear_permissions~~
297
+ * close
298
+ * ~~cookies~~
299
+ * ~~expose_binding~~
300
+ * ~~expose_function~~
301
+ * ~~grant_permissions~~
302
+ * new_page
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~~
311
+ * ~~storage_state~~
312
+ * ~~unroute~~
313
+
314
+ ## ~~CDPSession~~
315
+
316
+ * ~~detach~~
317
+ * ~~send_message~~
318
+
319
+ ## ChromiumBrowserContext
320
+
321
+ * ~~background_pages~~
322
+ * ~~new_cdp_session~~
323
+ * ~~service_workers~~
324
+
325
+ ## Browser
326
+
327
+ * close
328
+ * contexts
329
+ * connected?
330
+ * new_context
331
+ * new_page
332
+ * version
333
+
334
+ ## BrowserType
335
+
336
+ * ~~connect~~
337
+ * executable_path
338
+ * launch
339
+ * ~~launch_persistent_context~~
340
+ * ~~launch_server~~
341
+ * name
342
+
343
+ ## Playwright
344
+
345
+ * ~~close~~
346
+ * chromium
347
+ * devices
348
+ * ~~errors~~
349
+ * firefox
350
+ * ~~selectors~~
351
+ * webkit