playwright-ruby-client 0.0.4 → 0.0.9

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 +120 -6
  3. data/docs/api_coverage.md +351 -0
  4. data/lib/playwright.rb +9 -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 +20 -27
  9. data/lib/playwright/channel_owners/browser_context.rb +51 -0
  10. data/lib/playwright/channel_owners/console_message.rb +0 -4
  11. data/lib/playwright/channel_owners/element_handle.rb +306 -0
  12. data/lib/playwright/channel_owners/frame.rb +473 -7
  13. data/lib/playwright/channel_owners/js_handle.rb +51 -0
  14. data/lib/playwright/channel_owners/page.rb +589 -4
  15. data/lib/playwright/channel_owners/request.rb +98 -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 +17 -1
  20. data/lib/playwright/http_headers.rb +20 -0
  21. data/lib/playwright/input_files.rb +42 -0
  22. data/lib/playwright/input_type.rb +19 -0
  23. data/lib/playwright/input_types/android_input.rb +19 -0
  24. data/lib/playwright/input_types/keyboard.rb +32 -0
  25. data/lib/playwright/input_types/mouse.rb +4 -0
  26. data/lib/playwright/input_types/touchscreen.rb +4 -0
  27. data/lib/playwright/javascript.rb +13 -0
  28. data/lib/playwright/javascript/expression.rb +67 -0
  29. data/lib/playwright/javascript/function.rb +67 -0
  30. data/lib/playwright/javascript/value_parser.rb +75 -0
  31. data/lib/playwright/javascript/value_serializer.rb +54 -0
  32. data/lib/playwright/playwright_api.rb +45 -25
  33. data/lib/playwright/select_option_values.rb +32 -0
  34. data/lib/playwright/timeout_settings.rb +19 -0
  35. data/lib/playwright/url_matcher.rb +19 -0
  36. data/lib/playwright/utils.rb +37 -0
  37. data/lib/playwright/version.rb +1 -1
  38. data/lib/playwright/wait_helper.rb +73 -0
  39. data/lib/playwright_api/accessibility.rb +46 -6
  40. data/lib/playwright_api/android.rb +33 -0
  41. data/lib/playwright_api/android_device.rb +78 -0
  42. data/lib/playwright_api/android_input.rb +25 -0
  43. data/lib/playwright_api/binding_call.rb +18 -0
  44. data/lib/playwright_api/browser.rb +93 -12
  45. data/lib/playwright_api/browser_context.rb +279 -28
  46. data/lib/playwright_api/browser_type.rb +68 -5
  47. data/lib/playwright_api/cdp_session.rb +23 -1
  48. data/lib/playwright_api/chromium_browser_context.rb +26 -0
  49. data/lib/playwright_api/console_message.rb +20 -7
  50. data/lib/playwright_api/dialog.rb +48 -2
  51. data/lib/playwright_api/download.rb +19 -4
  52. data/lib/playwright_api/element_handle.rb +278 -104
  53. data/lib/playwright_api/file_chooser.rb +20 -3
  54. data/lib/playwright_api/frame.rb +452 -147
  55. data/lib/playwright_api/js_handle.rb +78 -19
  56. data/lib/playwright_api/keyboard.rb +99 -9
  57. data/lib/playwright_api/mouse.rb +22 -0
  58. data/lib/playwright_api/page.rb +864 -222
  59. data/lib/playwright_api/playwright.rb +116 -14
  60. data/lib/playwright_api/request.rb +86 -24
  61. data/lib/playwright_api/response.rb +18 -7
  62. data/lib/playwright_api/route.rb +49 -0
  63. data/lib/playwright_api/selectors.rb +28 -2
  64. data/lib/playwright_api/video.rb +8 -0
  65. data/lib/playwright_api/web_socket.rb +0 -8
  66. data/lib/playwright_api/worker.rb +25 -13
  67. data/playwright.gemspec +3 -0
  68. metadata +66 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b77f5e67e8a75aec27eca18c85bcaaf3236fcc0822659de3462a7f4d41d3a1a8
4
- data.tar.gz: 7791bc627ddcd7fc39fa36b7ec6f393c855d0cb506b5834922b43f84839dac63
3
+ metadata.gz: eccb7fbb7a1fba3116ceaa61893b164850dc7f21eb45cac637da161bc137120a
4
+ data.tar.gz: ceeab7bc64c7a743ef3b682dda05271ff49eb3727ad7b47ed722f527aedacba0
5
5
  SHA512:
6
- metadata.gz: 3ffbf8ebba62b54b51534b5f33f45dd02df9f73824b267500b9265827bb09b01898849fb43c461a2798c276801ae69a6beb52018872c4d7740ba56ff8ab99686
7
- data.tar.gz: 8b7acc19dd31389c0ea3361a8be430177d2319ec20284ffac65117a9421810b26808c1ab61bc33298e8bfd89c617772750f7c61b21258aebebd6db7d93598923
6
+ metadata.gz: 1414afc026223b47750708cd2f30dab6453aebb5b3ce06f97a7f4a51c793f6b2b57ef307ffc0b31df2f91158d7d7e40623f443846b1653ca8778b7a67bfe7a47
7
+ data.tar.gz: 33cf15f92e23a118264627067f534d4379876090b6a3bf74fb8c67253e2905b575495c548247144f82ed282b8b86a1c891e89ffdf8e51423202bd38ce03a5bb2
data/README.md CHANGED
@@ -4,18 +4,18 @@
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-cli, 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
- npm install playwright-cli
15
- ./node_modules/.bin/playwright-cli install
14
+ npm install playwright
15
+ ./node_modules/.bin/playwright install
16
16
  ```
17
17
 
18
- and then, set `playwright_cli_executable_path: ./node_modules/.bin/playwright-cli` at `Playwright.create`.
18
+ and then, set `playwright_cli_executable_path: ./node_modules/.bin/playwright` at `Playwright.create`.
19
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
 
@@ -24,7 +24,7 @@ Instead of npm install, you can also directly download playwright driver from pl
24
24
  ```ruby
25
25
  require 'playwright'
26
26
 
27
- Playwright.create(playwright_cli_executable_path: '/path/to/playwright-cli') do |playwright|
27
+ Playwright.create(playwright_cli_executable_path: '/path/to/playwright') do |playwright|
28
28
  playwright.chromium.launch(headless: false) do |browser|
29
29
  page = browser.new_page
30
30
  page.goto('https://github.com/YusukeIwaki')
@@ -33,6 +33,120 @@ Playwright.create(playwright_cli_executable_path: '/path/to/playwright-cli') do
33
33
  end
34
34
  ```
35
35
 
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)
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
+
36
150
  ## License
37
151
 
38
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