Let's add a couple of desired capabilities to our test now. One of the important concepts of test automation is to start with a clean slate; hence, we will add fullReset capabilities. Also, the Appium server waits for 60 secs for the new command by default, and then it quits the session because of inactivity; so we will tweak it a little to wait for 120 seconds now:
- fullReset: This is to reset the app state between each test
- newCommandTimeout: This is to stop the session from quitting if new commands are not passed within 120 seconds
Let's add these capabilities in the HomePageSteps class file under the iLaunchQuikrApp() method:
@When("^I launch Quikr app$")
public void iLaunchQuikrApp() throws Throwable {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "5.1");
capabilities.setCapability("deviceName", "Nexus");
capabilities.setCapability("fullReset", true);
capabilities.setCapability("newCommandTimeout", 120);
capabilities.setCapability("app",
"/Users/nishant/Development/HelloAppium/app/quikr.apk");
appiumDriver = new AppiumDriver(new
URL("http://0.0.0.0:4723/wd/hub"), capabilities);
appiumDriver.manage().timeouts().implicitlyWait(60,
TimeUnit.SECONDS);
}
We can try running the scenario again, and it will work seamlessly. After every refactoring, ensure that you execute the code so that you know the impact of the change.