playwright-ruby-client 0.8.1 → 1.14.beta3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/docs/api/accessibility.md +51 -1
  3. data/documentation/docs/api/browser_context.md +28 -0
  4. data/documentation/docs/api/download.md +97 -0
  5. data/documentation/docs/api/element_handle.md +28 -3
  6. data/documentation/docs/api/experimental/android.md +15 -2
  7. data/documentation/docs/api/frame.md +116 -114
  8. data/documentation/docs/api/locator.md +650 -0
  9. data/documentation/docs/api/mouse.md +3 -4
  10. data/documentation/docs/api/page.md +109 -19
  11. data/documentation/docs/api/request.md +15 -19
  12. data/documentation/docs/api/touchscreen.md +8 -0
  13. data/documentation/docs/api/tracing.md +13 -12
  14. data/documentation/docs/api/worker.md +37 -0
  15. data/documentation/docs/article/guides/inspector.md +31 -0
  16. data/documentation/docs/article/guides/playwright_on_alpine_linux.md +1 -1
  17. data/documentation/docs/article/guides/semi_automation.md +1 -1
  18. data/documentation/docs/include/api_coverage.md +70 -14
  19. data/lib/playwright.rb +0 -1
  20. data/lib/playwright/accessibility_impl.rb +50 -0
  21. data/lib/playwright/channel_owners/browser_context.rb +70 -0
  22. data/lib/playwright/channel_owners/frame.rb +79 -33
  23. data/lib/playwright/channel_owners/page.rb +133 -42
  24. data/lib/playwright/channel_owners/request.rb +8 -8
  25. data/lib/playwright/channel_owners/worker.rb +23 -0
  26. data/lib/playwright/{download.rb → download_impl.rb} +1 -1
  27. data/lib/playwright/javascript/expression.rb +5 -4
  28. data/lib/playwright/locator_impl.rb +314 -0
  29. data/lib/playwright/timeout_settings.rb +4 -4
  30. data/lib/playwright/touchscreen_impl.rb +7 -0
  31. data/lib/playwright/tracing_impl.rb +9 -8
  32. data/lib/playwright/version.rb +2 -2
  33. data/lib/playwright_api/accessibility.rb +1 -1
  34. data/lib/playwright_api/android.rb +21 -8
  35. data/lib/playwright_api/android_device.rb +6 -6
  36. data/lib/playwright_api/browser.rb +6 -6
  37. data/lib/playwright_api/browser_context.rb +16 -11
  38. data/lib/playwright_api/browser_type.rb +6 -6
  39. data/lib/playwright_api/cdp_session.rb +6 -6
  40. data/lib/playwright_api/console_message.rb +6 -6
  41. data/lib/playwright_api/dialog.rb +6 -6
  42. data/lib/playwright_api/download.rb +70 -0
  43. data/lib/playwright_api/element_handle.rb +34 -20
  44. data/lib/playwright_api/frame.rb +85 -53
  45. data/lib/playwright_api/js_handle.rb +6 -6
  46. data/lib/playwright_api/locator.rb +509 -0
  47. data/lib/playwright_api/page.rb +91 -57
  48. data/lib/playwright_api/playwright.rb +6 -6
  49. data/lib/playwright_api/request.rb +6 -6
  50. data/lib/playwright_api/response.rb +6 -6
  51. data/lib/playwright_api/route.rb +6 -6
  52. data/lib/playwright_api/selectors.rb +6 -6
  53. data/lib/playwright_api/touchscreen.rb +1 -1
  54. data/lib/playwright_api/web_socket.rb +6 -6
  55. data/lib/playwright_api/worker.rb +16 -6
  56. metadata +13 -6
@@ -9,7 +9,7 @@ module Playwright
9
9
  private def after_initialize
10
10
  @browser_context = @parent
11
11
  @timeout_settings = TimeoutSettings.new(@browser_context.send(:_timeout_settings))
12
- @accessibility = Accessibility.new(@channel)
12
+ @accessibility = AccessibilityImpl.new(@channel)
13
13
  @keyboard = KeyboardImpl.new(@channel)
14
14
  @mouse = MouseImpl.new(@channel)
15
15
  @touchscreen = TouchscreenImpl.new(@channel)
@@ -21,6 +21,7 @@ module Playwright
21
21
  }
22
22
  end
23
23
  @closed = false
24
+ @workers = Set.new
24
25
  @bindings = {}
25
26
  @routes = []
26
27
 
@@ -66,7 +67,7 @@ module Playwright
66
67
  })
67
68
  @channel.on('worker', ->(params) {
68
69
  worker = ChannelOwners::Worker.from(params['worker'])
69
- # on_worker(worker)
70
+ on_worker(worker)
70
71
  })
71
72
  end
72
73
 
@@ -110,9 +111,16 @@ module Playwright
110
111
  @browser_context.send(:on_binding, binding_call)
111
112
  end
112
113
 
114
+ private def on_worker(worker)
115
+ worker.page = self
116
+ @workers << worker
117
+ emit(Events::Page::Worker, worker)
118
+ end
119
+
113
120
  private def on_close
114
121
  @closed = true
115
122
  @browser_context.send(:remove_page, self)
123
+ @browser_context.send(:remove_background_page, self)
116
124
  emit(Events::Page::Close)
117
125
  end
118
126
 
@@ -124,7 +132,7 @@ module Playwright
124
132
  end
125
133
 
126
134
  private def on_download(params)
127
- download = Download.new(
135
+ download = DownloadImpl.new(
128
136
  page: self,
129
137
  url: params['url'],
130
138
  suggested_filename: params['suggestedFilename'],
@@ -205,44 +213,48 @@ module Playwright
205
213
  @channel.send_message_to_server('setDefaultTimeoutNoReply', timeout: timeout)
206
214
  end
207
215
 
208
- def query_selector(selector)
209
- @main_frame.query_selector(selector)
216
+ def query_selector(selector, strict: nil)
217
+ @main_frame.query_selector(selector, strict: strict)
210
218
  end
211
219
 
212
220
  def query_selector_all(selector)
213
221
  @main_frame.query_selector_all(selector)
214
222
  end
215
223
 
216
- def wait_for_selector(selector, state: nil, timeout: nil)
217
- @main_frame.wait_for_selector(selector, state: state, timeout: timeout)
224
+ def wait_for_selector(selector, state: nil, strict: nil, timeout: nil)
225
+ @main_frame.wait_for_selector(selector, state: state, strict: strict, timeout: timeout)
218
226
  end
219
227
 
220
- def checked?(selector, timeout: nil)
221
- @main_frame.checked?(selector, timeout: timeout)
228
+ def checked?(selector, strict: nil, timeout: nil)
229
+ @main_frame.checked?(selector, strict: strict, timeout: timeout)
222
230
  end
223
231
 
224
- def disabled?(selector, timeout: nil)
225
- @main_frame.disabled?(selector, timeout: timeout)
232
+ def disabled?(selector, strict: nil, timeout: nil)
233
+ @main_frame.disabled?(selector, strict: strict, timeout: timeout)
226
234
  end
227
235
 
228
- def editable?(selector, timeout: nil)
229
- @main_frame.editable?(selector, timeout: timeout)
236
+ def editable?(selector, strict: nil, timeout: nil)
237
+ @main_frame.editable?(selector, strict: strict, timeout: timeout)
230
238
  end
231
239
 
232
- def enabled?(selector, timeout: nil)
233
- @main_frame.enabled?(selector, timeout: timeout)
240
+ def enabled?(selector, strict: nil, timeout: nil)
241
+ @main_frame.enabled?(selector, strict: strict, timeout: timeout)
234
242
  end
235
243
 
236
- def hidden?(selector, timeout: nil)
237
- @main_frame.hidden?(selector, timeout: timeout)
244
+ def hidden?(selector, strict: nil, timeout: nil)
245
+ @main_frame.hidden?(selector, strict: strict, timeout: timeout)
238
246
  end
239
247
 
240
- def visible?(selector, timeout: nil)
241
- @main_frame.visible?(selector, timeout: timeout)
248
+ def visible?(selector, strict: nil, timeout: nil)
249
+ @main_frame.visible?(selector, strict: strict, timeout: timeout)
242
250
  end
243
251
 
244
- def dispatch_event(selector, type, eventInit: nil, timeout: nil)
245
- @main_frame.dispatch_event(selector, type, eventInit: eventInit, timeout: timeout)
252
+ def locator(selector)
253
+ @main_frame.locator(selector)
254
+ end
255
+
256
+ def dispatch_event(selector, type, eventInit: nil, strict: nil, timeout: nil)
257
+ @main_frame.dispatch_event(selector, type, eventInit: eventInit, strict: strict, timeout: timeout)
246
258
  end
247
259
 
248
260
  def evaluate(pageFunction, arg: nil)
@@ -253,8 +265,8 @@ module Playwright
253
265
  @main_frame.evaluate_handle(pageFunction, arg: arg)
254
266
  end
255
267
 
256
- def eval_on_selector(selector, pageFunction, arg: nil)
257
- @main_frame.eval_on_selector(selector, pageFunction, arg: arg)
268
+ def eval_on_selector(selector, pageFunction, arg: nil, strict: nil)
269
+ @main_frame.eval_on_selector(selector, pageFunction, arg: arg, strict: strict)
258
270
  end
259
271
 
260
272
  def eval_on_selector_all(selector, pageFunction, arg: nil)
@@ -439,6 +451,7 @@ module Playwright
439
451
  modifiers: nil,
440
452
  noWaitAfter: nil,
441
453
  position: nil,
454
+ strict: nil,
442
455
  timeout: nil,
443
456
  trial: nil)
444
457
 
@@ -451,6 +464,7 @@ module Playwright
451
464
  modifiers: modifiers,
452
465
  noWaitAfter: noWaitAfter,
453
466
  position: position,
467
+ strict: strict,
454
468
  timeout: timeout,
455
469
  trial: trial,
456
470
  )
@@ -461,6 +475,9 @@ module Playwright
461
475
  target,
462
476
  force: nil,
463
477
  noWaitAfter: nil,
478
+ sourcePosition: nil,
479
+ strict: nil,
480
+ targetPosition: nil,
464
481
  timeout: nil,
465
482
  trial: nil)
466
483
 
@@ -469,6 +486,9 @@ module Playwright
469
486
  target,
470
487
  force: force,
471
488
  noWaitAfter: noWaitAfter,
489
+ sourcePosition: sourcePosition,
490
+ strict: strict,
491
+ targetPosition: targetPosition,
472
492
  timeout: timeout,
473
493
  trial: trial)
474
494
  end
@@ -481,6 +501,7 @@ module Playwright
481
501
  modifiers: nil,
482
502
  noWaitAfter: nil,
483
503
  position: nil,
504
+ strict: nil,
484
505
  timeout: nil,
485
506
  trial: nil)
486
507
  @main_frame.dblclick(
@@ -491,6 +512,7 @@ module Playwright
491
512
  modifiers: modifiers,
492
513
  noWaitAfter: noWaitAfter,
493
514
  position: position,
515
+ strict: strict,
494
516
  timeout: timeout,
495
517
  trial: trial,
496
518
  )
@@ -502,6 +524,7 @@ module Playwright
502
524
  modifiers: nil,
503
525
  noWaitAfter: nil,
504
526
  position: nil,
527
+ strict: nil,
505
528
  timeout: nil,
506
529
  trial: nil)
507
530
  @main_frame.tap_point(
@@ -510,6 +533,7 @@ module Playwright
510
533
  modifiers: modifiers,
511
534
  noWaitAfter: noWaitAfter,
512
535
  position: position,
536
+ strict: strict,
513
537
  timeout: timeout,
514
538
  trial: trial,
515
539
  )
@@ -520,28 +544,35 @@ module Playwright
520
544
  value,
521
545
  force: nil,
522
546
  noWaitAfter: nil,
547
+ strict: nil,
523
548
  timeout: nil)
524
- @main_frame.fill(selector, value, force: force, noWaitAfter: noWaitAfter, timeout: timeout)
549
+ @main_frame.fill(
550
+ selector,
551
+ value,
552
+ force: force,
553
+ noWaitAfter: noWaitAfter,
554
+ strict: strict,
555
+ timeout: timeout)
525
556
  end
526
557
 
527
- def focus(selector, timeout: nil)
528
- @main_frame.focus(selector, timeout: timeout)
558
+ def focus(selector, strict: nil, timeout: nil)
559
+ @main_frame.focus(selector, strict: strict, timeout: timeout)
529
560
  end
530
561
 
531
- def text_content(selector, timeout: nil)
532
- @main_frame.text_content(selector, timeout: timeout)
562
+ def text_content(selector, strict: nil, timeout: nil)
563
+ @main_frame.text_content(selector, strict: strict, timeout: timeout)
533
564
  end
534
565
 
535
- def inner_text(selector, timeout: nil)
536
- @main_frame.inner_text(selector, timeout: timeout)
566
+ def inner_text(selector, strict: nil, timeout: nil)
567
+ @main_frame.inner_text(selector, strict: strict, timeout: timeout)
537
568
  end
538
569
 
539
- def inner_html(selector, timeout: nil)
540
- @main_frame.inner_html(selector, timeout: timeout)
570
+ def inner_html(selector, strict: nil, timeout: nil)
571
+ @main_frame.inner_html(selector, strict: strict, timeout: timeout)
541
572
  end
542
573
 
543
- def get_attribute(selector, name, timeout: nil)
544
- @main_frame.get_attribute(selector, name, timeout: timeout)
574
+ def get_attribute(selector, name, strict: nil, timeout: nil)
575
+ @main_frame.get_attribute(selector, name, strict: strict, timeout: timeout)
545
576
  end
546
577
 
547
578
  def hover(
@@ -549,6 +580,7 @@ module Playwright
549
580
  force: nil,
550
581
  modifiers: nil,
551
582
  position: nil,
583
+ strict: nil,
552
584
  timeout: nil,
553
585
  trial: nil)
554
586
  @main_frame.hover(
@@ -556,6 +588,7 @@ module Playwright
556
588
  force: force,
557
589
  modifiers: modifiers,
558
590
  position: position,
591
+ strict: strict,
559
592
  timeout: timeout,
560
593
  trial: trial,
561
594
  )
@@ -569,6 +602,7 @@ module Playwright
569
602
  label: nil,
570
603
  force: nil,
571
604
  noWaitAfter: nil,
605
+ strict: nil,
572
606
  timeout: nil)
573
607
  @main_frame.select_option(
574
608
  selector,
@@ -578,16 +612,22 @@ module Playwright
578
612
  label: label,
579
613
  force: force,
580
614
  noWaitAfter: noWaitAfter,
615
+ strict: strict,
581
616
  timeout: timeout,
582
617
  )
583
618
  end
584
619
 
585
- def input_value(selector, timeout: nil)
586
- @main_frame.input_value(selector, timeout: timeout)
620
+ def input_value(selector, strict: nil, timeout: nil)
621
+ @main_frame.input_value(selector, strict: strict, timeout: timeout)
587
622
  end
588
623
 
589
- def set_input_files(selector, files, noWaitAfter: nil, timeout: nil)
590
- @main_frame.set_input_files(selector, files, noWaitAfter: noWaitAfter, timeout: timeout)
624
+ def set_input_files(selector, files, noWaitAfter: nil, strict: nil,timeout: nil)
625
+ @main_frame.set_input_files(
626
+ selector,
627
+ files,
628
+ noWaitAfter: noWaitAfter,
629
+ strict: strict,
630
+ timeout: timeout)
591
631
  end
592
632
 
593
633
  def type(
@@ -595,9 +635,16 @@ module Playwright
595
635
  text,
596
636
  delay: nil,
597
637
  noWaitAfter: nil,
638
+ strict: nil,
598
639
  timeout: nil)
599
640
 
600
- @main_frame.type(selector, text, delay: delay, noWaitAfter: noWaitAfter, timeout: timeout)
641
+ @main_frame.type(
642
+ selector,
643
+ text,
644
+ delay: delay,
645
+ noWaitAfter: noWaitAfter,
646
+ strict: strict,
647
+ timeout: timeout)
601
648
  end
602
649
 
603
650
  def press(
@@ -605,9 +652,16 @@ module Playwright
605
652
  key,
606
653
  delay: nil,
607
654
  noWaitAfter: nil,
655
+ strict: nil,
608
656
  timeout: nil)
609
657
 
610
- @main_frame.press(selector, key, delay: delay, noWaitAfter: noWaitAfter, timeout: timeout)
658
+ @main_frame.press(
659
+ selector,
660
+ key,
661
+ delay: delay,
662
+ noWaitAfter: noWaitAfter,
663
+ strict: strict,
664
+ timeout: timeout)
611
665
  end
612
666
 
613
667
  def check(
@@ -615,10 +669,18 @@ module Playwright
615
669
  force: nil,
616
670
  noWaitAfter: nil,
617
671
  position: nil,
672
+ strict: nil,
618
673
  timeout: nil,
619
674
  trial: nil)
620
675
 
621
- @main_frame.check(selector, force: force, noWaitAfter: noWaitAfter, position: position, timeout: timeout, trial: trial)
676
+ @main_frame.check(
677
+ selector,
678
+ force: force,
679
+ noWaitAfter: noWaitAfter,
680
+ position: position,
681
+ strict: strict,
682
+ timeout: timeout,
683
+ trial: trial)
622
684
  end
623
685
 
624
686
  def uncheck(
@@ -626,16 +688,36 @@ module Playwright
626
688
  force: nil,
627
689
  noWaitAfter: nil,
628
690
  position: nil,
691
+ strict: nil,
629
692
  timeout: nil,
630
693
  trial: nil)
631
694
 
632
- @main_frame.uncheck(selector, force: force, noWaitAfter: noWaitAfter, position: position, timeout: timeout, trial: trial)
695
+ @main_frame.uncheck(
696
+ selector,
697
+ force: force,
698
+ noWaitAfter: noWaitAfter,
699
+ position: position,
700
+ strict: strict,
701
+ timeout: timeout,
702
+ trial: trial)
703
+ end
704
+
705
+ def wait_for_timeout(timeout)
706
+ @main_frame.wait_for_timeout(timeout)
633
707
  end
634
708
 
635
709
  def wait_for_function(pageFunction, arg: nil, polling: nil, timeout: nil)
636
710
  @main_frame.wait_for_function(pageFunction, arg: arg, polling: polling, timeout: timeout)
637
711
  end
638
712
 
713
+ def workers
714
+ @workers.to_a
715
+ end
716
+
717
+ def pause
718
+ @browser_context.send(:pause)
719
+ end
720
+
639
721
  def pdf(
640
722
  displayHeaderFooter: nil,
641
723
  footerTemplate: nil,
@@ -803,6 +885,10 @@ module Playwright
803
885
  expect_event(Events::Page::WebSocket, predicate: predicate, timeout: timeout, &block)
804
886
  end
805
887
 
888
+ def expect_worker(predicate: nil, timeout: nil, &block)
889
+ expect_event(Events::Page::Worker, predicate: predicate, timeout: timeout, &block)
890
+ end
891
+
806
892
  # called from Frame with send(:timeout_settings)
807
893
  private def timeout_settings
808
894
  @timeout_settings
@@ -813,6 +899,11 @@ module Playwright
813
899
  @bindings.key?(name)
814
900
  end
815
901
 
902
+ # called from Worker#on_close
903
+ private def remove_worker(worker)
904
+ @workers.delete(worker)
905
+ end
906
+
816
907
  # Expose guid for library developers.
817
908
  # Not intended to be used by users.
818
909
  def guid
@@ -100,14 +100,14 @@ module Playwright
100
100
  request_start:,
101
101
  response_start:)
102
102
 
103
- @timing["startTime"] = start_time
104
- @timing["domainLookupStart"] = domain_lookup_start
105
- @timing["domainLookupEnd"] = domain_lookup_end
106
- @timing["connectStart"] = connect_start
107
- @timing["secureConnectionStart"] = secure_connection_start
108
- @timing["connectEnd"] = connect_end
109
- @timing["requestStart"] = request_start
110
- @timing["responseStart"] = response_start
103
+ @timing[:startTime] = start_time
104
+ @timing[:domainLookupStart] = domain_lookup_start
105
+ @timing[:domainLookupEnd] = domain_lookup_end
106
+ @timing[:connectStart] = connect_start
107
+ @timing[:secureConnectionStart] = secure_connection_start
108
+ @timing[:connectEnd] = connect_end
109
+ @timing[:requestStart] = request_start
110
+ @timing[:responseStart] = response_start
111
111
  end
112
112
 
113
113
  private def update_headers(headers)
@@ -1,4 +1,27 @@
1
1
  module Playwright
2
2
  define_channel_owner :Worker do
3
+ attr_writer :context, :page
4
+
5
+ private def after_initialize
6
+ @channel.once('close', ->(_) { on_close })
7
+ end
8
+
9
+ private def on_close
10
+ @page&.send(:remove_worker, self)
11
+ @context&.send(:remove_service_worker, self)
12
+ emit(Events::Worker::Close, self)
13
+ end
14
+
15
+ def url
16
+ @initializer['url']
17
+ end
18
+
19
+ def evaluate(expression, arg: nil)
20
+ JavaScript::Expression.new(expression, arg).evaluate(@channel)
21
+ end
22
+
23
+ def evaluate_handle(expression, arg: nil)
24
+ JavaScript::Expression.new(expression, arg).evaluate_handle(@channel)
25
+ end
3
26
  end
4
27
  end