Search code examples
javamavenautomated-testsjunit4aws-device-farm

AWS Device Farm: APPIUM_JAVA_JUNIT_TEST_PACKAGE_CLASS_FILE_MISSING_IN_TESTS_JAR


I am trying to upload Appium Java JUnit tests to AWS Device Farm. I configured my pom.xml file like this:

<?xml version="1.0" encoding="UTF-8"?>
<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.acme</groupId>
   <artifactId>acme-android-appium</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>jar</packaging>
       <repositories>
            <repository>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
                <checksumPolicy>fail</checksumPolicy>
            </releases>
            <id>Experitest.repo1</id>
            <name>YourName</name>
            <url>https://cloud.experitest.com/repo/</url>
            <layout>default</layout>
        </repository>
    </repositories>
   <build>
      <sourceDirectory>src</sourceDirectory>
      <plugins>
         <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
               <source>1.8</source>
               <target>1.8</target>
            </configuration>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <classesDirectory>dummy</classesDirectory>
            </configuration>
            <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>
   <dependencies>
      <dependency>
         <groupId>com.amazonaws</groupId>
         <artifactId>aws-lambda-java-core</artifactId>
         <version>1.1.0</version>
      </dependency>
      <!-- extentreports -->
      <dependency>
         <groupId>com.relevantcodes</groupId>
         <artifactId>extentreports</artifactId>
         <version>2.41.2</version>
      </dependency>
      <dependency>
         <groupId>com.experitest</groupId>
         <artifactId>appium</artifactId>
         <version>4.1.2</version>
      </dependency>
   </dependencies>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
</project>

When I am trying to compile my code by maven (through CMD with this command: mvn clean package -DskipTests=true) I got some info rows including this information:

[WARNING] /C:/Users/Adam Peretz/workspace/Sweetch/src/Utilites/CommonOps.java: Some input files use unchecked or unsafe operations.

[WARNING] /C:/Users/Adam Peretz/workspace/Sweetch/src/Utilites/CommonOps.java: Recompile with -Xlint:unchecked for details.

[WARNING] JAR will be empty - no content was marked for inclusion!

[INFO] BUILD SUCCESS

and after it, I uploaded the "zip-with-dependencies.zip" file to AWS Device Farm and got this error:

There was a problem processing your file. We could not find a class file within the tests JAR file. Please unzip your test package and then unjar the tests JAR file, verify that at least one class file is within the JAR file, and try again. For more information about this issue, please see the documentation.

What should I do? I really don't know what to do, I tried everything.


Solution

  • Where did you put the Java files? The warning relates back to the jar file that's created by default in maven and not the *-test.jar

    Device Farm uses the *-test.jar file and the error message suggests that it is empty. Are the test Java files under ./src/test/java? If not they will need to be otherwise maven will not package those class files into the *-test.jar.

    Here is an example to compare with.

    https://github.com/aws-samples/aws-device-farm-appium-tests-for-sample-app

    Hope that helps

    James