playwright-ruby-client 1.61.0 → 1.62.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 (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -17
  3. data/documentation/docs/api/api_response.md +12 -0
  4. data/documentation/docs/api/browser_context.md +5 -3
  5. data/documentation/docs/api/browser_type.md +2 -0
  6. data/documentation/docs/api/credentials.md +6 -2
  7. data/documentation/docs/api/element_handle.md +7 -0
  8. data/documentation/docs/api/frame.md +8 -0
  9. data/documentation/docs/api/locator.md +29 -0
  10. data/documentation/docs/api/locator_assertions.md +4 -2
  11. data/documentation/docs/api/page.md +14 -0
  12. data/documentation/docs/api/playwright.md +2 -2
  13. data/documentation/docs/article/getting_started.md +12 -11
  14. data/documentation/docs/article/guides/download_playwright_driver.md +11 -32
  15. data/documentation/docs/article/guides/launch_browser.md +5 -4
  16. data/documentation/docs/article/guides/playwright_on_alpine_linux.md +6 -5
  17. data/documentation/docs/article/guides/rails_integration.md +72 -4
  18. data/documentation/docs/article/guides/rails_integration_with_null_driver.md +4 -3
  19. data/documentation/docs/article/guides/semi_automation.md +1 -1
  20. data/documentation/docs/article/guides/use_storage_state.md +1 -1
  21. data/documentation/docs/include/api_coverage.md +2 -0
  22. data/documentation/docusaurus.config.js +31 -0
  23. data/documentation/package.json +3 -0
  24. data/documentation/yarn.lock +159 -174
  25. data/lib/playwright/api_response_impl.rb +16 -0
  26. data/lib/playwright/channel_owners/browser_context.rb +6 -2
  27. data/lib/playwright/channel_owners/element_handle.rb +14 -4
  28. data/lib/playwright/channel_owners/frame.rb +14 -0
  29. data/lib/playwright/channel_owners/page.rb +19 -8
  30. data/lib/playwright/connection.rb +9 -1
  31. data/lib/playwright/locator_assertions_impl.rb +14 -1
  32. data/lib/playwright/locator_impl.rb +28 -5
  33. data/lib/playwright/screencast.rb +20 -6
  34. data/lib/playwright/screenshot_utils.rb +24 -0
  35. data/lib/playwright/test.rb +12 -2
  36. data/lib/playwright/url_matcher.rb +120 -4
  37. data/lib/playwright/version.rb +2 -2
  38. data/lib/playwright.rb +2 -2
  39. data/lib/playwright_api/api_request_context.rb +6 -6
  40. data/lib/playwright_api/api_response.rb +9 -0
  41. data/lib/playwright_api/browser.rb +6 -6
  42. data/lib/playwright_api/browser_context.rb +14 -12
  43. data/lib/playwright_api/browser_type.rb +8 -6
  44. data/lib/playwright_api/cdp_session.rb +6 -6
  45. data/lib/playwright_api/credentials.rb +6 -2
  46. data/lib/playwright_api/dialog.rb +6 -6
  47. data/lib/playwright_api/element_handle.rb +20 -13
  48. data/lib/playwright_api/frame.rb +29 -21
  49. data/lib/playwright_api/js_handle.rb +6 -6
  50. data/lib/playwright_api/locator.rb +39 -13
  51. data/lib/playwright_api/locator_assertions.rb +6 -4
  52. data/lib/playwright_api/page.rb +37 -23
  53. data/lib/playwright_api/playwright.rb +6 -6
  54. data/lib/playwright_api/request.rb +8 -8
  55. data/lib/playwright_api/response.rb +6 -6
  56. data/lib/playwright_api/route.rb +6 -6
  57. data/lib/playwright_api/tracing.rb +6 -6
  58. data/lib/playwright_api/web_socket.rb +6 -6
  59. data/lib/playwright_api/worker.rb +8 -8
  60. data/playwright.gemspec +5 -0
  61. data/sig/playwright.rbs +41 -39
  62. metadata +7 -3
@@ -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')
@@ -462,8 +462,12 @@ module Playwright
462
462
  @channel.send_message_to_server('pause')
463
463
  end
464
464
 
465
- def storage_state(path: nil, indexedDB: nil)
466
- @channel.send_message_to_server_result('storageState', { indexedDB: indexedDB }.compact).tap do |result|
465
+ def storage_state(path: nil, indexedDB: nil, credentials: nil)
466
+ params = {
467
+ indexedDB: indexedDB,
468
+ credentials: credentials,
469
+ }.compact
470
+ @channel.send_message_to_server_result('storageState', params).tap do |result|
467
471
  if path
468
472
  File.open(path, 'w') do |f|
469
473
  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,
@@ -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
@@ -483,7 +484,7 @@ module Playwright
483
484
  type: nil)
484
485
 
485
486
  params = {
486
- type: type,
487
+ type: ScreenshotUtils.determine_type(path: path, type: type),
487
488
  quality: quality,
488
489
  fullPage: fullPage,
489
490
  clip: clip,
@@ -545,6 +546,7 @@ module Playwright
545
546
  modifiers: nil,
546
547
  noWaitAfter: nil,
547
548
  position: nil,
549
+ scroll: nil,
548
550
  strict: nil,
549
551
  timeout: nil,
550
552
  trial: nil,
@@ -559,6 +561,7 @@ module Playwright
559
561
  modifiers: modifiers,
560
562
  noWaitAfter: noWaitAfter,
561
563
  position: position,
564
+ scroll: scroll,
562
565
  strict: strict,
563
566
  timeout: timeout,
564
567
  trial: trial,
@@ -571,6 +574,7 @@ module Playwright
571
574
  target,
572
575
  force: nil,
573
576
  noWaitAfter: nil,
577
+ scroll: nil,
574
578
  sourcePosition: nil,
575
579
  strict: nil,
576
580
  targetPosition: nil,
@@ -583,6 +587,7 @@ module Playwright
583
587
  target,
584
588
  force: force,
585
589
  noWaitAfter: noWaitAfter,
590
+ scroll: scroll,
586
591
  sourcePosition: sourcePosition,
587
592
  strict: strict,
588
593
  targetPosition: targetPosition,
@@ -600,6 +605,7 @@ module Playwright
600
605
  modifiers: nil,
601
606
  noWaitAfter: nil,
602
607
  position: nil,
608
+ scroll: nil,
603
609
  strict: nil,
604
610
  timeout: nil,
605
611
  trial: nil,
@@ -612,6 +618,7 @@ module Playwright
612
618
  modifiers: modifiers,
613
619
  noWaitAfter: noWaitAfter,
614
620
  position: position,
621
+ scroll: scroll,
615
622
  strict: strict,
616
623
  timeout: timeout,
617
624
  trial: trial,
@@ -625,6 +632,7 @@ module Playwright
625
632
  modifiers: nil,
626
633
  noWaitAfter: nil,
627
634
  position: nil,
635
+ scroll: nil,
628
636
  strict: nil,
629
637
  timeout: nil,
630
638
  trial: nil)
@@ -634,6 +642,7 @@ module Playwright
634
642
  modifiers: modifiers,
635
643
  noWaitAfter: noWaitAfter,
636
644
  position: position,
645
+ scroll: scroll,
637
646
  strict: strict,
638
647
  timeout: timeout,
639
648
  trial: trial,
@@ -690,16 +699,12 @@ module Playwright
690
699
  @channel.send_message_to_server('hideHighlight')
691
700
  end
692
701
 
693
- def aria_snapshot(boxes: nil, depth: nil, mode: nil, timeout: nil, _track: nil)
702
+ def aria_snapshot(boxes: nil, depth: nil, mode: nil, timeout: nil)
694
703
  params = { selector: 'body' }
695
704
  params[:timeout] = @timeout_settings.timeout(timeout)
696
705
  params[:boxes] = boxes unless boxes.nil?
697
706
  params[:depth] = depth if depth
698
707
  params[:mode] = mode if mode
699
- if _track
700
- params.delete(:selector)
701
- params[:track] = _track
702
- end
703
708
  result = @main_frame.channel.send_message_to_server_result('ariaSnapshot', params)
704
709
  result['snapshot']
705
710
  end
@@ -748,6 +753,7 @@ module Playwright
748
753
  modifiers: nil,
749
754
  noWaitAfter: nil,
750
755
  position: nil,
756
+ scroll: nil,
751
757
  strict: nil,
752
758
  timeout: nil,
753
759
  trial: nil)
@@ -757,6 +763,7 @@ module Playwright
757
763
  modifiers: modifiers,
758
764
  noWaitAfter: noWaitAfter,
759
765
  position: position,
766
+ scroll: scroll,
760
767
  strict: strict,
761
768
  timeout: timeout,
762
769
  trial: trial,
@@ -838,6 +845,7 @@ module Playwright
838
845
  force: nil,
839
846
  noWaitAfter: nil,
840
847
  position: nil,
848
+ scroll: nil,
841
849
  strict: nil,
842
850
  timeout: nil,
843
851
  trial: nil)
@@ -847,6 +855,7 @@ module Playwright
847
855
  force: force,
848
856
  noWaitAfter: noWaitAfter,
849
857
  position: position,
858
+ scroll: scroll,
850
859
  strict: strict,
851
860
  timeout: timeout,
852
861
  trial: trial)
@@ -857,6 +866,7 @@ module Playwright
857
866
  force: nil,
858
867
  noWaitAfter: nil,
859
868
  position: nil,
869
+ scroll: nil,
860
870
  strict: nil,
861
871
  timeout: nil,
862
872
  trial: nil)
@@ -866,6 +876,7 @@ module Playwright
866
876
  force: force,
867
877
  noWaitAfter: noWaitAfter,
868
878
  position: position,
879
+ scroll: scroll,
869
880
  strict: strict,
870
881
  timeout: timeout,
871
882
  trial: trial)
@@ -962,8 +973,8 @@ module Playwright
962
973
  @main_frame.locator(result['selector'])
963
974
  end
964
975
 
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)
976
+ def snapshot_for_ai(timeout: nil, depth: nil, boxes: nil)
977
+ aria_snapshot(mode: 'ai', timeout: timeout, depth: depth, boxes: boxes)
967
978
  end
968
979
 
969
980
  def _assertions(timeout, is_not, message)
@@ -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
 
@@ -214,7 +214,20 @@ module Playwright
214
214
  end
215
215
  _define_negation :to_have_accessible_error_message
216
216
 
217
- def to_have_attribute(name, value, ignoreCase: nil, timeout: nil)
217
+ def to_have_attribute(name, value: nil, ignoreCase: nil, timeout: nil)
218
+ if value.nil?
219
+ return expect_impl(
220
+ 'to.have.attribute',
221
+ {
222
+ expressionArg: name,
223
+ timeout: timeout,
224
+ },
225
+ nil,
226
+ 'Locator expected to have attribute',
227
+ 'Expect "to_have_attribute"',
228
+ )
229
+ end
230
+
218
231
  expected_text = to_expected_text_values([value], ignore_case: ignoreCase)
219
232
  expect_impl(
220
233
  "to.have.attribute.value",
@@ -105,6 +105,7 @@ module Playwright
105
105
  force: nil,
106
106
  noWaitAfter: nil,
107
107
  position: nil,
108
+ scroll: nil,
108
109
  timeout: nil,
109
110
  trial: nil)
110
111
 
@@ -113,6 +114,7 @@ module Playwright
113
114
  force: force,
114
115
  noWaitAfter: noWaitAfter,
115
116
  position: position,
117
+ scroll: scroll,
116
118
  timeout: timeout,
117
119
  trial: trial)
118
120
  end
@@ -125,6 +127,7 @@ module Playwright
125
127
  modifiers: nil,
126
128
  noWaitAfter: nil,
127
129
  position: nil,
130
+ scroll: nil,
128
131
  timeout: nil,
129
132
  trial: nil,
130
133
  steps: nil)
@@ -138,6 +141,7 @@ module Playwright
138
141
  modifiers: modifiers,
139
142
  noWaitAfter: noWaitAfter,
140
143
  position: position,
144
+ scroll: scroll,
141
145
  timeout: timeout,
142
146
  trial: trial,
143
147
  steps: steps)
@@ -150,6 +154,7 @@ module Playwright
150
154
  modifiers: nil,
151
155
  noWaitAfter: nil,
152
156
  position: nil,
157
+ scroll: nil,
153
158
  timeout: nil,
154
159
  trial: nil,
155
160
  steps: nil)
@@ -162,6 +167,7 @@ module Playwright
162
167
  modifiers: modifiers,
163
168
  noWaitAfter: noWaitAfter,
164
169
  position: position,
170
+ scroll: scroll,
165
171
  timeout: timeout,
166
172
  trial: trial,
167
173
  steps: steps)
@@ -174,6 +180,7 @@ module Playwright
174
180
  def drag_to(target,
175
181
  force: nil,
176
182
  noWaitAfter: nil,
183
+ scroll: nil,
177
184
  sourcePosition: nil,
178
185
  targetPosition: nil,
179
186
  timeout: nil,
@@ -185,6 +192,7 @@ module Playwright
185
192
  target.instance_variable_get(:@selector),
186
193
  force: force,
187
194
  noWaitAfter: noWaitAfter,
195
+ scroll: scroll,
188
196
  sourcePosition: sourcePosition,
189
197
  targetPosition: targetPosition,
190
198
  timeout: timeout,
@@ -363,6 +371,7 @@ module Playwright
363
371
  modifiers: nil,
364
372
  noWaitAfter: nil,
365
373
  position: nil,
374
+ scroll: nil,
366
375
  timeout: nil,
367
376
  trial: nil)
368
377
  @frame.hover(@selector,
@@ -371,6 +380,7 @@ module Playwright
371
380
  modifiers: modifiers,
372
381
  noWaitAfter: noWaitAfter,
373
382
  position: position,
383
+ scroll: scroll,
374
384
  timeout: timeout,
375
385
  trial: trial)
376
386
  end
@@ -426,7 +436,7 @@ module Playwright
426
436
  end
427
437
  end
428
438
 
429
- def aria_snapshot(boxes: nil, depth: nil, mode: nil, timeout: nil, _track: nil)
439
+ def aria_snapshot(boxes: nil, depth: nil, mode: nil, timeout: nil)
430
440
  params = {
431
441
  selector: @selector,
432
442
  timeout: _timeout(timeout),
@@ -434,10 +444,6 @@ module Playwright
434
444
  params[:boxes] = boxes unless boxes.nil?
435
445
  params[:depth] = depth if depth
436
446
  params[:mode] = mode if mode
437
- if _track
438
- params.delete(:selector)
439
- params[:track] = _track
440
- end
441
447
  result = @frame.channel.send_message_to_server_result('ariaSnapshot', params.compact)
442
448
  result['snapshot']
443
449
  end
@@ -499,6 +505,7 @@ module Playwright
499
505
  modifiers: nil,
500
506
  noWaitAfter: nil,
501
507
  position: nil,
508
+ scroll: nil,
502
509
  timeout: nil,
503
510
  trial: nil)
504
511
  @frame.tap_point(@selector,
@@ -507,6 +514,7 @@ module Playwright
507
514
  modifiers: modifiers,
508
515
  noWaitAfter: noWaitAfter,
509
516
  position: position,
517
+ scroll: scroll,
510
518
  timeout: timeout,
511
519
  trial: trial)
512
520
  end
@@ -527,6 +535,7 @@ module Playwright
527
535
  force: nil,
528
536
  noWaitAfter: nil,
529
537
  position: nil,
538
+ scroll: nil,
530
539
  timeout: nil,
531
540
  trial: nil)
532
541
  @frame.uncheck(@selector,
@@ -534,10 +543,24 @@ module Playwright
534
543
  force: force,
535
544
  noWaitAfter: noWaitAfter,
536
545
  position: position,
546
+ scroll: scroll,
537
547
  timeout: timeout,
538
548
  trial: trial)
539
549
  end
540
550
 
551
+ def wait_for_function(expression, arg: nil, timeout: nil)
552
+ @frame.channel.send_message_to_server(
553
+ 'waitForFunction',
554
+ selector: @selector,
555
+ strict: true,
556
+ expression: expression,
557
+ isFunction: true,
558
+ arg: JavaScript::ValueSerializer.new(arg).serialize,
559
+ timeout: _timeout(timeout),
560
+ )
561
+ nil
562
+ end
563
+
541
564
  def wait_for(state: nil, timeout: nil)
542
565
  @frame.wait_for_selector(@selector, strict: true, state: state, timeout: timeout)
543
566
  end
@@ -86,12 +86,26 @@ module Playwright
86
86
  end
87
87
 
88
88
  private def handle_screencast_frame(event)
89
- @on_frame&.call({
90
- data: Base64.strict_decode64(event['data']),
91
- timestamp: event['timestamp'],
92
- viewportWidth: event['viewportWidth'],
93
- viewportHeight: event['viewportHeight'],
94
- })
89
+ on_frame = @on_frame
90
+ Thread.new do
91
+ begin
92
+ on_frame&.call({
93
+ data: Base64.strict_decode64(event['data']),
94
+ timestamp: event['timestamp'],
95
+ viewportWidth: event['viewportWidth'],
96
+ viewportHeight: event['viewportHeight'],
97
+ })
98
+ ensure
99
+ begin
100
+ @page.send(:channel).async_send_message_to_server(
101
+ 'screencastFrameAck',
102
+ frameId: event['frameId'],
103
+ )
104
+ rescue Transport::AlreadyDisconnectedError
105
+ # The page or driver may close while a callback is running.
106
+ end
107
+ end
108
+ end
95
109
  end
96
110
  end
97
111
  end
@@ -0,0 +1,24 @@
1
+ require 'mime/types'
2
+
3
+ module Playwright
4
+ module ScreenshotUtils
5
+ module_function
6
+
7
+ def determine_type(path:, type:)
8
+ return type if type
9
+ return nil unless path
10
+
11
+ mime_type = MIME::Types.type_for(path).first
12
+ case mime_type&.content_type
13
+ when 'image/png'
14
+ 'png'
15
+ when 'image/jpeg'
16
+ 'jpeg'
17
+ when 'image/webp'
18
+ 'webp'
19
+ else
20
+ raise ArgumentError.new("path: unsupported mime type \"#{mime_type}\"")
21
+ end
22
+ end
23
+ end
24
+ end
@@ -30,7 +30,7 @@ module Playwright
30
30
  end
31
31
 
32
32
  def matches?(actual)
33
- assertions_for(actual, false).send(@method, *@args, **@kwargs)
33
+ call_assertion(actual, false)
34
34
  true
35
35
  rescue AssertionError => e
36
36
  @failure_message = e.full_message
@@ -38,7 +38,7 @@ module Playwright
38
38
  end
39
39
 
40
40
  def does_not_match?(actual)
41
- assertions_for(actual, true).send(@method, *@args, **@kwargs)
41
+ call_assertion(actual, true)
42
42
  true
43
43
  rescue AssertionError => e
44
44
  @failure_message = e.full_message
@@ -55,6 +55,16 @@ module Playwright
55
55
 
56
56
  private
57
57
 
58
+ def call_assertion(actual, is_not)
59
+ args = @args
60
+ kwargs = @kwargs
61
+ if ['to_have_attribute', 'not_to_have_attribute'].include?(@method) && args.length == 2 && !kwargs.key?(:value)
62
+ args = [args.first]
63
+ kwargs = kwargs.merge(value: @args.last)
64
+ end
65
+ assertions_for(actual, is_not).send(@method, *args, **kwargs)
66
+ end
67
+
58
68
  def assertions_for(actual, is_not)
59
69
  if actual.respond_to?(:_assertions)
60
70
  actual._assertions(::Playwright::Test.expect_timeout, is_not, nil)