Selenium python do test every 10 seconds
Question: I am using selenium (python) testing and I need to test my application
automatically every 10 seconds.

How can I do this?


Answer: You could use
[threading.Timer](http://docs.python.org/library/threading.html#timer-
objects):

    
    
    import threading
    import logging
    
    def print_timer(count):
        if count:
            t = threading.Timer(10.0, print_timer,args=[count-1])
            t.start()
        logger.info("Begin print_timer".format(c=count))
        time.sleep(15)
        logger.info("End print_timer".format(c=count))
    
    def using_timer():
        t = threading.Timer(0.0, print_timer,args=[3])
        t.start()
    
    if __name__=='__main__':
        logging.basicConfig(level=logging.DEBUG,
                            format='%(threadName)s: %(asctime)s: %(message)s',
                            datefmt='%H:%M:%S')    
        using_timer()
    

yields

    
    
    Thread-1: 06:46:18: Begin print_timer  --
                                             | 10 seconds
    Thread-2: 06:46:28: Begin print_timer  --
    Thread-1: 06:46:33: End print_timer      | 10 seconds
    Thread-3: 06:46:38: Begin print_timer  --
    Thread-2: 06:46:43: End print_timer      | 10 seconds
    Thread-4: 06:46:48: Begin print_timer  --
    Thread-3: 06:46:53: End print_timer
    Thread-4: 06:47:03: End print_timer
    

Note that this will spawn a new thread ever 10 seconds. Be sure to provide
some way for the thread-spawning to cease before the number of threads becomes
intolerable.

