I am wondering about to create correct Bat file ,
I am using Maven + Selenium(TestNG)
I have tried many different ways to
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 with pom.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:
package demoJenkins;
import org.testng.annotations.Test;
public class DemoJenkinsJob
{
@Test
public void testJenkins()
{
System.out.println("Welcome to Jenkins World");
}
}
Run As TestNG Test
TestNG -> Convert to TestNG
and testng.xml
gets created.The testng.xml
will look like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test">
<classes>
<class name="demoJenkins.DemoJenkinsJob"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
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:
>set classpath=<Project Directory>\bin;<Project Directory>\lib\*;
Through CLI execute testng.xml
as follows:
Project_Directory>java org.testng.TestNG testng.xml
On successful execution, within the Project Directory create a new text document and add the following code:
java -cp bin;lib/* org.testng.TestNG testng.xml
Save the file as run.bat
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.