Class: Selenium::WebDriver::Interactions::PointerPress

Inherits:
Interaction
  • Object
show all
Defined in:
lib/selenium/webdriver/common/interactions/pointer_input.rb

Overview

PointerInput

Constant Summary collapse

BUTTONS =
{left: 0, middle: 1, right: 2}.freeze
DIRECTIONS =
{down: :pointerDown, up: :pointerUp}.freeze

Constants inherited from Interaction

Interaction::PAUSE

Instance Attribute Summary

Attributes inherited from Interaction

#source

Instance Method Summary collapse

Constructor Details

#initialize(source, direction, button) ⇒ PointerPress

Returns a new instance of PointerPress.



70
71
72
73
74
# File 'lib/selenium/webdriver/common/interactions/pointer_input.rb', line 70

def initialize(source, direction, button)
  super(source)
  @direction = assert_direction(direction)
  @button = assert_button(button)
end

Instance Method Details

#assert_button(button) ⇒ Object

Raises:

  • (ArgumentError)


80
81
82
83
84
85
86
87
# File 'lib/selenium/webdriver/common/interactions/pointer_input.rb', line 80

def assert_button(button)
  if button.is_a? Symbol
    raise TypeError, "#{button.inspect} is not a valid button!" unless BUTTONS.key? button
    button = BUTTONS[button]
  end
  raise ArgumentError, 'Button number cannot be negative!' unless button >= 0
  button
end

#assert_direction(direction) ⇒ Object

Raises:

  • (TypeError)


89
90
91
92
# File 'lib/selenium/webdriver/common/interactions/pointer_input.rb', line 89

def assert_direction(direction)
  raise TypeError, "#{direction.inspect} is not a valid button direction" unless DIRECTIONS.key? direction
  DIRECTIONS[direction]
end

#encodeObject



94
95
96
# File 'lib/selenium/webdriver/common/interactions/pointer_input.rb', line 94

def encode
  {type: type, button: @button}
end

#typeObject



76
77
78
# File 'lib/selenium/webdriver/common/interactions/pointer_input.rb', line 76

def type
  @direction
end