airtest.core.android.android module

class Android(serialno=None, host=None, cap_method='MINICAP_STREAM', touch_method='MINITOUCH', ime_method='YOSEMITEIME')[source]

Bases: airtest.core.device.Device

Android Device Class

list_app(third_only=False)[source]

Return list of packages

Parameters:third_only – if True, only third party applications are listed
Returns:array of applications
path_app(package)[source]

Print the full path to the package

Parameters:package – package name
Returns:the full path to the package
check_app(package)[source]

Check is package exists on the device

Parameters:package – package name
Returns:True or False whether the package exists on the device or not
start_app(package, activity=None)[source]

Start the application and activity

Parameters:
  • package – package name
  • activity – activity name
Returns:

None

stop_app(package)[source]

Stop the application

Parameters:package – package name
Returns:None
clear_app(package)[source]

Clear all application data

Parameters:package – package name
Returns:None
install_app(filepath, replace=False)[source]

Install the application on the device

Parameters:
  • filepath – full path to the apk file to be installed on the device
  • replace – True or False to replace the existing application
Returns:

output from installation process

uninstall_app(package)[source]

Uninstall the application from the device

Parameters:package – package name
Returns:output from the uninstallation process
snapshot(filename=None, ensure_orientation=True)[source]

Take the screenshot of the display. The output is send to stdout by default.

Parameters:
  • filename – name of the file where to store the screenshot, default is None which si stdout
  • ensure_orientation – True or False whether to keep the orientation same as display
Returns:

screenshot output

shell(*args, **kwargs)[source]

Return adb shell interpreter :param *args: optional shell commands :param **kwargs: optional shell commands

Returns:None
keyevent(keyname, **kwargs)[source]

Perform keyevent on the device :param keyname: keyeven name :param **kwargs: optional arguments

Returns:None
wake()[source]

Perform wake up event

Returns:None
home()[source]

Press HOME button

Returns:None
text(text, enter=True)[source]

Input text on the device

Parameters:
  • text – text to input
  • enter – True or False whether to press Enter key
Returns:

None

touch(pos, times=1, duration=0.01)[source]

Perform touch event on the device

Parameters:
  • pos – coordinates (x, y)
  • times – how many touches to be performed
  • duration – how long to touch the screen
Returns:

None

swipe(p1, p2, duration=0.5, steps=5)[source]

Perform swipe event on the device

Parameters:
  • p1 – start point
  • p2 – end point
  • duration – how long to swipe the screen, default 0.5
  • steps – how big is the swipe step, default 5
Returns:

None

pinch(*args, **kwargs)[source]

Perform pinch event on the device

Parameters:
  • *args – optional arguments
  • **kwargs – optional arguments
Returns:

None

logcat(*args, **kwargs)[source]

Perform `logcat`operations :param *args: optional arguments :param **kwargs: optional arguments

Returns:logcat output
getprop(key, strip=True)[source]

Get properties for given key

Parameters:
  • key – key name
  • strip – True or False whether to strip the output or not
Returns:

property value(s)

get_ip_address()[source]
Perform several set of commands to obtain the IP address
  • adb shell netcfg | grep wlan0
  • adb shell ifconfig
  • adb getprop dhcp.wlan0.ipaddress
Returns:None if no IP address has been found, otherwise return the IP address
get_top_activity()[source]

Get the top activity

Returns:package, activity and pid
get_top_activity_name_and_pid()[source]
get_top_activity_name()[source]

Get the top activity name

Returns:package, activity and pid
is_keyboard_shown()[source]

Return True or False whether soft keyboard is shown or not

Notes

Might not work on all devices

Returns:True or False
is_screenon()[source]

Return True or False whether the screen is on or not

Notes

Might not work on all devices

Returns:True or False
is_locked()[source]

Return True or False whether the device is locked or not

Notes

Might not work on all devices

Returns:True or False
unlock()[source]

Unlock the device

Notes

Might not work on all devices

Returns:None
display_info

Return the display info (orientation, rotation and max values for x and y coordinates)

Returns:display information
get_display_info()[source]

Return the display physical info (orientation, rotation and max values for x and y coordinates)

Returns:display physical information
get_current_resolution()[source]

Return current resolution after rotaion

Returns:width and height of the display
start_recording(*args, **kwargs)[source]

Start recording the device display

Parameters:
  • *args – optional arguments
  • **kwargs – optional arguments
Returns:

None

stop_recording(*args, **kwargs)[source]

Stop recording the device display. Recoding file will be kept in the device.

Parameters:
  • *args – optional arguments
  • **kwargs – optional arguments
Returns:

None