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.



11
12
13
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 11

def initialize(bridge)
  @bridge = bridge
end

Instance Method Details

#double_tap(element) ⇒ Object



20
21
22
23
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 20

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

#down(x, y = nil) ⇒ Object



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

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

#flick(*args) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 59

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



25
26
27
28
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 25

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

#move(x, y = nil) ⇒ Object



40
41
42
43
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 40

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

#scroll(*args) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 45

def scroll(*args)
  case args.size
  when 2
    x, y = args
    @bridge.touchScroll nil, x, y
  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



15
16
17
18
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 15

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

#up(x, y = nil) ⇒ Object



35
36
37
38
# File 'lib/selenium/webdriver/common/touch_screen.rb', line 35

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