playwright-ruby-client 1.51.0 → 1.56.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 (78) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +5 -0
  3. data/README.md +4 -0
  4. data/documentation/docs/api/browser_context.md +7 -3
  5. data/documentation/docs/api/console_message.md +0 -3
  6. data/documentation/docs/api/experimental/android.md +10 -0
  7. data/documentation/docs/api/frame.md +1 -0
  8. data/documentation/docs/api/frame_locator.md +1 -0
  9. data/documentation/docs/api/locator.md +24 -0
  10. data/documentation/docs/api/locator_assertions.md +47 -1
  11. data/documentation/docs/api/mouse.md +2 -0
  12. data/documentation/docs/api/page.md +34 -2
  13. data/documentation/docs/api/route.md +2 -0
  14. data/documentation/docs/api/selectors.md +10 -0
  15. data/documentation/docs/api/tracing.md +8 -0
  16. data/documentation/docs/article/guides/inspector.md +1 -1
  17. data/documentation/docs/article/guides/playwright_on_alpine_linux.md +9 -69
  18. data/documentation/docs/include/api_coverage.md +8 -2
  19. data/documentation/package.json +3 -3
  20. data/documentation/yarn.lock +12372 -8623
  21. data/lib/playwright/channel.rb +6 -3
  22. data/lib/playwright/channel_owners/android.rb +12 -0
  23. data/lib/playwright/channel_owners/android_device.rb +6 -5
  24. data/lib/playwright/channel_owners/api_request_context.rb +6 -1
  25. data/lib/playwright/channel_owners/browser.rb +37 -6
  26. data/lib/playwright/channel_owners/browser_context.rb +47 -38
  27. data/lib/playwright/channel_owners/browser_type.rb +43 -14
  28. data/lib/playwright/channel_owners/element_handle.rb +22 -17
  29. data/lib/playwright/channel_owners/frame.rb +65 -34
  30. data/lib/playwright/channel_owners/page.rb +39 -9
  31. data/lib/playwright/channel_owners/playwright.rb +10 -4
  32. data/lib/playwright/channel_owners/web_socket.rb +1 -1
  33. data/lib/playwright/connection.rb +3 -0
  34. data/lib/playwright/console_message_impl.rb +3 -2
  35. data/lib/playwright/file_chooser_impl.rb +3 -2
  36. data/lib/playwright/frame_locator_impl.rb +5 -8
  37. data/lib/playwright/javascript/value_parser.rb +54 -2
  38. data/lib/playwright/locator_assertions_impl.rb +100 -34
  39. data/lib/playwright/locator_impl.rb +26 -36
  40. data/lib/playwright/page_assertions_impl.rb +16 -11
  41. data/lib/playwright/selectors_impl.rb +45 -0
  42. data/lib/playwright/test.rb +21 -3
  43. data/lib/playwright/timeout_settings.rb +5 -0
  44. data/lib/playwright/transport.rb +1 -1
  45. data/lib/playwright/utils.rb +0 -33
  46. data/lib/playwright/version.rb +2 -2
  47. data/lib/playwright/web_socket_client.rb +4 -1
  48. data/lib/playwright/web_socket_transport.rb +3 -1
  49. data/lib/playwright.rb +14 -14
  50. data/lib/playwright_api/android.rb +12 -7
  51. data/lib/playwright_api/android_device.rb +8 -8
  52. data/lib/playwright_api/api_request.rb +1 -0
  53. data/lib/playwright_api/api_request_context.rb +6 -6
  54. data/lib/playwright_api/browser.rb +6 -6
  55. data/lib/playwright_api/browser_context.rb +17 -17
  56. data/lib/playwright_api/browser_type.rb +6 -6
  57. data/lib/playwright_api/cdp_session.rb +6 -6
  58. data/lib/playwright_api/console_message.rb +0 -4
  59. data/lib/playwright_api/dialog.rb +6 -6
  60. data/lib/playwright_api/element_handle.rb +6 -6
  61. data/lib/playwright_api/frame.rb +12 -6
  62. data/lib/playwright_api/frame_locator.rb +1 -0
  63. data/lib/playwright_api/js_handle.rb +6 -6
  64. data/lib/playwright_api/locator.rb +30 -3
  65. data/lib/playwright_api/locator_assertions.rb +47 -3
  66. data/lib/playwright_api/mouse.rb +2 -0
  67. data/lib/playwright_api/page.rb +41 -13
  68. data/lib/playwright_api/playwright.rb +6 -6
  69. data/lib/playwright_api/request.rb +6 -6
  70. data/lib/playwright_api/response.rb +6 -6
  71. data/lib/playwright_api/route.rb +8 -6
  72. data/lib/playwright_api/selectors.rb +1 -28
  73. data/lib/playwright_api/tracing.rb +14 -6
  74. data/lib/playwright_api/web_socket.rb +6 -6
  75. data/lib/playwright_api/worker.rb +8 -8
  76. data/sig/playwright.rbs +15 -1
  77. metadata +6 -5
  78. data/lib/playwright/channel_owners/selectors.rb +0 -26
@@ -26,6 +26,14 @@ module Playwright
26
26
  attr_reader :page, :parent_frame
27
27
  attr_writer :detached
28
28
 
29
+ private def _timeout(timeout)
30
+ @page.send(:_timeout_settings).timeout(timeout)
31
+ end
32
+
33
+ private def _navigation_timeout(timeout)
34
+ @page.send(:_timeout_settings).navigation_timeout(timeout)
35
+ end
36
+
29
37
  private def on_load_state(add:, remove:)
30
38
  if add
31
39
  @load_states << add
@@ -63,7 +71,7 @@ module Playwright
63
71
  def goto(url, timeout: nil, waitUntil: nil, referer: nil)
64
72
  params = {
65
73
  url: url,
66
- timeout: timeout,
74
+ timeout: _navigation_timeout(timeout),
67
75
  waitUntil: waitUntil,
68
76
  referer: referer
69
77
  }.compact
@@ -94,7 +102,7 @@ module Playwright
94
102
 
95
103
  def expect_navigation(timeout: nil, url: nil, waitUntil: nil, &block)
96
104
  option_wait_until = waitUntil || 'load'
97
- option_timeout = timeout || @page.send(:timeout_settings).navigation_timeout
105
+ option_timeout = _navigation_timeout(timeout)
98
106
  time_start = Time.now
99
107
 
100
108
  waiter = setup_navigation_waiter(wait_name: :expect_navigation, timeout_value: option_timeout)
@@ -148,7 +156,7 @@ module Playwright
148
156
 
149
157
  def wait_for_load_state(state: nil, timeout: nil)
150
158
  option_state = state || 'load'
151
- option_timeout = timeout || @page.send(:timeout_settings).navigation_timeout
159
+ option_timeout = _navigation_timeout(timeout)
152
160
  unless %w(load domcontentloaded networkidle commit).include?(option_state)
153
161
  raise ArgumentError.new('state: expected one of (load|domcontentloaded|networkidle|commit)')
154
162
  end
@@ -204,39 +212,39 @@ module Playwright
204
212
  end
205
213
 
206
214
  def wait_for_selector(selector, state: nil, strict: nil, timeout: nil)
207
- params = { selector: selector, state: state, strict: strict, timeout: timeout }.compact
215
+ params = { selector: selector, state: state, strict: strict, timeout: _timeout(timeout) }.compact
208
216
  resp = @channel.send_message_to_server('waitForSelector', params)
209
217
 
210
218
  ChannelOwners::ElementHandle.from_nullable(resp)
211
219
  end
212
220
 
213
221
  def checked?(selector, strict: nil, timeout: nil)
214
- params = { selector: selector, strict: strict, timeout: timeout }.compact
222
+ params = { selector: selector, strict: strict, timeout: _timeout(timeout) }.compact
215
223
  @channel.send_message_to_server('isChecked', params)
216
224
  end
217
225
 
218
226
  def disabled?(selector, strict: nil, timeout: nil)
219
- params = { selector: selector, strict: strict, timeout: timeout }.compact
227
+ params = { selector: selector, strict: strict, timeout: _timeout(timeout) }.compact
220
228
  @channel.send_message_to_server('isDisabled', params)
221
229
  end
222
230
 
223
231
  def editable?(selector, strict: nil, timeout: nil)
224
- params = { selector: selector, strict: strict, timeout: timeout }.compact
232
+ params = { selector: selector, strict: strict, timeout: _timeout(timeout) }.compact
225
233
  @channel.send_message_to_server('isEditable', params)
226
234
  end
227
235
 
228
236
  def enabled?(selector, strict: nil, timeout: nil)
229
- params = { selector: selector, strict: strict, timeout: timeout }.compact
237
+ params = { selector: selector, strict: strict, timeout: _timeout(timeout) }.compact
230
238
  @channel.send_message_to_server('isEnabled', params)
231
239
  end
232
240
 
233
241
  def hidden?(selector, strict: nil, timeout: nil)
234
- params = { selector: selector, strict: strict, timeout: timeout }.compact
242
+ params = { selector: selector, strict: strict, timeout: _timeout(timeout) }.compact
235
243
  @channel.send_message_to_server('isHidden', params)
236
244
  end
237
245
 
238
246
  def visible?(selector, strict: nil, timeout: nil)
239
- params = { selector: selector, strict: strict, timeout: timeout }.compact
247
+ params = { selector: selector, strict: strict, timeout: _timeout(timeout) }.compact
240
248
  @channel.send_message_to_server('isVisible', params)
241
249
  end
242
250
 
@@ -246,7 +254,7 @@ module Playwright
246
254
  type: type,
247
255
  eventInit: JavaScript::ValueSerializer.new(eventInit).serialize,
248
256
  strict: strict,
249
- timeout: timeout,
257
+ timeout: _timeout(timeout),
250
258
  }.compact
251
259
  @channel.send_message_to_server('dispatchEvent', params)
252
260
 
@@ -268,7 +276,7 @@ module Playwright
268
276
  def set_content(html, timeout: nil, waitUntil: nil)
269
277
  params = {
270
278
  html: html,
271
- timeout: timeout,
279
+ timeout: _navigation_timeout(timeout),
272
280
  waitUntil: waitUntil,
273
281
  }.compact
274
282
 
@@ -341,7 +349,7 @@ module Playwright
341
349
  noWaitAfter: noWaitAfter,
342
350
  position: position,
343
351
  strict: strict,
344
- timeout: timeout,
352
+ timeout: _timeout(timeout),
345
353
  trial: trial,
346
354
  }.compact
347
355
  @channel.send_message_to_server('click', params)
@@ -368,7 +376,7 @@ module Playwright
368
376
  sourcePosition: sourcePosition,
369
377
  strict: strict,
370
378
  targetPosition: targetPosition,
371
- timeout: timeout,
379
+ timeout: _timeout(timeout),
372
380
  trial: trial,
373
381
  }.compact
374
382
  @channel.send_message_to_server('dragAndDrop', params)
@@ -397,7 +405,7 @@ module Playwright
397
405
  noWaitAfter: noWaitAfter,
398
406
  position: position,
399
407
  strict: strict,
400
- timeout: timeout,
408
+ timeout: _timeout(timeout),
401
409
  trial: trial,
402
410
  }.compact
403
411
  @channel.send_message_to_server('dblclick', params)
@@ -421,7 +429,7 @@ module Playwright
421
429
  noWaitAfter: noWaitAfter,
422
430
  position: position,
423
431
  strict: strict,
424
- timeout: timeout,
432
+ timeout: _timeout(timeout),
425
433
  trial: trial,
426
434
  }.compact
427
435
  @channel.send_message_to_server('tap', params)
@@ -442,7 +450,7 @@ module Playwright
442
450
  force: force,
443
451
  noWaitAfter: noWaitAfter,
444
452
  strict: strict,
445
- timeout: timeout,
453
+ timeout: _timeout(timeout),
446
454
  }.compact
447
455
  @channel.send_message_to_server('fill', params)
448
456
 
@@ -457,7 +465,6 @@ module Playwright
457
465
  hasText: nil)
458
466
  LocatorImpl.new(
459
467
  frame: self,
460
- timeout_settings: @page.send(:timeout_settings),
461
468
  selector: selector,
462
469
  has: has,
463
470
  hasNot: hasNot,
@@ -466,27 +473,27 @@ module Playwright
466
473
  end
467
474
 
468
475
  def frame_locator(selector)
469
- FrameLocatorImpl.new(frame: self, timeout_settings: @page.send(:timeout_settings), frame_selector: selector)
476
+ FrameLocatorImpl.new(frame: self, frame_selector: selector)
470
477
  end
471
478
 
472
479
  def focus(selector, strict: nil, timeout: nil)
473
- params = { selector: selector, strict: strict, timeout: timeout }.compact
480
+ params = { selector: selector, strict: strict, timeout: _timeout(timeout) }.compact
474
481
  @channel.send_message_to_server('focus', params)
475
482
  nil
476
483
  end
477
484
 
478
485
  def text_content(selector, strict: nil, timeout: nil)
479
- params = { selector: selector, strict: strict, timeout: timeout }.compact
486
+ params = { selector: selector, strict: strict, timeout: _timeout(timeout) }.compact
480
487
  @channel.send_message_to_server('textContent', params)
481
488
  end
482
489
 
483
490
  def inner_text(selector, strict: nil, timeout: nil)
484
- params = { selector: selector, strict: strict, timeout: timeout }.compact
491
+ params = { selector: selector, strict: strict, timeout: _timeout(timeout) }.compact
485
492
  @channel.send_message_to_server('innerText', params)
486
493
  end
487
494
 
488
495
  def inner_html(selector, strict: nil, timeout: nil)
489
- params = { selector: selector, strict: strict, timeout: timeout }.compact
496
+ params = { selector: selector, strict: strict, timeout: _timeout(timeout) }.compact
490
497
  @channel.send_message_to_server('innerHTML', params)
491
498
  end
492
499
 
@@ -495,7 +502,7 @@ module Playwright
495
502
  selector: selector,
496
503
  name: name,
497
504
  strict: strict,
498
- timeout: timeout,
505
+ timeout: _timeout(timeout),
499
506
  }.compact
500
507
  @channel.send_message_to_server('getAttribute', params)
501
508
  end
@@ -516,7 +523,7 @@ module Playwright
516
523
  noWaitAfter: noWaitAfter,
517
524
  position: position,
518
525
  strict: strict,
519
- timeout: timeout,
526
+ timeout: _timeout(timeout),
520
527
  trial: trial,
521
528
  }.compact
522
529
  @channel.send_message_to_server('hover', params)
@@ -540,12 +547,12 @@ module Playwright
540
547
  value: value,
541
548
  label: label,
542
549
  ).as_params
543
- params = base_params.merge({ selector: selector, force: force, noWaitAfter: noWaitAfter, strict: strict, timeout: timeout }.compact)
550
+ params = base_params.merge({ selector: selector, force: force, noWaitAfter: noWaitAfter, strict: strict, timeout: _timeout(timeout) }.compact)
544
551
  @channel.send_message_to_server('selectOption', params)
545
552
  end
546
553
 
547
554
  def input_value(selector, strict: nil, timeout: nil)
548
- params = { selector: selector, strict: strict, timeout: timeout }.compact
555
+ params = { selector: selector, strict: strict, timeout: _timeout(timeout) }.compact
549
556
  @channel.send_message_to_server('inputValue', params)
550
557
  end
551
558
 
@@ -555,7 +562,7 @@ module Playwright
555
562
  selector: selector,
556
563
  noWaitAfter: noWaitAfter,
557
564
  strict: strict,
558
- timeout: timeout,
565
+ timeout: _timeout(timeout),
559
566
  }.compact)
560
567
  @channel.send_message_to_server(method_name, params)
561
568
 
@@ -576,7 +583,7 @@ module Playwright
576
583
  delay: delay,
577
584
  noWaitAfter: noWaitAfter,
578
585
  strict: strict,
579
- timeout: timeout,
586
+ timeout: _timeout(timeout),
580
587
  }.compact
581
588
  @channel.send_message_to_server('type', params)
582
589
 
@@ -597,7 +604,7 @@ module Playwright
597
604
  delay: delay,
598
605
  noWaitAfter: noWaitAfter,
599
606
  strict: strict,
600
- timeout: timeout,
607
+ timeout: _timeout(timeout),
601
608
  }.compact
602
609
  @channel.send_message_to_server('press', params)
603
610
 
@@ -619,7 +626,7 @@ module Playwright
619
626
  noWaitAfter: noWaitAfter,
620
627
  position: position,
621
628
  strict: strict,
622
- timeout: timeout,
629
+ timeout: _timeout(timeout),
623
630
  trial: trial,
624
631
  }.compact
625
632
  @channel.send_message_to_server('check', params)
@@ -642,7 +649,7 @@ module Playwright
642
649
  noWaitAfter: noWaitAfter,
643
650
  position: position,
644
651
  strict: strict,
645
- timeout: timeout,
652
+ timeout: _timeout(timeout),
646
653
  trial: trial,
647
654
  }.compact
648
655
  @channel.send_message_to_server('uncheck', params)
@@ -659,7 +666,7 @@ module Playwright
659
666
  end
660
667
 
661
668
  def wait_for_timeout(timeout)
662
- @channel.send_message_to_server('waitForTimeout', timeout: timeout)
669
+ @channel.send_message_to_server('waitForTimeout', waitTimeout: timeout)
663
670
 
664
671
  nil
665
672
  end
@@ -670,7 +677,7 @@ module Playwright
670
677
  end
671
678
 
672
679
  expression = JavaScript::Expression.new(pageFunction, arg)
673
- expression.wait_for_function(@channel, polling: polling, timeout: timeout)
680
+ expression.wait_for_function(@channel, polling: polling, timeout: _timeout(timeout))
674
681
  end
675
682
 
676
683
  def title
@@ -681,6 +688,30 @@ module Playwright
681
688
  @channel.send_message_to_server('highlight', selector: selector)
682
689
  end
683
690
 
691
+ def expect(selector, expression, options, title)
692
+ if options.key?(:expectedValue)
693
+ options[:expectedValue] = JavaScript::ValueSerializer
694
+ .new(options[:expectedValue])
695
+ .serialize
696
+ end
697
+
698
+ result = @channel.send_message_to_server_result(
699
+ title, # title
700
+ "expect", # method
701
+ { # params
702
+ selector: selector,
703
+ expression: expression,
704
+ **options,
705
+ }.compact
706
+ )
707
+
708
+ if result.key?('received')
709
+ result['received'] = JavaScript::ValueParser.new(result['received']).parse
710
+ end
711
+
712
+ result
713
+ end
714
+
684
715
  # @param page [Page]
685
716
  # @note This method should be used internally. Accessed via .send method, so keep private!
686
717
  private def update_page_from_page(page)
@@ -42,6 +42,7 @@ module Playwright
42
42
  @channel.on('fileChooser', ->(params) {
43
43
  chooser = FileChooserImpl.new(
44
44
  page: self,
45
+ timeout_settings: @timeout_settings,
45
46
  element_handle: ChannelOwners::ElementHandle.from(params['element']),
46
47
  is_multiple: params['isMultiple'])
47
48
  emit(Events::Page::FileChooser, chooser)
@@ -57,6 +58,7 @@ module Playwright
57
58
  })
58
59
  @channel.on('route', ->(params) { on_route(ChannelOwners::Route.from(params['route'])) })
59
60
  @channel.on('video', method(:on_video))
61
+ @channel.on('viewportSizeChanged', method(:on_viewport_size_changed))
60
62
  @channel.on('webSocket', ->(params) {
61
63
  emit(Events::Page::WebSocket, ChannelOwners::WebSocket.from(params['webSocket']))
62
64
  })
@@ -147,7 +149,6 @@ module Playwright
147
149
  private def on_close
148
150
  @closed = true
149
151
  @browser_context.send(:remove_page, self)
150
- @browser_context.send(:remove_background_page, self)
151
152
  if @closed_or_crashed_promise.pending?
152
153
  @closed_or_crashed_promise.fulfill(close_error_with_reason)
153
154
  end
@@ -177,6 +178,13 @@ module Playwright
177
178
  video.send(:set_artifact, artifact)
178
179
  end
179
180
 
181
+ private def on_viewport_size_changed(params)
182
+ @viewport_size = {
183
+ width: params['viewportSize']['width'],
184
+ height: params['viewportSize']['height'],
185
+ }
186
+ end
187
+
180
188
  # @override
181
189
  private def perform_event_emitter_callback(event, callback, args)
182
190
  should_callback_async = [
@@ -230,12 +238,10 @@ module Playwright
230
238
 
231
239
  def set_default_navigation_timeout(timeout)
232
240
  @timeout_settings.default_navigation_timeout = timeout
233
- @channel.send_message_to_server('setDefaultNavigationTimeoutNoReply', timeout: timeout)
234
241
  end
235
242
 
236
243
  def set_default_timeout(timeout)
237
244
  @timeout_settings.default_timeout = timeout
238
- @channel.send_message_to_server('setDefaultTimeoutNoReply', timeout: timeout)
239
245
  end
240
246
 
241
247
  def query_selector(selector, strict: nil)
@@ -339,7 +345,7 @@ module Playwright
339
345
 
340
346
  def reload(timeout: nil, waitUntil: nil)
341
347
  params = {
342
- timeout: timeout,
348
+ timeout: @timeout_settings.timeout(timeout),
343
349
  waitUntil: waitUntil,
344
350
  }.compact
345
351
  resp = @channel.send_message_to_server('reload', params)
@@ -355,13 +361,13 @@ module Playwright
355
361
  end
356
362
 
357
363
  def go_back(timeout: nil, waitUntil: nil)
358
- params = { timeout: timeout, waitUntil: waitUntil }.compact
364
+ params = { timeout: @timeout_settings.timeout(timeout), waitUntil: waitUntil }.compact
359
365
  resp = @channel.send_message_to_server('goBack', params)
360
366
  ChannelOwners::Response.from_nullable(resp)
361
367
  end
362
368
 
363
369
  def go_forward(timeout: nil, waitUntil: nil)
364
- params = { timeout: timeout, waitUntil: waitUntil }.compact
370
+ params = { timeout: @timeout_settings.timeout(timeout), waitUntil: waitUntil }.compact
365
371
  resp = @channel.send_message_to_server('goForward', params)
366
372
  ChannelOwners::Response.from_nullable(resp)
367
373
  end
@@ -432,7 +438,7 @@ module Playwright
432
438
 
433
439
  def route_from_har(har, notFound: nil, update: nil, url: nil, updateContent: nil, updateMode: nil)
434
440
  if update
435
- @browser_context.send(:record_into_har, har, self, notFound: notFound, url: url, updateContent: updateContent, updateMode: updateMode)
441
+ @browser_context.send(:record_into_har, har, self, url: url, update_content: updateContent, update_mode: updateMode)
436
442
  return
437
443
  end
438
444
 
@@ -481,7 +487,7 @@ module Playwright
481
487
  caret: caret,
482
488
  scale: scale,
483
489
  style: style,
484
- timeout: timeout,
490
+ timeout: @timeout_settings.timeout(timeout),
485
491
  }.compact
486
492
  if mask.is_a?(Enumerable)
487
493
  params[:mask] = mask.map do |locator|
@@ -632,6 +638,20 @@ module Playwright
632
638
  timeout: timeout)
633
639
  end
634
640
 
641
+ def console_messages
642
+ messages = @channel.send_message_to_server('consoleMessages')
643
+ messages.map do |message|
644
+ ConsoleMessageImpl.new(message, self)
645
+ end
646
+ end
647
+
648
+ def page_errors
649
+ errors = @channel.send_message_to_server('pageErrors')
650
+ errors.map do |error|
651
+ Error.parse(error['error'])
652
+ end
653
+ end
654
+
635
655
  def locator(
636
656
  selector,
637
657
  has: nil,
@@ -819,6 +839,12 @@ module Playwright
819
839
  @workers.to_a
820
840
  end
821
841
 
842
+ def requests
843
+ @channel.send_message_to_server('requests').map do |req|
844
+ ChannelOwners::Request.from(req)
845
+ end
846
+ end
847
+
822
848
  def request
823
849
  @browser_context.request
824
850
  end
@@ -875,6 +901,10 @@ module Playwright
875
901
  @video ||= Video.new(self)
876
902
  end
877
903
 
904
+ def snapshot_for_ai(timeout: nil)
905
+ @channel.send_message_to_server('snapshotForAI', timeout: @timeout_settings.timeout(timeout))
906
+ end
907
+
878
908
  def start_js_coverage(resetOnNavigation: nil, reportAnonymousScripts: nil)
879
909
  params = {
880
910
  resetOnNavigation: resetOnNavigation,
@@ -1003,7 +1033,7 @@ module Playwright
1003
1033
  end
1004
1034
 
1005
1035
  # called from Frame with send(:timeout_settings)
1006
- private def timeout_settings
1036
+ private def _timeout_settings
1007
1037
  @timeout_settings
1008
1038
  end
1009
1039
 
@@ -1,15 +1,21 @@
1
1
  module Playwright
2
2
  define_channel_owner :Playwright do
3
3
  def chromium
4
- @chromium ||= ::Playwright::ChannelOwners::BrowserType.from(@initializer['chromium'])
4
+ @chromium ||= ::Playwright::ChannelOwners::BrowserType.from(@initializer['chromium']).tap do |browser_type|
5
+ browser_type.send(:update_playwright, self)
6
+ end
5
7
  end
6
8
 
7
9
  def firefox
8
- @firefox ||= ::Playwright::ChannelOwners::BrowserType.from(@initializer['firefox'])
10
+ @firefox ||= ::Playwright::ChannelOwners::BrowserType.from(@initializer['firefox']).tap do |browser_type|
11
+ browser_type.send(:update_playwright, self)
12
+ end
9
13
  end
10
14
 
11
15
  def webkit
12
- @webkit ||= ::Playwright::ChannelOwners::BrowserType.from(@initializer['webkit'])
16
+ @webkit ||= ::Playwright::ChannelOwners::BrowserType.from(@initializer['webkit']).tap do |browser_type|
17
+ browser_type.send(:update_playwright, self)
18
+ end
13
19
  end
14
20
 
15
21
  def android
@@ -21,7 +27,7 @@ module Playwright
21
27
  end
22
28
 
23
29
  def selectors
24
- @selectors ||= ::Playwright::ChannelOwners::Selectors.from(@initializer['selectors'])
30
+ @selectors ||= ::Playwright::SelectorsImpl.new
25
31
  end
26
32
 
27
33
  def devices
@@ -35,7 +35,7 @@ module Playwright
35
35
 
36
36
  def expect_event(event, predicate: nil, timeout: nil, &block)
37
37
  waiter = Waiter.new(self, wait_name: "WebSocket.expect_event(#{event})")
38
- timeout_value = timeout || @parent.send(:timeout_settings).timeout
38
+ timeout_value = timeout || @parent.send(:_timeout_settings).timeout
39
39
  waiter.reject_on_timeout(timeout_value, "Timeout #{timeout_value}ms exceeded while waiting for event \"#{event}\"")
40
40
 
41
41
  unless event == Events::WebSocket::Close
@@ -90,6 +90,9 @@ module Playwright
90
90
  _metadata[:apiName] = metadata[:apiName]
91
91
  _metadata[:location] = metadata[:stack].first
92
92
  _metadata[:internal] = !metadata[:apiName]
93
+ if metadata[:title]
94
+ _metadata[:title] = metadata[:title]
95
+ end
93
96
  end
94
97
  _metadata.compact!
95
98
 
@@ -1,11 +1,12 @@
1
1
  module Playwright
2
2
  define_api_implementation :ConsoleMessageImpl do
3
- def initialize(event)
3
+ def initialize(event, page)
4
4
  @event = event
5
+ @page = page
5
6
  end
6
7
 
7
8
  def page
8
- @page ||= ChannelOwners::Page.from_nullable(@event['page'])
9
+ @page
9
10
  end
10
11
 
11
12
  def type
@@ -1,7 +1,8 @@
1
1
  module Playwright
2
2
  define_api_implementation :FileChooserImpl do
3
- def initialize(page:, element_handle:, is_multiple:)
3
+ def initialize(page:, timeout_settings:, element_handle:, is_multiple:)
4
4
  @page = page
5
+ @timeout_settings = timeout_settings
5
6
  @element_handle = element_handle
6
7
  @is_multiple = is_multiple
7
8
  end
@@ -17,7 +18,7 @@ module Playwright
17
18
  end
18
19
 
19
20
  def set_files(files, noWaitAfter: nil, timeout: nil)
20
- @element_handle.set_input_files(files, noWaitAfter: noWaitAfter, timeout: timeout)
21
+ @element_handle.set_input_files(files, noWaitAfter: noWaitAfter, timeout: @timeout_settings.timeout(timeout))
21
22
  end
22
23
  end
23
24
  end
@@ -4,12 +4,15 @@ module Playwright
4
4
  define_api_implementation :FrameLocatorImpl do
5
5
  include LocatorUtils
6
6
 
7
- def initialize(frame:, timeout_settings:, frame_selector:)
7
+ def initialize(frame:, frame_selector:)
8
8
  @frame = frame
9
- @timeout_settings = timeout_settings
10
9
  @frame_selector = frame_selector
11
10
  end
12
11
 
12
+ private def _timeout(timeout)
13
+ @frame.send(:_timeout, timeout)
14
+ end
15
+
13
16
  def locator(
14
17
  selector,
15
18
  has: nil,
@@ -18,7 +21,6 @@ module Playwright
18
21
  hasText: nil)
19
22
  LocatorImpl.new(
20
23
  frame: @frame,
21
- timeout_settings: @timeout_settings,
22
24
  selector: "#{@frame_selector} >> internal:control=enter-frame >> #{selector}",
23
25
  has: has,
24
26
  hasNot: hasNot,
@@ -29,7 +31,6 @@ module Playwright
29
31
  def owner
30
32
  LocatorImpl.new(
31
33
  frame: @frame,
32
- timeout_settings: @timeout_settings,
33
34
  selector: @frame_selector,
34
35
  )
35
36
  end
@@ -37,7 +38,6 @@ module Playwright
37
38
  def frame_locator(selector)
38
39
  FrameLocatorImpl.new(
39
40
  frame: @frame,
40
- timeout_settings: @timeout_settings,
41
41
  frame_selector: "#{@frame_selector} >> internal:control=enter-frame >> #{selector}",
42
42
  )
43
43
  end
@@ -45,7 +45,6 @@ module Playwright
45
45
  def first
46
46
  FrameLocatorImpl.new(
47
47
  frame: @frame,
48
- timeout_settings: @timeout_settings,
49
48
  frame_selector: "#{@frame_selector} >> nth=0",
50
49
  )
51
50
  end
@@ -53,7 +52,6 @@ module Playwright
53
52
  def last
54
53
  FrameLocatorImpl.new(
55
54
  frame: @frame,
56
- timeout_settings: @timeout_settings,
57
55
  frame_selector: "#{@frame_selector} >> nth=-1",
58
56
  )
59
57
  end
@@ -61,7 +59,6 @@ module Playwright
61
59
  def nth(index)
62
60
  FrameLocatorImpl.new(
63
61
  frame: @frame,
64
- timeout_settings: @timeout_settings,
65
62
  frame_selector: "#{@frame_selector} >> nth=#{index}",
66
63
  )
67
64
  end
@@ -1,4 +1,5 @@
1
- require 'date'
1
+ require 'base64'
2
+ require 'time'
2
3
 
3
4
  module Playwright
4
5
  module JavaScript
@@ -45,7 +46,7 @@ module Playwright
45
46
  end
46
47
 
47
48
  if hash.key?('d')
48
- return DateTime.parse(hash['d'])
49
+ return Time.parse(hash['d'])
49
50
  end
50
51
 
51
52
  if hash.key?('u')
@@ -105,6 +106,57 @@ module Playwright
105
106
  return @handles[hash['h']]
106
107
  end
107
108
 
109
+ if hash.key?('ta')
110
+ encoded_bytes = hash['ta']['b']
111
+ decoded_bytes = Base64.strict_decode64(encoded_bytes)
112
+ array_type = hash['ta']['k']
113
+
114
+ if array_type == 'i8'
115
+ word_size = 1
116
+ unpack_format = 'c*' # signed char
117
+ elsif array_type == 'ui8' || array_type == 'ui8c'
118
+ word_size = 1
119
+ unpack_format = 'C*' # unsigned char
120
+ elsif array_type == 'i16'
121
+ word_size = 2
122
+ unpack_format = 's<*' # signed short, little-endian
123
+ elsif array_type == 'ui16'
124
+ word_size = 2
125
+ unpack_format = 'S<*' # unsigned short, little-endian
126
+ elsif array_type == 'i32'
127
+ word_size = 4
128
+ unpack_format = 'l<*' # signed long, little-endian
129
+ elsif array_type == 'ui32'
130
+ word_size = 4
131
+ unpack_format = 'L<*' # unsigned long, little-endian
132
+ elsif array_type == 'f32'
133
+ word_size = 4
134
+ unpack_format = 'e*' # float, little-endian
135
+ elsif array_type == 'f64'
136
+ word_size = 8
137
+ unpack_format = 'E*' # double, little-endian
138
+ elsif array_type == 'bi64'
139
+ word_size = 8
140
+ unpack_format = 'q<*' # signed long long, little-endian
141
+ elsif array_type == 'bui64'
142
+ word_size = 8
143
+ unpack_format = 'Q<*' # unsigned long long, little-endian
144
+ else
145
+ raise ArgumentError, "Unsupported array type: #{array_type}"
146
+ end
147
+
148
+ byte_len = decoded_bytes.bytesize
149
+ if byte_len.zero?
150
+ return []
151
+ end
152
+
153
+ if byte_len % word_size != 0
154
+ raise ArgumentError, "Decoded bytes length #{byte_len} is not a multiple of word size #{word_size} for type #{array_type}"
155
+ end
156
+
157
+ return decoded_bytes.unpack(unpack_format)
158
+ end
159
+
108
160
  raise ArgumentError.new("Unexpected value: #{hash}")
109
161
  end
110
162
  end