playwright-ruby-client 0.0.8 → 0.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04f50e523a846e243058cbb53a44e0f4a6ecce32aa843a02ace9b855b2264862
4
- data.tar.gz: a8c99b7550206d0ff90ad033e0391a9224f780ae1e009a8cab48441070adabaa
3
+ metadata.gz: eccb7fbb7a1fba3116ceaa61893b164850dc7f21eb45cac637da161bc137120a
4
+ data.tar.gz: ceeab7bc64c7a743ef3b682dda05271ff49eb3727ad7b47ed722f527aedacba0
5
5
  SHA512:
6
- metadata.gz: d5e089555dc0d1ee2a86980d14d8310e338fa1d23b529a3d711895532dba64101300a198ed55b80f90342116b86baae8937c7526f992bc7ea9816297e385c436
7
- data.tar.gz: d1da5e4e141043a37f3eccdd300865437264c795e343fa5652534d2fa04168d6f1326f7311c1f8c0212c98fd0d365b5b8f684b18b4b615b8825d5d65fa185562
6
+ metadata.gz: 1414afc026223b47750708cd2f30dab6453aebb5b3ce06f97a7f4a51c793f6b2b57ef307ffc0b31df2f91158d7d7e40623f443846b1653ca8778b7a67bfe7a47
7
+ data.tar.gz: 33cf15f92e23a118264627067f534d4379876090b6a3bf74fb8c67253e2905b575495c548247144f82ed282b8b86a1c891e89ffdf8e51423202bd38ce03a5bb2
data/docs/api_coverage.md CHANGED
@@ -9,7 +9,6 @@
9
9
  * method
10
10
  * post_data
11
11
  * post_data_buffer
12
- * post_data_json
13
12
  * redirected_from
14
13
  * redirected_to
15
14
  * resource_type
@@ -23,7 +22,6 @@
23
22
  * ~~finished~~
24
23
  * ~~frame~~
25
24
  * ~~headers~~
26
- * ~~json~~
27
25
  * ~~ok~~
28
26
  * ~~request~~
29
27
  * ~~status~~
@@ -42,7 +40,6 @@
42
40
 
43
41
  * ~~closed?~~
44
42
  * ~~url~~
45
- * ~~expect_event~~
46
43
 
47
44
  ## Keyboard
48
45
 
@@ -76,16 +73,14 @@
76
73
 
77
74
  ## ElementHandle
78
75
 
79
- * query_selector
80
- * query_selector_all
81
- * eval_on_selector
82
- * eval_on_selector_all
83
76
  * bounding_box
84
77
  * check
85
78
  * click
86
79
  * content_frame
87
80
  * dblclick
88
81
  * dispatch_event
82
+ * eval_on_selector
83
+ * eval_on_selector_all
89
84
  * fill
90
85
  * focus
91
86
  * get_attribute
@@ -100,6 +95,8 @@
100
95
  * visible?
101
96
  * owner_frame
102
97
  * press
98
+ * query_selector
99
+ * query_selector_all
103
100
  * screenshot
104
101
  * scroll_into_view_if_needed
105
102
  * select_option
@@ -125,10 +122,6 @@
125
122
 
126
123
  ## Frame
127
124
 
128
- * query_selector
129
- * query_selector_all
130
- * eval_on_selector
131
- * eval_on_selector_all
132
125
  * add_script_tag
133
126
  * add_style_tag
134
127
  * check
@@ -137,6 +130,8 @@
137
130
  * content
138
131
  * dblclick
139
132
  * dispatch_event
133
+ * eval_on_selector
134
+ * eval_on_selector_all
140
135
  * evaluate
141
136
  * evaluate_handle
142
137
  * fill
@@ -158,6 +153,8 @@
158
153
  * page
159
154
  * parent_frame
160
155
  * press
156
+ * query_selector
157
+ * query_selector_all
161
158
  * select_option
162
159
  * set_content
163
160
  * set_input_files
@@ -170,7 +167,7 @@
170
167
  * wait_for_function
171
168
  * wait_for_load_state
172
169
  * expect_navigation
173
- * ~~wait_for_selector~~
170
+ * wait_for_selector
174
171
  * ~~wait_for_timeout~~
175
172
 
176
173
  ## ~~Worker~~
@@ -214,74 +211,74 @@
214
211
 
215
212
  ## Page
216
213
 
217
- * query_selector
218
- * query_selector_all
219
- * eval_on_selector
220
- * eval_on_selector_all
221
- * ~~add_init_script~~
214
+ * add_init_script
222
215
  * add_script_tag
223
216
  * add_style_tag
224
- * ~~bring_to_front~~
225
- * ~~check~~
217
+ * bring_to_front
218
+ * check
226
219
  * click
227
220
  * close
228
221
  * content
229
222
  * context
230
223
  * dblclick
231
- * ~~dispatch_event~~
232
- * ~~emulate_media~~
224
+ * dispatch_event
225
+ * emulate_media
226
+ * eval_on_selector
227
+ * eval_on_selector_all
233
228
  * evaluate
234
229
  * evaluate_handle
235
- * ~~expose_binding~~
236
- * ~~expose_function~~
230
+ * expose_binding
231
+ * expose_function
237
232
  * fill
238
233
  * focus
239
234
  * frame
240
235
  * frames
241
- * ~~get_attribute~~
242
- * ~~go_back~~
243
- * ~~go_forward~~
236
+ * get_attribute
237
+ * go_back
238
+ * go_forward
244
239
  * goto
245
- * ~~hover~~
246
- * ~~inner_html~~
247
- * ~~inner_text~~
248
- * ~~checked?~~
240
+ * hover
241
+ * inner_html
242
+ * inner_text
243
+ * checked?
249
244
  * closed?
250
- * ~~disabled?~~
251
- * ~~editable?~~
252
- * ~~enabled?~~
253
- * ~~hidden?~~
254
- * ~~visible?~~
245
+ * disabled?
246
+ * editable?
247
+ * enabled?
248
+ * hidden?
249
+ * visible?
255
250
  * main_frame
256
251
  * opener
257
- * ~~pdf~~
252
+ * ~~pause~~
253
+ * pdf
258
254
  * press
255
+ * query_selector
256
+ * query_selector_all
259
257
  * reload
260
258
  * ~~route~~
261
259
  * screenshot
262
- * ~~select_option~~
260
+ * select_option
263
261
  * set_content
264
262
  * set_default_navigation_timeout
265
263
  * set_default_timeout
266
- * ~~set_extra_http_headers~~
267
- * ~~set_input_files~~
264
+ * set_extra_http_headers
265
+ * set_input_files
268
266
  * set_viewport_size
269
- * ~~tap_point~~
270
- * ~~text_content~~
267
+ * tap_point
268
+ * text_content
271
269
  * title
272
270
  * type
273
- * ~~uncheck~~
271
+ * uncheck
274
272
  * ~~unroute~~
275
273
  * url
276
274
  * ~~video~~
277
275
  * viewport_size
278
- * expect_event
279
276
  * wait_for_function
280
277
  * wait_for_load_state
281
278
  * expect_navigation
282
279
  * expect_request
283
280
  * expect_response
284
- * ~~wait_for_selector~~
281
+ * wait_for_selector
285
282
  * ~~wait_for_timeout~~
286
283
  * ~~workers~~
287
284
  * accessibility
@@ -313,7 +310,6 @@
313
310
  * ~~set_offline~~
314
311
  * ~~storage_state~~
315
312
  * ~~unroute~~
316
- * ~~expect_event~~
317
313
 
318
314
  ## ~~CDPSession~~
319
315
 
@@ -346,6 +342,7 @@
346
342
 
347
343
  ## Playwright
348
344
 
345
+ * ~~close~~
349
346
  * chromium
350
347
  * devices
351
348
  * ~~errors~~
data/lib/playwright.rb CHANGED
@@ -15,6 +15,7 @@ require 'playwright/utils'
15
15
 
16
16
  require 'playwright/channel'
17
17
  require 'playwright/channel_owner'
18
+ require 'playwright/http_headers'
18
19
  require 'playwright/input_files'
19
20
  require 'playwright/input_type'
20
21
  require 'playwright/connection'
@@ -8,7 +8,10 @@ module Playwright
8
8
  @pages = Set.new
9
9
 
10
10
  @channel.once('close', ->(_) { on_close })
11
- @channel.on('page', ->(hash) { on_page(ChannelOwners::Page.from(hash['page']) )})
11
+ @channel.on('page', ->(params) { on_page(ChannelOwners::Page.from(params['page']) )})
12
+ @channel.on('route', ->(params) {
13
+ on_route(ChannelOwners::Route.from(params['route']), ChannelOwners::Request.from(params['request']))
14
+ })
12
15
  end
13
16
 
14
17
  private def on_page(page)
@@ -17,6 +20,11 @@ module Playwright
17
20
  emit(Events::BrowserContext::Page, page)
18
21
  end
19
22
 
23
+ private def on_route(route, request)
24
+ # @routes.each ...
25
+ route.continue_
26
+ end
27
+
20
28
  def pages
21
29
  @pages.to_a
22
30
  end
@@ -144,6 +144,13 @@ module Playwright
144
144
  end
145
145
  end
146
146
 
147
+ def wait_for_selector(selector, state: nil, timeout: nil)
148
+ params = { selector: selector, state: state, timeout: timeout }.compact
149
+ resp = @channel.send_message_to_server('waitForSelector', params)
150
+
151
+ ChannelOwners::ElementHandle.from_nullable(resp)
152
+ end
153
+
147
154
  def checked?(selector, timeout: nil)
148
155
  params = { selector: selector, timeout: timeout }.compact
149
156
  @channel.send_message_to_server('isChecked', params)
@@ -26,7 +26,12 @@ module Playwright
26
26
  console_message = ChannelOwners::ConsoleMessage.from(params['message'])
27
27
  emit(Events::Page::Console, console_message)
28
28
  })
29
+ @channel.on('crash', ->(_) { emit(Events::Page::Crash) })
30
+ @channel.on('dialog', method(:on_dialog))
29
31
  @channel.on('domcontentloaded', ->(_) { emit(Events::Page::DOMContentLoaded) })
32
+ @channel.on('download', ->(params) {
33
+ emit(Events::Page::Download, ChannelOwners::Download.from(params['download']))
34
+ })
30
35
  @channel.on('frameAttached', ->(params) {
31
36
  on_frame_attached(ChannelOwners::Frame.from(params['frame']))
32
37
  })
@@ -34,9 +39,43 @@ module Playwright
34
39
  on_frame_detached(ChannelOwners::Frame.from(params['frame']))
35
40
  })
36
41
  @channel.on('load', ->(_) { emit(Events::Page::Load) })
42
+ @channel.on('pageError', ->(params) {
43
+ emit(Events::Page::PageError, Error.parse(params['error']['error']))
44
+ })
37
45
  @channel.on('popup', ->(params) {
38
46
  emit(Events::Page::Popup, ChannelOwners::Page.from(params['page']))
39
47
  })
48
+ @channel.on('request', ->(params) {
49
+ emit(Events::Page::Request, ChannelOwners::Request.from(params['request']))
50
+ })
51
+ @channel.on('requestFailed', ->(params) {
52
+ on_request_failed(
53
+ ChannelOwners::Request.from(params['request']),
54
+ params['responseEndTiming'],
55
+ params['failureText'],
56
+ )
57
+ })
58
+ @channel.on('requestFinished', ->(params) {
59
+ on_request_finished(
60
+ ChannelOwners::Request.from(params['request']),
61
+ params['responseEndTiming'],
62
+ )
63
+ })
64
+ @channel.on('response', ->(params) {
65
+ emit(Events::Page::Response, ChannelOwners::Response.from(params['response']))
66
+ })
67
+ @channel.on('route', ->(params) {
68
+ on_route(ChannelOwners::Route.from(params['route']), ChannelOwners::Request.from(params['request']))
69
+ })
70
+ @channel.on('video', ->(params) {
71
+ video.send(:update_relative_path, params['relativePath'])
72
+ })
73
+ @channel.on('webSocket', ->(params) {
74
+ emit(Events::Page::WebSocket, ChannelOwners::WebSocket.from(params['webSocket']))
75
+ })
76
+ @channel.on('worker', ->(params) {
77
+ on_worker(ChannelOwners::Worker.from(params['worker']))
78
+ })
40
79
  end
41
80
 
42
81
  attr_reader \
@@ -47,6 +86,17 @@ module Playwright
47
86
  :viewport_size,
48
87
  :main_frame
49
88
 
89
+ private def on_request_failed(request, response_end_timing, failure_text)
90
+ request.send(:update_failure_text, failure_text)
91
+ request.send(:update_response_end_timing, response_end_timing)
92
+ emit(Events::Page::RequestFailed)
93
+ end
94
+
95
+ private def on_request_finished(request, response_end_timing)
96
+ request.send(:update_response_end_timing, response_end_timing)
97
+ emit(Events::Page::RequestFinished)
98
+ end
99
+
50
100
  private def on_frame_attached(frame)
51
101
  frame.send(:update_page_from_page, self)
52
102
  @frames << frame
@@ -59,12 +109,25 @@ module Playwright
59
109
  emit(Events::Page::FrameDetached, frame)
60
110
  end
61
111
 
112
+ private def on_route(route, request)
113
+ # @routes.each ...
114
+ @browser_context.send(:on_route, route, request)
115
+ end
116
+
62
117
  private def on_close
63
118
  @closed = true
64
119
  @browser_context.send(:remove_page, self)
65
120
  emit(Events::Page::Close)
66
121
  end
67
122
 
123
+ private def on_dialog(params)
124
+ dialog = ChannelOwners::Dialog.from(params['dialog'])
125
+ unless emit(Events::Page::Dialog, dialog)
126
+ dialog.dismiss # FIXME: this should be asynchronous
127
+ end
128
+ end
129
+
130
+
68
131
  def context
69
132
  @browser_context
70
133
  end
@@ -121,6 +184,38 @@ module Playwright
121
184
  @main_frame.query_selector_all(selector)
122
185
  end
123
186
 
187
+ def wait_for_selector(selector, state: nil, timeout: nil)
188
+ @main_frame.wait_for_selector(selector, state: state, timeout: timeout)
189
+ end
190
+
191
+ def checked?(selector, timeout: nil)
192
+ @main_frame.checked?(selector, timeout: timeout)
193
+ end
194
+
195
+ def disabled?(selector, timeout: nil)
196
+ @main_frame.disabled?(selector, timeout: timeout)
197
+ end
198
+
199
+ def editable?(selector, timeout: nil)
200
+ @main_frame.editable?(selector, timeout: timeout)
201
+ end
202
+
203
+ def enabled?(selector, timeout: nil)
204
+ @main_frame.enabled?(selector, timeout: timeout)
205
+ end
206
+
207
+ def hidden?(selector, timeout: nil)
208
+ @main_frame.hidden?(selector, timeout: timeout)
209
+ end
210
+
211
+ def visible?(selector, timeout: nil)
212
+ @main_frame.visible?(selector, timeout: timeout)
213
+ end
214
+
215
+ def dispatch_event(selector, type, eventInit: nil, timeout: nil)
216
+ @main_frame.dispatch_event(selector, type, eventInit: eventInit, timeout: timeout)
217
+ end
218
+
124
219
  def evaluate(pageFunction, arg: nil)
125
220
  @main_frame.evaluate(pageFunction, arg: arg)
126
221
  end
@@ -145,6 +240,25 @@ module Playwright
145
240
  @main_frame.add_style_tag(content: content, path: path, url: url)
146
241
  end
147
242
 
243
+ def expose_function(name, callback)
244
+ @channel.send_message_to_server('exposeBinding', name: name)
245
+ @bindings[name] = ->(_source, *args) { callback.call(*args) }
246
+ end
247
+
248
+ def expose_binding(name, callback, handle: nil)
249
+ params = {
250
+ name: name,
251
+ needsHandle: handle,
252
+ }.compact
253
+ @channel.send_message_to_server('exposeBinding', params)
254
+ @bindings[name] = callback
255
+ end
256
+
257
+ def set_extra_http_headers(headers)
258
+ serialized_headers = HttpHeaders.new(headers).as_serialized
259
+ @channel.send_message_to_server('setExtraHTTPHeaders', headers: serialized_headers)
260
+ end
261
+
148
262
  def url
149
263
  @main_frame.url
150
264
  end
@@ -174,12 +288,45 @@ module Playwright
174
288
  @main_frame.wait_for_load_state(state: state, timeout: timeout)
175
289
  end
176
290
 
291
+ def go_back(timeout: nil, waitUntil: nil)
292
+ params = { timeout: timeout, waitUntil: waitUntil }.compact
293
+ resp = @channel.send_message_to_server('goBack', params)
294
+ ChannelOwners::Response.from_nullable(resp)
295
+ end
296
+
297
+ def go_forward(timeout: nil, waitUntil: nil)
298
+ params = { timeout: timeout, waitUntil: waitUntil }.compact
299
+ resp = @channel.send_message_to_server('goForward', params)
300
+ ChannelOwners::Response.from_nullable(resp)
301
+ end
302
+
303
+ def emulate_media(colorScheme: nil, media: nil)
304
+ params = {
305
+ colorScheme: colorScheme,
306
+ media: media,
307
+ }.compact
308
+ @channel.send_message_to_server('emulateMedia', params)
309
+
310
+ nil
311
+ end
312
+
177
313
  def set_viewport_size(viewportSize)
178
314
  @viewport_size = viewportSize
179
315
  @channel.send_message_to_server('setViewportSize', { viewportSize: viewportSize })
180
316
  nil
181
317
  end
182
318
 
319
+ def bring_to_front
320
+ @channel.send_message_to_server('bringToFront')
321
+ nil
322
+ end
323
+
324
+ def add_init_script(script, arg: nil)
325
+ @channel.send_message_to_server('addInitScript', source: script)
326
+ # FIXME: handling `arg` for function `script`
327
+ nil
328
+ end
329
+
183
330
  def screenshot(
184
331
  path: nil,
185
332
  type: nil,
@@ -269,6 +416,23 @@ module Playwright
269
416
  )
270
417
  end
271
418
 
419
+ def tap_point(
420
+ selector,
421
+ force: nil,
422
+ modifiers: nil,
423
+ noWaitAfter: nil,
424
+ position: nil,
425
+ timeout: nil)
426
+ @main_frame.tap_point(
427
+ selector,
428
+ force: force,
429
+ modifiers: modifiers,
430
+ noWaitAfter: noWaitAfter,
431
+ position: position,
432
+ timeout: timeout,
433
+ )
434
+ end
435
+
272
436
  def fill(selector, value, noWaitAfter: nil, timeout: nil)
273
437
  @main_frame.fill(selector, value, noWaitAfter: noWaitAfter, timeout: timeout)
274
438
  end
@@ -277,6 +441,45 @@ module Playwright
277
441
  @main_frame.focus(selector, timeout: timeout)
278
442
  end
279
443
 
444
+ def text_content(selector, timeout: nil)
445
+ @main_frame.text_content(selector, timeout: timeout)
446
+ end
447
+
448
+ def inner_text(selector, timeout: nil)
449
+ @main_frame.inner_text(selector, timeout: timeout)
450
+ end
451
+
452
+ def inner_html(selector, timeout: nil)
453
+ @main_frame.inner_html(selector, timeout: timeout)
454
+ end
455
+
456
+ def get_attribute(selector, name, timeout: nil)
457
+ @main_frame.get_attribute(selector, name, timeout: timeout)
458
+ end
459
+
460
+ def hover(
461
+ selector,
462
+ force: nil,
463
+ modifiers: nil,
464
+ position: nil,
465
+ timeout: nil)
466
+ @main_frame.hover(
467
+ selector,
468
+ force: force,
469
+ modifiers: modifiers,
470
+ position: position,
471
+ timeout: timeout,
472
+ )
473
+ end
474
+
475
+ def select_option(selector, values, noWaitAfter: nil, timeout: nil)
476
+ @main_frame.select_option(selector, values, noWaitAfter: noWaitAfter, timeout: timeout)
477
+ end
478
+
479
+ def set_input_files(selector, files, noWaitAfter: nil, timeout: nil)
480
+ @main_frame.set_input_files(selector, files, noWaitAfter: noWaitAfter, timeout: timeout)
481
+ end
482
+
280
483
  def type(
281
484
  selector,
282
485
  text,
@@ -297,10 +500,57 @@ module Playwright
297
500
  @main_frame.press(selector, key, delay: delay, noWaitAfter: noWaitAfter, timeout: timeout)
298
501
  end
299
502
 
503
+ def check(selector, force: nil, noWaitAfter: nil, timeout: nil)
504
+ @main_frame.check(selector, force: force, noWaitAfter: noWaitAfter, timeout: timeout)
505
+ end
506
+
507
+ def uncheck(selector, force: nil, noWaitAfter: nil, timeout: nil)
508
+ @main_frame.uncheck(selector, force: force, noWaitAfter: noWaitAfter, timeout: timeout)
509
+ end
510
+
300
511
  def wait_for_function(pageFunction, arg: nil, polling: nil, timeout: nil)
301
512
  @main_frame.wait_for_function(pageFunction, arg: arg, polling: polling, timeout: timeout)
302
513
  end
303
514
 
515
+ def pdf(
516
+ displayHeaderFooter: nil,
517
+ footerTemplate: nil,
518
+ format: nil,
519
+ headerTemplate: nil,
520
+ height: nil,
521
+ landscape: nil,
522
+ margin: nil,
523
+ pageRanges: nil,
524
+ path: nil,
525
+ preferCSSPageSize: nil,
526
+ printBackground: nil,
527
+ scale: nil,
528
+ width: nil)
529
+
530
+ params = {
531
+ displayHeaderFooter: displayHeaderFooter,
532
+ footerTemplate: footerTemplate,
533
+ format: format,
534
+ headerTemplate: headerTemplate,
535
+ height: height,
536
+ landscape: landscape,
537
+ margin: margin,
538
+ pageRanges: pageRanges,
539
+ preferCSSPageSize: preferCSSPageSize,
540
+ printBackground: printBackground,
541
+ scale: scale,
542
+ width: width,
543
+ }.compact
544
+ encoded_binary = @channel.send_message_to_server('pdf', params)
545
+ decoded_binary = Base64.strict_decode64(encoded_binary)
546
+ if path
547
+ File.open(path, 'wb') do |f|
548
+ f.write(decoded_binary)
549
+ end
550
+ end
551
+ decoded_binary
552
+ end
553
+
304
554
  class CrashedError < StandardError
305
555
  def initialize
306
556
  super('Page crashed')