Handle the idle timeout error
Learn about possible solutions to resolve the BROWSERSTACK_IDLE_TIMEOUT error in this section.
Issue
When you run a test using BrowserStack App Automate, the following error might appear in the Text Logs
section of your App Automate session page:
[BROWSERSTACK_IDLE_TIMEOUT] Session timed out due to inactivity for configured time interval (default: 90 secs)
Cause
Some common causes for the BROWSERSTACK_IDLE_TIMEOUT
error to occur are as follows:
- The
driver.quit
command is not added in the test script. - The test script has encountered some exceptions due to which it failed to run the
driver.quit
command. - The test script paused the test execution for more than 90 seconds.
Resolution/Workaround
Try the following resolutions to resolve the BROWSERSTACK_IDLE_TIMEOUT
error:
- Add the driver.quit command in test script
- Increase the default timeout duration
- Handle exceptions in the test script
Add driver.quit command in test script
BrowserStack, by default, does not know when your test scripts have completed running. Add the following driver.quit
command at the end of your test script to let BrowserStack know about the completion of all test commands.
driver.quit();
driver.quit();
driver.Quit();
$driver->quit();
driver.quit()
driver.quit
$driver->quit();
BROWSERSTACK_IDLE_TIMEOUT
error even after adding driver.quit
in your test script. In such a case, your test script might have encountered an unhandled exception. This exception prevents the test flow from reaching the driver.quit
command, resulting in a timeout error. Check out the handle exceptions to learn about exception handling.
Increase timeout duration
BrowserStack generates a BROWSERSTACK_IDLE_TIMEOUT
error if a session has not received any commands for more than the default timeout of 90 seconds.
You might get the BROWSERSTACK_IDLE_TIMEOUT
error even if the driver.quit
command is added to the test script. This happens because a test command took more than 90 seconds to run. Thus, the test script fails to reach and run the driver.quit
command, resulting in a timeout.
If you anticipate that a test command might take more than 90 seconds to run, you can increase the timeout using either the idleTimeout
capability or Appium’s newCommandTimeout
capability.
When using the idleTimeout
capability, you can increase the timeout to a maximum of 300 seconds.
Use the following sample code snippets to set the idleTimeout
capability in your test script:
If you are using BrowserStack SDK, you can set the capabilities covered in this document within the browserstack.yml
file:
BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.
DesiredCapabilities caps = new DesiredCapabilities();
// BrowserStack's capability to increase timeout duration to a maximum of 300 seconds
caps.setCapability("browserstack.idleTimeout", "<time_in_seconds>");
// Appium's capabiliy to increase timeout duration
caps.setCapability("newCommandTimeout", "<time_in_seconds>");
var capabilities = {
// BrowserStack's capability to increase timeout duration to a maximum of 300 seconds
"browserstack.idleTimeout" : "<time_in_seconds>",
// Appium's capabiliy to increase timeout duration
"newCommandTimeout", "<time_in_seconds>",
}
AppiumOptions capabilities = new AppiumOptions();
// BrowserStack's capability to increase timeout duration to a maximum of 300 seconds
capabilities.AddAdditionalCapability("browserstack.idleTimeout", "<time_in_seconds>");
// Appium's capabiliy to increase timeout duration
capabilities.AddAdditionalCapability("newCommandTimeout", "<time_in_seconds>");
$caps = array(
# BrowserStack's capability to increase timeout duration to a maximum of 300 seconds
"browserstack.idleTimeout" => "<time_in_seconds>",
# Appium's capabiliy to increase timeout duration
"newCommandTimeout" => "<time_in_seconds>",
);
capabilities = {
# BrowserStack's capability to increase timeout duration to a maximum of 300 seconds
"browserstack.idleTimeout": "<time_in_seconds>",
# Appium's capabiliy to increase timeout duration
"newCommandTimeout": "<time_in_seconds>",
}
caps = Selenium::WebDriver::Remote::Capabilities.new
# BrowserStack's capability to increase timeout duration to a maximum of 300 seconds
caps["browserstack.idleTimeout"] = "<time_in_seconds>"
# Appium's capabiliy to increase timeout duration
caps["newCommandTimeout"] = "<time_in_seconds>"
my $capabilities = {
# BrowserStack's capability to increase timeout duration to a maximum of 300 seconds
"browserstack.idleTimeout" => "<time_in_seconds>",
# Appium's capabiliy to increase timeout duration
"newCommandTimeout" => "<time_in_seconds>",
}
Handle exceptions
When your test script encounters an exception in the test flow, it might never reach the driver.quit
command in your test script.
Some of the common causes for the exception to occur are:
- Unable to locate an element on the screen
- Elements are not interactable or clickable
- Elements did not load within a particular time, etc.
The recommended way to handle exceptions is to use a try...catch
block in your test scripts. As a best practice add your code statements in a try
block, and add the logic to handle any exceptions in the catch
block of your test script.
Adding the try...catch
block ensures that irrespective of whether the test script encounters an error or not, the driver.quit
command is executed to avoid the BROWSERSTACK_IDLE_TIMEOUT
error.
Check out our getting started section to see a sample script that uses wait.
Need some help?
If you need additional help, contact our Support team.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!