Closed jamesknowsbest closed 6 years ago
Related information:
[1] https://github.com/awslabs/aws-device-farm-appium-tests-for-sample-app [2] https://github.com/awslabs/aws-device-farm-sample-app-for-android [3]https://maven.apache.org/pom.html#Resources [4]https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html [5]http://docs.aws.amazon.com/devicefarm/latest/developerguide/troubleshooting-appium-web-java-testng.html
Hello James, Thanks for the update. I'm able to see only one testng.xml is in the test jar root but when I run it, it still run all of the tests. Here are the list of files:
Pom: <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.XXX.webapp</groupId>
<artifactId>XXX-WebApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>XXX-WebApp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>4.1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-validator/commons-validator -->
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>json-path</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.126</version>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
<includes>
<include>testng_TestSmokeTest.xml</include>
</includes>
</testResource>
</testResources>
<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>Smoke_Test</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/zip.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<!-- <configuration>
<suiteXmlFiles>
<suiteXmlFile>Test_Web_Regression_I/Purchase/AWS_QA1_Purchases_Regression_COPY/upgradeSW_Annual_To_U3B.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration> -->
</plugin>
</plugins>
</build>
This is one of the XML: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
then I packaged the zip file, and cd to target folder to run the below command: jar tf XXX-WebApp-0.0.1-SNAPSHOT-tests.jar
I only saw one testng.xml, which is great, however, I upload the test to Device Farm, all the tests being executed instead just the one I specify in the pom and testng.
Issue
When uploading appium testNG test package to aws Device Farm it is required to have the testng.xml file in the root of the jar. This is not clearly documented and this pull request should help with resolving and preventing future issues customers may face
Short Description
This pull request describes how to include the testng.xml files in the root of the jar file created using a maven command from awslabs github project. Resolution
What I did
To exemplify using the testng.xml file we'll use the sample appium java project [1]and the sample android project [2]from awslabs github page.
After downloading or cloning the appium java testng sample project, and extracting it if necessary, change the active directory to that project.
cd aws-device-farm-appium-tests-for-sample-app/
Then we'll create the /src/test/resources directory to take advantage of the super pom default configuration:
mkdir src/test/resources
Content added to the src/test/resources directory gets added because of this tag in the super pom which is configured to added all files to the jar that are in the resources directory [3] . To view the super pom of the project run this command:
mvn help:effective-pom
Alternatively, we can implement the testResources tags in the pom.xml to explictly reference another directory besides src/test/resources as in this maven doc:
https://maven.apache.org/pom.html#The_Super_POM
From docs:
I then created the testng.xml file in the src/test/resources directory and added this content to it to only run the AlertPageTest class:
mvn clean package -DskipTests=true
This created the zip-with-dependencies.zip file in the target directory with the two jar files. I extracted the jar to verify that the test.xml was in the root (see screenshot targetDirectoryBeforeExtraction.png and targetDirectoryAfterExtraction.png) using this command [5]:
jar xf nameOfTheProjectFromPom-1.0-SNAPSHOT-tests.jar