Module: Capybara::Apparition::Drag
- Included in:
- Node
- Defined in:
- lib/capybara/apparition/node/drag.rb
Instance Method Summary collapse
Instance Method Details
#drag_by(x, y, delay: 0.1) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/capybara/apparition/node/drag.rb', line 28 def drag_by(x, y, delay: 0.1) pos = visible_center raise ::Capybara::Apparition::MouseEventImpossible.new(self, 'args' => ['hover']) if pos.nil? other_pos = { x: pos[:x] + x, y: pos[:y] + y } raise ::Capybara::Apparition::MouseEventFailed.new(self, 'args' => ['drag', test['selector'], pos]) unless mouse_event_test?(pos) @page.mouse.move_to(pos).down sleep delay @page.mouse.move_to(other_pos.merge(button: 'left')) sleep delay @page.mouse.up end |
#drag_to(other, delay: 0.1) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/capybara/apparition/node/drag.rb', line 5 def drag_to(other, delay: 0.1) return html5_drag_to(other) if html5_draggable? pos = visible_center raise ::Capybara::Apparition::MouseEventImpossible.new(self, 'args' => ['drag_to']) if pos.nil? test = mouse_event_test(pos) raise ::Capybara::Apparition::MouseEventFailed.new(self, 'args' => ['drag', test.selector, pos]) unless test.success begin @page.mouse.move_to(pos).down sleep delay other_pos = other.visible_center raise ::Capybara::Apparition::MouseEventImpossible.new(self, 'args' => ['drag_to']) if other_pos.nil? @page.mouse.move_to(other_pos.merge(button: 'left')) sleep delay ensure @page.mouse.up end end |