Class: Capybara::Playwright::Node::DragTo

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/playwright/node.rb

Constant Summary collapse

MODIFIERS =
{
  alt: 'Alt',
  ctrl: 'Control',
  control: 'Control',
  meta: 'Meta',
  command: 'Meta',
  cmd: 'Meta',
  shift: 'Shift',
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(page, source, target, options) ⇒ DragTo

Returns a new instance of DragTo.

Parameters:

  • page (Playwright::Page)
  • source (Playwright::ElementHandle)
  • target (Playwright::ElementHandle)


649
650
651
652
653
654
# File 'lib/capybara/playwright/node.rb', line 649

def initialize(page, source, target, options)
  @page = page
  @source = source
  @target = target
  @options = options
end

Instance Method Details

#executeObject



656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
# File 'lib/capybara/playwright/node.rb', line 656

def execute
  @source.scroll_into_view_if_needed

  # down
  position_from = center_of(@source)
  @page.mouse.move(*position_from)
  @page.mouse.down

  @target.scroll_into_view_if_needed

  # move and up
  sleep_delay
  position_to = center_of(@target)
  with_key_pressing(drop_modifiers) do
    @page.mouse.move(*position_to, steps: 6)
    sleep_delay
    @page.mouse.up
  end
  sleep_delay
end