How to provide your TestsScripts & Dependencies to AWS Device Farm

02 / May / 2016 by Sumit Gambhir 8 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:

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

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.

[java]
<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>
[/java]

 

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

[java]
<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>
[/java]

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:

[java]
<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 ;
<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>
[/java]

 

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.

[java]
<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>
[/java]

 

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

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

[java]mvn clean package -DskipTests=true[/java]

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 (8)

  1. vaidehi

    Hi,

    I am facing the issue in creating zip file.
    tests jar are created successfully but it is not creating dependency jar and zip folder for the same.

    My ‘classes’ & ‘test-cases’ folder are created in target folder.

    please suggest me solution.

    Reply
    1. Sumit

      Hi Jahnvi, thanks for reading this article. I just want to say, please recheck at your framework level, that you must have to follow these steps:

      1. Folder structure should be as per Maven project, i.e. ‘src’ will have ‘main’ & ‘test’, then ‘test’ will have your ‘classes’ & ‘test-cases’
      2. Update your ‘pom’ file as per the above steps (you can use latest versions of plugins)
      3. The plugins you mentioned in your ‘pom’ file will consider only that stuff available in you test directory (path: src/)
      After re-verifying just re-build the package (step-vi in the blog)

      Reply
  2. ahmed

    I am doing all these already, Using testNG,Appium java client 5.0.0, selenium 3.0.1, I have added all the deps which can be seen in my comment below but while running my test on AWS farm getting an exception Failed to invoke configuration method login.startsession:com.google.common.collect.Multimaps.transformValues(Lcom/google/common/collect/ListMultimap;Lcom/google/common/base/Function;)Lcom/google/common/collect/ListMultimap;
    [TestNG] FAILED CONFIGURATION: “Command line test” – @BeforeTest login.startsession() finished in 0 ms
    [TestNG] java.lang.NoSuchMethodError: com.google.common.collect.Multimaps.transformValues(Lcom/google/common/collect/ListMultimap;Lcom/google/common/base/Function;)Lcom/google/common/collect/ListMultimap;
    [TestNG] at com.google.common.net.MediaType.toString(MediaType.java:668)
    Here is my POM.xml

    4.0.0
    MontyAWS
    montyandroidd
    0.0.1-SNAPSHOT
    jar

    montyandroidd

    maven.apache.org

    UTF-8

    org.testng

    testng

    6.9.9

    test

    org.seleniumhq.selenium

    selenium-java

    3.0.1

    io.appium

    java-client

    5.0.0-BETA3

    com.google.guava
    guava
    21.0

    com.google.code.gson
    gson
    2.8.0

    org.seleniumhq.selenium
    selenium-server
    3.0.0

    org.apache.maven.plugins

    maven-jar-plugin

    2.6

    test-jar

    org.apache.maven.plugins

    maven-dependency-plugin

    2.10

    copy-dependencies

    package

    copy-dependencies

    ${project.build.directory}/dependency-jars/

    maven-assembly-plugin

    2.5.4

    package

    single

    zip-with-dependencies

    false

    src/main/assembly/zip.xml

    Reply
    1. ahmed

      4.0.0
      MontyAWS
      montyandroidd
      0.0.1-SNAPSHOT
      jar

      montyandroidd

      maven.apache.org

      UTF-8

      org.testng

      testng

      6.9.9

      test

      org.seleniumhq.selenium

      selenium-java

      3.0.1

      io.appium

      java-client

      5.0.0-BETA3

      com.google.guava
      guava
      21.0

      com.google.code.gson
      gson
      2.8.0

      org.seleniumhq.selenium
      selenium-server
      3.0.0

      org.apache.maven.plugins

      maven-jar-plugin

      2.6

      test-jar

      org.apache.maven.plugins

      maven-dependency-plugin

      2.10

      copy-dependencies

      package

      copy-dependencies

      ${project.build.directory}/dependency-jars/

      maven-assembly-plugin

      2.5.4

      package

      single

      zip-with-dependencies

      false

      src/main/assembly/zip.xml

      Reply
      1. Sumit

        Hi Ahmed, thanks for referring this blog.
        There is a problem in your code & the dependency you add in ‘pom’ file for ‘Google Core Libraries’, try the lower version i.e. 18 or 19.
        Then try !!

        Reply

Leave a Reply

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