docs/ios_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
–
find_eles_attr ios
> def find_eles_attr tag_name, attribute
iOS only. Android uses uiautomator instead of uiautomation.
Get an array of attribute values from elements exactly matching tag name.
Parameters:
[String] tag_name - the tag name to find
[String] attribute - the attribute to collect
Returns:
[Array] an array of strings containing the attribute from found elements of type tag_name.
–
find_2_eles_attr ios
> def find_2_eles_attr tag_name_1, tag_name_2, attribute
iOS only. Android doesn’t use find_2_eles_attr.
Get an array of attribute values from elements exactly matching tag name.
Parameters:
[String] tag_name_1 - the 1st tag name to find
[String] tag_name_2 - the 2nd tag name to find
[String] attribute - the attribute to collect
Returns:
[Array] an array of strings containing the attribute from found elements of type tag_name.
–
password ios
> def password length=1
iOS only. On Android uiautomator always returns an empty string for EditText password.
Password character returned from value of UIASecureTextField
Parameters:
[Integer] length - the length of the password to generate
Returns:
[String] the returned string is of size length
–
get_page_class ios
> def get_page_class
Returns a string of class counts.
–
page_class ios
> def page_class
–
lazy_load_strings ios
> def lazy_load_strings
–
get_page ios
> def get_page element=source_window(0)
Returns a string of interesting elements. iOS only.
Defaults to inspecting the 1st windows source only.
use get_page(get_source) for all window sources
Parameters:
[Object] element - the element to search. omit to search everything
Returns:
[String]
–
page ios
> def page
Prints a string of interesting elements to the console.
Returns:
[void]
–
source_window ios
> def source_window window_number=0
Gets the JSON source of window number
Parameters:
[Integer] window_number - the int index of the target window
Returns:
[JSON]
–
page_window ios
> def page_window window_number=0
Prints parsed page source to console.
example: page_window 0
Parameters:
[Integer] window_number - the int index of the target window
–
fast_duration ios
> def fast_duration
The fastest duration that can be used on iOS.
Returns:
[Float]
–
alert_click ios
> def alert_click value
iOS only
Tap the alert button identified by value.
Click the ok button:
alert_click ‘OK’
Click the first button:
alert_click 0
Parameters:
[Integer, String] value - either an integer index of the button or the button’s name
Returns:
[void]
–
alert_text ios
> def alert_text
Get the alert message text.
Returns:
[String]
–
alert_accept ios
> def alert_accept
Accept the alert.
Returns:
[void]
–
alert_accept_text ios
> def alert_accept_text
Get the text of the alert’s accept button.
The last button is considered “accept.”
Returns:
[String]
–
alert_dismiss ios
> def alert_dismiss
Dismiss the alert.
Returns:
[void]
–
alert_dismiss_text ios
> def alert_dismiss_text
Get the text of the alert’s dismiss button.
The first button is considered “dismiss.”
Returns:
[String]
–
find ios
> def find text
Return the first element matching text.
Parameters:
[String] text - the text to search for
Returns:
[Element] the first matching element
–
finds ios
> def finds text
Return all elements matching text.
Parameters:
[String] text - the text to search for
Returns:
[Array] all matching elements
–
text ios
> def text text
Return the first element matching text.
Parameters:
[String] text - the text to search for
Returns:
[Element] the first matching element
–
texts ios
> def texts text
Return all elements matching text.
Parameters:
[String] text - the text to search for
Returns:
[Array] all matching elements
–
name ios
> 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 ios
> 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
–
textfields ios
> def textfields
Get an array of textfield texts.
Returns:
[Array]
–
e_textfields ios
> def e_textfields
Get an array of textfield elements.
Returns:
[Array]
–
first_textfield ios
> def first_textfield
Get the first textfield element.
Returns:
[Textfield]
–
last_textfield ios
> def last_textfield
Get the last textfield element.
Returns:
[Textfield]
–
textfield ios
> def textfield text
Get the first textfield that matches text.
Parameters:
[String, Integer] text - the text to match exactly. If int then the textfield at that index is returned.
Returns:
[Textfield]
–
textfield_include ios
> def textfield_include text
Get the first textfield that includes text.
Parameters:
[String] text - the text the textfield must include
Returns:
[Textfield]
–
textfield_exact ios
> def textfield_exact text
Get the first textfield that exactly matches text.
Parameters:
[String] text - the text the textfield must exactly 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]
–