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

touch_proxy

Perform touch operation according to self.touch_method

Returns:TouchProxy
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, install_options=None)[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
  • install_options – list of options, default is []
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, max_size=None)[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]
  • max_size – the maximum size of the picture, e.g 1200
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(center=None, percent=0.5, duration=0.5, steps=5, in_or_out='in')[source]

Perform pinch event on the device, only for minitouch and maxtouch

Parameters:
  • center – the center point of the pinch operation
  • percent – pinch distance to half of screen, default is 0.5
  • duration – time interval for swipe duration, default is 0.8
  • steps – size of swipe step, default is 5
  • in_or_out – pinch in or pinch out, default is ‘in’
Returns:

None

Raises:

TypeError – An error occurred when center is not a list/tuple or None

swipe_along(coordinates_list, duration=0.8, steps=5)[source]

Perform swipe event across multiple points in sequence, only for minitouch and maxtouch

Parameters:
  • coordinates_list – list of coordinates: [(x1, y1), (x2, y2), (x3, y3)]
  • duration – time interval for swipe duration, default is 0.8
  • steps – size of swipe step, default is 5
Returns:

None

two_finger_swipe(tuple_from_xy, tuple_to_xy, duration=0.8, steps=5, offset=(0, 50))[source]

Perform two finger swipe action, only for minitouch and maxtouch

Parameters:
  • tuple_from_xy – start point
  • tuple_to_xy – end point
  • duration – time interval for swipe duration, default is 0.8
  • steps – size of swipe step, default is 5
  • offset – coordinate offset of the second finger, default is (0, 50)
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