In this post, you’ll find how to run Selenium tests using a task scheduler in Windows 7. With the steps given here, you’ll be able to schedule your tests for daily execution.
However, there are many ready-made CI tools available that can help you do it. But they need a lot of configuration which many of us would prefer to avoid.
Like CronTab in Linux, Windows OS has this built-in feature that allows creating tasks and scheduling them for execution. So it’s easy to run Selenium tests using task scheduler.
However, you need to be a little careful while setting up an automation task in the scheduler.
First, you require admin rights to use the task scheduler. Then, you’ve to choose the appropriate settings to open a browser and run Selenium tests.
Run Selenium Tests Using Task Scheduler in Windows 7
Before we tell you the steps to run Selenium tests using the task scheduler, you should know how to run the tests from the command line. Once you know this command, you can place it in a batch file. It would be the final batch file which we’ll add to the task scheduler to run the Selenium tests on a daily basis.
1- Prepare a Windows Batch File to Run Selenium Tests.
There could be three use cases that you may need to handle.
1.1- You have the Selenium tests in single or multiple class files.
Use the below command to run the tests. Keep the Selenium library on the current path. And name the Java class file as <SeleniumTests.java>.
java -classpath .;selenium-server-standalone-2.53.0.jar SeleniumTests
1.2- You have the Selenium tests exported from Eclipse as a Runnable Jar file.
Use the below command to run the tests. Make sure the output Jar contains all the Selenium dependencies.
java -jar SeleniumTests.jar
1.3- You might be using <testng.xml> to run Selenium tests.
Use the below command to run the tests.
java -cp "path/to/testng.jar:path/to/testClass" org.testng.TestNG testng.xml
You can check more details from here to run testng.xml from the command line.
1.4- Now, use the below code to add to a batch file. Save the batch file as <run.bat>.
set MyProject=C:\tests\SeleniumTests echo %MyProject% set classpath=%MyProject%\bin;%MyProject%\Lib\* echo %classpath% java org.testng.TestNG %MyProject%\testng.xml
2- How to run a batch file using the task scheduler in Windows 7?
2.1- Open control panel.
2.2- Go to <Administrative tool >>Task scheduler>.
2.3- Create a task to run the batch file. Also, specify the time to start the execution.
2.4- Don’t forget to check the below setting in the task scheduler.
"Run only when user is logged on"
Read from this link for more details on the task scheduler.
If you have any queries about the above steps, then do leave them in the comment box. We’ll try to address this earliest possible.
All the Best,
TechBeamers