playwright-ruby-client 1.61.0 → 1.63.0

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 (63) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -17
  3. data/documentation/docs/api/api_request_context.md +3 -0
  4. data/documentation/docs/api/api_response.md +12 -0
  5. data/documentation/docs/api/browser_context.md +5 -3
  6. data/documentation/docs/api/browser_type.md +2 -0
  7. data/documentation/docs/api/credentials.md +6 -2
  8. data/documentation/docs/api/element_handle.md +7 -0
  9. data/documentation/docs/api/frame.md +20 -1
  10. data/documentation/docs/api/frame_locator.md +20 -0
  11. data/documentation/docs/api/locator.md +57 -0
  12. data/documentation/docs/api/locator_assertions.md +4 -2
  13. data/documentation/docs/api/page.md +26 -1
  14. data/documentation/docs/api/playwright.md +2 -2
  15. data/documentation/docs/api/tracing.md +3 -1
  16. data/documentation/docs/article/getting_started.md +12 -11
  17. data/documentation/docs/article/guides/download_playwright_driver.md +11 -32
  18. data/documentation/docs/article/guides/launch_browser.md +5 -4
  19. data/documentation/docs/article/guides/playwright_on_alpine_linux.md +6 -5
  20. data/documentation/docs/article/guides/rails_integration.md +72 -4
  21. data/documentation/docs/article/guides/rails_integration_with_null_driver.md +4 -3
  22. data/documentation/docs/article/guides/semi_automation.md +1 -1
  23. data/documentation/docs/article/guides/use_storage_state.md +1 -1
  24. data/documentation/docs/include/api_coverage.md +3 -0
  25. data/documentation/docusaurus.config.js +31 -0
  26. data/documentation/package.json +3 -0
  27. data/documentation/yarn.lock +159 -174
  28. data/lib/playwright/api_request_impl.rb +3 -1
  29. data/lib/playwright/api_response_impl.rb +16 -0
  30. data/lib/playwright/channel.rb +2 -1
  31. data/lib/playwright/channel_owners/browser.rb +1 -0
  32. data/lib/playwright/channel_owners/browser_context.rb +22 -3
  33. data/lib/playwright/channel_owners/element_handle.rb +14 -4
  34. data/lib/playwright/channel_owners/frame.rb +16 -2
  35. data/lib/playwright/channel_owners/page.rb +21 -9
  36. data/lib/playwright/channel_owners/tracing.rb +43 -13
  37. data/lib/playwright/connection.rb +9 -1
  38. data/lib/playwright/events.rb +2 -0
  39. data/lib/playwright/frame_locator_impl.rb +20 -5
  40. data/lib/playwright/locator_assertions_impl.rb +14 -1
  41. data/lib/playwright/locator_impl.rb +32 -5
  42. data/lib/playwright/screencast.rb +20 -6
  43. data/lib/playwright/screenshot_utils.rb +24 -0
  44. data/lib/playwright/test.rb +12 -2
  45. data/lib/playwright/url_matcher.rb +120 -4
  46. data/lib/playwright/utils.rb +12 -0
  47. data/lib/playwright/version.rb +2 -2
  48. data/lib/playwright.rb +2 -2
  49. data/lib/playwright_api/api_request_context.rb +3 -1
  50. data/lib/playwright_api/api_response.rb +9 -0
  51. data/lib/playwright_api/browser_context.rb +16 -14
  52. data/lib/playwright_api/browser_type.rb +2 -0
  53. data/lib/playwright_api/credentials.rb +6 -2
  54. data/lib/playwright_api/element_handle.rb +14 -7
  55. data/lib/playwright_api/frame.rb +28 -9
  56. data/lib/playwright_api/frame_locator.rb +20 -0
  57. data/lib/playwright_api/locator.rb +64 -13
  58. data/lib/playwright_api/locator_assertions.rb +6 -4
  59. data/lib/playwright_api/page.rb +46 -21
  60. data/lib/playwright_api/tracing.rb +4 -2
  61. data/playwright.gemspec +5 -0
  62. data/sig/playwright.rbs +49 -46
  63. metadata +7 -3
@@ -3,6 +3,8 @@ require 'json'
3
3
 
4
4
  module Playwright
5
5
  define_api_implementation :APIRequestImpl do
6
+ include Utils::PrepareHttpCredentials
7
+
6
8
  def initialize(playwright)
7
9
  @playwright = playwright
8
10
  end
@@ -24,7 +26,7 @@ module Playwright
24
26
  clientCertificates: prepare_client_certificates(clientCertificates),
25
27
  extraHTTPHeaders: extraHTTPHeaders ? HttpHeaders.new(extraHTTPHeaders).as_serialized : nil,
26
28
  failOnStatusCode: failOnStatusCode,
27
- httpCredentials: httpCredentials,
29
+ httpCredentials: prepare_http_credentials(httpCredentials),
28
30
  ignoreHTTPSErrors: ignoreHTTPSErrors,
29
31
  maxRedirects: maxRedirects,
30
32
  proxy: proxy,
@@ -47,6 +47,22 @@ module Playwright
47
47
  @initializer['serverAddr']
48
48
  end
49
49
 
50
+ def timing
51
+ response_end = @initializer['responseEndTiming']
52
+ {
53
+ 'startTime' => -1,
54
+ 'domainLookupStart' => -1,
55
+ 'domainLookupEnd' => -1,
56
+ 'connectStart' => -1,
57
+ 'secureConnectionStart' => -1,
58
+ 'connectEnd' => -1,
59
+ 'requestStart' => -1,
60
+ 'responseStart' => -1,
61
+ }.merge(@initializer['timing'] || {}).merge(
62
+ 'responseEnd' => response_end.nil? ? -1 : response_end,
63
+ )
64
+ end
65
+
50
66
  class AlreadyDisposedError < StandardError
51
67
  def initialize
52
68
  super('Response has been disposed')
@@ -75,7 +75,8 @@ module Playwright
75
75
  wallTime: (Time.now.to_f * 1000).to_i,
76
76
  apiName: api_name,
77
77
  stack: stacks.map do |loc|
78
- { file: loc.absolute_path || '', line: loc.lineno, function: loc.label }
78
+ # Ruby backtraces do not provide a column, but the trace protocol requires one.
79
+ { file: loc.absolute_path || '', line: loc.lineno, column: 0, function: loc.label }
79
80
  end,
80
81
  }
81
82
  end
@@ -156,6 +156,7 @@ module Playwright
156
156
 
157
157
  private def setup_browser_context(context)
158
158
  context.tracing.send(:update_traces_dir, @traces_dir)
159
+ context.request.tracing.send(:update_traces_dir, @traces_dir)
159
160
  @browser_type.send(:playwright_selectors_browser_contexts) << context
160
161
  end
161
162
 
@@ -42,6 +42,11 @@ module Playwright
42
42
  @channel.on('dialog', ->(params) {
43
43
  on_dialog(ChannelOwners::Dialog.from(params['dialog']))
44
44
  })
45
+ @channel.on('dialogClosed', ->(params) {
46
+ dialog = ChannelOwners::Dialog.from(params['dialog'])
47
+ emit(Events::BrowserContext::DialogClosed, dialog)
48
+ dialog.page&.emit(Events::Page::DialogClosed, dialog)
49
+ })
45
50
  @channel.on('request', ->(params) {
46
51
  on_request(
47
52
  ChannelOwners::Request.from(params['request']),
@@ -69,6 +74,7 @@ module Playwright
69
74
  set_event_to_subscription_mapping({
70
75
  Events::BrowserContext::Console => 'console',
71
76
  Events::BrowserContext::Dialog => 'dialog',
77
+ Events::BrowserContext::DialogClosed => 'dialogClosed',
72
78
  Events::BrowserContext::Request => "request",
73
79
  Events::BrowserContext::Response => "response",
74
80
  Events::BrowserContext::RequestFinished => "requestFinished",
@@ -93,6 +99,7 @@ module Playwright
93
99
  private def update_options(context_options:, browser_options:)
94
100
  @options = context_options
95
101
  @tracing.send(:update_traces_dir, browser_options[:tracesDir])
102
+ @request.tracing.send(:update_traces_dir, browser_options[:tracesDir])
96
103
  end
97
104
 
98
105
  private def on_page(page)
@@ -418,6 +425,7 @@ module Playwright
418
425
  @browser.browser_type.send(:playwright_selectors_browser_contexts).delete(self)
419
426
  end
420
427
  @tracing.send(:reset_stack_counter)
428
+ @request.tracing.send(:reset_stack_counter)
421
429
  emit(Events::BrowserContext::Close)
422
430
  @closed_promise.fulfill(true)
423
431
  end
@@ -427,9 +435,15 @@ module Playwright
427
435
  @close_was_called = true
428
436
  @close_reason = reason
429
437
  @request.dispose(reason: reason)
430
- @tracing.send(:export_all_hars)
438
+ har_error = nil
439
+ begin
440
+ @tracing.send(:export_all_hars)
441
+ rescue => error
442
+ har_error = error
443
+ end
431
444
  @channel.send_message_to_server('close', { reason: reason }.compact)
432
445
  @closed_promise.value!
446
+ raise har_error if har_error
433
447
  nil
434
448
  end
435
449
 
@@ -462,8 +476,13 @@ module Playwright
462
476
  @channel.send_message_to_server('pause')
463
477
  end
464
478
 
465
- def storage_state(path: nil, indexedDB: nil)
466
- @channel.send_message_to_server_result('storageState', { indexedDB: indexedDB }.compact).tap do |result|
479
+ def storage_state(path: nil, indexedDB: nil, opfs: nil, credentials: nil)
480
+ params = {
481
+ indexedDB: indexedDB,
482
+ opfs: opfs,
483
+ credentials: credentials,
484
+ }.compact
485
+ @channel.send_message_to_server_result('storageState', params).tap do |result|
467
486
  if path
468
487
  File.open(path, 'w') do |f|
469
488
  f.write(JSON.dump(result))
@@ -1,4 +1,5 @@
1
1
  require_relative './js_handle'
2
+ require_relative '../screenshot_utils'
2
3
 
3
4
  module Playwright
4
5
  module ChannelOwners
@@ -86,6 +87,7 @@ module Playwright
86
87
  modifiers: nil,
87
88
  noWaitAfter: nil,
88
89
  position: nil,
90
+ scroll: nil,
89
91
  timeout: nil,
90
92
  trial: nil)
91
93
  params = {
@@ -93,6 +95,7 @@ module Playwright
93
95
  modifiers: modifiers,
94
96
  noWaitAfter: noWaitAfter,
95
97
  position: position,
98
+ scroll: scroll,
96
99
  timeout: _timeout(timeout),
97
100
  trial: trial,
98
101
  }.compact
@@ -109,6 +112,7 @@ module Playwright
109
112
  modifiers: nil,
110
113
  noWaitAfter: nil,
111
114
  position: nil,
115
+ scroll: nil,
112
116
  timeout: nil,
113
117
  trial: nil,
114
118
  steps: nil)
@@ -121,6 +125,7 @@ module Playwright
121
125
  modifiers: modifiers,
122
126
  noWaitAfter: noWaitAfter,
123
127
  position: position,
128
+ scroll: scroll,
124
129
  timeout: _timeout(timeout),
125
130
  trial: trial,
126
131
  steps: steps,
@@ -137,6 +142,7 @@ module Playwright
137
142
  modifiers: nil,
138
143
  noWaitAfter: nil,
139
144
  position: nil,
145
+ scroll: nil,
140
146
  timeout: nil,
141
147
  trial: nil,
142
148
  steps: nil)
@@ -148,6 +154,7 @@ module Playwright
148
154
  modifiers: modifiers,
149
155
  noWaitAfter: noWaitAfter,
150
156
  position: position,
157
+ scroll: scroll,
151
158
  timeout: _timeout(timeout),
152
159
  trial: trial,
153
160
  steps: steps,
@@ -180,6 +187,7 @@ module Playwright
180
187
  modifiers: nil,
181
188
  noWaitAfter: nil,
182
189
  position: nil,
190
+ scroll: nil,
183
191
  timeout: nil,
184
192
  trial: nil)
185
193
 
@@ -188,6 +196,7 @@ module Playwright
188
196
  modifiers: modifiers,
189
197
  noWaitAfter: noWaitAfter,
190
198
  position: position,
199
+ scroll: scroll,
191
200
  timeout: _timeout(timeout),
192
201
  trial: trial,
193
202
  }.compact
@@ -263,11 +272,12 @@ module Playwright
263
272
  nil
264
273
  end
265
274
 
266
- def check(force: nil, noWaitAfter: nil, position: nil, timeout: nil, trial: nil)
275
+ def check(force: nil, noWaitAfter: nil, position: nil, scroll: nil, timeout: nil, trial: nil)
267
276
  params = {
268
277
  force: force,
269
278
  noWaitAfter: noWaitAfter,
270
279
  position: position,
280
+ scroll: scroll,
271
281
  timeout: _timeout(timeout),
272
282
  trial: trial,
273
283
  }.compact
@@ -276,11 +286,12 @@ module Playwright
276
286
  nil
277
287
  end
278
288
 
279
- def uncheck(force: nil, noWaitAfter: nil, position: nil, timeout: nil, trial: nil)
289
+ def uncheck(force: nil, noWaitAfter: nil, position: nil, scroll: nil, timeout: nil, trial: nil)
280
290
  params = {
281
291
  force: force,
282
292
  noWaitAfter: noWaitAfter,
283
293
  position: position,
294
+ scroll: scroll,
284
295
  timeout: _timeout(timeout),
285
296
  trial: trial,
286
297
  }.compact
@@ -319,12 +330,11 @@ module Playwright
319
330
  caret: caret,
320
331
  maskColor: maskColor,
321
332
  omitBackground: omitBackground,
322
- path: path,
323
333
  quality: quality,
324
334
  scale: scale,
325
335
  style: style,
326
336
  timeout: _timeout(timeout),
327
- type: type,
337
+ type: ScreenshotUtils.determine_type(path: path, type: type),
328
338
  }.compact
329
339
  if mask.is_a?(Enumerable)
330
340
  params[:mask] = mask.map do |locator|
@@ -338,6 +338,7 @@ module Playwright
338
338
  modifiers: nil,
339
339
  noWaitAfter: nil,
340
340
  position: nil,
341
+ scroll: nil,
341
342
  strict: nil,
342
343
  timeout: nil,
343
344
  trial: nil,
@@ -352,6 +353,7 @@ module Playwright
352
353
  modifiers: modifiers,
353
354
  noWaitAfter: noWaitAfter,
354
355
  position: position,
356
+ scroll: scroll,
355
357
  strict: strict,
356
358
  timeout: _timeout(timeout),
357
359
  trial: trial,
@@ -367,6 +369,7 @@ module Playwright
367
369
  target,
368
370
  force: nil,
369
371
  noWaitAfter: nil,
372
+ scroll: nil,
370
373
  sourcePosition: nil,
371
374
  strict: nil,
372
375
  targetPosition: nil,
@@ -379,6 +382,7 @@ module Playwright
379
382
  target: target,
380
383
  force: force,
381
384
  noWaitAfter: noWaitAfter,
385
+ scroll: scroll,
382
386
  sourcePosition: sourcePosition,
383
387
  strict: strict,
384
388
  targetPosition: targetPosition,
@@ -416,6 +420,7 @@ module Playwright
416
420
  modifiers: nil,
417
421
  noWaitAfter: nil,
418
422
  position: nil,
423
+ scroll: nil,
419
424
  strict: nil,
420
425
  timeout: nil,
421
426
  trial: nil,
@@ -429,6 +434,7 @@ module Playwright
429
434
  modifiers: modifiers,
430
435
  noWaitAfter: noWaitAfter,
431
436
  position: position,
437
+ scroll: scroll,
432
438
  strict: strict,
433
439
  timeout: _timeout(timeout),
434
440
  trial: trial,
@@ -445,6 +451,7 @@ module Playwright
445
451
  modifiers: nil,
446
452
  noWaitAfter: nil,
447
453
  position: nil,
454
+ scroll: nil,
448
455
  strict: nil,
449
456
  timeout: nil,
450
457
  trial: nil)
@@ -454,6 +461,7 @@ module Playwright
454
461
  modifiers: modifiers,
455
462
  noWaitAfter: noWaitAfter,
456
463
  position: position,
464
+ scroll: scroll,
457
465
  strict: strict,
458
466
  timeout: _timeout(timeout),
459
467
  trial: trial,
@@ -498,8 +506,8 @@ module Playwright
498
506
  hasText: hasText)
499
507
  end
500
508
 
501
- def frame_locator(selector)
502
- FrameLocatorImpl.new(frame: self, frame_selector: selector)
509
+ def frame_locator(selector = nil)
510
+ FrameLocatorImpl.new(frame: self, frame_selector: selector || 'internal:control=any-frame')
503
511
  end
504
512
 
505
513
  def focus(selector, strict: nil, timeout: nil)
@@ -539,6 +547,7 @@ module Playwright
539
547
  modifiers: nil,
540
548
  noWaitAfter: nil,
541
549
  position: nil,
550
+ scroll: nil,
542
551
  strict: nil,
543
552
  timeout: nil,
544
553
  trial: nil)
@@ -548,6 +557,7 @@ module Playwright
548
557
  modifiers: modifiers,
549
558
  noWaitAfter: noWaitAfter,
550
559
  position: position,
560
+ scroll: scroll,
551
561
  strict: strict,
552
562
  timeout: _timeout(timeout),
553
563
  trial: trial,
@@ -642,6 +652,7 @@ module Playwright
642
652
  force: nil,
643
653
  noWaitAfter: nil,
644
654
  position: nil,
655
+ scroll: nil,
645
656
  strict: nil,
646
657
  timeout: nil,
647
658
  trial: nil)
@@ -651,6 +662,7 @@ module Playwright
651
662
  force: force,
652
663
  noWaitAfter: noWaitAfter,
653
664
  position: position,
665
+ scroll: scroll,
654
666
  strict: strict,
655
667
  timeout: _timeout(timeout),
656
668
  trial: trial,
@@ -665,6 +677,7 @@ module Playwright
665
677
  force: nil,
666
678
  noWaitAfter: nil,
667
679
  position: nil,
680
+ scroll: nil,
668
681
  strict: nil,
669
682
  timeout: nil,
670
683
  trial: nil)
@@ -674,6 +687,7 @@ module Playwright
674
687
  force: force,
675
688
  noWaitAfter: noWaitAfter,
676
689
  position: position,
690
+ scroll: scroll,
677
691
  strict: strict,
678
692
  timeout: _timeout(timeout),
679
693
  trial: trial,
@@ -1,5 +1,6 @@
1
1
  require 'base64'
2
2
  require_relative '../locator_utils'
3
+ require_relative '../screenshot_utils'
3
4
 
4
5
  module Playwright
5
6
  # @ref https://github.com/microsoft/playwright-python/blob/master/playwright/_impl/_page.py
@@ -71,6 +72,7 @@ module Playwright
71
72
  set_event_to_subscription_mapping({
72
73
  Events::Page::Console => "console",
73
74
  Events::Page::Dialog => "dialog",
75
+ Events::Page::DialogClosed => "dialogClosed",
74
76
  Events::Page::Request => "request",
75
77
  Events::Page::Response => "response",
76
78
  Events::Page::RequestFinished => "requestFinished",
@@ -483,7 +485,7 @@ module Playwright
483
485
  type: nil)
484
486
 
485
487
  params = {
486
- type: type,
488
+ type: ScreenshotUtils.determine_type(path: path, type: type),
487
489
  quality: quality,
488
490
  fullPage: fullPage,
489
491
  clip: clip,
@@ -545,6 +547,7 @@ module Playwright
545
547
  modifiers: nil,
546
548
  noWaitAfter: nil,
547
549
  position: nil,
550
+ scroll: nil,
548
551
  strict: nil,
549
552
  timeout: nil,
550
553
  trial: nil,
@@ -559,6 +562,7 @@ module Playwright
559
562
  modifiers: modifiers,
560
563
  noWaitAfter: noWaitAfter,
561
564
  position: position,
565
+ scroll: scroll,
562
566
  strict: strict,
563
567
  timeout: timeout,
564
568
  trial: trial,
@@ -571,6 +575,7 @@ module Playwright
571
575
  target,
572
576
  force: nil,
573
577
  noWaitAfter: nil,
578
+ scroll: nil,
574
579
  sourcePosition: nil,
575
580
  strict: nil,
576
581
  targetPosition: nil,
@@ -583,6 +588,7 @@ module Playwright
583
588
  target,
584
589
  force: force,
585
590
  noWaitAfter: noWaitAfter,
591
+ scroll: scroll,
586
592
  sourcePosition: sourcePosition,
587
593
  strict: strict,
588
594
  targetPosition: targetPosition,
@@ -600,6 +606,7 @@ module Playwright
600
606
  modifiers: nil,
601
607
  noWaitAfter: nil,
602
608
  position: nil,
609
+ scroll: nil,
603
610
  strict: nil,
604
611
  timeout: nil,
605
612
  trial: nil,
@@ -612,6 +619,7 @@ module Playwright
612
619
  modifiers: modifiers,
613
620
  noWaitAfter: noWaitAfter,
614
621
  position: position,
622
+ scroll: scroll,
615
623
  strict: strict,
616
624
  timeout: timeout,
617
625
  trial: trial,
@@ -625,6 +633,7 @@ module Playwright
625
633
  modifiers: nil,
626
634
  noWaitAfter: nil,
627
635
  position: nil,
636
+ scroll: nil,
628
637
  strict: nil,
629
638
  timeout: nil,
630
639
  trial: nil)
@@ -634,6 +643,7 @@ module Playwright
634
643
  modifiers: modifiers,
635
644
  noWaitAfter: noWaitAfter,
636
645
  position: position,
646
+ scroll: scroll,
637
647
  strict: strict,
638
648
  timeout: timeout,
639
649
  trial: trial,
@@ -690,16 +700,12 @@ module Playwright
690
700
  @channel.send_message_to_server('hideHighlight')
691
701
  end
692
702
 
693
- def aria_snapshot(boxes: nil, depth: nil, mode: nil, timeout: nil, _track: nil)
703
+ def aria_snapshot(boxes: nil, depth: nil, mode: nil, timeout: nil)
694
704
  params = { selector: 'body' }
695
705
  params[:timeout] = @timeout_settings.timeout(timeout)
696
706
  params[:boxes] = boxes unless boxes.nil?
697
707
  params[:depth] = depth if depth
698
708
  params[:mode] = mode if mode
699
- if _track
700
- params.delete(:selector)
701
- params[:track] = _track
702
- end
703
709
  result = @main_frame.channel.send_message_to_server_result('ariaSnapshot', params)
704
710
  result['snapshot']
705
711
  end
@@ -718,7 +724,7 @@ module Playwright
718
724
  hasText: hasText)
719
725
  end
720
726
 
721
- def frame_locator(selector)
727
+ def frame_locator(selector = nil)
722
728
  @main_frame.frame_locator(selector)
723
729
  end
724
730
 
@@ -748,6 +754,7 @@ module Playwright
748
754
  modifiers: nil,
749
755
  noWaitAfter: nil,
750
756
  position: nil,
757
+ scroll: nil,
751
758
  strict: nil,
752
759
  timeout: nil,
753
760
  trial: nil)
@@ -757,6 +764,7 @@ module Playwright
757
764
  modifiers: modifiers,
758
765
  noWaitAfter: noWaitAfter,
759
766
  position: position,
767
+ scroll: scroll,
760
768
  strict: strict,
761
769
  timeout: timeout,
762
770
  trial: trial,
@@ -838,6 +846,7 @@ module Playwright
838
846
  force: nil,
839
847
  noWaitAfter: nil,
840
848
  position: nil,
849
+ scroll: nil,
841
850
  strict: nil,
842
851
  timeout: nil,
843
852
  trial: nil)
@@ -847,6 +856,7 @@ module Playwright
847
856
  force: force,
848
857
  noWaitAfter: noWaitAfter,
849
858
  position: position,
859
+ scroll: scroll,
850
860
  strict: strict,
851
861
  timeout: timeout,
852
862
  trial: trial)
@@ -857,6 +867,7 @@ module Playwright
857
867
  force: nil,
858
868
  noWaitAfter: nil,
859
869
  position: nil,
870
+ scroll: nil,
860
871
  strict: nil,
861
872
  timeout: nil,
862
873
  trial: nil)
@@ -866,6 +877,7 @@ module Playwright
866
877
  force: force,
867
878
  noWaitAfter: noWaitAfter,
868
879
  position: position,
880
+ scroll: scroll,
869
881
  strict: strict,
870
882
  timeout: timeout,
871
883
  trial: trial)
@@ -962,8 +974,8 @@ module Playwright
962
974
  @main_frame.locator(result['selector'])
963
975
  end
964
976
 
965
- def snapshot_for_ai(timeout: nil, depth: nil, boxes: nil, _track: nil)
966
- aria_snapshot(mode: 'ai', timeout: timeout, depth: depth, boxes: boxes, _track: _track)
977
+ def snapshot_for_ai(timeout: nil, depth: nil, boxes: nil)
978
+ aria_snapshot(mode: 'ai', timeout: timeout, depth: depth, boxes: boxes)
967
979
  end
968
980
 
969
981
  def _assertions(timeout, is_not, message)
@@ -5,15 +5,16 @@ module Playwright
5
5
  @har_id = nil
6
6
  end
7
7
 
8
- def start(name: nil, title: nil, screenshots: nil, snapshots: nil, sources: nil, live: nil)
8
+ def start(name: nil, title: nil, screenshots: nil, snapshots: nil, ariaSnapshots: nil, screenSnapshots: nil, sources: nil, live: nil)
9
9
  params = {
10
10
  name: name,
11
- screenshots: screenshots,
12
- snapshots: snapshots,
13
- sources: sources,
11
+ screencast: screenshots,
12
+ snapshotDom: snapshots,
13
+ snapshotAria: ariaSnapshots,
14
+ snapshotScreen: screenSnapshots,
14
15
  live: live,
15
16
  }.compact
16
- @include_sources = params[:sources] || false
17
+ @include_sources = sources || false
17
18
  @channel.send_message_to_server('tracingStart', params)
18
19
  trace_name = @channel.send_message_to_server('tracingStartChunk', { title: title, name: name }.compact)
19
20
  start_collecting_stacks(trace_name)
@@ -38,19 +39,43 @@ module Playwright
38
39
  end
39
40
 
40
41
  def stop(path: nil)
41
- do_stop_chunk(file_path: path)
42
+ save_error = nil
43
+ begin
44
+ do_stop_chunk(file_path: path)
45
+ rescue => error
46
+ save_error = error
47
+ end
42
48
  @channel.send_message_to_server('tracingStop')
49
+ raise save_error if save_error
43
50
  end
44
51
 
45
52
  private def do_stop_chunk(file_path:)
46
53
  reset_stack_counter
54
+ stacks_id = @stacks_id
55
+ @stacks_id = nil
56
+ begin
57
+ save_chunk(file_path: file_path, stacks_id: stacks_id)
58
+ rescue
59
+ # Release the session even if saving fails so subsequent traces start fresh.
60
+ if stacks_id
61
+ begin
62
+ @connection.local_utils&.trace_discarded(stacks_id)
63
+ rescue
64
+ # Preserve the error from saving the trace.
65
+ end
66
+ end
67
+ raise
68
+ end
69
+ end
70
+
71
+ private def save_chunk(file_path:, stacks_id:)
47
72
  local_utils = @connection.local_utils
48
73
 
49
74
  unless file_path
50
75
  # Not interested in any artifacts
51
76
  @channel.send_message_to_server('tracingStopChunk', mode: 'discard')
52
- if @stacks_id
53
- local_utils.trace_discarded(@stacks_id) if local_utils
77
+ if stacks_id
78
+ local_utils.trace_discarded(stacks_id) if local_utils
54
79
  end
55
80
 
56
81
  return
@@ -66,7 +91,7 @@ module Playwright
66
91
  local_utils.zip(
67
92
  zipFile: file_path,
68
93
  entries: result['entries'],
69
- stacksId: @stacks_id,
94
+ stacksId: stacks_id,
70
95
  mode: 'write',
71
96
  includeSources: @include_sources,
72
97
  )
@@ -78,8 +103,8 @@ module Playwright
78
103
  result = @channel.send_message_to_server_result('tracingStopChunk', mode: 'archive')
79
104
  # The artifact may be missing if the browser closed while stopping tracing.
80
105
  unless result['artifact']
81
- if @stacks_id
82
- local_utils.trace_discarded(@stacks_id) if local_utils
106
+ if stacks_id
107
+ local_utils.trace_discarded(stacks_id) if local_utils
83
108
  end
84
109
 
85
110
  return
@@ -87,7 +112,12 @@ module Playwright
87
112
 
88
113
  # Save trace to the final local file.
89
114
  artifact = ChannelOwners::Artifact.from(result['artifact'])
90
- artifact.save_as(file_path)
115
+ begin
116
+ artifact.save_as(file_path)
117
+ rescue
118
+ artifact.delete rescue nil
119
+ raise
120
+ end
91
121
  artifact.delete
92
122
 
93
123
  return unless local_utils
@@ -95,7 +125,7 @@ module Playwright
95
125
  local_utils.zip(
96
126
  zipFile: file_path,
97
127
  entries: [],
98
- stacksId: @stacks_id,
128
+ stacksId: stacks_id,
99
129
  mode: 'append',
100
130
  includeSources: @include_sources,
101
131
  )
@@ -87,6 +87,13 @@ module Playwright
87
87
  # @see https://github.com/YusukeIwaki/puppeteer-ruby/pull/34
88
88
  @callbacks_mutex.synchronize { @callbacks[id] = callback } unless fire_and_forget
89
89
 
90
+ wire_params = params.dup
91
+ timeout = if wire_params.key?(:timeout)
92
+ wire_params.delete(:timeout)
93
+ elsif wire_params.key?('timeout')
94
+ wire_params.delete('timeout')
95
+ end
96
+
90
97
  _metadata = {}
91
98
  frames = []
92
99
  if metadata
@@ -99,13 +106,14 @@ module Playwright
99
106
  _metadata[:title] = metadata[:title]
100
107
  end
101
108
  end
109
+ _metadata[:timeout] = timeout unless timeout.nil?
102
110
  _metadata.compact!
103
111
 
104
112
  message = {
105
113
  id: id,
106
114
  guid: guid,
107
115
  method: method,
108
- params: replace_channels_with_guids(params),
116
+ params: replace_channels_with_guids(wire_params),
109
117
  metadata: _metadata,
110
118
  }
111
119
 
@@ -29,6 +29,7 @@ end
29
29
  Close: 'close',
30
30
  Console: 'console',
31
31
  Dialog: 'dialog',
32
+ DialogClosed: 'dialogclosed',
32
33
  Download: 'download',
33
34
  FrameAttached: 'frameattached',
34
35
  FrameDetached: 'framedetached',
@@ -53,6 +54,7 @@ end
53
54
  Crash: 'crash',
54
55
  Console: 'console',
55
56
  Dialog: 'dialog',
57
+ DialogClosed: 'dialogclosed',
56
58
  Download: 'download',
57
59
  FileChooser: 'filechooser',
58
60
  DOMContentLoaded: 'domcontentloaded',