Skip to main content

Development

Mobile Testing on Cloud with Appium Using AWS Device Farm

With Amazon’s Device Farm technology, you can now easily upload your app and choose an Android or an iOS device to test your app. You will get screenshots, videos of the tests that were run and most importantly, the real-time reports of the tests that were completed. It is as simple as uploading a file that contains your test cases with all the dependencies that were used in the project and click on Run.

Building Test Package Using Maven

The file that you upload to the Device Farm should be in a zip format containing your test classes as well as all the dependencies in one fat jar file. You can see how to do that below:

Set the packaging to ‘jar’ in your pom.xml file, like below:

<groupId>com.aws.appium</groupId>
   <artifactId>appium-android-test</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>jar</packaging>

 

Maven Jar Plugin

Add the Maven jar plug-in to your pom.xml to build all the test cases that are in the src/test directory (the plug-in chooses this path by default), into a big fat jar file:

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-jar-plugin</artifactId>
     <version>3.0.2</version>
     <executions>
        <execution>
           <goals>
              <goal>test-jar</goal>
           </goals>
        </execution>
     </executions>
   </plugin>

 

Maven Dependency Plugin

Add the Maven dependency plug-in to your pom.xml to copy and build a jar file into the dependency-jars directory:

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-dependency-plugin</artifactId>
     <version>3.0.0</version>
     <executions>
       <execution>
          <id>copy-dependencies</id>
          <phase>package</phase>
          <goals>
             <goal>copy-dependencies</goal>
          </goals>
          <configuration>
             <outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
          </configuration>
       </execution>
     </executions>
   </plugin>

 

Assembly.xml to create a ZIP file

Add the below XML assembly definition to src/main/assembly/zip.xml, to build a .zip file with everything that is in the root of your build output directory and the dependency-jars directory:

<assembly
   xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0
   http://maven.apache.org/xsd/assembly-1.1.0.xsd">
      <id>zip</id>
      <formats>
         <format>zip</format>
      </formats>
      <includeBaseDirectory>false</includeBaseDirectory>
      <fileSets>
         <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory>./</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
         </fileSet>
         <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory>./</outputDirectory>
            <includes>
                <include>/dependency-jars/</include>
            </includes>
         </fileSet>
      </fileSets>
   </assembly>

 

Maven Assembly Plugin

Add the Maven assembly plug-in to your pom.xml to build the test cases and the dependencies into a .zip file. Whenever the mvn package is run, this plug-in creates a zip-with-dependencies.zip file in the build output directory:

<plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <version>3.0.0</version>
      <executions>
         <execution>
             <phase>package</phase>
             <goals>
                <goal>single</goal>
             </goals>
             <configuration>
                <finalName>zip-with-dependencies</finalName>
                <appendAssemblyId>false</appendAssemblyId>
                   <descriptors>
                       <descriptor>src/main/assembly/zip.xml</descriptor>
                   </descriptors>
             </configuration>
         </execution>
      </executions>
   </plugin>

 

Building the Maven project

Now do a clean, build and verify, like below

 $ mvn clean package –-DskipTests=true

 

AWS Device Farm

Go to the Amazon Device Farm and sign in to the console. Under Mobile services, click on Device Farm.
Then click ‘+Create a new project‘ button. Enter a project name like below and click Create Project

Mobile Testing on Cloud with Appium Using AWS Device FarmClick on ‘Create a new run’ button to configure your test

Mobile Testing on Cloud with Appium Using AWS Device Farm

Upload your app’s *.apk file

Mobile Testing on Cloud with Appium Using AWS Device Farm

Select the appropriate test type, in our case it is Appium Java TestNG. Then upload the zip-with-dependencies.zip file that we have already built using Maven to the Device Farm.

Mobile Testing on Cloud with Appium Using AWS Device Farm

Choose one or more devices that you want your test(s) to run. AWS Device Farms automatically check and let you know if the app is compatible with the devices that you choose. You can also add and customize a separate set of devices for your app by clicking on ‘Create a new device pool’.

Mobile Testing on Cloud with Appium Using AWS Device Farm

It is optional to set the device state parameters like uploading another apk, enabling WiFi, Bluetooth, GPS, etc. as per your requirement on the next screen

Mobile Testing on Cloud with Appium Using AWS Device Farm

Review and set up the time limit per device. The first few minutes of testing is free as a part of free trial and after which Amazon charges as per the requirement.

Mobile Testing on Cloud with Appium Using AWS Device Farm

After you click on ‘Confirm and start run‘ button, the app will be installed on the selected devices in the AWS Device Farm and it will start executing the tests. Once your tests are run, you can see the summary of the test report like below

Mobile Testing on Cloud with Appium Using AWS Device Farm

The tests are run based on the availability of the device (usually in few seconds) and the console displays the testing status. Also we have access to the screenshots, the video of the tests that were captured during the execution, CPU performance of the device, etc.

Mobile Testing on Cloud with Appium Using AWS Device Farm

 

Capturing screenshots

Apart from capturing video, AWS Device Farm allows you to take screenshots of the tests while running. Below is the code snippet to take screenshots. Edit and add them to your tests and you will be all set.

public boolean takeScreenshot(final String name) {
   String screenshotDirectory = System.getProperty("appium.screenshots.dir", 
   System.getProperty("java.io.tmpdir", ""));
   File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
   return screenshot.renameTo(new File(screenshotDirectory, String.format("%s.png", name)));
   }

The AWS Device Farm can further be enhanced by automating all of the above steps using Selenium WebDriver. It can also be integrated with Jenkins and other Continuous Integration tools.

Check out the blog by Eric Guo on How to Configure Appium Grid for Mobile Automation Testing.

 

Source:

http://docs.aws.amazon.com/devicefarm/latest/developerguide/

Thoughts on “Mobile Testing on Cloud with Appium Using AWS Device Farm”

  1. Thanx for sharing this valuable information with us.

    I also work as a software tester but I have never be into the automated testing.

    Can you tell me one thing?

    If I want to shift to automation testing after 3 years of experience in manual testing.

    Is it possible for me?

    Please suggest, right now I am like a muddleheaded.

  2. HI is it possible to configure mobile grid on aws . Instead of single devices. selenium grid for appium on aws device farm .

  3. Derrick Nirmal Post author

    Hi Kiran, you can add your tests to the AWS to execute them on multiple devices in parallel (by default, you can always have the tests running on 5 devices in parallel). But, if you are trying to split your tests, say 2 tests on each mobile device, then I doubt that this feature is not added yet to the AWS Device Farm, as of today.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Derrick Nirmal

More from this Author

Categories
Follow Us