Thursday, June 9, 2016

EASY TO WAIT IN APPIUM WITHOUT GETTING TIMEDOUT AND SHUTTING DOWN APPIUM SERVER

Here, problem is Appium gets timed out if it doesn't get any new command for specific time.
This can be solved by two ways:

1. Simulate ExplicitWait to wait for specific time.



public void wait(int timeInSec) throws Exception {

log.info("Wait for " + timeInSec + " Seconds");

WebDriverWait wait = new WebDriverWait(_Driver, timeInSec);

try {
wait.until(ExpectedConditions.visibilityOfElementLocated(By
.className("dummy")));
} catch (Exception e) {

}

}


Here, we are continuously waiting for visibility of elements having className as "dummy" that doesn't exists means Appium is getting continuous commands till timeout provided in explicit wait. And after waiting for timeout "timeInSec", it will throw timedout exeception that we are catching in catch block.
So call "wait(int timeInSec)" method wherever you want to wait, Appium will not get timedout.


2. Second solution would be to increase "New_Command_Timeout" for Appium. That we can achieve by setting it in DesiredCapability like below:


DesiredCapabilities capabilities = new DesiredCapabilities();
.....
capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT,900);
.....


Here we set NEW_COMMAND_TIMEOUT to 15 minutes.


Happy Automation !!

No comments:

Post a Comment