class Capybara::Apparition::Mouse
Constants
- BUTTONS
Public Class Methods
new(page, keyboard)
click to toggle source
# 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
Public Instance Methods
click_at(x:, y:, button: 'left', count: 1, delay: 0, modifiers: [])
click to toggle source
# File lib/capybara/apparition/page/mouse.rb, line 12 def click_at(x:, y:, button: 'left', count: 1, delay: 0, 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) sleep(delay || 0) up(**mouse_params) end end self end
down(button: 'left', **options)
click to toggle source
# File lib/capybara/apparition/page/mouse.rb, line 31 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)
click to toggle source
# File lib/capybara/apparition/page/mouse.rb, line 25 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)
click to toggle source
# File lib/capybara/apparition/page/mouse.rb, line 38 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
Private Instance Methods
mouse_event(type, x:, y:, button: 'none', count: 1)
click to toggle source
# File lib/capybara/apparition/page/mouse.rb, line 47 def mouse_event(type, x:, y:, button: 'none', count: 1) @page.command('Input.dispatchMouseEvent', type: type, button: button.to_s, buttons: @current_buttons, x: x, y: y, modifiers: @keyboard.modifiers, clickCount: count) end