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.
source
share