airtest.core.android.android module

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

Bases: airtest.core.device.Device

Android Device Class

get_default_device()[source]

Get local default device when no serialno

Returns:local device serialno
uuid
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 if package exists on the device

Parameters:package – package name
Returns:True if package exists on the device
Raises:AirtestError – raised if package is not found
start_app(package, activity=None)[source]

Start the application and activity

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

None

start_app_timing(package, activity)[source]

Start the application and activity, and measure time

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

app launch time

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, install_options=None)[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
  • install_options – list of options, default is []
Returns:

output from installation process

install_multiple_app(filepath, replace=False)[source]

Install multiple 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, quality=10)[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 is stdout
  • ensure_orientation – True or False whether to keep the orientation same as display
  • quality – The image quality, integer in range [1, 99]
Returns:

screenshot output

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

Return adb shell interpreter

Parameters:
  • *args – optional shell commands
  • **kwargs – optional shell commands
Returns:

None

keyevent(keyname, **kwargs)[source]

Perform keyevent on the device

Parameters:
  • keyname – keyevent name
  • **kwargs – optional arguments
Returns:

None

wake()[source]

Perform wake up event

Returns:None
home()[source]

Press HOME button

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

Input text on the device

Parameters:
  • text – text to input
  • enter – True or False whether to press Enter key
  • search – True or False whether to press Search key on IME after input
Returns:

None

touch(pos, duration=0.01)[source]

Perform touch event on the device

Parameters:
  • pos – coordinates (x, y)
  • duration – how long to touch the screen
Returns:

None

double_click(pos)[source]
swipe(p1, p2, duration=0.5, steps=5, fingers=1)[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
  • fingers – the number of fingers. 1 or 2.
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

Parameters:
  • *args – optional arguments
  • **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 some 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 (width, height, orientation and max_x, max_y)

Returns:display information
get_display_info()[source]

Return the display info (width, height, orientation and max_x, max_y)

Returns:display information
get_current_resolution()[source]

Return current resolution after rotation

Returns:width and height of the display
get_render_resolution(refresh=False)[source]

Return render resolution after rotation

Parameters:refresh – whether to force refresh render resolution
Returns:offset_x, offset_y, offset_width and offset_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

adjust_all_screen()[source]

Adjust the render resolution for all_screen device.

Returns:None