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)


729
730
731
732
733
734
# File 'lib/capybara/playwright/node.rb', line 729

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

Instance Method Details

#executeObject



736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
# File 'lib/capybara/playwright/node.rb', line 736

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