How to provide your TestsScripts & Dependencies to AWS Device Farm

02 / May / 2016 by Sumit Gambhir 1 comments

If you are using Appium, TestNG & Maven test frameworks and Java language for your mobile automation project, then it’ll help you.

To run your Appium Java TestNG scripts, you need to club your test-cases & all the dependencies in one file and provide it to Device Farm. And to attain this, do some modifications in the pom.xml file in your project.

i) Set packaging as a JAR file:

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

ii) Include maven-jar-plugin to build your tests into a JAR file:

This plugin will build your test source code (anything on this path src/test directory) into a JAR file.

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

 

iii) Use maven-dependency-plugin which will build all the dependencies as JAR files:

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

iv) Now save the following XML assembly to this path (src/main/assembly/zip.xml).

This XML is an assembly definition which will 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>

 

v) Use maven-assembly-plugin to club all the test cases and dependencies:

Now after adding the above assemble, use this plugin maven-assembly-plugin which will package all tests and dependencies into a single .zip file.

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

 

vi) At Last, build the package with the following command

In command prompt & the directory should be that where pom.xml file exist:

mvn clean package -DskipTests=true

After successful build, you can check the target folder, all your test-cases & dependencies have been club in single .zip file named zip-with-dependencies.zip

targetFolder
Then use this file to automate your test-cases on AWS Device Farm:  on the Configure test page, choose Appium Java TestNG as test suite and Upload this file ‘zip-with-dependencies.zip’ and Enjoy your test-suite on multiple devices in parallel. :)

uploadDependencies

FOUND THIS USEFUL? SHARE IT

comments (1 “How to provide your TestsScripts & Dependencies to AWS Device Farm”)

Leave a comment -