AWS Mobile Blog

Test iOS apps on AWS Device Farm using Appium – Part 2: Packaging your TestNG test suite for AWS Device Farm

by Asha Chakrabarty | on | Permalink | Comments |  Share

With AWS Device Farm, you can quickly get started testing your Android, iOS, and FireOS apps on real devices in the AWS cloud. Simply upload your app, choose your test framework and the devices you want to test your app on, and start your test run. AWS Device Farm will provide the results of your tests including pass / fail status, logs, performance characteristics, and screenshots.

Previously in Part 1, we focused on the prerequisites and creation of the TestNG test suite. In this article, Part 2 of the three-part series, we will walk through how to package your test suite for uploading to AWS DeviceFarm. Before uploading your test suite to AWS Device Farm, the test suite should be packaged correctly and contain all the required dependencies. Both the tests and associated dependencies must be packaged as a zip file. In Part 3, we will upload the package from this post and run the tests on AWS Device Farm.

Package your TestNG Test Suite

Create a new Maven project in Eclipse using the quickstart archetype (maven-archetype-quickstart). It is recommended to match the Group Id / Artifact Id with the root package as shown in the sample pom.xml. For this sample, our package name is com.aws.devicefarm.example.appiumiostest.

Copy the TestNG class created in the previous step to your Maven project under src/test/java.

Save the following XML assembly to src/main/assembly/zip.xml. The following XML is an assembly definition that, when configured, instructs Maven to build a .zip file containing everything 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>

Replace your pom.xml with the following (NOTE: Change the groupId, artifactId, and name elements to match that of your Maven project).

	<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

	  <modelVersion>4.0.0</modelVersion>

	

	  <groupId>com.aws.devicefarm.example</groupId>

	  <artifactId>appiumiostest</artifactId>

	  <version>0.0.1-SNAPSHOT</version>

	  <packaging>jar</packaging>

	  <name>appiumiostest</name>

	  <url>http://maven.apache.org</url>

	

	  <properties>

	    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

	  </properties>

	  <dependencies>

	        <dependency>

	            <groupId>org.testng</groupId>

	            <artifactId>testng</artifactId>

	            <version>6.8.8</version>

	            <scope>test</scope>

	        </dependency>

	        <dependency>

	            <groupId>org.seleniumhq.selenium</groupId>

	            <artifactId>selenium-java</artifactId>

	            <version>2.42.2</version>

	        </dependency>

	        <dependency>

	            <groupId>io.appium</groupId>

	            <artifactId>java-client</artifactId>

	            <version>1.4.0</version>

	        </dependency>

	  </dependencies>

	  <build>

	        <plugins>

	            <plugin>

	                <groupId>org.apache.maven.plugins</groupId>

	                <artifactId>maven-jar-plugin</artifactId>

	                <version>2.6</version>

	                <executions>

	                    <execution>

	                        <goals>

	                            <goal>test-jar</goal>

	                        </goals>

	                    </execution>

	                </executions>

	            </plugin>

	            <plugin>

	                <groupId>org.apache.maven.plugins</groupId>

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

	            <plugin>

	                <artifactId>maven-assembly-plugin</artifactId>

	                <version>2.5.4</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>

	        </plugins>

	  </build>

	</project>

Build, package, and verify your Maven project using the following command.

mvn clean package –DskipTests=true

The Maven project structure should look similar to the below. Note the zip-with-dependencies file that was created under the “target” folder. This contains our test code with all dependencies:

Summary

Now that we have packaged our tests and have a sample iOS app to test, in Part 3 we will upload both to AWS Device Farm to test across multiple devices and receive test results within minutes. Feel free to post any suggestions, comments or questions in the comments section below or in our developer forum. We look forward to hearing your feedback.