0

I am trying to create a standalone selenium-TestNG tests Jar file that can be executed in any OS as part of CI/CD.

My POM.xml is as follows:

<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>SeleniumTutorial</groupId>
  <artifactId>SeleniumTutorial</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>SeleniumJar</name>
  <description>SeleniumJar</description>

  <repositories> 
  <repository> 
    <id>jcenter</id> 
    <name>bintray</name> 
    <url>http://jcenter.bintray.com</url> 
  </repository> 
</repositories> 

  <dependencies>  


<!-- https://testng.org/doc/download.html -->
<dependency> 
  <groupId>org.testng</groupId> 
  <artifactId>testng</artifactId> 
  <version>6.10</version>  
</dependency> 


<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-testng</artifactId>
    <version>2.0.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>

</dependencies>

  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>

      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <source>1.9</source>
          <target>1.9</target>
        </configuration>
      </plugin>

                <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>org.testng.TestNG</mainClass>
                        </manifest>
                    </archive>

                </configuration>
            </plugin>

   <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <suiteXmlFiles>

                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
    </plugin>


<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.2.1</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <transformers>
                    <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>org.testng.TestNG</mainClass>
                    </transformer>
                </transformers>
            </configuration>
        </execution>
    </executions>
</plugin>



    </plugins>
  </build>
</project>

I am using eclipse and built this project using goal "clean install". On build completion 3 Jar files got created:

original-SeleniumTutorial-0.0.1-SNAPSHOT.jar SeleniumTutorial-0.0.1-SNAPSHOT SeleniumTutorial-0.0.1-SNAPSHOT-jar-with-dependencies

On executing these jar files using the command "java -jar ", I get the below error:

On running jar files I get this message

How to proceed from here , how to create a standalone Jar file that on running the command runs the TestNG tests

Note: https://sqa.stackexchange.com/a/39529/40022 suggest some implementation but i am not sure how to create the package in maven, and I cannot comment in that post as I dont have enough reputation

  • Does it need to be an executable jar? We use maven in Bamboo here, and we just use maven lifecycle commands, e.g. "mvn test" to run the tests as part of a build. – anonygoose Jun 17 at 12:56
  • and you will be using just the pom.xml ? – PDHide Jun 17 at 13:06
  • yeah the POM and an entry to point it to the xml file, as described here: maven.apache.org/surefire/maven-surefire-plugin/examples/… – anonygoose Jun 17 at 13:40
  • When I try that it says textng.xml not found , I have to manually place the file in that location. What to do to make sure the text.xml is available without having to provide it separately – PDHide Jun 17 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.