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.



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

def initialize(bridge)
  @bridge = bridge
end

Instance Method Details

#double_tap(element) ⇒ Object



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

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

#down(x, y = nil) ⇒ Object



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

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

#flick(*args) ⇒ Object



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

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



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

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

#move(x, y = nil) ⇒ Object



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

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

#scroll(*args) ⇒ Object



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

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



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

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

#up(x, y = nil) ⇒ Object



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

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