Module: Appium

Includes:
Selenium
Included in:
Mobile
Defined in:
lib/selenium/appium/appium.rb

Overview

Appium defines all the Appium methods in a module so that they can be included by other classes

Instance Method Summary collapse

Methods included from Selenium

#back?, #element, #element?, #elements, #elements?, #time_to_element, #time_to_elements, #type?

Instance Method Details

#double_click?(*args) ⇒ Boolean

Public: Double-clicks an element or coordinates.

For any String criteria, a Regular Expression may be used by adding the 'regexp:' prefix.

name - String name of the element (default: nil). Corresponds to Android ‘resource-id’ and Ios ‘name’. text - String text of the element (default: nil). Corresponds to Android ‘text’ and Ios ‘value’. type - String type of the element (default: nil). Corresponds to element class/tag. description - String description of the element (default: nil).

Corresponds to Android 'content-desc' and Ios 'label'.

selector - String automation selector (default: nil). index - Integer index of element to use among all matching elements (default: nil).

By default, exactly one element must match.

is_visible - Boolean indicating whether the element is visible (default: nil).

Corresponds to Ios 'visible'. Always true for Android.

is_on_screen - Boolean indicating whether any part of the element is within screen boundaries (default: nil). is_tappable - Boolean indicating whether the element may be tapped (default: nil).

Corresponds to Android 'clickable'. Android only.

is_password - Boolean indicating whether the element is a password field (default: nil).

Corresponds to Android 'password'. Android only.

is_enabled - Boolean indicating whether the element is enabled (default: nil).

Corresponds to Android and Ios 'enabled'.

is_checked - Boolean indicating whether the element is checked (default: nil).

Corresponds to Android 'checked'. Android only.

is_selected - Boolean indicating whether the element is selected (default: nil).

Corresponds to Android 'selected'.

is_checkable - Boolean indicating whether the element can be checked (default: nil).

Corresponds to Android 'checkable'. Android only.

is_focusable - Boolean indicating whether the element can be focused (default: nil).

Corresponds to Android 'focusable'. Android only.

is_long_pressable - Boolean indicating whether the element can be long-pressed (default: nil).

Corresponds to Android 'long-clickable'. Android only.

is_scrollable - Boolean indicating whether the element can be scrolled (default: nil).

Corresponds to Android 'scrollable'. Android only.

is_recordable - Boolean indicating whether the element can be recorded (default: nil). x - Integer x coordinate of the element (default: nil). y - Integer y coordinate of the element (default: nil). width - Integer width of the element (default: nil). height - Integer height of the element (default: nil). number - Integer channel number (default: nil). Channel elements only. start_time - Integer start time (default: nil). Channel/show elements only. end_time - Integer end time (default: nil). Channel/show elements only. coordinates - Boolean indicating whether absolute coordinates are given (default: false). duration - Integer press duration in milliseconds (default: 0). count - Integer number of times to press (default: 2). info - Array of Symbols specifying attributes to retrieve (default: []).

By default, all attributes will be retrieved.

min - Integer minimum number of matching elements to require (default: 0).

By default, no restriction is imposed.

max - Integer maximum number of matching elements to require (default: nil).

By default, no restriction is imposed.

timeout - Integer total milliseconds to allow for element search (default: 30.sec). sleep_time - Integer total milliseconds to sleep after interacting (default: 0).

Returns a Boolean true if successfully double-clicked, otherwise false.

Returns:

  • (Boolean)


152
153
154
155
156
157
# File 'lib/selenium/appium/appium.rb', line 152

def double_click?(*args)
  args = args[0].merge(args[1] || {})
  ret = selenium_post('double-click', args)
  sleep(args.fetch(:sleep_time, 0.sec))
  !ret.nil?
end

#flick?(*args) ⇒ Boolean

Public: Flicks from/to element(s), coordinates, or offsets.

For any String criteria, a Regular Expression may be used by adding the 'regexp:' prefix.

from - Hash of attributes for element or coordinates from which to flick.

See element for valid attributes.

to - Hash of attributes for element, coordinates, or offsets to which to flick (default: nil).

See element for valid attributes. Offsets may be specified with the following keys:
:x_offset - Integer pixels or Float percent of screen/element to flick on the X axis (default: -0.1).
:y_offset - Integer pixels or Float percent of screen/element to flick on the Y axis (default: 0.1).

duration - Integer flick duration in milliseconds (default: 200). sleep_time - Integer total milliseconds to sleep after flick (default: 0).

Returns a Boolean true if successfully flicked, otherwise false.

Returns:

  • (Boolean)


270
271
272
273
274
275
# File 'lib/selenium/appium/appium.rb', line 270

def flick?(*args)
  args = args[0].merge(args[1] || {})
  ret = selenium_post('flick', args)
  sleep(args.fetch(:sleep_time, 0.sec))
  !ret.nil?
end

#home?(args = {}) ⇒ Boolean

Public: Presses device Home button.

sleep_time - Integer total milliseconds to wait after pressing Home (default: 0).

Returns a Boolean true if successfully pressed Home, otherwise false.

Returns:

  • (Boolean)


371
372
373
374
375
# File 'lib/selenium/appium/appium.rb', line 371

def home?(args={})
  ret = selenium_post('home', {})
  sleep(args.fetch(:sleep_time, 0.sec))
  !ret.nil?
end

#long_press?(*args) ⇒ Boolean

Public: Long-presses an element or coordinates.

For any String criteria, a Regular Expression may be used by adding the 'regexp:' prefix.

name - String name of the element (default: nil). Corresponds to Android ‘resource-id’ and Ios ‘name’. text - String text of the element (default: nil). Corresponds to Android ‘text’ and Ios ‘value’. type - String type of the element (default: nil). Corresponds to element class/tag. description - String description of the element (default: nil).

Corresponds to Android 'content-desc' and Ios 'label'.

selector - String automation selector (default: nil). index - Integer index of element to use among all matching elements (default: nil).

By default, exactly one element must match.

is_visible - Boolean indicating whether the element is visible (default: nil).

Corresponds to Ios 'visible'. Always true for Android.

is_on_screen - Boolean indicating whether any part of the element is within screen boundaries (default: nil). is_tappable - Boolean indicating whether the element may be tapped (default: nil).

Corresponds to Android 'clickable'. Android only.

is_password - Boolean indicating whether the element is a password field (default: nil).

Corresponds to Android 'password'. Android only.

is_enabled - Boolean indicating whether the element is enabled (default: nil).

Corresponds to Android and Ios 'enabled'.

is_checked - Boolean indicating whether the element is checked (default: nil).

Corresponds to Android 'checked'. Android only.

is_selected - Boolean indicating whether the element is selected (default: nil).

Corresponds to Android 'selected'.

is_checkable - Boolean indicating whether the element can be checked (default: nil).

Corresponds to Android 'checkable'. Android only.

is_focusable - Boolean indicating whether the element can be focused (default: nil).

Corresponds to Android 'focusable'. Android only.

is_long_pressable - Boolean indicating whether the element can be long-pressed (default: nil).

Corresponds to Android 'long-clickable'. Android only.

is_scrollable - Boolean indicating whether the element can be scrolled (default: nil).

Corresponds to Android 'scrollable'. Android only.

is_recordable - Boolean indicating whether the element can be recorded (default: nil). x - Integer x coordinate of the element (default: nil). y - Integer y coordinate of the element (default: nil). width - Integer width of the element (default: nil). height - Integer height of the element (default: nil). number - Integer channel number (default: nil). Channel elements only. start_time - Integer start time (default: nil). Channel/show elements only. end_time - Integer end time (default: nil). Channel/show elements only. coordinates - Boolean indicating whether absolute coordinates are given (default: false). duration - Integer press duration in milliseconds (default: 2000). count - Integer number of times to press (default: 1). info - Array of Symbols specifying attributes to retrieve (default: []).

By default, all attributes will be retrieved.

min - Integer minimum number of matching elements to require (default: 0).

By default, no restriction is imposed.

max - Integer maximum number of matching elements to require (default: nil).

By default, no restriction is imposed.

timeout - Integer total milliseconds to allow for element search (default: 30.sec). sleep_time - Integer total milliseconds to sleep after interacting (default: 0).

Returns a Boolean true if successfully long-pressed, otherwise false.

Returns:

  • (Boolean)


212
213
214
215
216
217
# File 'lib/selenium/appium/appium.rb', line 212

def long_press?(*args)
  args = args[0].merge(args[1] || {})
  ret = selenium_post('long-press', args)
  sleep(args.fetch(:sleep_time, 0.sec))
  !ret.nil?
end

#orientationObject

Public: Gets the current screen orientation.

Returns the Symbol screen orientation, which may be :portrait, :landscape, or nil if it could not be determined.



280
281
282
283
284
285
286
287
288
# File 'lib/selenium/appium/appium.rb', line 280

def orientation
  ret = selenium_get('orientation')
  begin
    orientation = ret['orientation']
      return orientation
  rescue
    return nil
  end
end

#orientation=(orientation) ⇒ Object

Public: Sets the current screen orientation.

orientation - Symbol desired screen orientation as :portrait or :landscape.

Returns a Boolean true if successfully set the orientation, otherwise false.



295
296
297
298
# File 'lib/selenium/appium/appium.rb', line 295

def orientation=(orientation)
  ret = selenium_post('orientation', {'orientation' =>  orientation.to_s})
  !ret.nil?
end

#power?(args = {}) ⇒ Boolean

Public: Presses device Power button.

sleep_time - Integer total milliseconds to wait after pressing Power (default: 0).

Returns a Boolean true if successfully pressed Power, otherwise false.

Returns:

  • (Boolean)


382
383
384
385
386
# File 'lib/selenium/appium/appium.rb', line 382

def power?(args={})
  ret = selenium_post('power', {})
  sleep(args.fetch(:sleep_time, 0.sec))
  !ret.nil?
end

#rotate_landscape?(args = {}) ⇒ Boolean

Public: Sets the current image rotation to landscape.

sleep_time - Integer total milliseconds to wait after setting the rotation (default: 0).

Returns a Boolean true if successfully set the rotation, otherwise false.

Returns:

  • (Boolean)


327
328
329
330
331
# File 'lib/selenium/appium/appium.rb', line 327

def rotate_landscape?(args={})
  ret = self.rotation=(:landscape)
  sleep(args.fetch(:sleep_time, 0.sec))
  ret
end

#rotate_portrait?(args = {}) ⇒ Boolean

Public: Sets the current image rotation to portrait.

sleep_time - Integer total milliseconds to wait after setting the rotation (default: 0).

Returns a Boolean true if successfully set the rotation, otherwise false.

Returns:

  • (Boolean)


338
339
340
341
342
# File 'lib/selenium/appium/appium.rb', line 338

def rotate_portrait?(args={})
  ret = self.rotation=(:portrait)
  sleep(args.fetch(:sleep_time, 0.sec))
  ret
end

#rotationObject

Public: Gets the current image rotation.

Returns the Symbol image rotation, which may be :portrait or :landscape.



303
304
305
# File 'lib/selenium/appium/appium.rb', line 303

def rotation
  @rotation
end

#rotation=(rotation) ⇒ Object

Public: Sets the current image rotation.

rotation - Symbol desired image rotation as :portrait or :landscape.

Returns a Boolean true if successfully set the rotation, otherwise false.



312
313
314
315
316
317
318
319
320
# File 'lib/selenium/appium/appium.rb', line 312

def rotation=(rotation)
  ret = selenium_post('rotation', {'rotation' => rotation.to_s})
  if ret.nil?
    false
  else
    @rotation = rotation
    true
  end
end

#scroll?(*args) ⇒ Boolean

Public: Scrolls from/to element(s), coordinates, or offsets.

from - Hash of attributes for element or coordinates from which to scroll.

See element for valid attributes.

to - Hash of attributes for element, coordinates, or offsets to which to scroll (default: nil).

See element for valid attributes. Offsets may be specified with the following keys:
:x_offset - Integer pixels or Float percent of screen/element to scroll on the X axis (default: 0).
:y_offset - Integer pixels or Float percent of screen/element to scroll on the Y axis (default: 0.45).

duration - Integer scroll duration in milliseconds (default: 1000). sleep_time - Integer total milliseconds to sleep after scroll (default: 0).

Returns a Boolean true if successfully scrolled, otherwise false.

Returns:

  • (Boolean)


250
251
252
253
254
255
# File 'lib/selenium/appium/appium.rb', line 250

def scroll?(*args)
  args = args[0].merge(args[1] || {})
  ret = selenium_post('scroll', args)
  sleep(args.fetch(:sleep_time, 0.sec))
  !ret.nil?
end

#set_landscape?(args = {}) ⇒ Boolean

Public: Sets the current screen orientation to landscape.

sleep_time - Integer total milliseconds to wait after setting the orientation (default: 0).

Returns a Boolean true if successfully set the orientation, otherwise false.

Returns:

  • (Boolean)


360
361
362
363
364
# File 'lib/selenium/appium/appium.rb', line 360

def set_landscape?(args={})
  ret = self.orientation=(:landscape)
  sleep(args.fetch(:sleep_time, 0.sec))
  ret
end

#set_portrait?(args = {}) ⇒ Boolean

Public: Sets the current screen orientation to portrait.

sleep_time - Integer total milliseconds to wait after setting the orientation (default: 0).

Returns a Boolean true if successfully set the orientation, otherwise false.

Returns:

  • (Boolean)


349
350
351
352
353
# File 'lib/selenium/appium/appium.rb', line 349

def set_portrait?(args={})
  ret = self.orientation=(:portrait)
  sleep(args.fetch(:sleep_time, 0.sec))
  ret
end

#start_session?(args = {}) ⇒ Boolean

Public: Starts a new session with the given parameters.

new_session - Boolean indicating whether to establish a new session (default: true). software_version - String version of app to install (default: nil).

If default, value of :software_version: from configuration will be used.

software_url - String URL to software network location (default: nil).

By default, it is assumed that software is stored locally.

install_software - Boolean indicating whether to install provided software version (default: true). app_package - String mobile app package to use (default: nil).

By default, app package will be chosen based on mobile platform.

app_activity - String mobile app activity to use (default: nil).

By default, app activity will be chosen based on mobile platform.

bundle_id - String mobile bundle id to use (default: nil).

By default, bundle id will be chosen based on mobile platform.

sleep_time - Integer total milliseconds to sleep after establishing the session (default: 0).

Returns a Boolean true if the session was started, otherwise false.

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
# File 'lib/selenium/appium/appium.rb', line 29

def start_session?(args={})
  args[:new_session] = args.fetch(:new_session, true)
  args[:app_version] = args.delete(:software_version) if args.include?(:software_version)
  args[:install_app] = args.delete(:install_software) if args.include?(:install_software)
  args[:app_url] = args.delete(:software_url) if args.include?(:software_url)
  ret = selenium_post('session', args)
  sleep(args.fetch(:sleep_time, 0.sec))
  !ret.nil?
end

#swipe?(*args) ⇒ Boolean

Public: Swipes from/to element(s), coordinates, or offsets.

from - Hash of attributes for element or coordinates from which to swipe.

See element for valid attributes.

to - Hash of attributes for element, coordinates, or offsets to which to swipe (default: nil).

See element for valid attributes. Offsets may be specified with the following keys:
:x_offset - Integer pixels or Float percent of screen/element to swipe on the X axis (default: -0.45).
:y_offset - Integer pixels or Float percent of screen/element to swipe on the Y axis (default: 0).

duration - Integer swipe duration in milliseconds (default: 500). sleep_time - Integer total milliseconds to sleep after flick (default: 0).

Returns a Boolean true if successfully swiped, otherwise false.

Returns:

  • (Boolean)


231
232
233
234
235
236
# File 'lib/selenium/appium/appium.rb', line 231

def swipe?(*args)
  args = args[0].merge(args[1] || {})
  ret = selenium_post('swipe', args)
  sleep(args.fetch(:sleep_time, 0.sec))
  !ret.nil?
end

#tap?(*args) ⇒ Boolean

Public: Taps an element or coordinates.

For any String criteria, a Regular Expression may be used by adding the 'regexp:' prefix.

name - String name of the element (default: nil). Corresponds to Android ‘resource-id’ and Ios ‘name’. text - String text of the element (default: nil). Corresponds to Android ‘text’ and Ios ‘value’. type - String type of the element (default: nil). Corresponds to element class/tag. description - String description of the element (default: nil).

Corresponds to Android 'content-desc' and Ios 'label'.

selector - String automation selector (default: nil). index - Integer index of element to use among all matching elements (default: nil).

By default, exactly one element must match.

is_visible - Boolean indicating whether the element is visible (default: nil).

Corresponds to Ios 'visible'. Always true for Android.

is_on_screen - Boolean indicating whether any part of the element is within screen boundaries (default: nil). is_tappable - Boolean indicating whether the element may be tapped (default: nil).

Corresponds to Android 'clickable'. Android only.

is_password - Boolean indicating whether the element is a password field (default: nil).

Corresponds to Android 'password'. Android only.

is_enabled - Boolean indicating whether the element is enabled (default: nil).

Corresponds to Android and Ios 'enabled'.

is_checked - Boolean indicating whether the element is checked (default: nil).

Corresponds to Android 'checked'. Android only.

is_selected - Boolean indicating whether the element is selected (default: nil).

Corresponds to Android 'selected'.

is_checkable - Boolean indicating whether the element can be checked (default: nil).

Corresponds to Android 'checkable'. Android only.

is_focusable - Boolean indicating whether the element can be focused (default: nil).

Corresponds to Android 'focusable'. Android only.

is_long_pressable - Boolean indicating whether the element can be long-pressed (default: nil).

Corresponds to Android 'long-clickable'. Android only.

is_scrollable - Boolean indicating whether the element can be scrolled (default: nil).

Corresponds to Android 'scrollable'. Android only.

is_recordable - Boolean indicating whether the element can be recorded (default: nil). x - Integer x coordinate of the element (default: nil). y - Integer y coordinate of the element (default: nil). width - Integer width of the element (default: nil). height - Integer height of the element (default: nil). number - Integer channel number (default: nil). Channel elements only. start_time - Integer start time (default: nil). Channel/show elements only. end_time - Integer end time (default: nil). Channel/show elements only. coordinates - Boolean indicating whether absolute coordinates are given (default: false). duration - Integer press duration in milliseconds (default: 0). count - Integer number of times to press (default: 1). info - Array of Symbols specifying attributes to retrieve (default: []).

By default, all attributes will be retrieved.

min - Integer minimum number of matching elements to require (default: 0).

By default, no restriction is imposed.

max - Integer maximum number of matching elements to require (default: nil).

By default, no restriction is imposed.

timeout - Integer total milliseconds to allow for element search (default: 30.sec). sleep_time - Integer total milliseconds to sleep after interacting (default: 0).

Returns a Boolean true if successfully tapped, otherwise false.

Returns:

  • (Boolean)


92
93
94
95
96
97
# File 'lib/selenium/appium/appium.rb', line 92

def tap?(*args)
  args = args[0].merge(args[1] || {})
  ret = selenium_post('tap', args)
  sleep(args.fetch(:sleep_time, 0.sec))
  !ret.nil?
end