playwright-ruby-client 0.7.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -0
- data/documentation/docs/api/browser.md +18 -2
- data/documentation/docs/api/browser_context.md +10 -0
- data/documentation/docs/api/browser_type.md +1 -0
- data/documentation/docs/api/cdp_session.md +41 -1
- data/documentation/docs/api/download.md +97 -0
- data/documentation/docs/api/element_handle.md +38 -4
- data/documentation/docs/api/experimental/android_device.md +1 -0
- data/documentation/docs/api/frame.md +78 -17
- data/documentation/docs/api/keyboard.md +11 -20
- data/documentation/docs/api/locator.md +650 -0
- data/documentation/docs/api/page.md +107 -19
- data/documentation/docs/api/response.md +16 -0
- data/documentation/docs/article/guides/inspector.md +31 -0
- data/documentation/docs/article/guides/playwright_on_alpine_linux.md +91 -0
- data/documentation/docs/article/guides/rails_integration.md +1 -1
- data/documentation/docs/article/guides/semi_automation.md +5 -1
- data/documentation/docs/include/api_coverage.md +70 -7
- data/lib/playwright.rb +36 -4
- data/lib/playwright/channel_owners/artifact.rb +4 -0
- data/lib/playwright/channel_owners/browser.rb +5 -0
- data/lib/playwright/channel_owners/browser_context.rb +37 -3
- data/lib/playwright/channel_owners/cdp_session.rb +19 -0
- data/lib/playwright/channel_owners/element_handle.rb +11 -4
- data/lib/playwright/channel_owners/frame.rb +103 -34
- data/lib/playwright/channel_owners/page.rb +140 -53
- data/lib/playwright/channel_owners/response.rb +9 -1
- data/lib/playwright/connection.rb +2 -4
- data/lib/playwright/{download.rb → download_impl.rb} +5 -1
- data/lib/playwright/javascript/expression.rb +5 -4
- data/lib/playwright/locator_impl.rb +314 -0
- data/lib/playwright/route_handler_entry.rb +3 -2
- data/lib/playwright/timeout_settings.rb +4 -4
- data/lib/playwright/transport.rb +0 -1
- data/lib/playwright/url_matcher.rb +12 -2
- data/lib/playwright/version.rb +2 -2
- data/lib/playwright/web_socket_client.rb +164 -0
- data/lib/playwright/web_socket_transport.rb +104 -0
- data/lib/playwright_api/android.rb +6 -6
- data/lib/playwright_api/android_device.rb +10 -9
- data/lib/playwright_api/browser.rb +17 -11
- data/lib/playwright_api/browser_context.rb +14 -9
- data/lib/playwright_api/browser_type.rb +8 -7
- data/lib/playwright_api/cdp_session.rb +30 -8
- data/lib/playwright_api/console_message.rb +6 -6
- data/lib/playwright_api/dialog.rb +6 -6
- data/lib/playwright_api/download.rb +70 -0
- data/lib/playwright_api/element_handle.rb +44 -24
- data/lib/playwright_api/frame.rb +100 -49
- data/lib/playwright_api/js_handle.rb +6 -6
- data/lib/playwright_api/locator.rb +509 -0
- data/lib/playwright_api/page.rb +110 -57
- data/lib/playwright_api/playwright.rb +6 -6
- data/lib/playwright_api/request.rb +6 -6
- data/lib/playwright_api/response.rb +15 -10
- data/lib/playwright_api/route.rb +6 -6
- data/lib/playwright_api/selectors.rb +6 -6
- data/lib/playwright_api/web_socket.rb +6 -6
- data/lib/playwright_api/worker.rb +6 -6
- metadata +15 -5
@@ -22,7 +22,7 @@ module Playwright
|
|
22
22
|
end
|
23
23
|
@closed = false
|
24
24
|
@bindings = {}
|
25
|
-
@routes =
|
25
|
+
@routes = []
|
26
26
|
|
27
27
|
@main_frame = ChannelOwners::Frame.from(@initializer['mainFrame'])
|
28
28
|
@main_frame.send(:update_page_from_page, self)
|
@@ -124,7 +124,7 @@ module Playwright
|
|
124
124
|
end
|
125
125
|
|
126
126
|
private def on_download(params)
|
127
|
-
download =
|
127
|
+
download = DownloadImpl.new(
|
128
128
|
page: self,
|
129
129
|
url: params['url'],
|
130
130
|
suggested_filename: params['suggestedFilename'],
|
@@ -184,15 +184,8 @@ module Playwright
|
|
184
184
|
if name
|
185
185
|
@frames.find { |f| f.name == name }
|
186
186
|
elsif url
|
187
|
-
|
188
|
-
|
189
|
-
when String
|
190
|
-
@frames.find { |f| f.url == url }
|
191
|
-
when Regexp
|
192
|
-
@frames.find { |f| url.match?(f.url) }
|
193
|
-
else
|
194
|
-
raise NotImplementedError.new('Page#frame with url is not completely implemented yet')
|
195
|
-
end
|
187
|
+
matcher = UrlMatcher.new(url, base_url: @browser_context.send(:base_url))
|
188
|
+
@frames.find { |f| matcher.match?(f.url) }
|
196
189
|
else
|
197
190
|
raise ArgumentError.new('Either name or url matcher should be specified')
|
198
191
|
end
|
@@ -212,44 +205,48 @@ module Playwright
|
|
212
205
|
@channel.send_message_to_server('setDefaultTimeoutNoReply', timeout: timeout)
|
213
206
|
end
|
214
207
|
|
215
|
-
def query_selector(selector)
|
216
|
-
@main_frame.query_selector(selector)
|
208
|
+
def query_selector(selector, strict: nil)
|
209
|
+
@main_frame.query_selector(selector, strict: strict)
|
217
210
|
end
|
218
211
|
|
219
212
|
def query_selector_all(selector)
|
220
213
|
@main_frame.query_selector_all(selector)
|
221
214
|
end
|
222
215
|
|
223
|
-
def wait_for_selector(selector, state: nil, timeout: nil)
|
224
|
-
@main_frame.wait_for_selector(selector, state: state, timeout: timeout)
|
216
|
+
def wait_for_selector(selector, state: nil, strict: nil, timeout: nil)
|
217
|
+
@main_frame.wait_for_selector(selector, state: state, strict: strict, timeout: timeout)
|
218
|
+
end
|
219
|
+
|
220
|
+
def checked?(selector, strict: nil, timeout: nil)
|
221
|
+
@main_frame.checked?(selector, strict: strict, timeout: timeout)
|
225
222
|
end
|
226
223
|
|
227
|
-
def
|
228
|
-
@main_frame.
|
224
|
+
def disabled?(selector, strict: nil, timeout: nil)
|
225
|
+
@main_frame.disabled?(selector, strict: strict, timeout: timeout)
|
229
226
|
end
|
230
227
|
|
231
|
-
def
|
232
|
-
@main_frame.
|
228
|
+
def editable?(selector, strict: nil, timeout: nil)
|
229
|
+
@main_frame.editable?(selector, strict: strict, timeout: timeout)
|
233
230
|
end
|
234
231
|
|
235
|
-
def
|
236
|
-
@main_frame.
|
232
|
+
def enabled?(selector, strict: nil, timeout: nil)
|
233
|
+
@main_frame.enabled?(selector, strict: strict, timeout: timeout)
|
237
234
|
end
|
238
235
|
|
239
|
-
def
|
240
|
-
@main_frame.
|
236
|
+
def hidden?(selector, strict: nil, timeout: nil)
|
237
|
+
@main_frame.hidden?(selector, strict: strict, timeout: timeout)
|
241
238
|
end
|
242
239
|
|
243
|
-
def
|
244
|
-
@main_frame.
|
240
|
+
def visible?(selector, strict: nil, timeout: nil)
|
241
|
+
@main_frame.visible?(selector, strict: strict, timeout: timeout)
|
245
242
|
end
|
246
243
|
|
247
|
-
def
|
248
|
-
@main_frame.
|
244
|
+
def locator(selector)
|
245
|
+
@main_frame.locator(selector)
|
249
246
|
end
|
250
247
|
|
251
|
-
def dispatch_event(selector, type, eventInit: nil, timeout: nil)
|
252
|
-
@main_frame.dispatch_event(selector, type, eventInit: eventInit, timeout: timeout)
|
248
|
+
def dispatch_event(selector, type, eventInit: nil, strict: nil, timeout: nil)
|
249
|
+
@main_frame.dispatch_event(selector, type, eventInit: eventInit, strict: strict, timeout: timeout)
|
253
250
|
end
|
254
251
|
|
255
252
|
def evaluate(pageFunction, arg: nil)
|
@@ -260,8 +257,8 @@ module Playwright
|
|
260
257
|
@main_frame.evaluate_handle(pageFunction, arg: arg)
|
261
258
|
end
|
262
259
|
|
263
|
-
def eval_on_selector(selector, pageFunction, arg: nil)
|
264
|
-
@main_frame.eval_on_selector(selector, pageFunction, arg: arg)
|
260
|
+
def eval_on_selector(selector, pageFunction, arg: nil, strict: nil)
|
261
|
+
@main_frame.eval_on_selector(selector, pageFunction, arg: arg, strict: strict)
|
265
262
|
end
|
266
263
|
|
267
264
|
def eval_on_selector_all(selector, pageFunction, arg: nil)
|
@@ -377,8 +374,8 @@ module Playwright
|
|
377
374
|
end
|
378
375
|
|
379
376
|
def route(url, handler)
|
380
|
-
entry = RouteHandlerEntry.new(url, handler)
|
381
|
-
@routes
|
377
|
+
entry = RouteHandlerEntry.new(url, @browser_context.send(:base_url), handler)
|
378
|
+
@routes.unshift(entry)
|
382
379
|
if @routes.count >= 1
|
383
380
|
@channel.send_message_to_server('setNetworkInterceptionEnabled', enabled: true)
|
384
381
|
end
|
@@ -446,6 +443,7 @@ module Playwright
|
|
446
443
|
modifiers: nil,
|
447
444
|
noWaitAfter: nil,
|
448
445
|
position: nil,
|
446
|
+
strict: nil,
|
449
447
|
timeout: nil,
|
450
448
|
trial: nil)
|
451
449
|
|
@@ -458,11 +456,31 @@ module Playwright
|
|
458
456
|
modifiers: modifiers,
|
459
457
|
noWaitAfter: noWaitAfter,
|
460
458
|
position: position,
|
459
|
+
strict: strict,
|
461
460
|
timeout: timeout,
|
462
461
|
trial: trial,
|
463
462
|
)
|
464
463
|
end
|
465
464
|
|
465
|
+
def drag_and_drop(
|
466
|
+
source,
|
467
|
+
target,
|
468
|
+
force: nil,
|
469
|
+
noWaitAfter: nil,
|
470
|
+
strict: nil,
|
471
|
+
timeout: nil,
|
472
|
+
trial: nil)
|
473
|
+
|
474
|
+
@main_frame.drag_and_drop(
|
475
|
+
source,
|
476
|
+
target,
|
477
|
+
force: force,
|
478
|
+
noWaitAfter: noWaitAfter,
|
479
|
+
strict: strict,
|
480
|
+
timeout: timeout,
|
481
|
+
trial: trial)
|
482
|
+
end
|
483
|
+
|
466
484
|
def dblclick(
|
467
485
|
selector,
|
468
486
|
button: nil,
|
@@ -471,6 +489,7 @@ module Playwright
|
|
471
489
|
modifiers: nil,
|
472
490
|
noWaitAfter: nil,
|
473
491
|
position: nil,
|
492
|
+
strict: nil,
|
474
493
|
timeout: nil,
|
475
494
|
trial: nil)
|
476
495
|
@main_frame.dblclick(
|
@@ -481,6 +500,7 @@ module Playwright
|
|
481
500
|
modifiers: modifiers,
|
482
501
|
noWaitAfter: noWaitAfter,
|
483
502
|
position: position,
|
503
|
+
strict: strict,
|
484
504
|
timeout: timeout,
|
485
505
|
trial: trial,
|
486
506
|
)
|
@@ -492,6 +512,7 @@ module Playwright
|
|
492
512
|
modifiers: nil,
|
493
513
|
noWaitAfter: nil,
|
494
514
|
position: nil,
|
515
|
+
strict: nil,
|
495
516
|
timeout: nil,
|
496
517
|
trial: nil)
|
497
518
|
@main_frame.tap_point(
|
@@ -500,33 +521,46 @@ module Playwright
|
|
500
521
|
modifiers: modifiers,
|
501
522
|
noWaitAfter: noWaitAfter,
|
502
523
|
position: position,
|
524
|
+
strict: strict,
|
503
525
|
timeout: timeout,
|
504
526
|
trial: trial,
|
505
527
|
)
|
506
528
|
end
|
507
529
|
|
508
|
-
def fill(
|
509
|
-
|
530
|
+
def fill(
|
531
|
+
selector,
|
532
|
+
value,
|
533
|
+
force: nil,
|
534
|
+
noWaitAfter: nil,
|
535
|
+
strict: nil,
|
536
|
+
timeout: nil)
|
537
|
+
@main_frame.fill(
|
538
|
+
selector,
|
539
|
+
value,
|
540
|
+
force: force,
|
541
|
+
noWaitAfter: noWaitAfter,
|
542
|
+
strict: strict,
|
543
|
+
timeout: timeout)
|
510
544
|
end
|
511
545
|
|
512
|
-
def focus(selector, timeout: nil)
|
513
|
-
@main_frame.focus(selector, timeout: timeout)
|
546
|
+
def focus(selector, strict: nil, timeout: nil)
|
547
|
+
@main_frame.focus(selector, strict: strict, timeout: timeout)
|
514
548
|
end
|
515
549
|
|
516
|
-
def text_content(selector, timeout: nil)
|
517
|
-
@main_frame.text_content(selector, timeout: timeout)
|
550
|
+
def text_content(selector, strict: nil, timeout: nil)
|
551
|
+
@main_frame.text_content(selector, strict: strict, timeout: timeout)
|
518
552
|
end
|
519
553
|
|
520
|
-
def inner_text(selector, timeout: nil)
|
521
|
-
@main_frame.inner_text(selector, timeout: timeout)
|
554
|
+
def inner_text(selector, strict: nil, timeout: nil)
|
555
|
+
@main_frame.inner_text(selector, strict: strict, timeout: timeout)
|
522
556
|
end
|
523
557
|
|
524
|
-
def inner_html(selector, timeout: nil)
|
525
|
-
@main_frame.inner_html(selector, timeout: timeout)
|
558
|
+
def inner_html(selector, strict: nil, timeout: nil)
|
559
|
+
@main_frame.inner_html(selector, strict: strict, timeout: timeout)
|
526
560
|
end
|
527
561
|
|
528
|
-
def get_attribute(selector, name, timeout: nil)
|
529
|
-
@main_frame.get_attribute(selector, name, timeout: timeout)
|
562
|
+
def get_attribute(selector, name, strict: nil, timeout: nil)
|
563
|
+
@main_frame.get_attribute(selector, name, strict: strict, timeout: timeout)
|
530
564
|
end
|
531
565
|
|
532
566
|
def hover(
|
@@ -534,6 +568,7 @@ module Playwright
|
|
534
568
|
force: nil,
|
535
569
|
modifiers: nil,
|
536
570
|
position: nil,
|
571
|
+
strict: nil,
|
537
572
|
timeout: nil,
|
538
573
|
trial: nil)
|
539
574
|
@main_frame.hover(
|
@@ -541,6 +576,7 @@ module Playwright
|
|
541
576
|
force: force,
|
542
577
|
modifiers: modifiers,
|
543
578
|
position: position,
|
579
|
+
strict: strict,
|
544
580
|
timeout: timeout,
|
545
581
|
trial: trial,
|
546
582
|
)
|
@@ -552,7 +588,9 @@ module Playwright
|
|
552
588
|
index: nil,
|
553
589
|
value: nil,
|
554
590
|
label: nil,
|
591
|
+
force: nil,
|
555
592
|
noWaitAfter: nil,
|
593
|
+
strict: nil,
|
556
594
|
timeout: nil)
|
557
595
|
@main_frame.select_option(
|
558
596
|
selector,
|
@@ -560,13 +598,24 @@ module Playwright
|
|
560
598
|
index: index,
|
561
599
|
value: value,
|
562
600
|
label: label,
|
601
|
+
force: force,
|
563
602
|
noWaitAfter: noWaitAfter,
|
603
|
+
strict: strict,
|
564
604
|
timeout: timeout,
|
565
605
|
)
|
566
606
|
end
|
567
607
|
|
568
|
-
def
|
569
|
-
@main_frame.
|
608
|
+
def input_value(selector, strict: nil, timeout: nil)
|
609
|
+
@main_frame.input_value(selector, strict: strict, timeout: timeout)
|
610
|
+
end
|
611
|
+
|
612
|
+
def set_input_files(selector, files, noWaitAfter: nil, strict: nil,timeout: nil)
|
613
|
+
@main_frame.set_input_files(
|
614
|
+
selector,
|
615
|
+
files,
|
616
|
+
noWaitAfter: noWaitAfter,
|
617
|
+
strict: strict,
|
618
|
+
timeout: timeout)
|
570
619
|
end
|
571
620
|
|
572
621
|
def type(
|
@@ -574,9 +623,16 @@ module Playwright
|
|
574
623
|
text,
|
575
624
|
delay: nil,
|
576
625
|
noWaitAfter: nil,
|
626
|
+
strict: nil,
|
577
627
|
timeout: nil)
|
578
628
|
|
579
|
-
@main_frame.type(
|
629
|
+
@main_frame.type(
|
630
|
+
selector,
|
631
|
+
text,
|
632
|
+
delay: delay,
|
633
|
+
noWaitAfter: noWaitAfter,
|
634
|
+
strict: strict,
|
635
|
+
timeout: timeout)
|
580
636
|
end
|
581
637
|
|
582
638
|
def press(
|
@@ -584,9 +640,16 @@ module Playwright
|
|
584
640
|
key,
|
585
641
|
delay: nil,
|
586
642
|
noWaitAfter: nil,
|
643
|
+
strict: nil,
|
587
644
|
timeout: nil)
|
588
645
|
|
589
|
-
@main_frame.press(
|
646
|
+
@main_frame.press(
|
647
|
+
selector,
|
648
|
+
key,
|
649
|
+
delay: delay,
|
650
|
+
noWaitAfter: noWaitAfter,
|
651
|
+
strict: strict,
|
652
|
+
timeout: timeout)
|
590
653
|
end
|
591
654
|
|
592
655
|
def check(
|
@@ -594,10 +657,18 @@ module Playwright
|
|
594
657
|
force: nil,
|
595
658
|
noWaitAfter: nil,
|
596
659
|
position: nil,
|
660
|
+
strict: nil,
|
597
661
|
timeout: nil,
|
598
662
|
trial: nil)
|
599
663
|
|
600
|
-
@main_frame.check(
|
664
|
+
@main_frame.check(
|
665
|
+
selector,
|
666
|
+
force: force,
|
667
|
+
noWaitAfter: noWaitAfter,
|
668
|
+
position: position,
|
669
|
+
strict: strict,
|
670
|
+
timeout: timeout,
|
671
|
+
trial: trial)
|
601
672
|
end
|
602
673
|
|
603
674
|
def uncheck(
|
@@ -605,16 +676,28 @@ module Playwright
|
|
605
676
|
force: nil,
|
606
677
|
noWaitAfter: nil,
|
607
678
|
position: nil,
|
679
|
+
strict: nil,
|
608
680
|
timeout: nil,
|
609
681
|
trial: nil)
|
610
682
|
|
611
|
-
@main_frame.uncheck(
|
683
|
+
@main_frame.uncheck(
|
684
|
+
selector,
|
685
|
+
force: force,
|
686
|
+
noWaitAfter: noWaitAfter,
|
687
|
+
position: position,
|
688
|
+
strict: strict,
|
689
|
+
timeout: timeout,
|
690
|
+
trial: trial)
|
612
691
|
end
|
613
692
|
|
614
693
|
def wait_for_function(pageFunction, arg: nil, polling: nil, timeout: nil)
|
615
694
|
@main_frame.wait_for_function(pageFunction, arg: arg, polling: polling, timeout: timeout)
|
616
695
|
end
|
617
696
|
|
697
|
+
def pause
|
698
|
+
@browser_context.send(:pause)
|
699
|
+
end
|
700
|
+
|
618
701
|
def pdf(
|
619
702
|
displayHeaderFooter: nil,
|
620
703
|
footerTemplate: nil,
|
@@ -748,7 +831,7 @@ module Playwright
|
|
748
831
|
predicate =
|
749
832
|
case urlOrPredicate
|
750
833
|
when String, Regexp
|
751
|
-
url_matcher = UrlMatcher.new(urlOrPredicate)
|
834
|
+
url_matcher = UrlMatcher.new(urlOrPredicate, base_url: @browser_context.send(:base_url))
|
752
835
|
-> (req){ url_matcher.match?(req.url) }
|
753
836
|
when Proc
|
754
837
|
urlOrPredicate
|
@@ -759,11 +842,15 @@ module Playwright
|
|
759
842
|
expect_event(Events::Page::Request, predicate: predicate, timeout: timeout, &block)
|
760
843
|
end
|
761
844
|
|
845
|
+
def expect_request_finished(predicate: nil, timeout: nil, &block)
|
846
|
+
expect_event(Events::Page::RequestFinished, predicate: predicate, timeout: timeout, &block)
|
847
|
+
end
|
848
|
+
|
762
849
|
def expect_response(urlOrPredicate, timeout: nil, &block)
|
763
850
|
predicate =
|
764
851
|
case urlOrPredicate
|
765
852
|
when String, Regexp
|
766
|
-
url_matcher = UrlMatcher.new(urlOrPredicate)
|
853
|
+
url_matcher = UrlMatcher.new(urlOrPredicate, base_url: @browser_context.send(:base_url))
|
767
854
|
-> (req){ url_matcher.match?(req.url) }
|
768
855
|
when Proc
|
769
856
|
urlOrPredicate
|
@@ -4,7 +4,7 @@ require 'json'
|
|
4
4
|
module Playwright
|
5
5
|
# @ref https://github.com/microsoft/playwright-python/blob/master/playwright/_impl/_network.py
|
6
6
|
define_channel_owner :Response do
|
7
|
-
def after_initialize
|
7
|
+
private def after_initialize
|
8
8
|
@request = ChannelOwners::Request.from(@initializer['request'])
|
9
9
|
timing = @initializer['timing']
|
10
10
|
@request.send(:update_timings,
|
@@ -44,6 +44,14 @@ module Playwright
|
|
44
44
|
end.to_h
|
45
45
|
end
|
46
46
|
|
47
|
+
def server_addr
|
48
|
+
@channel.send_message_to_server('serverAddr')
|
49
|
+
end
|
50
|
+
|
51
|
+
def security_details
|
52
|
+
@channel.send_message_to_server('securityDetails')
|
53
|
+
end
|
54
|
+
|
47
55
|
def finished
|
48
56
|
@channel.send_message_to_server('finished')
|
49
57
|
end
|
@@ -5,10 +5,8 @@ module Playwright
|
|
5
5
|
# https://github.com/microsoft/playwright-python/blob/master/playwright/_impl/_connection.py
|
6
6
|
# https://github.com/microsoft/playwright-java/blob/master/playwright/src/main/java/com/microsoft/playwright/impl/Connection.java
|
7
7
|
class Connection
|
8
|
-
def initialize(
|
9
|
-
@transport =
|
10
|
-
playwright_cli_executable_path: playwright_cli_executable_path
|
11
|
-
)
|
8
|
+
def initialize(transport)
|
9
|
+
@transport = transport
|
12
10
|
@transport.on_message_received do |message|
|
13
11
|
dispatch(message)
|
14
12
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Playwright
|
2
|
-
|
2
|
+
define_api_implementation :DownloadImpl do
|
3
3
|
def initialize(page:, url:, suggested_filename:, artifact:)
|
4
4
|
@page = page
|
5
5
|
@url = url
|
@@ -24,5 +24,9 @@ module Playwright
|
|
24
24
|
def save_as(path)
|
25
25
|
@artifact.save_as(path)
|
26
26
|
end
|
27
|
+
|
28
|
+
def cancel
|
29
|
+
@artifact.cancel
|
30
|
+
end
|
27
31
|
end
|
28
32
|
end
|