Coder Social home page Coder Social logo

testng_runnable's Introduction

Info

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.

Note

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.

See also:

TODO

Make it possible to build the jar in a different os than tests are going to run.

License

This project is licensed under the terms of the MIT license.

Author

Serguei Kouzmine

testng_runnable's People

Contributors

sergueik avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.