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

前端 未结 4 1753
无人及你
无人及你 2021-01-03 06:42
  • Currently working on Selenium WebDriver and using Java. I have a project called*Test*.
  • In that Project i have many
4条回答
  •  借酒劲吻你
    2021-01-03 07:21

    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.

提交回复
热议问题