0

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;
            }
        }
    }
}
Karan2404
  • 1
  • 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 16 '22 at 13:10
  • Looking for 3 things to do with this code: 1) want to do parallel testing for this code on multiple browsers. I tried running parallel sessions timer function stops working. 2) function timer.cancel(); is not working 3) Is there a way when timer.schedule function is refreshing the page concurrently and any new information gets updated or any change occur on webpage immediately code execute timer.cancel() function. – Karan2404 May 17 '22 at 16:25

0 Answers0