Does the code written in @BeforeTest, @AfterTest gets included in the package created in TestProject when we upload the jar file? I am using Maven project with TestNG. I had @BeforeTest, @AfterTest and 2 @Test. After uploading the jar file with dependencies, I can only see the 2 tests which were mentioned as @Test in the created package . Because of this I am getting error while executing the test from TestProject as my code for Driverbuilder is inside @BeforeTest.
ChromeDriver driver;
@BeforeTest
public void setup() throws Exception {
System.out.println(“Setup”);
driver = new DriverBuilder(new ChromeOptions())
.withRemoteAddress(new URL(“http://localhost:8585”))
.withToken(“XXXXXXX”)
.build(ChromeDriver.class);
}
Error I am getting is - “Failed to execute test ‘test1’ on Chrome: null” ; Failed to execute test ‘test2’ on Chrome: null
I removed the @BeforeTest and added the DriverBuilder code inside the @Test,created & uploaded the jar file, then created the package, again executed the test but now my test fails with error :
Failed to create an instance of io.testproject.sdk.drivers.web.ChromeDriver
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:17:03’
System info: host: ‘XXXXXXX’, ip: ‘XXXXXX’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘13.0.1’
Driver info: driver.version: unknown
I am working with Java 11, using Test Agent Version 3.5, java-sdk 1.3.0-RELEASE and TestNG 7.5 version. All tests are getting executed in Eclipse successfully.
Hi @parulgoyal ,
Yes, it is included in the package.
This JAR must contain all the dependencies (including TestProject SDK) and your unit tests (JUnit / TestNG).
Since unit Tests are not packaged by default, they must be included explicitly during build.
More valuable information about maven projects you can find here:
Let me know if you have managed.
Hi @alex.ivanov,
Thank you for the reply.
I have used the pom.xml and Assembly descriptor as mentioned in the article mentioned by you.
3 jars were created "TestProjectSDKDemo-0.0.1-SNAPSHOT.jar", “TestProjectSDKDemo-0.0.1-SNAPSHOT-test-jar-with-dependencies.jar” and “TestProjectSDKDemo-0.0.1-SNAPSHOT-tests.jar”. I uploaded “TestProjectSDKDemo-0.0.1-SNAPSHOT-test-jar-with-dependencies.jar”.
But getting errors as mentioned in my original post.
Here is my pom.xml:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.testrojectsdk.demo</groupId>
<artifactId>TestProjectSDKDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.testproject/java-sdk -->
<dependency>
<groupId>io.testproject</groupId>
<artifactId>java-sdk</artifactId>
<version>1.3.0-RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Use maven-jar-plugin to include tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Use maven-assembly-plugin plugin with a custom descriptor -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<!-- Path to the descriptor file -->
<descriptor>src/main/java/assembly/test-jar-with-dependencies.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
Here is my Assembly descriptor:
<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>test-jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<useProjectAttachments>true</useProjectAttachments>
<unpack>true</unpack>
<scope>test</scope>
</dependencySet>
</dependencySets>
</assembly>