playwright-ruby-client 0.5.10 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d682be32d3779d51176de1b0845e34dc4a71dd9d9ec36ad153e6e830e5ed1fb1
4
- data.tar.gz: 68252f26c6d3bde1d7dcbf69aee343f376ba4c99d35a02eec8109a7371f20fff
3
+ metadata.gz: a283a84899327e4b56db01800535c7231c1c2e94e7cbf11bd72ec60b1415c92c
4
+ data.tar.gz: 5e929e57b0b8d3b0970c2a0cb5029acd6cc5bd23e419bf06bc1b0a45e2f5e781
5
5
  SHA512:
6
- metadata.gz: 98d45f36d68aa8557460f3fa709858970fc17cb975fb627c26dc4df67ef859b4ca786be10f571fabe9d157eccd41f00cbb7ad2f06b5ec067f9d8ca5f6fc43127
7
- data.tar.gz: a8175d11c80424badb3218d803b58746aa95c72dfb51503476a4db30a394d2983d6fb6d2f8164c5c1644fa8db7001ddd891a484e2b10274d484781e4453dd9a7
6
+ metadata.gz: d13545073c8a110c55098547c7f7c5c4adae5c542b6b18f78be4cf3e5187cf2c92d8ccc86484c0e7bdfbeaf619ff6c8f77ce2f9c82b5eccad4c72dffb22603a5
7
+ data.tar.gz: ea4a751f747e5738121c8603eb3e495dd2ef32082d1fbd92841c2a0182637300b7c3bde0a00acbf1b25bdc572b140ff4e8a5a694dda95152f568ea5aa2760fef
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # 🎭 Playwright client for Ruby
4
4
 
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)
5
+ #### [Docs](https://playwright-ruby-client.vercel.app/docs/article/getting_started) | [API](https://playwright-ruby-client.vercel.app/docs/api/playwright)
6
6
 
7
7
  ## Getting Started
8
8
 
data/docs/api_coverage.md CHANGED
@@ -313,6 +313,7 @@
313
313
  * expect_event
314
314
  * expect_page
315
315
  * ~~wait_for_event~~
316
+ * tracing
316
317
 
317
318
  ## ~~CDPSession~~
318
319
 
@@ -333,6 +334,8 @@
333
334
 
334
335
  ## BrowserType
335
336
 
337
+ * ~~connect~~
338
+ * connect_over_cdp
336
339
  * executable_path
337
340
  * launch
338
341
  * ~~launch_persistent_context~~
@@ -347,6 +350,12 @@
347
350
  * selectors
348
351
  * webkit
349
352
 
353
+ ## Tracing
354
+
355
+ * export
356
+ * start
357
+ * stop
358
+
350
359
  ## Android
351
360
 
352
361
  * devices
@@ -5,6 +5,10 @@ module Playwright
5
5
  include Utils::PrepareBrowserContextOptions
6
6
 
7
7
  private def after_initialize
8
+ @connected = true
9
+ @closed_or_closing = false
10
+ @remote = true
11
+
8
12
  @contexts = Set.new
9
13
  @channel.on('close', method(:on_close))
10
14
  end
@@ -48,6 +52,14 @@ module Playwright
48
52
 
49
53
  def close
50
54
  return if @closed_or_closing
55
+ if @remote
56
+ @contexts.each do |context|
57
+ context.pages.each do |page|
58
+ page.send(:on_close)
59
+ end
60
+ context.send(:on_close)
61
+ end
62
+ end
51
63
  @closed_or_closing = true
52
64
  @channel.send_message_to_server('close')
53
65
  nil
@@ -77,8 +89,16 @@ module Playwright
77
89
 
78
90
  private def on_close(_ = {})
79
91
  @connected = false
80
- emit(Events::Browser::Disconnected)
81
- @closed_or_closing = false
92
+ if @remote
93
+ @contexts.each do |context|
94
+ context.pages.each do |page|
95
+ page.send(:on_close)
96
+ end
97
+ context.send(:on_close)
98
+ end
99
+ end
100
+ emit(Events::Browser::Disconnected, self)
101
+ @closed_or_closing = true
82
102
  end
83
103
 
84
104
  # called from BrowserType#connectOverCDP
@@ -86,6 +106,11 @@ module Playwright
86
106
  @contexts << context
87
107
  end
88
108
 
109
+ # called from BrowserType#connectOverCDP
110
+ private def update_as_remote
111
+ @remote = true
112
+ end
113
+
89
114
  # called from BrowserContext#on_close with send(:remove_context), so keep private.
90
115
  private def remove_context(context)
91
116
  @contexts.delete(context)
@@ -4,6 +4,7 @@ module Playwright
4
4
  include Utils::Errors::SafeCloseError
5
5
  attr_accessor :browser
6
6
  attr_writer :owner_page, :options
7
+ attr_reader :tracing
7
8
 
8
9
  private def after_initialize
9
10
  @pages = Set.new
@@ -11,16 +12,43 @@ module Playwright
11
12
  @bindings = {}
12
13
  @timeout_settings = TimeoutSettings.new
13
14
 
15
+ @tracing = TracingImpl.new(@channel, self)
14
16
  @channel.on('bindingCall', ->(params) { on_binding(ChannelOwners::BindingCall.from(params['binding'])) })
15
17
  @channel.once('close', ->(_) { on_close })
16
18
  @channel.on('page', ->(params) { on_page(ChannelOwners::Page.from(params['page']) )})
17
19
  @channel.on('route', ->(params) {
18
20
  on_route(ChannelOwners::Route.from(params['route']), ChannelOwners::Request.from(params['request']))
19
21
  })
22
+ @channel.on('request', ->(params) {
23
+ on_request(
24
+ ChannelOwners::Request.from(params['request']),
25
+ ChannelOwners::Request.from_nullable(params['page']),
26
+ )
27
+ })
28
+ @channel.on('requestFailed', ->(params) {
29
+ on_request_failed(
30
+ ChannelOwners::Request.from(params['request']),
31
+ params['responseEndTiming'],
32
+ params['failureText'],
33
+ ChannelOwners::Request.from_nullable(params['page']),
34
+ )
35
+ })
36
+ @channel.on('requestFinished', ->(params) {
37
+ on_request_finished(
38
+ ChannelOwners::Request.from(params['request']),
39
+ params['responseEndTiming'],
40
+ ChannelOwners::Request.from_nullable(params['page']),
41
+ )
42
+ })
43
+ @channel.on('response', ->(params) {
44
+ on_response(
45
+ ChannelOwners::Response.from(params['response']),
46
+ ChannelOwners::Request.from_nullable(params['page']),
47
+ )
48
+ })
20
49
  end
21
50
 
22
51
  private def on_page(page)
23
- page.send(:update_browser_context, self)
24
52
  @pages << page
25
53
  emit(Events::BrowserContext::Page, page)
26
54
  page.send(:emit_popup_event_from_browser_context)
@@ -45,6 +73,29 @@ module Playwright
45
73
  end
46
74
  end
47
75
 
76
+ private def on_request_failed(request, response_end_timing, failure_text, page)
77
+ request.send(:update_failure_text, failure_text)
78
+ request.send(:update_response_end_timing, response_end_timing)
79
+ emit(Events::BrowserContext::RequestFailed, request)
80
+ page&.emit(Events::Page::RequestFailed, request)
81
+ end
82
+
83
+ private def on_request_finished(request, response_end_timing, page)
84
+ request.send(:update_response_end_timing, response_end_timing)
85
+ emit(Events::BrowserContext::RequestFinished, request)
86
+ page&.emit(Events::Page::RequestFinished, request)
87
+ end
88
+
89
+ private def on_request(request, page)
90
+ emit(Events::BrowserContext::Request, request)
91
+ page&.emit(Events::Page::Request, request)
92
+ end
93
+
94
+ private def on_response(response, page)
95
+ emit(Events::BrowserContext::Response, response)
96
+ page&.emit(Events::Page::Response, response)
97
+ end
98
+
48
99
  def set_default_navigation_timeout(timeout)
49
100
  @timeout_settings.default_navigation_timeout = timeout
50
101
  @channel.send_message_to_server('setDefaultNavigationTimeoutNoReply', timeout: timeout)
@@ -23,17 +23,24 @@ module Playwright
23
23
  end
24
24
  end
25
25
 
26
- def connect_over_cdp(endpointURL, slowMo: nil, timeout: nil, &block)
26
+ def connect_over_cdp(endpointURL, headers: nil, slowMo: nil, timeout: nil, &block)
27
27
  raise 'Connecting over CDP is only supported in Chromium.' unless name == 'chromium'
28
28
 
29
29
  params = {
30
30
  sdkLanguage: 'ruby',
31
31
  endpointURL: endpointURL,
32
+ headers: headers,
32
33
  slowMo: slowMo,
33
34
  timeout: timeout,
34
35
  }.compact
36
+
37
+ if headers
38
+ params[:headers] = HttpHeaders.new(headers).as_serialized
39
+ end
40
+
35
41
  result = @channel.send_message_to_server_result('connectOverCDP', params)
36
42
  browser = ChannelOwners::Browser.from(result['browser'])
43
+ browser.send(:update_as_remote)
37
44
 
38
45
  if result['defaultContext']
39
46
  context = ChannelOwners::BrowserContext.from(result['defaultContext'])
@@ -76,12 +76,13 @@ module Playwright
76
76
  nil
77
77
  end
78
78
 
79
- def hover(force: nil, modifiers: nil, position: nil, timeout: nil)
79
+ def hover(force: nil, modifiers: nil, position: nil, timeout: nil, trial: nil)
80
80
  params = {
81
81
  force: force,
82
82
  modifiers: modifiers,
83
83
  position: position,
84
84
  timeout: timeout,
85
+ trial: trial,
85
86
  }.compact
86
87
  @channel.send_message_to_server('hover', params)
87
88
 
@@ -96,7 +97,8 @@ module Playwright
96
97
  modifiers: nil,
97
98
  noWaitAfter: nil,
98
99
  position: nil,
99
- timeout: nil)
100
+ timeout: nil,
101
+ trial: nil)
100
102
 
101
103
  params = {
102
104
  button: button,
@@ -107,6 +109,7 @@ module Playwright
107
109
  noWaitAfter: noWaitAfter,
108
110
  position: position,
109
111
  timeout: timeout,
112
+ trial: trial,
110
113
  }.compact
111
114
  @channel.send_message_to_server('click', params)
112
115
 
@@ -120,7 +123,8 @@ module Playwright
120
123
  modifiers: nil,
121
124
  noWaitAfter: nil,
122
125
  position: nil,
123
- timeout: nil)
126
+ timeout: nil,
127
+ trial: nil)
124
128
 
125
129
  params = {
126
130
  button: button,
@@ -130,6 +134,7 @@ module Playwright
130
134
  noWaitAfter: noWaitAfter,
131
135
  position: position,
132
136
  timeout: timeout,
137
+ trial: trial,
133
138
  }.compact
134
139
  @channel.send_message_to_server('dblclick', params)
135
140
 
@@ -158,7 +163,8 @@ module Playwright
158
163
  modifiers: nil,
159
164
  noWaitAfter: nil,
160
165
  position: nil,
161
- timeout: nil)
166
+ timeout: nil,
167
+ trial: nil)
162
168
 
163
169
  params = {
164
170
  force: force,
@@ -166,6 +172,7 @@ module Playwright
166
172
  noWaitAfter: noWaitAfter,
167
173
  position: position,
168
174
  timeout: timeout,
175
+ trial: trial,
169
176
  }.compact
170
177
  @channel.send_message_to_server('tap', params)
171
178
 
@@ -228,24 +235,26 @@ module Playwright
228
235
  nil
229
236
  end
230
237
 
231
- def check(force: nil, noWaitAfter: nil, position: nil, timeout: nil)
238
+ def check(force: nil, noWaitAfter: nil, position: nil, timeout: nil, trial: nil)
232
239
  params = {
233
240
  force: force,
234
241
  noWaitAfter: noWaitAfter,
235
242
  position: position,
236
243
  timeout: timeout,
244
+ trial: trial,
237
245
  }.compact
238
246
  @channel.send_message_to_server('check', params)
239
247
 
240
248
  nil
241
249
  end
242
250
 
243
- def uncheck(force: nil, noWaitAfter: nil, position: nil, timeout: nil)
251
+ def uncheck(force: nil, noWaitAfter: nil, position: nil, timeout: nil, trial: nil)
244
252
  params = {
245
253
  force: force,
246
254
  noWaitAfter: noWaitAfter,
247
255
  position: position,
248
256
  timeout: timeout,
257
+ trial: trial,
249
258
  }.compact
250
259
  @channel.send_message_to_server('uncheck', params)
251
260
 
@@ -289,7 +289,8 @@ module Playwright
289
289
  modifiers: nil,
290
290
  noWaitAfter: nil,
291
291
  position: nil,
292
- timeout: nil)
292
+ timeout: nil,
293
+ trial: nil)
293
294
 
294
295
  params = {
295
296
  selector: selector,
@@ -301,6 +302,7 @@ module Playwright
301
302
  noWaitAfter: noWaitAfter,
302
303
  position: position,
303
304
  timeout: timeout,
305
+ trial: trial,
304
306
  }.compact
305
307
  @channel.send_message_to_server('click', params)
306
308
 
@@ -315,7 +317,8 @@ module Playwright
315
317
  modifiers: nil,
316
318
  noWaitAfter: nil,
317
319
  position: nil,
318
- timeout: nil)
320
+ timeout: nil,
321
+ trial: nil)
319
322
 
320
323
  params = {
321
324
  selector: selector,
@@ -326,6 +329,7 @@ module Playwright
326
329
  noWaitAfter: noWaitAfter,
327
330
  position: position,
328
331
  timeout: timeout,
332
+ trial: trial,
329
333
  }.compact
330
334
  @channel.send_message_to_server('dblclick', params)
331
335
 
@@ -338,7 +342,8 @@ module Playwright
338
342
  modifiers: nil,
339
343
  noWaitAfter: nil,
340
344
  position: nil,
341
- timeout: nil)
345
+ timeout: nil,
346
+ trial: nil)
342
347
  params = {
343
348
  selector: selector,
344
349
  force: force,
@@ -346,6 +351,7 @@ module Playwright
346
351
  noWaitAfter: noWaitAfter,
347
352
  position: position,
348
353
  timeout: timeout,
354
+ trial: trial,
349
355
  }.compact
350
356
  @channel.send_message_to_server('tap', params)
351
357
 
@@ -399,13 +405,15 @@ module Playwright
399
405
  force: nil,
400
406
  modifiers: nil,
401
407
  position: nil,
402
- timeout: nil)
408
+ timeout: nil,
409
+ trial: nil)
403
410
  params = {
404
411
  selector: selector,
405
412
  force: force,
406
413
  modifiers: modifiers,
407
414
  position: position,
408
415
  timeout: timeout,
416
+ trial: trial,
409
417
  }.compact
410
418
  @channel.send_message_to_server('hover', params)
411
419
 
@@ -481,7 +489,8 @@ module Playwright
481
489
  force: nil,
482
490
  noWaitAfter: nil,
483
491
  position: nil,
484
- timeout: nil)
492
+ timeout: nil,
493
+ trial: nil)
485
494
 
486
495
  params = {
487
496
  selector: selector,
@@ -489,6 +498,7 @@ module Playwright
489
498
  noWaitAfter: noWaitAfter,
490
499
  position: position,
491
500
  timeout: timeout,
501
+ trial: trial,
492
502
  }.compact
493
503
  @channel.send_message_to_server('check', params)
494
504
 
@@ -500,7 +510,8 @@ module Playwright
500
510
  force: nil,
501
511
  noWaitAfter: nil,
502
512
  position: nil,
503
- timeout: nil)
513
+ timeout: nil,
514
+ trial: nil)
504
515
 
505
516
  params = {
506
517
  selector: selector,
@@ -508,6 +519,7 @@ module Playwright
508
519
  noWaitAfter: noWaitAfter,
509
520
  position: position,
510
521
  timeout: timeout,
522
+ trial: trial,
511
523
  }.compact
512
524
  @channel.send_message_to_server('uncheck', params)
513
525
 
@@ -56,25 +56,6 @@ module Playwright
56
56
  @channel.on('pageError', ->(params) {
57
57
  emit(Events::Page::PageError, Error.parse(params['error']['error']))
58
58
  })
59
- @channel.on('request', ->(params) {
60
- emit(Events::Page::Request, ChannelOwners::Request.from(params['request']))
61
- })
62
- @channel.on('requestFailed', ->(params) {
63
- on_request_failed(
64
- ChannelOwners::Request.from(params['request']),
65
- params['responseEndTiming'],
66
- params['failureText'],
67
- )
68
- })
69
- @channel.on('requestFinished', ->(params) {
70
- on_request_finished(
71
- ChannelOwners::Request.from(params['request']),
72
- params['responseEndTiming'],
73
- )
74
- })
75
- @channel.on('response', ->(params) {
76
- emit(Events::Page::Response, ChannelOwners::Response.from(params['response']))
77
- })
78
59
  @channel.on('route', ->(params) {
79
60
  on_route(ChannelOwners::Route.from(params['route']), ChannelOwners::Request.from(params['request']))
80
61
  })
@@ -95,17 +76,6 @@ module Playwright
95
76
  :viewport_size,
96
77
  :main_frame
97
78
 
98
- private def on_request_failed(request, response_end_timing, failure_text)
99
- request.send(:update_failure_text, failure_text)
100
- request.send(:update_response_end_timing, response_end_timing)
101
- emit(Events::Page::RequestFailed, request)
102
- end
103
-
104
- private def on_request_finished(request, response_end_timing)
105
- request.send(:update_response_end_timing, response_end_timing)
106
- emit(Events::Page::RequestFinished, request)
107
- end
108
-
109
79
  private def on_frame_attached(frame)
110
80
  frame.send(:update_page_from_page, self)
111
81
  @frames << frame
@@ -145,6 +115,7 @@ module Playwright
145
115
 
146
116
  private def on_download(params)
147
117
  download = Download.new(
118
+ page: self,
148
119
  url: params['url'],
149
120
  suggested_filename: params['suggestedFilename'],
150
121
  artifact: ChannelOwners::Artifact.from(params['artifact']),
@@ -464,7 +435,8 @@ module Playwright
464
435
  modifiers: nil,
465
436
  noWaitAfter: nil,
466
437
  position: nil,
467
- timeout: nil)
438
+ timeout: nil,
439
+ trial: nil)
468
440
 
469
441
  @main_frame.click(
470
442
  selector,
@@ -476,6 +448,7 @@ module Playwright
476
448
  noWaitAfter: noWaitAfter,
477
449
  position: position,
478
450
  timeout: timeout,
451
+ trial: trial,
479
452
  )
480
453
  end
481
454
 
@@ -487,7 +460,8 @@ module Playwright
487
460
  modifiers: nil,
488
461
  noWaitAfter: nil,
489
462
  position: nil,
490
- timeout: nil)
463
+ timeout: nil,
464
+ trial: nil)
491
465
  @main_frame.dblclick(
492
466
  selector,
493
467
  button: button,
@@ -497,6 +471,7 @@ module Playwright
497
471
  noWaitAfter: noWaitAfter,
498
472
  position: position,
499
473
  timeout: timeout,
474
+ trial: trial,
500
475
  )
501
476
  end
502
477
 
@@ -506,7 +481,8 @@ module Playwright
506
481
  modifiers: nil,
507
482
  noWaitAfter: nil,
508
483
  position: nil,
509
- timeout: nil)
484
+ timeout: nil,
485
+ trial: nil)
510
486
  @main_frame.tap_point(
511
487
  selector,
512
488
  force: force,
@@ -514,6 +490,7 @@ module Playwright
514
490
  noWaitAfter: noWaitAfter,
515
491
  position: position,
516
492
  timeout: timeout,
493
+ trial: trial,
517
494
  )
518
495
  end
519
496
 
@@ -546,13 +523,15 @@ module Playwright
546
523
  force: nil,
547
524
  modifiers: nil,
548
525
  position: nil,
549
- timeout: nil)
526
+ timeout: nil,
527
+ trial: nil)
550
528
  @main_frame.hover(
551
529
  selector,
552
530
  force: force,
553
531
  modifiers: modifiers,
554
532
  position: position,
555
533
  timeout: timeout,
534
+ trial: trial,
556
535
  )
557
536
  end
558
537
 
@@ -604,9 +583,10 @@ module Playwright
604
583
  force: nil,
605
584
  noWaitAfter: nil,
606
585
  position: nil,
607
- timeout: nil)
586
+ timeout: nil,
587
+ trial: nil)
608
588
 
609
- @main_frame.check(selector, force: force, noWaitAfter: noWaitAfter, position: position, timeout: timeout)
589
+ @main_frame.check(selector, force: force, noWaitAfter: noWaitAfter, position: position, timeout: timeout, trial: trial)
610
590
  end
611
591
 
612
592
  def uncheck(
@@ -614,9 +594,10 @@ module Playwright
614
594
  force: nil,
615
595
  noWaitAfter: nil,
616
596
  position: nil,
617
- timeout: nil)
597
+ timeout: nil,
598
+ trial: nil)
618
599
 
619
- @main_frame.uncheck(selector, force: force, noWaitAfter: noWaitAfter, position: position, timeout: timeout)
600
+ @main_frame.uncheck(selector, force: force, noWaitAfter: noWaitAfter, position: position, timeout: timeout, trial: trial)
620
601
  end
621
602
 
622
603
  def wait_for_function(pageFunction, arg: nil, polling: nil, timeout: nil)
@@ -783,12 +764,6 @@ module Playwright
783
764
  expect_event(Events::Page::Response, predicate: predicate, timeout: timeout)
784
765
  end
785
766
 
786
- # called from BrowserContext#on_page with send(:update_browser_context, page), so keep private.
787
- private def update_browser_context(context)
788
- @browser_context = context
789
- @timeout_settings = TimeoutSettings.new(context.send(:_timeout_settings))
790
- end
791
-
792
767
  # called from Frame with send(:timeout_settings)
793
768
  private def timeout_settings
794
769
  @timeout_settings