Class: Selenium::WebDriver::TouchScreen

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium/webdriver/common/touch_screen.rb

Constant Summary collapse

FLICK_SPEED =
{normal: 0, fast: 1}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(bridge) ⇒ TouchScreen

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TouchScreen


29
30
31
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 29

def initialize(bridge)
  @bridge = bridge
end

Instance Method Details

#double_tap(element) ⇒ Object


38
39
40
41
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 38

def double_tap(element)
  assert_element element
  @bridge.touch_double_tap element.ref
end

#down(x, y = nil) ⇒ Object


48
49
50
51
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 48

def down(x, y = nil)
  x, y = coords_from x, y
  @bridge.touch_down x, y
end

#flick(*args) ⇒ Object


77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 77

def flick(*args)
  case args.size
  when 2
    x_speed, y_speed = args
    @bridge.touch_flick Integer(x_speed), Integer(y_speed)
  when 4
    element, xoffset, yoffset, speed = args

    assert_element element
    flick_speed = FLICK_SPEED[speed.to_sym]

    unless flick_speed
      raise ArgumentError, "expected one of #{FLICK_SPEED.keys.inspect}, got #{speed.inspect}"
    end

    @bridge.touch_element_flick element.ref, Integer(xoffset), Integer(yoffset), flick_speed
  else
    raise ArgumentError, "wrong number of arguments, expected 2 or 4, got #{args.size}"
  end
end

#long_press(element) ⇒ Object


43
44
45
46
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 43

def long_press(element)
  assert_element element
  @bridge.touch_long_press element.ref
end

#move(x, y = nil) ⇒ Object


58
59
60
61
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 58

def move(x, y = nil)
  x, y = coords_from x, y
  @bridge.touch_move x, y
end

#scroll(*args) ⇒ Object


63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 63

def scroll(*args)
  case args.size
  when 2
    x_offset, y_offset = args
    @bridge.touch_scroll nil, Integer(x_offset), Integer(y_offset)
  when 3
    element, x_offset, y_offset = args
    assert_element element
    @bridge.touch_scroll element.ref, Integer(x_offset), Integer(y_offset)
  else
    raise ArgumentError, "wrong number of arguments, expected 2..3, got #{args.size}"
  end
end

#single_tap(element) ⇒ Object


33
34
35
36
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 33

def single_tap(element)
  assert_element element
  @bridge.touch_single_tap element.ref
end

#up(x, y = nil) ⇒ Object


53
54
55
56
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 53

def up(x, y = nil)
  x, y = coords_from x, y
  @bridge.touch_up x, y
end