Skip to content

X. Using Bat Files to Run Scripts in Batches

1.Run the scripts in batch

After we finish writing the script, AirtestIDE allows us to run a single script at a time to verify the results. However, if we need to run multiple scripts simultaneously on multiple phones to complete batch execution of automated testing, AirtestIDE cannot meet our needs.

Currently, it is possible to achieve script multi-device operation through the command line. For example, in the Windows system, the simplest way is to write multiple .bat scripts to start running Airtest scripts in command line mode. In the following text, we will take a detailed look into this:

2.bat Script Introduction

.bat files are executable files that contain one or more commands. Using .bat files for batch processing operations can help us simplify daily or repetitive operations. Previously, our tutorial explained how to run Airtest scripts using the command line. In fact, the commands in the .bat file are also executed by cmd.exe, so we can write the command to run the airtest script in the .bat file, and use it to execute the airtest script.

3.Execute a single Airtest script using a bat file

Let's review first. The command for running an Airtest script through the command line is: airtest run + the file path of the script. Additionally, you can include parameters such as --device, --log, and --recording after the command. Here are a few examples of running the airtest script:

# Run script without any parameters
airtest run D:\test\newsLogin.air

# Run script with command line arguments
airtest run D:\test\newsLogin.air --device Android:/// --log log/ --recording

After reviewing the knowledge points of running airtest scripts in the command line, let's look at how to create a new .bat file. First, we need to create a new .txt file on the computer and enter the following content:

::Close echo
@echo off
::Switch to D drive
::Go to the test directory on the D drive
cd D:\test
::Execute the airtest run command
start airtest run newsLogin.air

::xxx" indicates that it is a comment and does not need to be written into the .txt file. Additionally, the path for the sample script is D:\test\newsLogin.air, so there is an operation to switch to the script path. You can adjust it based on the actual script situation. Also note that in the above examples, we have already added device and log initialization content at the beginning of the sample script, so there is no need to add various running parameters after the command.


If your testing equipment is relatively fixed, it is also recommended to directly write these parameters into the script, which can simplify the command for running the script on the command line. After finishing the above commands, close the .txt file and change its extension from txt to bat. Then a warning window will appear for renaming, touch yes. Finally, we can check the execution effect:


4.Execute multiple Airtest scripts in sequence using bat file

After successfully executing a single airtest script using a .bat file, let's try using the .bat file to execute multiple airtest scripts sequentially:

@echo off
cd D:\test
title Executing the first script
airtest run newsLogin.air
title Executing the second script
airtest run newsUsing.air
title Executing the third script
airtest run newsExit.air

As you can see, in addition to the sample script for logging into NetEase News mentioned above, we have added two more scripts to implement operations such as using NetEase News and logging out. Therefore, in the .bat file, we wrote three separate commands for running the corresponding scripts. The command title xxx is used to specify the title of the command prompt window, which allows us to see which script is currently being executed clearly. The final execution effect is as follows:


5.Using bat file to implement multi-device operation

In a .bat file, the start command can launch a separate command line window to run a specified program or command. Therefore, we can use the start command to open multiple command line windows and execute the same script on multiple devices:

@echo off
cd D:\test
start "Running script with LeiDian emulator " airtest run newsLogin.air --device Android://
start "Running script with mumu emulator" airtest run newsLogin.air --device Android://

The above command can achieve running the same script on one LeiDian emulator and one mumu emulator, with the following effect:

image Of course, we can also configure a separate .bat file for each device, and then write a general .bat file to schedule the .bat files used to run scripts on specific devices.

6.More Outlooks

If you are interested, you can also implement a task scheduling and multithreading running plan to run the script on your own. Please note that if you want to run multiple scripts simultaneously, try to run them in a local Python environment to avoid using AirtestIDE to run the scripts.

  • Example repository of multiple device parallelism + aggregate report
  • Enterprise-level automated testing solution - Netease Private Cloud