class Capybara::Playwright::Node::DragTo

Constants

MODIFIERS

Public Class Methods

new(page, source, target, options) click to toggle source

@param page [Playwright::Page] @param source [Playwright::ElementHandle] @param target [Playwright::ElementHandle]

# File lib/capybara/playwright/node.rb, line 631
def initialize(page, source, target, options)
  @page = page
  @source = source
  @target = target
  @options = options
end

Public Instance Methods

execute() click to toggle source
# File lib/capybara/playwright/node.rb, line 638
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

Private Instance Methods

center_of(element) click to toggle source

@param element [Playwright::ElementHandle]

# File lib/capybara/playwright/node.rb, line 660
        def center_of(element)
  box = element.bounding_box
  [box["x"] + box["width"] / 2, box["y"] + box["height"] / 2]
end
drop_modifiers() click to toggle source

@returns Array<String>

# File lib/capybara/playwright/node.rb, line 672
        def drop_modifiers
  return [] unless @options[:drop_modifiers]

  Array(@options[:drop_modifiers]).map do |key|
    MODIFIERS[key.to_sym]  or raise ArgumentError.new("Unknown modifier key: #{key}")
  end
end
sleep_delay() click to toggle source
# File lib/capybara/playwright/node.rb, line 680
        def sleep_delay
  return unless @options[:delay]

  sleep @options[:delay]
end
with_key_pressing(keys, &block) click to toggle source
# File lib/capybara/playwright/node.rb, line 665
        def with_key_pressing(keys, &block)
  keys.each { |key| @page.keyboard.down(key) }
  block.call
  keys.each { |key| @page.keyboard.up(key) }
end