This article is from the official account of the project: “AirtestProject” Copyright notice: It is allowed to be reproduced, but the original link must be retained. Do not use it for commercial or illegal purposes
1. Introduction
In the small task of obtaining local available devices with Airtest to automatically start or close the application in the last tweet, we realized the small task of automatically obtaining available devices and automatically opening NetEase Cloud Music APP on all mobile phones. So today, we’re going to look at how to make this a timed task, that is, make it do these things automatically without being attended.
In today’s tutorial, we will take you through the scheduling task on Windows, and then we will take you through the slightly more complex scheduling task on Linux.
2. Prepare the BAT script
Windows scheduled task allows us to periodically run some programs/scripts, so we can prepare a BAT script to perform the task of the previous period.
Create a new.txt file and write the following script inside:
:: Close the command output @echo off title Open the cloud music APP of all mobile phones :: Switch to drive D D: :: Go to the PythonProject directory in disk D CD D:\PythonProject :: Run the command to start the cloud music APP for all mobile phones start "Starting the cloud music APP for all mobile phones" python main.py start exitCopy the code
After saving the file, change the suffix of TXT to bat.
Let’s look at the running effect of the bat script:
3. Create a Windows scheduled task
① Open Windows Settings and search for management tools
② Find the task planner in administrative tools
③ In the task scheduler, click Create Task
4. Set scheduled tasks (configuring general tasks, triggers, and operations)
In general, we can configure the name and description of the task and select run with the highest permission (to prevent some programs/scripts from running properly due to insufficient permission) :
In the trigger configuration, we need to create a new trigger and set the start time of the task. Let’s say we need to execute the task only once at a certain time.
After setting, click “OK” to save the trigger.
Next we need to create a new action in the Action Configuration, where we set up the BAT script we need to run:
Similarly, click “OK” to save the operation after setting.
Finally, click “OK” on the task creation interface to save the task. We can find the scheduled task in the task planning library:
4. Effect of scheduled tasks
At this point, Windows scheduled task setup is complete, even in the case of unattended, Windows will follow our scheduled task, at the specified time, the specific program/script.
The effect is as follows:
5. Summary
The way of setting Windows scheduled tasks is very simple, but in practice, we rarely deploy tasks to run on our own computer, because we will deploy tasks to run on the server in consideration of the possibility of forgetting to boot up, Windows crash and so on.
The server is usually Linux system, and there is a service called crontab under the system, which can help us to implement the scheduled task. Next time, we will look at how to use the crontab service to help us to implement the scheduled task.
PS: Interested students can pay attention to us, in case you can’t find us next time
AirtestIDE download: airtest.netease.com/ Airtest tutorial website: airtest.doc.io.netease.com/ build enterprise private cloud service: airlab.163.com/b2b
Official Q group: 117973773
Ah ~ so seriously see here, help click on the left thumb, give me a thumbs-up support, ash often thank you!