Search code examples
javaseleniumselenium-webdriversleepthread-sleep

Sleep Interupt Exception: java.lang.InterruptedException: sleep interrupted - How to give timeout for browser for 40mins


I am trying to download an excel report from an web based application, which takes 30 mins for it to start downloading after I click 'download' button (30 mins for it to get generated and start downloading). Size of the file will be around 54 MB. Below is my code:

driver().findElement(By.xpath(locator_for_download)).click(); //to click on download button
TimeUnit.SECONDS.sleep(2400); //making it to sleep for 40 mins so that my report gets downloaded.

But, once 'download' button is clicked, after 5 mins I get below error and browser closes:

Exception: java.lang.InterruptedException: sleep interrupted

I have tried to give implicit wait for 2400 seconds:

driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS); 

and also pageload timeout none worked.

P.S - there is no change in the URL for whatever actions we perform on it. Web application has iframes and I am doing automation in Google chrome browser.

Can anybody please help me how do i download my report as sleep is not working for me? Is it because of the browser timeout being less and is forcefully shutting down? Any help really appreciated.


Solution

  • I think you are running the scripts on the node (grid/node model), if the answer is Yes. Then it explains why you are getting this exception.

    In your case the sleep time > node timeout, which is causing the exception. Default timeout for the node is 300 seconds (5 minutes), meaning if the node does not receive a command within the 5 minutes then hub will automatically release the node. If you want to wait for more than 5 minutes then you have to change the either set -timeout = 0 (to removes timeout completely) or increase it based on your scenario.

    Refer to SeleniumHQ Grid documentation here for more information.