Running scripts with AirtestIDE¶
Running scripts with AirtestIDE is very simple:
Run Script button in AirtestIDE, or press
After clicking Start, the scripts will be running and there will be a real-time loging displayed in the log window. If you want to stop the scripts, just click the
Stop Script button in the middle of the image above, or press
After running scripts, the results are displayed in the log window immediately, indicating success or failure. However, detailed results are not displayed here. Click View Report in AirtestIDE, the third button in the image above, or press Ctrl+L to see more details about the results. This opens a report page in the default browser:
Using python third-party libraries in AirtestIDE¶
If you want to run scripts in AirtestIDE, use other Python third-party libraries, or want to use the Python2 environment to run scripts, please follow the steps on local python environment deployment Then add the local Python.exe path in the AirtestIDE settings. For details, please refer to IDE Configuration - Custom Python Path .
Running scripts using the command line¶
Once the script is written, it can be run with AirtestIDE or using the command line.
Running with AirtestIDE command line¶
Even if python environment or Airtest&Poco are not installed locally, we can still run scripts using command line. Just copy the command line shown in the log window:
Copy the command line code AirtestIDE generated for each script run in the terminal and then press Enter.
Please NOTE that using command line is a simple and efficient to run AirtestIDE scripts. If you need to execute them for a long time or in bulk,, this might not be so efficient. For this, please install Airtest and Poco in a local python environment as described in the next section.
Running scripts in the local python environment¶
We described how to run scripts using AirtestIDE command line just now. This method is convenient but not suitable for more complicated operations (such as running several scripts on different devices at the same time). Besides, for some Python developers, they might need to use other third-party Python libraries in their scripts. Therefore, we highly recommend installing Airtest and Pocoui in a local python environment, then run the scripts from the command line.
Deploying your Python environment¶
If you want to run scripts in local python environment, you need to configure the local environment:
Python (2.7 or <=3.6). We recommend Python3 if it is possible, the use of virtual environments such as virtualenv to create a clean python environment.
- Use pip to install Airtest framework pip install airtest
- NOTE: On MacOS or Linux, you need to manually allow adb executable permission,
or you may have a Permission denied error while executing the script:
# macOS cd your_python_path/site-packages/airtest/core/android/static/adb/mac # linux cd your_python_path/site-packages/airtest/core/android/static/adb/linux chmod +x adb
If the 220.127.116.11 version cannot be found while installing opencv-contrib-python library, try updating pip. For the time being, please do not use the pyhont3.7 (python3.6.5 is stable).
- Use pip to install Poco framework pip install pocoui, note that the name of the library should be pocoui.
Once that the environment has been deployed and configured, we can run AirtestIDE scripts on different host machines and testing platforms.
Running scripts with python’s command line¶
Below is an example of running scripts with command line:
>airtest run untitled.air --device Android:///IMEI --log log/ >python -m airtest run untitled.air --device Android:///IMEI --log log/
These two lines have the same effect. We ran a script called
untitled.air using Airtest and passed two arguments:
The airtest run command must receive an argument to specify the path to the script. –device and –log are optional
For other arguments, please check Airtest-running-air-from-cli document.
About the device argument¶
--device used in the example above, receives a string. Take Android as an example, the full definition is as follows:
adbhost is ip of the host machine of adb server, adb port is 5037 by default, and serialno is serial number of the Android device. For more information about adb, please refer to ADB . Some examples of use of this command:
# Do not fill in anything to connect to the first device (default) Android:/// # Connect to a device that is plugged into the default port of the machine with the number 79d03fa Android://127.0.0.1:5037/79d03fa # Connect to a Windows window which window handle is 123456 Windows:///123456 # Connect to a Windows window with window name matching a certain regular expression Windows:///?title_re=Unity.* # Connect to an iOS device iOS:///127.0.0.1:8100
It is worth mentioning that the pywinauto library is used to connect to windows in Windows. In AirtestIDE, the currently connected window’s handle is used by default. As you might expect, if the window is closed, the handle could change the next time it is opened. That’s why our connection string supports
connect interface of
pywinauto. Check how to fill in arguments in Reference for more information about arguments of the connection string:
Special parameters for certain Android devices¶
In Frequently met issues about Android connection , we mentioned that for certain special devices, you should check
Use ADB orientation or
Use javacap in order to connect to devices. While you use command line to run scripts on these devices, you should also add these arguments to the connection string:
# Connect to the emulator and check "Use javacap" mode Android://127.0.0.1:5037/127.0.0.1:7555?cap_method=JAVACAP # Check all the options and then connect to the device. Use && to connect multiple argument strings Android://127.0.0.1:5037/79d03fa?cap_method=JAVACAP&&ori_method=ADBORI&&touch_method=ADBTOUCH
NOTE: On certain operating systems (such as Windows), escaping characters like ^ < > | & in the commandline is needed. For example, && should be rewritten it as ^&^&, which is:
# --device Android://127.0.0.1:5037/79d03fa?cap_method=JAVACAP&&ori_method=ADBORI Does not work on Windows --device Android://127.0.0.1:5037/79d03fa?cap_method=JAVACAP^&^&ori_method=ADBORI # Added ^ to escape
Set local Python.exe as default environment for AirtestIDE¶
AirtestIDE uses a default Python environment that has already installed Airtest and Poco. Despite its convenience, it does not support other third-party libraries if you wish to use any. We can set to use local Python.exe in AirtestIDE, to use the local Python environment to run scripts in AirtestIDE. In this way, Python2 would also be supported. For detailed instructions, please refer to Settings-Run scripts with local python environment .
Generating a test report¶
The process of running scripts is independent from the test report generation.
If the argument
--log is not specified, Airtest will use the directory of the current script as the log folder.
airtest report command generates an HTML test report:
# Simplest command line. log files and script files are in the same folder # Run the command below to generate log.html in the current directory >airtest report "untitled.air" log.html
The scripts executed must be passed to the airtest report. There are many other optional arguments supported. For details, please see Airtest_generate-html-report. Below demonstrates a common command line:
>airtest report untitled.air --log_root log/ --outfile log/log.html --lang en
This command generates the html report the specified log/ directory (the report is saved with the specified name log.html). The –lang argument specifies the language of the report, in this case, English.
Sometimes we need to copy the report to another directory, or pack it for someone else to review. However, the report generated cannot be directly copied to another directory. We provided an export mode that can be used by adding an argument in the command
--export which specifies the path to the export directory.
As mentioned before, we can copy commands from AirtestIDE’s log window. We can do this for generating reports: click the Generate Report button in AirtestIDE, then copy the command line for generating report that is shown in the log window.
Using Poco statements on the reports¶
Because the default report is exclusive to airtest, it does not completely support Poco statements. We provide plug-ins to support them: just add
--plugin poco.utils.airtest.report in the command line for report generation.
Multi-device collaboration scripts¶
In our scripts, we support switching the currently connected device through
set_current interface. This way we can use multiple devices in one script and write complicated script for multi-device interaction.
When running scripts with the command line, you can use multiple
--device Android:/// arguments to run the scripts in several devices. For example:
>airtest run untitled.air --device Android:///serialno1 --device Android:///serialno2 --device Android:///serialno1
For more information about writing and running multi-device scripts, please refer to the related sections in Quick start-Test on Android devices .
Running scripts from a batch file¶
AirtestIDE lets us run each script for testing results one at a time. But, it cannot run multiple scripts simultaneously on multiple devices and complete automation tests from a batch file. Currently, we can run scripts in multiple devices from a batch file by using the command line. For example, the simplest way to do this on Windows is to write several batch scripts to activate the command line and run Airtest scripts. If you are interested, you can also run scripts through task scheduling and multithreaded operations. Note: if you want to run multiple scripts at the same time, please do it in a local python environment instead of using AirtestIDE.
We plan to release a cloud test service platform in the near future which is still under development. Once it’s online, it will be on trial first. Visit here for more details.