- Currently working on Selenium WebDriver and using Java. I have a project called*Test*.
- In that Project i have many Java Programs such as Login.java, Testing1.java etc.,.
- The scenario is i want to run all my scripts daily morning at 12.00 a.m. Is there any possibility to create a scheduler to run my scripts automatically.
-
Amir, is your project a Maven project? If so, you can create a cronjob to run your tests at a specific time everyday. Also, if you use Jenkins it will run your tests via a start time everyday as well. Those are 2 options you can try. – Curtis Miller Feb 13 '14 at 04:00
-
As suggested by Curtis use CRON.. – Raghunandan Krishnamurthy Feb 13 '14 at 04:05
-
Why dont use jenkins. You can run all the batch file/pom file and you can also specify the time. Also it is platform independent. – Vinay Feb 13 '14 at 15:40
4 Answers
Create an testng.xml file say name as testsuite.xml.
Now follow below 2 steps:
Step 1: Create an batch file for scheduler:
use below code - modify it and paste in notepad. save the notepad in working directory as"run.bat"
set ProjectPath=C:\Selenium\Selenium_tests\DemoProject
echo %ProjectPath%
set classpath=%ProjectPath%\bin;%ProjectPath%\Lib\*
echo %classpath%
java org.testng.TestNG %ProjectPath%\testsuite.xml
a) First line is for setting project path .
b) second line is for verifying that path is set or not.
c) third line is for setting classpath - lib folder contain all the jar file added to project build path
d) fourth line is for verifying whether classpath is set or not
e) fifth line is for executing xml file having details of all test.
Step 2:
Go to control panel.
Administrative tool.
Task scheduler and create a task which will trigger run.bat file at the time you want.
It will work.

- 944
- 12
- 24

- 333
- 2
- 9
-
1hi should i save that notepad file(.bat) in my java project directory? – Varun Singh Jan 15 '19 at 12:08
-
Hi @sumitbit im tring to execute the same steps given by but unable to do, i tried to run the bat file after saving but its not , automation is not happening ... Can you please tell me what could be the issue ? – Tarit Ray Dec 19 '19 at 13:23
-
-
I ran the run.bat file and just got a cmd window popping for a second! and nothing happened!. Could you help how to solve this issue!? – TinTin Mar 12 '20 at 05:20
check with quartz scheduler.. http://quartz-scheduler.org/

- 1,099
- 3
- 17
- 30
-
no Its is not maven.. If it is not maven means is there any other way except cron and jenkins – testing Feb 13 '14 at 04:08
I am currently working on a similar project where I have to check different web applications for their availability every ~5 minutes and report any errors via mail. I am also using TestNG ans the WebDriver together. I solved my "scheduling problem" by using the TimerTask class.
Here's a short code example: (Find more code examples here)
import java.util.Timer;
import java.util.TimerTask;
public class KeepMeAwake {
*
* @param args
*/
public static void main(String[] args) {
TimerTask action = new TimerTask() {
public void run() {
Beep b = Beep.getInstance();
b.beep();
}
};
Timer caretaker = new Timer();
caretaker.schedule(action, 1000, 5000);
}
}
Since it implements Runnable, you can run multiple threads with it.
Hope that helps. If you have questions how to integrate it with your TestNG set up, just shoot.

- 327
- 2
- 5
- 17
Follow the above steps and in windows scheduler do the steps :
Task Scheduler in Windows > Create new Task>
'Action' settings - "Start in (Optional)" option.
Go the task properties --> Action tab --> Edit --> Fill up as below:
- Action: Start a program
- Program/script: path to your batch script e.g.
C:\Users\beruk\bodo.bat
- Add arguments (optional): <if necessary - depending on your script>
- Start in (optional): Put the full path to your batch script location e.g.
C:\Users\beruk\
(Do not put quotes around Start In)
Then Click OK
It works for me. Good Luck!