playwright-ruby-client 0.0.7 → 0.2.1

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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +38 -3
  3. data/docs/api_coverage.md +89 -84
  4. data/lib/playwright.rb +4 -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 +3 -5
  9. data/lib/playwright/channel_owners/android.rb +1 -1
  10. data/lib/playwright/channel_owners/android_device.rb +83 -13
  11. data/lib/playwright/channel_owners/browser.rb +1 -1
  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 +15 -4
  15. data/lib/playwright/channel_owners/frame.rb +228 -19
  16. data/lib/playwright/channel_owners/js_handle.rb +1 -1
  17. data/lib/playwright/channel_owners/page.rb +350 -27
  18. data/lib/playwright/channel_owners/request.rb +9 -1
  19. data/lib/playwright/errors.rb +1 -1
  20. data/lib/playwright/event_emitter.rb +8 -1
  21. data/lib/playwright/event_emitter_proxy.rb +49 -0
  22. data/lib/playwright/file_chooser_impl.rb +23 -0
  23. data/lib/playwright/http_headers.rb +20 -0
  24. data/lib/playwright/input_files.rb +1 -1
  25. data/lib/playwright/javascript/expression.rb +15 -0
  26. data/lib/playwright/javascript/function.rb +15 -0
  27. data/lib/playwright/javascript/value_parser.rb +1 -1
  28. data/lib/playwright/javascript/value_serializer.rb +1 -1
  29. data/lib/playwright/{input_types/keyboard.rb → keyboard_impl.rb} +5 -1
  30. data/lib/playwright/mouse_impl.rb +7 -0
  31. data/lib/playwright/playwright_api.rb +59 -20
  32. data/lib/playwright/select_option_values.rb +14 -4
  33. data/lib/playwright/timeout_settings.rb +1 -1
  34. data/lib/playwright/touchscreen_impl.rb +7 -0
  35. data/lib/playwright/utils.rb +3 -3
  36. data/lib/playwright/version.rb +1 -1
  37. data/lib/playwright/wait_helper.rb +1 -1
  38. data/lib/playwright_api/android.rb +9 -10
  39. data/lib/playwright_api/android_device.rb +43 -14
  40. data/lib/playwright_api/android_input.rb +25 -0
  41. data/lib/playwright_api/binding_call.rb +10 -6
  42. data/lib/playwright_api/browser.rb +20 -21
  43. data/lib/playwright_api/browser_context.rb +29 -20
  44. data/lib/playwright_api/browser_type.rb +16 -56
  45. data/lib/playwright_api/chromium_browser_context.rb +10 -8
  46. data/lib/playwright_api/console_message.rb +10 -6
  47. data/lib/playwright_api/dialog.rb +5 -1
  48. data/lib/playwright_api/download.rb +28 -11
  49. data/lib/playwright_api/element_handle.rb +107 -96
  50. data/lib/playwright_api/file_chooser.rb +17 -9
  51. data/lib/playwright_api/frame.rb +136 -132
  52. data/lib/playwright_api/js_handle.rb +18 -20
  53. data/lib/playwright_api/keyboard.rb +5 -5
  54. data/lib/playwright_api/page.rb +204 -149
  55. data/lib/playwright_api/playwright.rb +32 -44
  56. data/lib/playwright_api/request.rb +7 -8
  57. data/lib/playwright_api/response.rb +10 -6
  58. data/lib/playwright_api/selectors.rb +13 -9
  59. data/lib/playwright_api/web_socket.rb +10 -1
  60. data/lib/playwright_api/worker.rb +13 -13
  61. metadata +12 -6
  62. data/lib/playwright/input_type.rb +0 -19
  63. data/lib/playwright/input_types/mouse.rb +0 -4
  64. data/lib/playwright/input_types/touchscreen.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14f91dd4519f608e30d71da2f014e9640e99fdbf36eb90f07d34e28d526e66a7
4
- data.tar.gz: 97b9f16880fbd253af2e762e539824e066f43c132e5e6ca609a853bc8a981f33
3
+ metadata.gz: 140f77362280a6874d89ed73fde1e80fa47e2b83f075b6207835f02ab62cb97f
4
+ data.tar.gz: e715b39c620668eeea1a0dbb022865f759d02f59d2f3d23948c7c20536ca0136
5
5
  SHA512:
6
- metadata.gz: 737c326cc321c540f970eaa5e165ce02d012a0fae1491c1b7c6214ffb0285ed5382818f01eca5d05b7dd0541929c5478bc2e66ac84c941eeae3f4f7cbd825b20
7
- data.tar.gz: b4bf7bf326e259ac5f31719076f0541d0a7cffaaf209714c9e344364ebfde9c7493e78a0937955d0af5cbf33b283733bb3ffa713964da677178e764f64662c99
6
+ metadata.gz: 0315d44031788794eca7f506ba9a20a81dbb6bf77c15efda873a1efc3e25074d46e1629ae07551f2dd8368f8a7609568cd719fd1470fdd3bf2717373168655a2
7
+ data.tar.gz: a3b6a02b60059ac3ef14c0ca1222e3b88a3aaee588b8510c49ef748fab5f27c354417b1e38cc6adfe98e6b1f38805ed1c0cead8cfb465f4968e449c98dd5a9a5
data/README.md CHANGED
@@ -1,8 +1,6 @@
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
4
-
5
- A Ruby client for Playwright driver.
3
+ # 🎭 Playwright client for Ruby
6
4
 
7
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
 
@@ -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
@@ -111,6 +111,41 @@ end
111
111
 
112
112
  ![android-browser](https://user-images.githubusercontent.com/11763113/106615177-8467a800-65af-11eb-94d9-c56e71487e78.gif)
113
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
+ ```
114
149
 
115
150
  ## License
116
151
 
data/docs/api_coverage.md CHANGED
@@ -43,6 +43,7 @@
43
43
  * ~~closed?~~
44
44
  * ~~url~~
45
45
  * ~~expect_event~~
46
+ * ~~wait_for_event~~
46
47
 
47
48
  ## Keyboard
48
49
 
@@ -76,16 +77,14 @@
76
77
 
77
78
  ## ElementHandle
78
79
 
79
- * query_selector
80
- * query_selector_all
81
- * eval_on_selector
82
- * eval_on_selector_all
83
80
  * bounding_box
84
81
  * check
85
82
  * click
86
83
  * content_frame
87
84
  * dblclick
88
85
  * dispatch_event
86
+ * eval_on_selector
87
+ * eval_on_selector_all
89
88
  * fill
90
89
  * focus
91
90
  * get_attribute
@@ -100,6 +99,8 @@
100
99
  * visible?
101
100
  * owner_frame
102
101
  * press
102
+ * query_selector
103
+ * query_selector_all
103
104
  * screenshot
104
105
  * scroll_into_view_if_needed
105
106
  * select_option
@@ -116,61 +117,61 @@
116
117
 
117
118
  * ~~snapshot~~
118
119
 
119
- ## ~~FileChooser~~
120
+ ## FileChooser
120
121
 
121
- * ~~element~~
122
- * ~~multiple?~~
123
- * ~~page~~
124
- * ~~set_files~~
122
+ * element
123
+ * multiple?
124
+ * page
125
+ * set_files
125
126
 
126
127
  ## Frame
127
128
 
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~~
129
+ * add_script_tag
130
+ * add_style_tag
131
+ * check
135
132
  * child_frames
136
133
  * click
137
134
  * content
138
135
  * dblclick
139
- * ~~dispatch_event~~
136
+ * dispatch_event
137
+ * eval_on_selector
138
+ * eval_on_selector_all
140
139
  * evaluate
141
140
  * evaluate_handle
142
141
  * fill
143
142
  * focus
144
143
  * ~~frame_element~~
145
- * ~~get_attribute~~
144
+ * get_attribute
146
145
  * goto
147
- * ~~hover~~
148
- * ~~inner_html~~
149
- * ~~inner_text~~
150
- * ~~checked?~~
151
- * ~~detached?~~
152
- * ~~disabled?~~
153
- * ~~editable?~~
154
- * ~~enabled?~~
155
- * ~~hidden?~~
156
- * ~~visible?~~
146
+ * hover
147
+ * inner_html
148
+ * inner_text
149
+ * checked?
150
+ * detached?
151
+ * disabled?
152
+ * editable?
153
+ * enabled?
154
+ * hidden?
155
+ * visible?
157
156
  * name
158
157
  * page
159
158
  * parent_frame
160
159
  * press
161
- * ~~select_option~~
160
+ * query_selector
161
+ * query_selector_all
162
+ * select_option
162
163
  * set_content
163
- * ~~set_input_files~~
164
- * ~~tap_point~~
165
- * ~~text_content~~
164
+ * set_input_files
165
+ * tap_point
166
+ * text_content
166
167
  * title
167
168
  * type
168
- * ~~uncheck~~
169
+ * uncheck
169
170
  * url
170
- * ~~wait_for_function~~
171
+ * wait_for_function
171
172
  * wait_for_load_state
172
173
  * expect_navigation
173
- * ~~wait_for_selector~~
174
+ * wait_for_selector
174
175
  * ~~wait_for_timeout~~
175
176
 
176
177
  ## ~~Worker~~
@@ -198,15 +199,14 @@
198
199
  * ~~message~~
199
200
  * ~~type~~
200
201
 
201
- ## ~~Download~~
202
+ ## Download
202
203
 
203
- * ~~create_read_stream~~
204
- * ~~delete~~
205
- * ~~failure~~
206
- * ~~path~~
207
- * ~~save_as~~
208
- * ~~suggested_filename~~
209
- * ~~url~~
204
+ * delete
205
+ * failure
206
+ * path
207
+ * save_as
208
+ * suggested_filename
209
+ * url
210
210
 
211
211
  ## ~~Video~~
212
212
 
@@ -214,78 +214,84 @@
214
214
 
215
215
  ## Page
216
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~~
217
+ * add_init_script
218
+ * add_script_tag
219
+ * add_style_tag
220
+ * bring_to_front
221
+ * check
226
222
  * click
227
223
  * close
228
224
  * content
229
225
  * context
230
226
  * dblclick
231
- * ~~dispatch_event~~
232
- * ~~emulate_media~~
227
+ * dispatch_event
228
+ * emulate_media
229
+ * eval_on_selector
230
+ * eval_on_selector_all
233
231
  * evaluate
234
232
  * evaluate_handle
235
- * ~~expose_binding~~
236
- * ~~expose_function~~
233
+ * expose_binding
234
+ * expose_function
237
235
  * fill
238
236
  * focus
239
237
  * frame
240
238
  * frames
241
- * ~~get_attribute~~
242
- * ~~go_back~~
243
- * ~~go_forward~~
239
+ * get_attribute
240
+ * go_back
241
+ * go_forward
244
242
  * goto
245
- * ~~hover~~
246
- * ~~inner_html~~
247
- * ~~inner_text~~
248
- * ~~checked?~~
243
+ * hover
244
+ * inner_html
245
+ * inner_text
246
+ * checked?
249
247
  * closed?
250
- * ~~disabled?~~
251
- * ~~editable?~~
252
- * ~~enabled?~~
253
- * ~~hidden?~~
254
- * ~~visible?~~
248
+ * disabled?
249
+ * editable?
250
+ * enabled?
251
+ * hidden?
252
+ * visible?
255
253
  * main_frame
256
254
  * opener
257
- * ~~pdf~~
255
+ * ~~pause~~
256
+ * pdf
258
257
  * press
258
+ * query_selector
259
+ * query_selector_all
259
260
  * reload
260
261
  * ~~route~~
261
262
  * screenshot
262
- * ~~select_option~~
263
+ * select_option
263
264
  * set_content
264
- * ~~set_default_navigation_timeout~~
265
- * ~~set_default_timeout~~
266
- * ~~set_extra_http_headers~~
267
- * ~~set_input_files~~
265
+ * set_default_navigation_timeout
266
+ * set_default_timeout
267
+ * set_extra_http_headers
268
+ * set_input_files
268
269
  * set_viewport_size
269
- * ~~tap_point~~
270
- * ~~text_content~~
270
+ * tap_point
271
+ * text_content
271
272
  * title
272
273
  * type
273
- * ~~uncheck~~
274
+ * uncheck
274
275
  * ~~unroute~~
275
276
  * url
276
277
  * ~~video~~
277
278
  * viewport_size
278
279
  * expect_event
279
- * ~~wait_for_function~~
280
+ * wait_for_function
280
281
  * wait_for_load_state
281
282
  * expect_navigation
282
283
  * expect_request
283
284
  * expect_response
284
- * ~~wait_for_selector~~
285
+ * wait_for_selector
285
286
  * ~~wait_for_timeout~~
286
287
  * ~~workers~~
288
+ * expect_download
289
+ * expect_popup
290
+ * ~~expect_worker~~
291
+ * expect_console_message
292
+ * expect_file_chooser
293
+ * ~~wait_for_event~~
287
294
  * accessibility
288
- * ~~coverage~~
289
295
  * keyboard
290
296
  * mouse
291
297
  * touchscreen
@@ -309,11 +315,12 @@
309
315
  * ~~set_default_timeout~~
310
316
  * ~~set_extra_http_headers~~
311
317
  * ~~set_geolocation~~
312
- * ~~set_http_credentials~~
313
318
  * ~~set_offline~~
314
319
  * ~~storage_state~~
315
320
  * ~~unroute~~
316
321
  * ~~expect_event~~
322
+ * ~~expect_page~~
323
+ * ~~wait_for_event~~
317
324
 
318
325
  ## ~~CDPSession~~
319
326
 
@@ -337,18 +344,16 @@
337
344
 
338
345
  ## BrowserType
339
346
 
340
- * ~~connect~~
341
347
  * executable_path
342
348
  * launch
343
349
  * ~~launch_persistent_context~~
344
- * ~~launch_server~~
345
350
  * name
346
351
 
347
352
  ## Playwright
348
353
 
354
+ * ~~stop~~
349
355
  * chromium
350
356
  * devices
351
- * ~~errors~~
352
357
  * firefox
353
358
  * ~~selectors~~
354
359
  * webkit
data/lib/playwright.rb CHANGED
@@ -10,13 +10,15 @@ require 'concurrent'
10
10
  require 'playwright/errors'
11
11
  require 'playwright/events'
12
12
  require 'playwright/event_emitter'
13
+ require 'playwright/event_emitter_proxy'
13
14
  require 'playwright/javascript'
14
15
  require 'playwright/utils'
15
16
 
17
+ require 'playwright/api_implementation'
16
18
  require 'playwright/channel'
17
19
  require 'playwright/channel_owner'
20
+ require 'playwright/http_headers'
18
21
  require 'playwright/input_files'
19
- require 'playwright/input_type'
20
22
  require 'playwright/connection'
21
23
  require 'playwright/select_option_values'
22
24
  require 'playwright/timeout_settings'
@@ -37,7 +39,7 @@ module Playwright
37
39
 
38
40
  playwright_promise = connection.async_wait_for_object_with_known_name('Playwright')
39
41
  Thread.new { connection.run }
40
- playwright = PlaywrightApi.from_channel_owner(playwright_promise.value!)
42
+ playwright = PlaywrightApi.wrap(playwright_promise.value!)
41
43
  begin
42
44
  block.call(playwright)
43
45
  ensure
@@ -0,0 +1,23 @@
1
+ module Playwright
2
+ define_api_implementation :AndroidInputImpl do
3
+ def initialize(channel)
4
+ @channel = channel
5
+ end
6
+
7
+ def type(text)
8
+ @channel.send_message_to_server('inputType', text: text)
9
+ end
10
+
11
+ def press(key)
12
+ @channel.send_message_to_server('inputPress', key: key)
13
+ end
14
+
15
+ def tap_point(point)
16
+ @channel.send_message_to_server('inputTap', point: point)
17
+ end
18
+
19
+ def drag(from, to, steps)
20
+ @channel.send_message_to_server('inputDrag', from: from, to: to, steps: steps)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,18 @@
1
+ module Playwright
2
+ # Each Impl class include this module.
3
+ # Used for detecting whether the object is a XXXXImpl or not.
4
+ module ApiImplementation ; end
5
+
6
+ def self.define_api_implementation(class_name, &block)
7
+ klass = Class.new
8
+ klass.include(ApiImplementation)
9
+ klass.class_eval(&block) if block
10
+ if ::Playwright.const_defined?(class_name)
11
+ raise ArgumentError.new("Playwright::#{class_name} already exist. Choose another class name.")
12
+ end
13
+ ::Playwright.const_set(class_name, klass)
14
+ end
15
+ end
16
+
17
+ # load subclasses
18
+ Dir[File.join(__dir__, '*_impl.rb')].each { |f| require f }
@@ -24,5 +24,12 @@ module Playwright
24
24
  nil
25
25
  end
26
26
  end
27
+
28
+ # @param method [String]
29
+ # @param params [Hash]
30
+ def send_no_reply(method, params)
31
+ @connection.async_send_message_to_server(@guid, method, params)
32
+ nil
33
+ end
27
34
  end
28
35
  end