docs/android_docs
s_texts
> def s_texts
Get an array of text texts.
Returns:
[Array]
–
e_s_texts
> def e_s_texts
Get an array of text elements.
Returns:
[Array]
–
first_s_text
> def first_s_text
Get the first text element.
Returns:
[Text]
–
last_s_text
> def last_s_text
Get the last text element
Returns:
[Text]
–
s_text
> def s_text text
Get the first element that includes text.
Parameters:
[String, Integer] text - the text to find. If int then the text at that index is returned.
Returns:
[Text]
–
s_text_exact
> def s_text_exact text
Get the first textfield that matches text.
Parameters:
[String] text - the text that the tag must match
Returns:
[Text]
–
window_size
> def window_size
Get the window’s size
–
button
> def button text, number=0
Find a button by text and optionally number.
Parameters:
[String, Integer] text - the text to exactly match. If int then the button at that index is returned.
[Integer] number - the occurrence of the button matching text. Defaults to the first button.
Returns:
[Button] the button found with text and matching number
–
buttons
> def buttons text=nil
Get an array of button texts or button elements if text is provided.
Parameters:
[String] text - the text to exactly match
Returns:
[Array, Array] either an array of button texts or an array of button elements if text is provided.
–
first_button
> def first_button
Get the first button element.
Returns:
[Button]
–
last_button
> def last_button
Get the last button element.
Returns:
[Button]
–
button_exact
> def button_exact text
Get the first button element that exactly matches text.
Parameters:
[String] text - the text to match exactly
Returns:
[Button]
–
buttons_exact
> def buttons_exact text
Get all button elements that exactly match text.
Parameters:
[String] text - the text to match exactly
Returns:
[Array]
–
e_buttons
> def e_buttons
Get an array of button elements.
Returns:
[Array]
–
button_num
> def button_num text, number=1
Expected to be called via button method.
Get the button element exactly matching text and
occurrence. number=2 means the 2nd occurrence.
find the second Sign In button
b = e_button ‘Sign In’, 2
Button order will change in iOS vs Android
so if there’s no button found at number then
return the first button.
Parameters:
[String] text - the text to match
[Integer] number - the button occurance to return. 1 = first button
Returns:
[Button] the button that matches text and number
–
tag_name_to_android android
> def tag_name_to_android tag_name
Returns an array of android classes that match the tag name
Parameters:
[String] tag_name - the tag name to convert to an android class
Returns:
[String]
–
find_eles_attr android
> def find_eles_attr tag_name, attribute=nil
Find all elements matching the attribute
On android, assume the attr is name (which falls back to text).
find_eles_attr :text
Parameters:
[String] tag_name - the tag name to search for
Returns:
[Element]
–
get_selendroid_inspect android
> def get_selendroid_inspect
Selendroid only.
Returns a string containing interesting elements.
Returns:
[String]
–
get_page_class android
> def get_page_class
–
page_class android
> def page_class
Count all classes on screen and print to stdout.
Useful for appium_console.
–
lazy_load_strings android
> def lazy_load_strings
–
get_android_inspect android
> def get_android_inspect
Android only.
Returns a string containing interesting elements.
If an element has no content desc or text, then it’s not returned by this method.
Returns:
[String]
–
get_inspect android
> def get_inspect
Automatically detects selendroid or android.
Returns a string containing interesting elements.
Returns:
[String]
–
page android
> def page
Intended for use with console.
Inspects and prints the current page.
–
fast_duration android
> def fast_duration
JavaScript code from https://github.com/appium/appium/blob/master/app/android.js
Math.round((duration * 1000) / 200) (.20 * 1000) / 200 = 1
We want steps to be exactly 1. If it’s zero then a tap is used instead of a swipe.
–
xml_keys android
> def xml_keys target
Search strings.xml’s values for target.
Parameters:
[String] target - the target to search for in strings.xml values
Returns:
[Array]
–
xml_values android
> def xml_values target
Search strings.xml’s keys for target.
Parameters:
[String] target - the target to search for in strings.xml keys
Returns:
[Array]
–
resolve_id android
> def resolve_id id
Resolve id in strings.xml and return the value.
Parameters:
[String] id - the id to resolve
Returns:
[String]
–
current_app android
> def current_app
Lists package, activity, and adb shell am start -n value for current app.
Works on local host only (not remote).
–
alert_click android
> def alert_click value
Tap the alert button identified by value.
Parameters:
[Integer, String] value - either an integer index of the button or the button’s name
Returns:
[void]
–
alert_accept android
> def alert_accept
Accept the alert.
The last button is considered “accept.”
Returns:
[void]
–
alert_accept_text android
> def alert_accept_text
Get the text of the alert’s accept button.
The last button is considered “accept.”
Returns:
[String]
–
alert_dismiss android
> def alert_dismiss
Dismiss the alert.
The first button is considered “dismiss.”
Returns:
[void]
–
alert_dismiss_text android
> def alert_dismiss_text
Get the text of the alert’s dismiss button.
The first button is considered “dismiss.”
Returns:
[String]
–
find android
> def find val
Find the value contained in content description or text. Search elements
in this order: EditText, Button, ImageButton
Parameters:
[String] val - the value to search for
Returns:
[Element]
–
text android
> def text text
Return the first element matching text.
Parameters:
[String] text - the text to search for
Returns:
[Element] the first matching element
–
texts android
> def texts text
Return all elements matching text.
Parameters:
[String] text - the text to search for
Returns:
[Array] all matching elements
–
name android
> def name name
Return the first element matching name.
on Android name is content description
on iOS name is the accessibility label or the text.
Parameters:
[String] name - the name to search for
Returns:
[Element] the first matching element
–
names android
> def names name
Return all elements matching name.
on Android name is content description
on iOS name is the accessibility label or the text.
Parameters:
[String] name - the name to search for
Returns:
[Array] all matching elements
–
scroll_to android
> def scroll_to text
Scroll to an element containing target text or description.
Parameters:
[String] text - the text to search for in the text value and content description
Returns:
[Element] the element scrolled to
–
textfields android
> def textfields
Get an array of textfield texts.
Returns:
[Array]
–
e_textfields android
> def e_textfields
Get an array of textfield elements.
Returns:
[Array]
–
first_textfield android
> def first_textfield
Get the first textfield element.
Returns:
[Textfield]
–
last_textfield android
> def last_textfield
Get the last textfield element.
Returns:
[Textfield]
–
textfield android
> def textfield text
Get the first textfield that includes text or name (content description).
Parameters:
[String, Integer] text - the text to search for. If int then the textfield at that index is returned.
Returns:
[Textfield]
–
textfield_exact android
> def textfield_exact text
Get the first textfield that matches text.
Parameters:
[String] text - the text to match
Returns:
[Textfield]
–
wait
> def wait max_wait=30, interval=0.5, &block
Check every 0.5 seconds to see if block.call doesn’t raise an exception.
if .call raises an exception then it will be tried again.
if .call doesn’t raise an exception then it will stop waiting.
Example: wait { name(‘back’).click }
Give up after 30 seconds.
Parameters:
[Integer] max_wait - the maximum time in seconds to wait for.
Note that max wait 0 means infinity.
[Float] interval - the time in seconds to wait after calling the block
[Block] block - the block to call
Returns:
[Object] the result of block.call
–
ignore
> def ignore &block
Return block.call and ignore any exceptions.
–
wait_true
> def wait_true max_wait=30, interval=0.5, &block
Check every 0.5 seconds to see if block.call returns true. nil is considered a failure.
Give up after 30 seconds.
Parameters:
[Integer] max_wait - the maximum time in seconds to wait for
[Float] interval - the time in seconds to wait after calling the block
[Block] block - the block to call
Returns:
[Object] the result of block.call
–
id
> def id id
Find by id. Useful for selendroid
Parameters:
[String] id - the id to search for
Returns:
[Element]
–
back
> def back
Navigate back.
Returns:
[void]
–
session_id
> def session_id
For Sauce Labs reporting. Returns the current session id.
–
xpath
> def xpath xpath_str
Returns the first element that matches the provided xpath.
Parameters:
[String] xpath_str - the XPath string
Returns:
[Element]
–
xpaths
> def xpaths xpath_str
Returns all elements that match the provided xpath.
Parameters:
[String] xpath_str - the XPath string
Returns:
[Array]
–
ele_index
> def ele_index tag_name, index
Get the element of type tag_name at matching index.
Parameters:
[String] tag_name - the tag name to find
[Integer] index - the index
Returns:
[Element] the found element of type tag_name
–
find_eles
> def find_eles tag_name
Get all elements exactly matching tag name
Parameters:
[String] tag_name - the tag name to find
Returns:
[Array] the found elements of type tag_name
–
find_ele_by_text
> def find_ele_by_text tag, text
Get the first tag that exactly matches tag and text.
Parameters:
[String] tag - the tag name to match
[String] text - the text to exactly match
Returns:
[Element] the element of type tag exactly matching text
–
find_eles_by_text
> def find_eles_by_text tag, text
Get all tags that exactly match tag and text.
Parameters:
[String] tag - the tag name to match
[String] text - the text to exactly match
Returns:
[Array] the elements of type tag exactly matching text
–
find_ele_by_attr_include
> def find_ele_by_attr_include tag, attr, value
Get the first tag by attribute that exactly matches value.
Parameters:
[String] tag - the tag name to match
[String] attr - the attribute to compare
[String] value - the value of the attribute that the element must include
Returns:
[Element] the element of type tag who’s attribute includes value
–
find_eles_by_attr_include
> def find_eles_by_attr_include tag, attr, value
Get tags by attribute that include value.
Parameters:
[String] tag - the tag name to match
[String] attr - the attribute to compare
[String] value - the value of the attribute that the element must include
Returns:
[Array] the elements of type tag who’s attribute includes value
–
find_ele_by_text_include
> def find_ele_by_text_include tag, text
Get the first tag that includes text.
element.attribute(:text).include? text
Parameters:
[String] tag - the tag name to match
[String] text - the text the element must include
Returns:
[Element] the element of type tag that includes text
–
find_eles_by_text_include
> def find_eles_by_text_include tag, text
Get the tags that include text.
element.attribute(:text).include? text
Parameters:
[String] tag - the tag name to match
[String] text - the text the element must include
Returns:
[Array] the elements of type tag that includes text
–
first_ele
> def first_ele tag_name
Get the first tag that matches tag_name
Parameters:
[String] tag_name - the tag to match
Returns:
[Element]
–
last_ele
> def last_ele tag_name
Get the last tag that matches tag_name
Parameters:
[String] tag_name - the tag to match
Returns:
[Element]
–
source
> def source
Prints a JSON view of the current page
Returns:
[void]
–
get_source
> def get_source
Gets a JSON view of the current page
Returns:
[JSON]
–
find_name
> def find_name name
Returns the first element that exactly matches name
Parameters:
[String] name - the name to exactly match
Returns:
[Element]
–
find_names
> def find_names name
Returns all elements that exactly match name
Parameters:
[String] name - the name to exactly match
Returns:
[Array]
–
tag
> def tag tag_name
Returns the first element matching tag_name
Parameters:
[String] tag_name - the tag_name to search for
Returns:
[Element]
–
px_to_window_rel
> def px_to_window_rel opts={}
Converts pixel values to window relative values
px_to_window_rel x: 50, y: 150
–
value
> def value
Returns the value attribute
Fixes NoMethodError: undefined method `value’ for Selenium::WebDriver::Element
–
name
> def name
Returns the name attribute
Fixes NoMethodError: undefined method `name’ for Selenium::WebDriver::Element
–
tag_name
> def tag_name
Returns the type attribute
Fixes Selenium::WebDriver::Error::UnknownError: Not yet implemented
–
location_rel
> def location_rel
For use with mobile tap.
execute_script 'mobile: tap', :x => 0.0, :y => 0.98
https://github.com/appium/appium/wiki/Automating-mobile-gestures
Returns:
[OpenStruct] the relative x, y in a struct. ex: { x: 0.50, y: 0.20 }
–
CORE
> CORE = [ :array, :hash, :class, :file, :dir, :bigdecimal, :rational, :struct, :openstruct, :method, :unboundmethod ]
–
awesome_openstruct
> def awesome_openstruct target
–
load_appium_txt
> def load_appium_txt opts
Load appium.txt (toml format) into system ENV
the basedir of this file + appium.txt is what’s used
Parameters:
[Hash] opts - file: ‘/path/to/appium.txt’, verbose: true
Returns:
[Array] the require files. nil if require doesn’t exist
–
promote_appium_methods
> def self.promote_appium_methods class_array
Promote appium methods to class instance methods
To promote methods to all classes:
Appium.promote_appium_methods Object
Parameters:
[Array] class_array - An array of classes
–
default_wait
> def default_wait
Returns the default client side wait.
This value is independent of what the server is using
Returns:
[Integer]
–
app_path
> def app_path
Returns the value of attribute app_path
–
app_name
> def app_name
Returns the value of attribute app_name
–
device
> def device
Returns the value of attribute device
–
app_package
> def app_package
Returns the value of attribute app_package
–
app_activity
> def app_activity
Returns the value of attribute app_activity
–
app_wait_activity
> def app_wait_activity
Returns the value of attribute app_wait_activity
–
sauce_username
> def sauce_username
Returns the value of attribute sauce_username
–
sauce_access_key
> def sauce_access_key
Returns the value of attribute sauce_access_key
–
port
> def port
Returns the value of attribute port
–
debug
> def debug
Returns the value of attribute debug
–
export_session
> def export_session
Returns the value of attribute export_session
–
device_cap
> def device_cap
Returns the value of attribute device_cap
–
compress_xml
> def compress_xml
Returns the value of attribute compress_xml
–
global_webdriver_http_sleep
> def global_webdriver_http_sleep
The amount to sleep in seconds before every webdriver http call.
–
global_webdriver_http_sleep=
> def global_webdriver_http_sleep=(value)
The amount to sleep in seconds before every webdriver http call.
–
initialize
> def initialize opts={}
Creates a new driver.
:device is :android, :ios, or :selendroid
# Options include: :app_path, :app_name, :app_package, :app_activity, :app_wait_activity, :sauce_username, :sauce_access_key, :port, :os, :debug require 'rubygems' require 'appium_lib' # Start iOS driver app = { device: :ios, app_path: '/path/to/MyiOS.app'} Appium::Driver.new(app).start_driver # Start Android driver apk = { device: :android app_path: '/path/to/the.apk', app_package: 'com.example.pkg', app_activity: 'act.Start', app_wait_activity: 'act.Start' } Appium::Driver.new(apk).start_driver
Parameters:
[Object] opts - A hash containing various options.
Returns:
[Driver]
–
status
> def status
Returns the status payload
{"status"=>0, "value"=> {"build"=> {"version"=>"0.8.2", "revision"=>"f2a2bc3782e4b0370d97a097d7e04913cf008995"}}, "sessionId"=>"8f4b34a7-a9a9-4ac5-b125-36258143446a"}
Discover the Appium rev running on the server.
status["value"]["build"]["revision"]
f2a2bc3782e4b0370d97a097d7e04913cf008995
Returns:
[JSON]
–
server_version
> def server_version
Returns the server’s version string
Returns:
[String]
–
absolute_app_path
> def absolute_app_path
Converts environment variable APP_PATH to an absolute path.
Returns:
[String] APP_PATH as an absolute path
–
server_url
> def server_url
Get the server url for sauce or local based on env vars.
Returns:
[String] the server url
–
restart
> def restart
Restarts the driver
Returns:
[Driver] the driver
–
driver
> def driver
Returns the driver
Returns:
[Driver] the driver
–
screenshot
> def screenshot png_save_path
Takes a png screenshot and saves to the target path.
Example: screenshot ‘/tmp/hi.png’
Parameters:
[String] png_save_path - the full path to save the png
Returns:
[nil]
–
driver_quit
> def driver_quit
Quits the driver
Returns:
[void]
–
start_driver
> def start_driver
Creates a new global driver and quits the old one if it exists.
Returns:
[Selenium::WebDriver] the new global driver
–
no_wait
> def no_wait
Set implicit wait to zero.
–
set_wait
> def set_wait timeout=@default_wait
Set implicit wait to timeout, defaults to 30.
Parameters:
[Integer] timeout - the timeout in seconds
Returns:
[void]
–
exists
> def exists pre_check=0, post_check=@default_wait, &search_block
Returns existence of element.
Example:
exists { button(‘sign in’) } ? puts(‘true’) : puts(‘false’)
Parameters:
[Integer] pre_check - the amount in seconds to set the
wait to before checking existance
[Integer] post_check - the amount in seconds to set the
wait to after checking existance
[Block] search_block - the block to call
Returns:
[Boolean]
–
execute_script
> def execute_script script, *args
The same as @driver.execute_script
Parameters:
[String] script - the script to execute
[*args] args - the args to pass to the script
Returns:
[Object]
–
mobile
> def mobile method, *args
Helper method for mobile gestures
https://github.com/appium/appium/wiki/Automating-mobile-gestures
driver.execute_script ‘mobile: swipe’, endX: 100, endY: 100, duration: 0.01
becomes
mobile :swipe, endX: 100, endY: 100, duration: 0.01
Parameters:
[String, Symbol] method - the method to execute
[*args] args - the args to pass to the method
Returns:
[Object]
–
find_elements
> def find_elements *args
Calls @driver.find_elements
Parameters:
[*args] args - the args to use
Returns:
[Array] Array is empty when no elements are found.
–
find_element
> def find_element *args
Calls @driver.find_elements
Parameters:
[*args] args - the args to use
Returns:
[Element]
–
x
> def x
Quit the driver and Pry.
quit and exit are reserved by Pry.
Returns:
[void]
–