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}

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.



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

def initialize(bridge)
  @bridge = bridge
end

Instance Method Details

#double_tap(element) ⇒ Object



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

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

#down(x, y = nil) ⇒ Object



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

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

#flick(*args) ⇒ Object



76
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 76

def flick(*args)
  case args.size
  when 2
    x_speed, y_speed = args
    @bridge.touchFlick 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.touchElementFlick 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



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

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

#move(x, y = nil) ⇒ Object



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

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

#scroll(*args) ⇒ Object



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

def scroll(*args)
  case args.size
  when 2
    x_offset, y_offset = args
    @bridge.touchScroll nil, Integer(x_offset), Integer(y_offset)
  when 3
    element, x_offset, y_offset = args
    assert_element element
    @bridge.touchScroll 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



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

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

#up(x, y = nil) ⇒ Object



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

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