capybara-playwright-driver 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/lib/capybara/playwright/browser.rb +2 -2
- data/lib/capybara/playwright/node.rb +78 -2
- data/lib/capybara/playwright/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9e6ff7fd5aaa4b41cc19395605ea19820f140703b1e52d7e2e07aaaa73f0428a
|
|
4
|
+
data.tar.gz: d77b98b91bad49e4a115b2cc7c8238611f02389e882a444d065418aeea3c2ae2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e3eafd55be3b31d780fe7f4f1c7f5c3afa35ead692a5ce8ea22e755c4cceab37d390bbcf875fad6ae355e5475e047dc4719bbf6ebfd7abaf04732d52e9ed7c60
|
|
7
|
+
data.tar.gz: 7cf9a6db8a89ba6437e6790812924682c08bbf55bc182737159aea1883190313a86aeddf86a85219fba048ed884b93a0cfd868e97f74b25e171974f0c56ebabc
|
|
@@ -69,7 +69,7 @@ module Capybara
|
|
|
69
69
|
assert_page_alive
|
|
70
70
|
|
|
71
71
|
@playwright_page.capybara_current_frame.query_selector_all("xpath=#{query}").map do |el|
|
|
72
|
-
Node.new(@driver, @
|
|
72
|
+
Node.new(@driver, @playwright_page, el)
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
|
|
@@ -300,7 +300,7 @@ module Capybara
|
|
|
300
300
|
[key, wrap_node(value)]
|
|
301
301
|
end.to_h
|
|
302
302
|
when ::Playwright::ElementHandle
|
|
303
|
-
Node.new(@driver, @
|
|
303
|
+
Node.new(@driver, @playwright_page, arg)
|
|
304
304
|
when ::Playwright::JSHandle
|
|
305
305
|
arg.json_value
|
|
306
306
|
else
|
|
@@ -406,8 +406,11 @@ module Capybara
|
|
|
406
406
|
|
|
407
407
|
MODIFIERS = {
|
|
408
408
|
alt: 'Alt',
|
|
409
|
+
ctrl: 'Control',
|
|
409
410
|
control: 'Control',
|
|
410
411
|
meta: 'Meta',
|
|
412
|
+
command: 'Meta',
|
|
413
|
+
cmd: 'Meta',
|
|
411
414
|
shift: 'Shift',
|
|
412
415
|
}.freeze
|
|
413
416
|
|
|
@@ -440,8 +443,11 @@ module Capybara
|
|
|
440
443
|
class SendKeys
|
|
441
444
|
MODIFIERS = {
|
|
442
445
|
alt: 'Alt',
|
|
446
|
+
ctrl: 'Control',
|
|
443
447
|
control: 'Control',
|
|
444
448
|
meta: 'Meta',
|
|
449
|
+
command: 'Meta',
|
|
450
|
+
cmd: 'Meta',
|
|
445
451
|
shift: 'Shift',
|
|
446
452
|
}.freeze
|
|
447
453
|
|
|
@@ -576,7 +582,7 @@ module Capybara
|
|
|
576
582
|
|
|
577
583
|
class PressKey
|
|
578
584
|
def initialize(key:, modifiers:)
|
|
579
|
-
puts "PressKey: key=#{key} modifiers: #{modifiers}"
|
|
585
|
+
# puts "PressKey: key=#{key} modifiers: #{modifiers}"
|
|
580
586
|
if modifiers.empty?
|
|
581
587
|
@key = key
|
|
582
588
|
else
|
|
@@ -605,7 +611,77 @@ module Capybara
|
|
|
605
611
|
end
|
|
606
612
|
|
|
607
613
|
def drag_to(element, **options)
|
|
608
|
-
|
|
614
|
+
DragTo.new(@page, @element, element.element, options).execute
|
|
615
|
+
end
|
|
616
|
+
|
|
617
|
+
class DragTo
|
|
618
|
+
MODIFIERS = {
|
|
619
|
+
alt: 'Alt',
|
|
620
|
+
ctrl: 'Control',
|
|
621
|
+
control: 'Control',
|
|
622
|
+
meta: 'Meta',
|
|
623
|
+
command: 'Meta',
|
|
624
|
+
cmd: 'Meta',
|
|
625
|
+
shift: 'Shift',
|
|
626
|
+
}.freeze
|
|
627
|
+
|
|
628
|
+
# @param page [Playwright::Page]
|
|
629
|
+
# @param source [Playwright::ElementHandle]
|
|
630
|
+
# @param target [Playwright::ElementHandle]
|
|
631
|
+
def initialize(page, source, target, options)
|
|
632
|
+
@page = page
|
|
633
|
+
@source = source
|
|
634
|
+
@target = target
|
|
635
|
+
@options = options
|
|
636
|
+
end
|
|
637
|
+
|
|
638
|
+
def execute
|
|
639
|
+
@source.scroll_into_view_if_needed
|
|
640
|
+
|
|
641
|
+
# down
|
|
642
|
+
position_from = center_of(@source)
|
|
643
|
+
@page.mouse.move(*position_from)
|
|
644
|
+
@page.mouse.down
|
|
645
|
+
|
|
646
|
+
@target.scroll_into_view_if_needed
|
|
647
|
+
|
|
648
|
+
# move and up
|
|
649
|
+
sleep_delay
|
|
650
|
+
position_to = center_of(@target)
|
|
651
|
+
with_key_pressing(drop_modifiers) do
|
|
652
|
+
@page.mouse.move(*position_to, steps: 6)
|
|
653
|
+
sleep_delay
|
|
654
|
+
@page.mouse.up
|
|
655
|
+
end
|
|
656
|
+
sleep_delay
|
|
657
|
+
end
|
|
658
|
+
|
|
659
|
+
# @param element [Playwright::ElementHandle]
|
|
660
|
+
private def center_of(element)
|
|
661
|
+
box = element.bounding_box
|
|
662
|
+
[box["x"] + box["width"] / 2, box["y"] + box["height"] / 2]
|
|
663
|
+
end
|
|
664
|
+
|
|
665
|
+
private def with_key_pressing(keys, &block)
|
|
666
|
+
keys.each { |key| @page.keyboard.down(key) }
|
|
667
|
+
block.call
|
|
668
|
+
keys.each { |key| @page.keyboard.up(key) }
|
|
669
|
+
end
|
|
670
|
+
|
|
671
|
+
# @returns Array<String>
|
|
672
|
+
private def drop_modifiers
|
|
673
|
+
return [] unless @options[:drop_modifiers]
|
|
674
|
+
|
|
675
|
+
Array(@options[:drop_modifiers]).map do |key|
|
|
676
|
+
MODIFIERS[key.to_sym] or raise ArgumentError.new("Unknown modifier key: #{key}")
|
|
677
|
+
end
|
|
678
|
+
end
|
|
679
|
+
|
|
680
|
+
private def sleep_delay
|
|
681
|
+
return unless @options[:delay]
|
|
682
|
+
|
|
683
|
+
sleep @options[:delay]
|
|
684
|
+
end
|
|
609
685
|
end
|
|
610
686
|
|
|
611
687
|
def drop(*args)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: capybara-playwright-driver
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- YusukeIwaki
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-06-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: capybara
|