Module: SparklingWatir::Gestures

Included in:
App
Defined in:
lib/sparkling_watir/gestures.rb

Overview

This module handles all the possible gestures

Constant Summary collapse

VIEWPORT =
::Selenium::WebDriver::Interactions::PointerMove::VIEWPORT

Instance Method Summary collapse

Instance Method Details

#action(kind, name) ⇒ Object



10
11
12
# File 'lib/sparkling_watir/gestures.rb', line 10

def action(kind, name)
  @driver.action.add_pointer_input(kind, name)
end

#double_tap(opts = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sparkling_watir/gestures.rb', line 30

def double_tap(opts = {})
  double_tap = action(:touch, 'double_tap')
  coordinates = { x: opts[:x] || opts[:on].center[:x], y: opts[:y] || opts[:on].center[:y] }
  double_tap.create_pointer_move(duration: 0, x: coordinates[:x], y: coordinates[:y], origin: VIEWPORT)
  double_tap.create_pointer_down(:left)
  double_tap.create_pause(0.1)
  double_tap.create_pointer_up(:left)
  double_tap.create_pause(0.1)
  double_tap.create_pointer_down(:left)
  double_tap.create_pause(0.1)
  double_tap.create_pointer_up(:left)

  perform double_tap
end

#long_press(opts = {}) ⇒ Object



45
46
47
# File 'lib/sparkling_watir/gestures.rb', line 45

def long_press(opts = {})
  tap(duration: opts[:duration] || 0.5, on: opts[:on])
end

#perform(*actions) ⇒ Object



14
15
16
# File 'lib/sparkling_watir/gestures.rb', line 14

def perform(*actions)
  @driver.perform_actions actions
end

#scroll(opts = {}) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/sparkling_watir/gestures.rb', line 54

def scroll(opts = {})
  duration = opts[:duration] || 30
  timeout = Time.now + duration
  while Time.now < timeout
    swipe to: opts[:into], direction: opts[:direction], scrollable: true
    break if opts[:for].present?
  end
end

#swipe(opts = {}) ⇒ Object



49
50
51
52
# File 'lib/sparkling_watir/gestures.rb', line 49

def swipe(opts = {})
  coordinates = select_direction(opts[:to], opts[:direction], opts[:scrollable])
  execute_swipe(coordinates)
end

#tap(opts = {}) ⇒ Object Also known as: press



18
19
20
21
22
23
24
25
26
# File 'lib/sparkling_watir/gestures.rb', line 18

def tap(opts = {})
  coordinates = { x: opts[:x] || opts[:on].center[:x], y: opts[:y] || opts[:on].center[:y] }
  tap = action(:touch, 'tap')
  tap.create_pointer_move(duration: 0.1, x: coordinates[:x], y: coordinates[:y], origin: VIEWPORT)
  tap.create_pointer_down(:left)
  tap.create_pause(opts[:duration] || 0)
  tap.create_pointer_up(:left)
  perform tap
end