playwright-ruby-client 0.0.3 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +119 -12
  3. data/docs/api_coverage.md +354 -0
  4. data/lib/playwright.rb +8 -0
  5. data/lib/playwright/channel_owner.rb +16 -2
  6. data/lib/playwright/channel_owners/android.rb +10 -1
  7. data/lib/playwright/channel_owners/android_device.rb +163 -0
  8. data/lib/playwright/channel_owners/browser.rb +22 -29
  9. data/lib/playwright/channel_owners/browser_context.rb +43 -0
  10. data/lib/playwright/channel_owners/console_message.rb +21 -0
  11. data/lib/playwright/channel_owners/element_handle.rb +314 -0
  12. data/lib/playwright/channel_owners/frame.rb +466 -7
  13. data/lib/playwright/channel_owners/js_handle.rb +55 -0
  14. data/lib/playwright/channel_owners/page.rb +353 -5
  15. data/lib/playwright/channel_owners/request.rb +90 -0
  16. data/lib/playwright/channel_owners/webkit_browser.rb +1 -1
  17. data/lib/playwright/connection.rb +15 -14
  18. data/lib/playwright/errors.rb +1 -1
  19. data/lib/playwright/event_emitter.rb +13 -0
  20. data/lib/playwright/input_files.rb +42 -0
  21. data/lib/playwright/input_type.rb +19 -0
  22. data/lib/playwright/input_types/android_input.rb +19 -0
  23. data/lib/playwright/input_types/keyboard.rb +32 -0
  24. data/lib/playwright/input_types/mouse.rb +4 -0
  25. data/lib/playwright/input_types/touchscreen.rb +4 -0
  26. data/lib/playwright/javascript.rb +13 -0
  27. data/lib/playwright/javascript/expression.rb +67 -0
  28. data/lib/playwright/javascript/function.rb +67 -0
  29. data/lib/playwright/javascript/value_parser.rb +75 -0
  30. data/lib/playwright/javascript/value_serializer.rb +54 -0
  31. data/lib/playwright/playwright_api.rb +45 -25
  32. data/lib/playwright/select_option_values.rb +32 -0
  33. data/lib/playwright/timeout_settings.rb +19 -0
  34. data/lib/playwright/url_matcher.rb +19 -0
  35. data/lib/playwright/utils.rb +37 -0
  36. data/lib/playwright/version.rb +1 -1
  37. data/lib/playwright/wait_helper.rb +73 -0
  38. data/lib/playwright_api/accessibility.rb +60 -6
  39. data/lib/playwright_api/android.rb +33 -0
  40. data/lib/playwright_api/android_device.rb +78 -0
  41. data/lib/playwright_api/android_input.rb +25 -0
  42. data/lib/playwright_api/binding_call.rb +18 -0
  43. data/lib/playwright_api/browser.rb +136 -44
  44. data/lib/playwright_api/browser_context.rb +378 -51
  45. data/lib/playwright_api/browser_type.rb +137 -55
  46. data/lib/playwright_api/cdp_session.rb +32 -7
  47. data/lib/playwright_api/chromium_browser_context.rb +31 -0
  48. data/lib/playwright_api/console_message.rb +27 -7
  49. data/lib/playwright_api/dialog.rb +47 -3
  50. data/lib/playwright_api/download.rb +29 -5
  51. data/lib/playwright_api/element_handle.rb +429 -143
  52. data/lib/playwright_api/file_chooser.rb +13 -2
  53. data/lib/playwright_api/frame.rb +633 -179
  54. data/lib/playwright_api/js_handle.rb +97 -17
  55. data/lib/playwright_api/keyboard.rb +152 -24
  56. data/lib/playwright_api/mouse.rb +28 -3
  57. data/lib/playwright_api/page.rb +1183 -317
  58. data/lib/playwright_api/playwright.rb +174 -13
  59. data/lib/playwright_api/request.rb +115 -30
  60. data/lib/playwright_api/response.rb +22 -3
  61. data/lib/playwright_api/route.rb +63 -4
  62. data/lib/playwright_api/selectors.rb +29 -7
  63. data/lib/playwright_api/touchscreen.rb +2 -1
  64. data/lib/playwright_api/video.rb +11 -1
  65. data/lib/playwright_api/web_socket.rb +5 -5
  66. data/lib/playwright_api/worker.rb +29 -5
  67. data/playwright.gemspec +3 -0
  68. metadata +68 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac3e5cd3487407baf16ee61f1c08e9a2a20e7463027998218c5466c853c94acf
4
- data.tar.gz: add832c083cf0ce9cdf94f044649a815cfee24221385957594f3644264d97327
3
+ metadata.gz: 04f50e523a846e243058cbb53a44e0f4a6ecce32aa843a02ace9b855b2264862
4
+ data.tar.gz: a8c99b7550206d0ff90ad033e0391a9224f780ae1e009a8cab48441070adabaa
5
5
  SHA512:
6
- metadata.gz: beb033e38e066d9bf459af794b0112ded024038d7c1903f89902c0d36e9ed0c57191ce72ff2880664719cb333350aa5a85747ab18f5ad113f1b5df2a781c891e
7
- data.tar.gz: 5c0723a2d4bd529e30eb78adb5b44bbba44df43d1160ce48c1323aba91e064d05e19ee5fb74c1abe6c1f4ecce127fec297e45fd72172a4bde53add9ffc8376eb
6
+ metadata.gz: d5e089555dc0d1ee2a86980d14d8310e338fa1d23b529a3d711895532dba64101300a198ed55b80f90342116b86baae8937c7526f992bc7ea9816297e385c436
7
+ data.tar.gz: d1da5e4e141043a37f3eccdd300865437264c795e343fa5652534d2fa04168d6f1326f7311c1f8c0212c98fd0d365b5b8f684b18b4b615b8825d5d65fa185562
data/README.md CHANGED
@@ -4,24 +4,27 @@
4
4
 
5
5
  A Ruby client for Playwright driver.
6
6
 
7
- ## Getting Started
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
- At this point, playwright-ruby-client doesn't include the downloader of playwright-cli, so **we have to install [playwright-cli](https://github.com/microsoft/playwright-cli) in advance**.
9
+ ## Getting Started
10
10
 
11
- via npm: `npm install -g playwright-cli`
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
- or
13
+ ```sh
14
+ npm install playwright
15
+ ./node_modules/.bin/playwright install
16
+ ```
14
17
 
15
- direct download: `wget https://playwright.azureedge.net/builds/cli/next/playwright-cli-0.180.0-next.1608746109749-cbc13bd-mac.zip`
18
+ and then, set `playwright_cli_executable_path: ./node_modules/.bin/playwright` at `Playwright.create`.
16
19
 
17
- (`-mac.zip` should be replaced for another OS)
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)
18
21
 
19
22
  ### Capture a site
20
23
 
21
24
  ```ruby
22
25
  require 'playwright'
23
26
 
24
- Playwright.create(playwright_cli_executable_path: '/path/to/playwright-cli') do |playwright|
27
+ Playwright.create(playwright_cli_executable_path: '/path/to/playwright') do |playwright|
25
28
  playwright.chromium.launch(headless: false) do |browser|
26
29
  page = browser.new_page
27
30
  page.goto('https://github.com/YusukeIwaki')
@@ -30,15 +33,119 @@ Playwright.create(playwright_cli_executable_path: '/path/to/playwright-cli') do
30
33
  end
31
34
  ```
32
35
 
33
- ## Development
36
+ ![image](https://user-images.githubusercontent.com/11763113/104339718-412f9180-553b-11eb-9116-908e1e4b5186.gif)
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)
34
113
 
35
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
114
+ ### Android native automation
36
115
 
37
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
116
+ We have to download android-driver for Playwright in advance.
38
117
 
39
- ## Contributing
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
+ ```
40
122
 
41
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/playwright-ruby-client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
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
+ ```
42
149
 
43
150
  ## License
44
151
 
@@ -0,0 +1,354 @@
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
+
47
+ ## Keyboard
48
+
49
+ * down
50
+ * insert_text
51
+ * press
52
+ * type
53
+ * up
54
+
55
+ ## Mouse
56
+
57
+ * ~~click~~
58
+ * ~~dblclick~~
59
+ * ~~down~~
60
+ * ~~move~~
61
+ * ~~up~~
62
+
63
+ ## Touchscreen
64
+
65
+ * ~~tap_point~~
66
+
67
+ ## JSHandle
68
+
69
+ * as_element
70
+ * dispose
71
+ * evaluate
72
+ * evaluate_handle
73
+ * get_properties
74
+ * get_property
75
+ * json_value
76
+
77
+ ## ElementHandle
78
+
79
+ * query_selector
80
+ * query_selector_all
81
+ * eval_on_selector
82
+ * eval_on_selector_all
83
+ * bounding_box
84
+ * check
85
+ * click
86
+ * content_frame
87
+ * dblclick
88
+ * dispatch_event
89
+ * fill
90
+ * focus
91
+ * get_attribute
92
+ * hover
93
+ * inner_html
94
+ * inner_text
95
+ * checked?
96
+ * disabled?
97
+ * editable?
98
+ * enabled?
99
+ * hidden?
100
+ * visible?
101
+ * owner_frame
102
+ * press
103
+ * screenshot
104
+ * scroll_into_view_if_needed
105
+ * select_option
106
+ * select_text
107
+ * set_input_files
108
+ * tap_point
109
+ * text_content
110
+ * type
111
+ * uncheck
112
+ * wait_for_element_state
113
+ * wait_for_selector
114
+
115
+ ## ~~Accessibility~~
116
+
117
+ * ~~snapshot~~
118
+
119
+ ## ~~FileChooser~~
120
+
121
+ * ~~element~~
122
+ * ~~multiple?~~
123
+ * ~~page~~
124
+ * ~~set_files~~
125
+
126
+ ## Frame
127
+
128
+ * query_selector
129
+ * query_selector_all
130
+ * eval_on_selector
131
+ * eval_on_selector_all
132
+ * add_script_tag
133
+ * add_style_tag
134
+ * check
135
+ * child_frames
136
+ * click
137
+ * content
138
+ * dblclick
139
+ * dispatch_event
140
+ * evaluate
141
+ * evaluate_handle
142
+ * fill
143
+ * focus
144
+ * ~~frame_element~~
145
+ * get_attribute
146
+ * goto
147
+ * hover
148
+ * inner_html
149
+ * inner_text
150
+ * checked?
151
+ * detached?
152
+ * disabled?
153
+ * editable?
154
+ * enabled?
155
+ * hidden?
156
+ * visible?
157
+ * name
158
+ * page
159
+ * parent_frame
160
+ * press
161
+ * select_option
162
+ * set_content
163
+ * set_input_files
164
+ * tap_point
165
+ * text_content
166
+ * title
167
+ * type
168
+ * uncheck
169
+ * url
170
+ * wait_for_function
171
+ * wait_for_load_state
172
+ * expect_navigation
173
+ * ~~wait_for_selector~~
174
+ * ~~wait_for_timeout~~
175
+
176
+ ## ~~Worker~~
177
+
178
+ * ~~evaluate~~
179
+ * ~~evaluate_handle~~
180
+ * ~~url~~
181
+
182
+ ## Selectors
183
+
184
+ * ~~register~~
185
+
186
+ ## ConsoleMessage
187
+
188
+ * args
189
+ * location
190
+ * text
191
+ * type
192
+
193
+ ## ~~Dialog~~
194
+
195
+ * ~~accept~~
196
+ * ~~default_value~~
197
+ * ~~dismiss~~
198
+ * ~~message~~
199
+ * ~~type~~
200
+
201
+ ## ~~Download~~
202
+
203
+ * ~~create_read_stream~~
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
+ * query_selector
218
+ * query_selector_all
219
+ * eval_on_selector
220
+ * eval_on_selector_all
221
+ * ~~add_init_script~~
222
+ * add_script_tag
223
+ * add_style_tag
224
+ * ~~bring_to_front~~
225
+ * ~~check~~
226
+ * click
227
+ * close
228
+ * content
229
+ * context
230
+ * dblclick
231
+ * ~~dispatch_event~~
232
+ * ~~emulate_media~~
233
+ * evaluate
234
+ * evaluate_handle
235
+ * ~~expose_binding~~
236
+ * ~~expose_function~~
237
+ * fill
238
+ * focus
239
+ * frame
240
+ * frames
241
+ * ~~get_attribute~~
242
+ * ~~go_back~~
243
+ * ~~go_forward~~
244
+ * goto
245
+ * ~~hover~~
246
+ * ~~inner_html~~
247
+ * ~~inner_text~~
248
+ * ~~checked?~~
249
+ * closed?
250
+ * ~~disabled?~~
251
+ * ~~editable?~~
252
+ * ~~enabled?~~
253
+ * ~~hidden?~~
254
+ * ~~visible?~~
255
+ * main_frame
256
+ * opener
257
+ * ~~pdf~~
258
+ * press
259
+ * reload
260
+ * ~~route~~
261
+ * screenshot
262
+ * ~~select_option~~
263
+ * set_content
264
+ * set_default_navigation_timeout
265
+ * set_default_timeout
266
+ * ~~set_extra_http_headers~~
267
+ * ~~set_input_files~~
268
+ * set_viewport_size
269
+ * ~~tap_point~~
270
+ * ~~text_content~~
271
+ * title
272
+ * type
273
+ * ~~uncheck~~
274
+ * ~~unroute~~
275
+ * url
276
+ * ~~video~~
277
+ * viewport_size
278
+ * expect_event
279
+ * wait_for_function
280
+ * wait_for_load_state
281
+ * expect_navigation
282
+ * expect_request
283
+ * expect_response
284
+ * ~~wait_for_selector~~
285
+ * ~~wait_for_timeout~~
286
+ * ~~workers~~
287
+ * accessibility
288
+ * ~~coverage~~
289
+ * keyboard
290
+ * mouse
291
+ * touchscreen
292
+
293
+ ## BrowserContext
294
+
295
+ * ~~add_cookies~~
296
+ * ~~add_init_script~~
297
+ * ~~browser~~
298
+ * ~~clear_cookies~~
299
+ * ~~clear_permissions~~
300
+ * close
301
+ * ~~cookies~~
302
+ * ~~expose_binding~~
303
+ * ~~expose_function~~
304
+ * ~~grant_permissions~~
305
+ * new_page
306
+ * pages
307
+ * ~~route~~
308
+ * ~~set_default_navigation_timeout~~
309
+ * ~~set_default_timeout~~
310
+ * ~~set_extra_http_headers~~
311
+ * ~~set_geolocation~~
312
+ * ~~set_http_credentials~~
313
+ * ~~set_offline~~
314
+ * ~~storage_state~~
315
+ * ~~unroute~~
316
+ * ~~expect_event~~
317
+
318
+ ## ~~CDPSession~~
319
+
320
+ * ~~detach~~
321
+ * ~~send_message~~
322
+
323
+ ## ChromiumBrowserContext
324
+
325
+ * ~~background_pages~~
326
+ * ~~new_cdp_session~~
327
+ * ~~service_workers~~
328
+
329
+ ## Browser
330
+
331
+ * close
332
+ * contexts
333
+ * connected?
334
+ * new_context
335
+ * new_page
336
+ * version
337
+
338
+ ## BrowserType
339
+
340
+ * ~~connect~~
341
+ * executable_path
342
+ * launch
343
+ * ~~launch_persistent_context~~
344
+ * ~~launch_server~~
345
+ * name
346
+
347
+ ## Playwright
348
+
349
+ * chromium
350
+ * devices
351
+ * ~~errors~~
352
+ * firefox
353
+ * ~~selectors~~
354
+ * webkit