Class: Capybara::Apparition::Mouse

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/apparition/page/mouse.rb

Instance Method Summary collapse

Constructor Details

#initialize(page, keyboard) ⇒ Mouse

Returns a new instance of Mouse.



5
6
7
8
9
10
# File 'lib/capybara/apparition/page/mouse.rb', line 5

def initialize(page, keyboard)
  @page = page
  @keyboard = keyboard
  @current_pos = { x: 0, y: 0 }
  @current_buttons = BUTTONS[:none]
end

Instance Method Details

#click_at(x:, y:, button: 'left', count: 1, modifiers: []) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/capybara/apparition/page/mouse.rb', line 12

def click_at(x:, y:, button: 'left', count: 1, modifiers: [])
  move_to x: x, y: y
  count.times do |num|
    @keyboard.with_keys(modifiers) do
      mouse_params = { x: x, y: y, button: button, count: num + 1 }
      down(**mouse_params)
      up(**mouse_params)
    end
  end
  self
end

#down(button: 'left', **options) ⇒ Object



30
31
32
33
34
35
# File 'lib/capybara/apparition/page/mouse.rb', line 30

def down(button: 'left', **options)
  options = @current_pos.merge(button: button).merge(options)
  mouse_event('mousePressed', **options)
  @current_buttons |= BUTTONS[button.to_sym]
  self
end

#move_to(x:, y:, **options) ⇒ Object



24
25
26
27
28
# File 'lib/capybara/apparition/page/mouse.rb', line 24

def move_to(x:, y:, **options)
  @current_pos = { x: x, y: y }
  mouse_event('mouseMoved', x: x, y: y, **options)
  self
end

#up(button: 'left', **options) ⇒ Object



37
38
39
40
41
42
# File 'lib/capybara/apparition/page/mouse.rb', line 37

def up(button: 'left', **options)
  options = @current_pos.merge(button: button).merge(options)
  @current_buttons &= ~BUTTONS[button.to_sym]
  mouse_event('mouseReleased', **options)
  self
end