airtest.core.api module

This module contains the Airtest Core APIs.

init_device(platform='Android', uuid=None, **kwargs)[源代码]

Initialize device if not yet, and set as current device.

参数:
  • platform – Android, IOS or Windows
  • uuid – uuid for target device, e.g. serialno for Android, handle for Windows, uuid for iOS
  • kwargs – Optional platform specific keyword args, e.g. cap_method=JAVACAP for Android
返回:

device instance

connect_device(uri)[源代码]

Initialize device with uri, and set as current device.

参数:

uri – an URI where to connect to device, e.g. android://adbhost:adbport/serialno?param=value&param2=value2

返回:

device instance

Example:
  • android:/// # local adb device using default params
  • android://adbhost:adbport/1234566?cap_method=javacap&touch_method=adb # remote device using custom params
  • windows:/// # local Windows application
  • ios:/// # iOS device
device()[源代码]

Return the current active device.

返回:current device instance
set_current(idx)[源代码]

Set current active device.

参数:idx – uuid or index of initialized device instance
引发:IndexError – raised when device idx is not found
返回:None
Platforms:Android, iOS, Windows
auto_setup(basedir=None, devices=None, logdir=None, project_root=None)[源代码]

Auto setup running env and try connect android device if not device connected.

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

Start remote shell in the target device and execute the command

参数:cmd – command to be run on device, e.g. “ls /data/local/tmp”
返回:the output of the shell cmd
Platforms:Android
start_app(*args, **kwargs)[源代码]

Start the target application on device

参数:
  • package – name of the package to be started, e.g. “com.netease.my”
  • activity – the activity to start, default is None which means the main activity
返回:

None

Platforms:

Android, iOS

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

Stop the target application on device

参数:package – name of the package to stop, see also start_app
返回:None
Platforms:Android, iOS
clear_app(*args, **kwargs)[源代码]

Clear data of the target application on device

参数:package – name of the package, see also start_app
返回:None
Platforms:Android, iOS
install(*args, **kwargs)[源代码]

Install application on device

参数:filepath – the path to file to be installed on target device
返回:None
Platforms:Android, iOS
uninstall(*args, **kwargs)[源代码]

Uninstall application on device

参数:package – name of the package, see also start_app
返回:None
Platforms:Android, iOS
snapshot(*args, **kwargs)[源代码]

Take the screenshot of the target device and save it to the file.

参数:
  • filename – name of the file where to save the screenshot. If the relative path is provided, the default location is ST.LOG_DIR
  • msg – short description for screenshot, it will be recorded in the report
返回:

absolute path of the screenshot

Platforms:

Android, iOS, Windows

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

Wake up and unlock the target device

返回:None
Platforms:Android, iOS

注解

Might not work on some models

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

Return to the home screen of the target device.

返回:None
Platforms:Android, iOS
touch(*args, **kwargs)[源代码]

Perform the touch action on the device screen

参数:
  • v – target to touch, either a Template instance or absolute coordinates (x, y)
  • times – how many touches to be performed
  • kwargs – platform specific kwargs, please refer to corresponding docs
返回:

finial position to be clicked

Platforms:

Android, Windows, iOS

click(*args, **kwargs)

Perform the touch action on the device screen

参数:
  • v – target to touch, either a Template instance or absolute coordinates (x, y)
  • times – how many touches to be performed
  • kwargs – platform specific kwargs, please refer to corresponding docs
返回:

finial position to be clicked

Platforms:

Android, Windows, iOS

double_click(*args, **kwargs)[源代码]
swipe(*args, **kwargs)[源代码]

Perform the swipe action on the device screen.

There are two ways of assigning the parameters
  • swipe(v1, v2=Template(...)) # swipe from v1 to v2
  • swipe(v1, vector=(x, y)) # swipe starts at v1 and moves along the vector.
参数:
  • v1 – the start point of swipe, either a Template instance or absolute coordinates (x, y)
  • v2 – the end point of swipe, either a Template instance or absolute coordinates (x, y)
  • vector – a vector coordinates of swipe action, either absolute coordinates (x, y) or percentage of screen e.g.(0.5, 0.5)
  • **kwargs

    platform specific kwargs, please refer to corresponding docs

引发:

Exception – general exception when not enough parameters to perform swap action have been provided

返回:

Origin position and target position

Platforms:

Android, Windows, iOS

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

Perform the pinch action on the device screen

参数:
  • in_or_out – pinch in or pinch out, enum in [“in”, “out”]
  • center – center of pinch action, default as None which is the center of the screen
  • percent – percentage of the screen of pinch action, default is 0.5
返回:

None

Platforms:

Android

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

Perform key event on the device

参数:
  • keyname – platform specific key name
  • **kwargs

    platform specific kwargs, please refer to corresponding docs

返回:

None

Platforms:

Android, Windows, iOS

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

Input text on the target device. Text input widget must be active first.

参数:
  • text – text to input, unicode is supported
  • enter – input Enter keyevent after text input, default is True
返回:

None

Platforms:

Android, Windows, iOS

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

Set the sleep interval. It will be recorded in the report

参数:secs – seconds to sleep
返回:None
Platforms:Android, Windows, iOS
wait(*args, **kwargs)[源代码]

Wait to match the Template on the device screen

参数:
  • v – target object to wait for, Template instance
  • timeout – time interval to wait for the match, default is None which is ST.FIND_TIMEOUT
  • interval – time interval in seconds to attempt to find a match
  • intervalfunc – called after each unsuccessful attempt to find the corresponding match
引发:

TargetNotFoundError – raised if target is not found after the time limit expired

返回:

coordinates of the matched target

Platforms:

Android, Windows, iOS

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

Check whether given target exists on device screen

参数:v – target to be checked
返回:False if target is not found, otherwise returns the coordinates of the target
Platforms:Android, Windows, iOS
find_all(*args, **kwargs)[源代码]

Find all occurrences of the target on the device screen and return their coordinates

参数:v – target to find
返回:list of coordinates, [(x, y), (x1, y1), …]
Platforms:Android, Windows, iOS
assert_exists(*args, **kwargs)[源代码]

Assert target exists on device screen

参数:
  • v – target to be checked
  • msg – short description of assertion, it will be recorded in the report
引发:

AssertionError – if assertion fails

返回:

coordinates of the target

Platforms:

Android, Windows, iOS

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

Assert target does not exist on device screen

参数:
  • v – target to be checked
  • msg – short description of assertion, it will be recorded in the report
引发:

AssertionError – if assertion fails

返回:

None.

Platforms:

Android, Windows, iOS

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

Assert two values are equal

参数:
  • first – first value
  • second – second value
  • msg – short description of assertion, it will be recorded in the report
引发:

AssertionError – if assertion fails

返回:

None

Platforms:

Android, Windows, iOS

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

Assert two values are not equal

参数:
  • first – first value
  • second – second value
  • msg – short description of assertion, it will be recorded in the report
引发:

AssertionError – if assertion

返回:

None

Platforms:

Android, Windows, iOS