class Capybara::Playwright::Node::ClickOptions

Constants

MODIFIERS

Public Class Methods

new(element, keys, options, default_timeout) click to toggle source
# File lib/capybara/playwright/node.rb, line 361
def initialize(element, keys, options, default_timeout)
  @element = element
  @modifiers = keys.map do |key|
    MODIFIERS[key.to_sym] or raise ArgumentError.new("Unknown modifier key: #{key}")
  end
  if options[:x] && options[:y]
    @coords = {
      x: options[:x],
      y: options[:y],
    }
    @offset_center = options[:offset] == :center
  end
  @wait = options[:_playwright_wait]
  @delay = options[:delay]
  @default_timeout = default_timeout
end

Public Instance Methods

as_params() click to toggle source
# File lib/capybara/playwright/node.rb, line 378
def as_params
  {
    delay: delay_ms,
    modifiers: modifiers,
    position: position,
    timeout: timeout + delay_ms.to_i,
  }.compact
end

Private Instance Methods

delay_ms() click to toggle source
# File lib/capybara/playwright/node.rb, line 399
        def delay_ms
  if @delay && @delay > 0
    @delay * 1000
  else
    nil
  end
end
modifiers() click to toggle source
# File lib/capybara/playwright/node.rb, line 417
        def modifiers
  if @modifiers.empty?
    nil
  else
    @modifiers
  end
end
position() click to toggle source
# File lib/capybara/playwright/node.rb, line 425
        def position
  if @offset_center
    box = @element.bounding_box

    {
      x: @coords[:x] + box['width'] / 2,
      y: @coords[:y] + box['height'] / 2,
    }
  else
    @coords
  end
end
timeout() click to toggle source
# File lib/capybara/playwright/node.rb, line 387
        def timeout
  if @wait
    if @wait <= 0
      raise NotSupportedByDriverError.new("wait should be > 0 (wait = 0 is not supported on this driver)")
    end

    @wait * 1000
  else
    @default_timeout
  end
end