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.
Automatic save of scripts and retrieval of cache files¶
In the scripting work, we highly recommend that you use some version management software to manage the scripts you write, so as to avoid the loss of many scripts and the problem of multi-person collaboration.
When writing scripts using AirtestIDE, we will automatically save the scripts of the current editing window every 30 seconds to avoid missing scripts caused by forgetting to save.
However, in some extreme cases (computer blue screen, crash, etc.), there may be problems with the script edit box showing confusion, resulting in the loss of the original script. So we have added a script cache retrieving function. Whenever manually select save or run script, the current file is considered to be a good script file, so it will automatically be in the system cache directory. Save the plain text content of a script. If you encounter an exception and need to retrieve a previously saved script, you can right click on the script title:
In the dialog, there are 3 options:
The leftmost button is a one-button auto-recovery that restores the contents of the most recent cache file to the current edit window. The middle button is to open the cache folder. When you open it, you will see some plain text files. The naming rule is to replace the
:\/ symbols in the path of the script file with
%, and finally with time. At the end of the stamp, you can find the cache file corresponding to the file name in the edit, and open it with a text editor to see the automatically saved content.