I am wondering about to create correct Bat file ,
I am using Maven + Selenium(TestNG)
I have tried many different ways to Resolve exception, But its one of the most common exception: Could not find or load main class / java.lang.ClassNotFoundException
In my Maven project there is no bin or lib folder, And I am wondering for it. Whether to call library from .m2(Maven) installation.
To call class file, In my maven project .class file located something like : E:\testBatchDemo\target\classes\mytest
Here is sample of What I have tried so far,
set projectLocation=E:\testBatchDemo
cd %projectLocation%
set classpath=E:\testBatchDemo\target\classes\mytest;
java -cp %classpath% C:\Users\Desktop-pc\.m2\repository\org\testng\testng\6.14.3\testng-6.14.3.jar; C:\Users\Desktop-pc\.m2\repository\org\seleniumhq\selenium\selenium-java\3.12.0\selenium-java-3.12.0.jar; org.testng.TestNG %projectLocation%\testng.xml
pause
Anyone can please assist, Which library need to call or How can I achieve correct .class path.
As per your question description I think there are certain grey areas which we need to address beofre jumping into the solution.
batch
(i.e..bat
) file: Fundamentally, Maven is a build tool which extensively works in-conjunction withpom.xml
and doesn't requires any Windows batch file.pom.xml
and Maven.Now, your usecase must match to one of the above mentioned requirement as mentioned below:
As you have extensively spoken about the Windows batch file so here are the relevant details as per the first option Windows Batch file + TestNG:
Write a simple code block with
@Test
annotation of TestNG as follows:Run As
TestNG Test
TestNG -> Convert to TestNG
andtestng.xml
gets created.The
testng.xml
will look like:Get the absolute Project Location from your IDE (i.e. Eclipse), browse to the sub-directory, create a directory lib
Copy all the relevant jars and libraries (Selenium and TestNG jars) in the lib directory.
selenium-server-standalone-3.13.0.jar
org.testng_6.14.2.r201802161450.jar
com.beust.jcommander_1.72.0.jar
org.apache-extras.beanshell.bsh_2.0.0.b6.jar
org.yaml.snakeyaml_1.17.0.jar
Through CLI browse to the Project Directory and provide the following classpath:
Through CLI execute
testng.xml
as follows:On successful execution, within the Project Directory create a new text document and add the following code:
Save the file as run.bat
Update
As per your question and subsequent comment,
When you use TestNG and/or Maven, these framework/buildtool keeps all the relevant jars in their respective location. But when you intend the configure the buildpath manually you have to create the lib directory manually and keep a copy of the relevant jars.
Perhaps you don't need to create the bin directory manually as on successful compilation of your Java program your program will automatically create the bin and keeps the class file before execution.