How to run the below code parallely for multiple browsers. Secondly, timer.cancel not working and is there a way we could stop the timer command if there is any change in the web page.
class Calender {
private int count = 0;
public static void main(String[] args) throws InterruptedException {
WebDriverManager.chromedriver().setup();
ChromeOptions opt = new ChromeOptions();
opt.setExperimentalOption("debuggerAddress", "localhost:9222");
WebDriver driver = new ChromeDriver(opt);
//driver.get("https://youtube.com");
new Calender().refreshYoutube(driver);
}
public void refreshYoutube(WebDriver driver) {
Calendar today = Calendar.getInstance();
today.set(Calendar.HOUR_OF_DAY, 13);
today.set(Calendar.MINUTE, 33);
today.set(Calendar.SECOND, 6);
Timer timer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
System.out.println("Inside method1()");
driver.navigate().refresh();
}
};
timer.schedule(task, today.getTime(), TimeUnit.MILLISECONDS.convert(5, TimeUnit.SECONDS)); // period: 5 seconds
count++;
if (count >= 2) {
timer.cancel();
timer.purge() ;
return;
}
}
}
}