Test Amazon Shopping App with Aws DeviceFarm and Appium

Raghwendra Sonu
4 min readMay 21, 2020

Introduction to AWS Device Farm

AWS Device Farm is App Service Testing hosted by Amazon. This provides platform to test and interact with iOS, Android and web applications on real mobile devices and tablets. AWS Device farm can be used for :

1. Automated testing of apps and

2. Remote access of devices for real time interaction.

Why Appium with AWS Device Farm?

There are many reasons for this, like support for parallel execution. Availability of multiple mobile and tablet devices and also it helps us to identify

Here is the list of pre- requisite:

1. Appium (Prefer using latest stable version)
2. Java IDE- I will be using Eclipse
3. Appium script written in Java, TestNG, Maven
4. AWS Account with IAM user permissions

Here is the list of supported methods to test applications on AWS Device Farm.

> Appium Java JUnit
> Appium Java TestNG
> Appium Python
> Calabash
> Instrumentation
> UI Automator

Here is what needs to be done to execute Appium tests on AWS Device Farm?

We have to do two things:
1. Appium Java package wrapped into .zip format for upload on AWS Device Farm
2. Package contain all of the test's dependencies.

Preparing Android Appium Java TestNG

Step 1:

Ensure that packaging type is Jar in POM.xml file. This jar file will be used in AWS device farm to execute our tests.

Step 2:

Add the below plugin in POM file, this will allow to package our test classes as a jar file using “test-jar” goal.

<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>

Step 3:

Add maven-dependency-plugin to build dependencies as JAR files using “copy-dependencies” goal. This takes the list of project dependencies and copies them to a specified location, stripping the version if desired.

<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</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>

Step 4:

We need to copy zip.XML assembly file from AWS to our project directory. This zip file will copy all dependencies jar directory and the jar file that contains all the test scripts. It will bundle everything and finally create a zip file. This xml file should be placed inside “src/main/assembly/zip.xml” folder.

<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>

Step 5:

Use maven-assembly-plugin to package tests and all dependencies into a single zip file.

            <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</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>

Step 6:

Build, package and verify

mvn clean package -DskipTests=true

Step 7:

Upload the package on Device Farm Console.

We need to upload all the artifacts highlights from above screenshot in the AWS device farm, as Device Farm will be using them. Below are the steps for this.

Follow the steps as in above diagram, after login to AWS, create a new run, upload zip file of the application, select devices to execute tests and start run.

Once the execution is completed, you will see report, screenshots and execution video. You can also explore logs. Just to let you know AWS device farm gives initial 250 minutes of test execution fee of cost.

Hope this was useful! If you ever need my help, you can write in comments sections. Also, you can contact me through my LinkedIn Profile.

Git repository for the project used in this article is here:

https://github.com/raghwendra-sonu/AWSDeviceFarm

--

--

Raghwendra Sonu

Software Automation Testing expert with 9 years of work experience in diverse tools and technologies.