Scripting Related FAQs¶
How shall I start to write my own scripts?¶
Have a look on our tutorial before you start scripting.
Which Python version is supported?¶
If you are using AirtestIDE to write scripts, it is recommended to use Python 2.7 syntax.
If you want to use Python 3 syntax, you can install the Airtest and Poco libraries by executing
pip install pocoui
pip install airtest commands in your local Python environment, then use the Python 3 syntax to write
your own scripts and run the scripts in the local Python environment using the command line.
How to use a command line to run a script?¶
There are two ways how to run a script from the command line:
Then use the command line to run the script, see the documentation for more info.
Here are several examples how to run scripts from command line:
Let’s assume that the script we want to run is in the current directory called untitled.air, and we are going to store
the runtime generated logs and screenshots content in the
python -m airtest run path_to_directory/untitled.air --device Android:///phone_device_number --log path_to_dir/log/
After the operation finishes, the Airtest will put the all logs and screenshot images to the
log/ directory that we
have specified above.
Use following command to generate the report:
python -m airtest report path_to_directory/untitled.air --log_root log/ --outfile log/log.html --lang en
This will use the log content in the
log/ directory to generate a html report and place it to the log directory.
The used language will be English.
Sometimes it is necessary to copy the report to another directory, and/or send it to others for reviewing, however the
generated report cannot be copied directly. Therefore, we do provide an export mode. After adding a
-- export path_where_to_export parameter, the report will be also completely exported to given directory path.
Which APIs are available in the script?¶
In the script, you can directly use the Airtest interfaces such as touch() interface which is related to image recognition, and we also provide some additional interfaces that can make the scripting a lot easier. For example:
shell("ls") # run the command adb shell ls sleep(2) # equivalent to time.sleep(2)
For more supported interfaces, please visit the Airtest API documentation
If you use Poco, visit the Poco documentation for more information.
Are the batch operations supported?¶
At this moment, we do not support batch operations. If you need to use the batch operations, write a python script to encapsulate them. For more details, please refer to our tutorial, the command line operation script section.
How to use a third-party python libraries?¶
If you want to use third-party Python libraries, you can specify them in AirtestIDE settings Options - Settings and provide the path:
If you are using command line to run the script, follow the steps:
- if you are using IDE’s command line to execute the script, you need to create system environment variable IDEPYTHONPATH and set the path to third-party library to it
- if you are using the Python command line to execute the script, you do not need to add the python environment path manually - this is the preferred way to use this method. For more details, please refer to How to use a command line to run a script? above.