Class: Capybara::Apparition::Mouse
- Inherits:
-
Object
- Object
- Capybara::Apparition::Mouse
- Defined in:
- lib/capybara/apparition/page/mouse.rb
Instance Method Summary collapse
- #click_at(x:, y:, button: 'left', count: 1, modifiers: []) ⇒ Object
- #down(button: 'left', **options) ⇒ Object
-
#initialize(page, keyboard) ⇒ Mouse
constructor
A new instance of Mouse.
- #move_to(x:, y:, **options) ⇒ Object
- #up(button: 'left', **options) ⇒ Object
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: , 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', **) = @current_pos.merge(button: ).merge() mouse_event('mousePressed', **) @current_buttons |= BUTTONS[.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:, **) @current_pos = { x: x, y: y } mouse_event('mouseMoved', x: x, y: y, **) 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', **) = @current_pos.merge(button: ).merge() @current_buttons &= ~BUTTONS[.to_sym] mouse_event('mouseReleased', **) self end |