This directory contains project based on crossbrowsertesting/selenium-testng and testng documentation and http://www.baeldung.com/executable-jar-with-maven See also jinahya/executable-jar-with-maven-example.
To enable single runnable jar with dependencies (at a cost of the size), use runnable-jar-with-dependencies
profile:
mvn -P single clean package
and run
set DUMMYDIR=c:\temp\dummydir
mkdir %DUMMYDIR%
copy target\runnable_testng-jar-with-dependencies.jar %DUMMYDIR%
mkdir %DUMMYDIR%\target\classes
copy target\classes\Test.xlsx %DUMMYDIR%\target\classes
copy testng.xml %DUMMYDIR%
The %DUMMYDIR%
represents the Jenkins workspace directory
Running the test from %DUMMYDIR%
pushd %DUMMYDIR%
java -jar runnable_testng-jar-with-dependencies.jar testng.xml
would produce:
Test Name: failedLoginPage
Test Name: loginPage
===============================================
Command line suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================
Alternatively the jar can be moved to a Vagrant box mounted directory which would make it appear in the target instance - this is WIP.
When bulilt with default
profile, dependencies are copied to the target/lib
during package
phase,
and can be stored anywhere in the system
mvn clean package
robocopy target\lib c:\temp\shared /s
rd /s/q target\lib
java -cp c:\temp\shared\*;target\runnable_testng-0.2-SNAPSHOT.jar demo.EntryPoint
This would also produce:
Test Name: failedLoginPage
Test Name: loginPage
===============================================
Command line suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================
Note that this example project has the data parameter file Tests.xlsx
which is loaded from file system like below:
File file = new File(System.getProperty("user.dir") + File.separator
+ "target\\classes\\Test.xlsx");
therefore one has to make it avalable from the specific path relative to the directory jar is placed.
It has to be checked in to src/main/resources
.
The default
profile makes the project version part of resulting jar filename,
the runnable-jar-with-dependencies
profile strips it away.
The packaging of all and every dependencies into one jar has a disadvantage of seriously increasing the size of that jar file, in our case from under 15 K
02/27/2018 08:55 AM 14,445 runnable-testng-0.2-SNAPSHOT.jar
to over 36M:
02/27/2018 08:57 AM 36,901,791 monolithic_runnable_testng.jar
NOTE: One cannot run the test class(es) as th regular testng test:
mvn clean test
[WARNING] No processor claimed any of these annotations: org.testng.annotations.
BeforeSuite,org.testng.annotations.BeforeMethod,org.testng.annotations.Test,org.
testng.annotations.AfterSuite,org.testng.annotations.AfterMethod
For test annonated classes to be found, require rearranging the project files to store tests under src/test/java
directory
but this will prevent the bootstrap class from seeing those (due to separation of build phases handling main
and test
):
mvn compile
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.0:
compile (default-compile) on project runnable_testng: Compilation failure
[ERROR] /c:/developer/sergueik/testng_runnable/src/main/java/demo/EntryPoint.java:[5,12] cannot find symbol
[ERROR] symbol: class TestWithData
For running Maven testNG tests from a jar without dedicated bootstrap class see this.
Make it possible to build the jar in a different os than tests are going to run.
This project is licensed under the terms of the MIT license.