How to create a scheduler to run my script every night at 12.00 - Selenium WebDriver

  • Currently working on Selenium WebDriver and uses Java . I have a project called * Test *.
  • In this project, I have many Java programs, such as Login.java , Testing1.java , etc.,.
  • Scenario: I want to run all my scripts daily in the morning at 12.00 in the morning. Is it possible to create a scheduler to automatically run my scripts.
+3
source share
3 answers

Create a testng.xml file, name the name as testuite.xml.

Now follow these steps:

Step 1. Create a batch file for the scheduler:

- . "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) ) , . c) classpath - lib jar, d) , . e) xml, .

2: > > , run.bat , .

.

+3

I am currently working on a similar project where I have to check various web applications for their availability every 5 minutes and report any errors by mail. I also use TestNG and WebDriver. I solved my "scheduling problem" using the TimerTask class.

Here is an example of a short code: (Here you can find code examples)

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 this helps. If you have questions about how to integrate it with TestNG setup, just shoot.

0
source

All Articles