airtest.core.android.android module

class Android(serialno=None, host=None, cap_method='MINICAP_STREAM', touch_method='MINITOUCH', ime_method='YOSEMITEIME', ori_method='MINICAPORI')[源代码]

基类:airtest.core.device.Device

Android Device Class

uuid
list_app(third_only=False)[源代码]

Return list of packages

参数:third_only – if True, only third party applications are listed
返回:array of applications
path_app(package)[源代码]

Print the full path to the package

参数:package – package name
返回:the full path to the package
check_app(package)[源代码]

Check is package exists on the device

参数:package – package name
返回:True or False whether the package exists on the device or not
start_app(package, activity=None)[源代码]

Start the application and activity

参数:
  • package – package name
  • activity – activity name
返回:

None

stop_app(package)[源代码]

Stop the application

参数:package – package name
返回:None
clear_app(package)[源代码]

Clear all application data

参数:package – package name
返回:None
install_app(filepath, replace=False)[源代码]

Install the application on the device

参数:
  • filepath – full path to the apk file to be installed on the device
  • replace – True or False to replace the existing application
返回:

output from installation process

uninstall_app(package)[源代码]

Uninstall the application from the device

参数:package – package name
返回:output from the uninstallation process
snapshot(filename=None, ensure_orientation=True)[源代码]

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

参数:
  • 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
返回:

screenshot output

shell(*args, **kwargs)[源代码]

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

返回:None
keyevent(keyname, **kwargs)[源代码]

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

返回:None
wake()[源代码]

Perform wake up event

返回:None
home()[源代码]

Press HOME button

返回:None
text(text, enter=True)[源代码]

Input text on the device

参数:
  • text – text to input
  • enter – True or False whether to press Enter key
返回:

None

touch(pos, duration=0.01)[源代码]

Perform touch event on the device

参数:
  • pos – coordinates (x, y)
  • duration – how long to touch the screen
返回:

None

double_click(pos)[源代码]
swipe(p1, p2, duration=0.5, steps=5, fingers=1)[源代码]

Perform swipe event on the device

参数:
  • 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.
返回:

None

pinch(*args, **kwargs)[源代码]

Perform pinch event on the device

参数:
  • *args – optional arguments
  • **kwargs – optional arguments
返回:

None

logcat(*args, **kwargs)[源代码]

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

返回:logcat output
getprop(key, strip=True)[源代码]

Get properties for given key

参数:
  • key – key name
  • strip – True or False whether to strip the output or not
返回:

property value(s)

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

Get the top activity

返回:package, activity and pid
get_top_activity_name_and_pid()[源代码]
get_top_activity_name()[源代码]

Get the top activity name

返回:package, activity and pid
is_keyboard_shown()[源代码]

Return True or False whether soft keyboard is shown or not

Notes

Might not work on all devices

返回:True or False
is_screenon()[源代码]

Return True or False whether the screen is on or not

Notes

Might not work on all devices

返回:True or False
is_locked()[源代码]

Return True or False whether the device is locked or not

Notes

Might not work on some devices

返回:True or False
unlock()[源代码]

Unlock the device

Notes

Might not work on all devices

返回:None
display_info

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

返回:display information
get_display_info()[源代码]

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

返回:display information
get_current_resolution()[源代码]

Return current resolution after rotation

返回:width and height of the display
start_recording(*args, **kwargs)[源代码]

Start recording the device display

参数:
  • *args – optional arguments
  • **kwargs – optional arguments
返回:

None

stop_recording(*args, **kwargs)[源代码]

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

参数:
  • *args – optional arguments
  • **kwargs – optional arguments
返回:

None