Refactoring -4

When we want to use the app that is already installed on the emulator, we need to use the appPackage and appActivity capabilities and not use the app capability. Let's look at the code we have written till now for starting an app in the HomePageSteps.

@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("noReset", false);
capabilities.setCapability("fullReset", true);
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);
}

When we execute the preceding code, it performs a full reset and deploys the app every time. Let's modify this code to use the installed app and perform a fast reset of the app. Comment or delete the lines, as shown:

        // capabilities.setCapability("noReset", false);
// capabilities.setCapability("fullReset", true);
// capabilities.setCapability("app",
"/Users/nishant/Development/HelloAppium/app/quikr.apk");

Also, add the following lines. Once done, run the test by right-clicking on the feature file and selecting the Run Scenario... option:

capabilities.setCapability("appPackage", "com.quikr");
capabilities.setCapability("appActivity", "com.quikr.old.SplashActivity");

If we have an Android virtual device created (using Android SDK, we created one in Chapter 2, Setting Up the Machine), we can use the following code that will start the emulator first and then run the test:

capabilities.setCapability("avd", "Nexus6_API_24");
capabilities.setCapability("avdReadyTimeout", 180000);

So, with the preceding change, the iLaunchQuikrApp method will look like this:

@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("newCommandTimeout", 120);

// Launches the below android virtual device and waits for 120
seconds for AVD to be ready
capabilities.setCapability("avd", "Nexus6_API_24");
capabilities.setCapability("avdReadyTimeout", 120000);

capabilities.setCapability("appPackage", "com.quikr");
capabilities.setCapability("appActivity",
"com.quikr.old.SplashActivity");

appiumDriver = new AppiumDriver(new
URL("http://0.0.0.0:4723/wd/hub"), capabilities);
appiumDriver.manage().timeouts().implicitlyWait(60,
TimeUnit.SECONDS);
}

Once we make the preceding changes, we should be able to run it; this will launch the Android virtual device as well before triggering the test on it.

Let's take a look at the iOS only capabilities. Even though the app behavior is more or less similar across the devices, Appium exposes a bunch of different sets of capabilities for iOS.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.224.226