Speeding up Test Automation with Appium

Share

It is essential to run tests in a distributed fashion in order to get quicker results and also, concurrently, to get better device coverage. Appium, a cross platform automation tool, can run tests on both Android and iOS. Android testing is complicated enough with device and OS fragmentation. Automated Android testing is extremely important in order to release or update mobile apps in a growing, fast-paced environment. Appium is considered to speed up automated Android testing.

There are three special capabilities available in Appium for speeding up Android test initialization (available in the latest Appium version). Also, using the appPackage and appActivity desired capabilities instead of the app capability, help in speeding up Android test automation.

  1. skipDeviceInitialization
  2. skipServerInstallation
  3. ignoreUnimportantViews

skipDeviceInitialization is available for all Android platforms. This desired capability can be passed with the boolean value, true to skip installing the io.appium.settings app on the device. This special app is installed by the Appium Android Driver at the beginning of each test and is used to manage specific settings on the device, such as: Wifi/data settings

  • Disabling animation
  • Setting a locale
  • IME settings

Without the io.appium.settings app, the Appium Android driver cannot automate these functions. But if the device previously, had this app installed by Appium, you don’t need to install it again. If you know that your device is already in the proper state, then you can set skipDeviceInitialization to true and skip the time it takes to reinstall it. Appium checks if the settings app is already installed on the device, but with this capability enabled it even skips the check to see if the app is installed.

skipServerInstallation desired capability only applies when using the UiAutomator2 automation method. The way the UIAutomator2 driver works, it installs a special server onto the device, which listens to test commands from Appium and executes them. By default, Appium installs this server onto the device at the beginning of every test session. If the value of skipServerInstallation is set to true, you can skip the time it takes to install this server. Of course, without the server on the device Appium can’t automate it. But if you know that the server was installed during a previous test run, you can safely skip this step.

ignoreUnimportantViews desired capability is not new, but it deserves to be mentioned as another way to potentially speed up Android automation tests, especially if your tests focus on finding many elements using XPath locators. Set this to true to speed up Appium’s ability to find elements in Android apps.

Another major time-saver when it comes to Android tests is using the appPackage and appActivity desired capabilities instead of the app capability.  Appium needs to know which app to test. Usually, you use the app capability, which can be a path to an .apk, .apks, or a .zip file stored in your computer’s filesystem or on a public website. If the app under test is known to be already installed on the device (most likely from a previous test run), the app package name and main activity can be passed instead (using appPackage and appActivity desired capabilities). Skipping the time to download a large file or install it on the Android operating system leads to big savings.

Below is the sample code which explains how you can use it in your automation script:

DesiredCapabilities caps = new DesiredCapabilities();

caps.setCapability(“platformName”, “Android”);

caps.setCapability(“deviceName”, “Android Emulator”);

caps.setCapability(“automationName”, “UiAutomator2”);

// App is already installed on device, so can be launched by Package name and Activity

caps.setCapability(“appPackage”, “io.cloudgrey.the_app”);

caps.setCapability(“appActivity”, “io.cloudgrey.the_app.MainActivity”);

// Skip the installation of io.appium.settings app and the UIAutomator 2 server.

caps.setCapability(“skipDeviceInitialization”, true);

caps.setCapability(“skipServerInstallation”, true);

caps.setCapability(“ignoreUnimportantViews”, true);

driver = new AppiumDriver(new URL(“http://localhost:4723/wd/hub”), caps);

Appium Testing- Facilitating Android Automation

Appium allows testers to install applications on devices, simulate and automate several use cases. The devices employed in Appium for Android testing can be connected remotely, locally or be emulated. With these instructions and few examples, you should be able to build tests that get started instantly, enable simultaneous test runs and provide you with the results from devices that you feel are important for your app.

Try to practice the above mentioned methods in your Android Automation and feel the difference in execution speed.

 

By Sanoj Swaminathan

Test Architect, RapidValue

2 COMMENTS

  1. David says:

    Hi Sanoj, for speeding up iOS, what do you recommend?

  2. Sanoj says:

    Hi David,

    Following are the details for iOS,

    First improvement is to set the app location to a file already on the host device. Then you can directly use the bundleId (example: caps.setCapability(“bundleId”, “io.test.app”);). Please ignore the remote path of your application in the code instead of that you can use the local application path, once it gets installed on the device avoid the local path and stick to use bundleId.

    Running the tests, it’s easy to notice that the app gets reinstalled on the device for each test. This takes a lot of time and can be skipped. You may have certain tests which require a fresh install or need all the app data cleaned, but those tests could be put into a separate suite, leaving the majority of tests to run faster by reusing the same app. Most users should be familiar with the noReset desired capability.

    Appium uses the simctl command-line tool provided by Apple to match the deviceName desired capability to the udid of the device. We can skip this step by specifying the device udid ourselves.

    When loading the WedDriverAgent server, Appium loads the files from wherever XCode saved it after compilation. This location is called the “Derived Data Directory” and Appium executes an xcodebuild command in order to get the location. You can use the desired capability derivedDataPath allowing Appium to skip the work of calculating it.

    The last optimization is to specify the webDriverAgentUrl desired capability. If specified, Appium skips a step where it checks to make sure that there are no obsolete or abandoned WebDriverAgent processes still running. The WebDriverAgent server needs to already be running at this location, so we can only use this desired capability after the first test starts the server.

    Thanks,
    Sanoj

Please Share Your Thoughts & Comments Below.

How can we help you?