I need to wait in the middle of my test for 5 minutes but the Appium session has default newCommandTimeout of 60s. and I get exception in the next command that my session is timeout.
AndroidDriver appiumDriver = new AndroidDriver(new URL(getMcmUrl()), capabilities);
Thread.sleep(5*60*1000); // 5 minutes sleep time
appiumDriver.executeScript("...")
in case that the timeout is 60s, you need to execute any command at least once in a minute, to keep the session alive. Show activity on this post. In your DesiredCapabilities add newCommandTimeout capabilities. DesiredCapabilities caps=new DesiredCapabilities(); //other desired caps //add the following line caps.
The default suggested timeout for a test run on Bitbar Testing is 10 minutes, which can be adjusted according to your personal needs up to 60 minutes. To adjust this timeout with the client-side Appium, you'll need to familiarize yourself with a new capability and use it in your scrips – testdroid_testTimeout.
sleep() is a static wait, it is not recommended in the appium scripting you can use Implicit wait, It can be applied to all steps where you are locating the elements. It can be used immediately after initializing the driver object. Below is the code syntax.
Implicit wait is a way to tell the Appium driver to poll the DOM (Document Object Model) for a certain amount of time before throwing an exception to the effect that it can't find the element on the page. The default timeout value is set to 0 seconds.
newCommandTimeout:
How long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the session
in case that the timeout is 60s, you need to execute any command at least once in a minute, to keep the session alive.
For example, this is how sleep for 5 minutes should look like
for (int i = 0; i < 5; i++) {
driver.getOrientation(); // execute some command to keep the session alive
Thread.sleep(59*1000); // wake up before session expired
}
Read this article for more information
https://l18.me/how-to-keep-alive-appium-driver-da9227b2fa
In your DesiredCapabilities add newCommandTimeout capabilities.
DesiredCapabilities caps=new DesiredCapabilities();
//other desired caps
//add the following line
caps.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 300);
//then define your driver here
AppiumDriver<MobileElement> driver= new AndroidDriver(new URL(getMcmUrl()), caps);
newCommandTimeout means How long (in seconds) Appium will wait for a new command from the client before assuming the client quit and ending the session.
300 sec = 5 minutes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With