1
votes

I have crated a Maven project for my selenium test. I have added some testNG classes under src/test/java. The package name under which testNG classes are is named as "tests".

Now I have created a Project in Jenkins to build that project and I am using a .bat file to do that.

The .bat file looks like this:

set classpath=D:\Learning\Eclipse\Workspace\CabiGroup\target\test-classes;D:\Learning\Eclipse\Workspace\CabiGroup\lib\*

java -cp bin;D:\Learning\Eclipse\Workspace\CabiGroup\lib\* org.testng.TestNG XML\CabiDirect.xml XML\CabiHome.xml

In the classpath; I understand that I need to provide the path of bin folder of the Maven project; but I do not see any bin folder under the Maven Project in my Workspace.

That is why the build is failing with error:

Cannot find class in classpath: tests.VerifyAdvanceSearch

(VerifyAdvanceSearch.class is a testNG class under tests package).

How do I see the bin folder under workspace and provide the path in the .bat file properly?

Please help.

Edit: I have followed what can I do to make display the bin folder on eclipse? but it did not help.

1
there is no bin folder in maven, you are probably looking for target\classesA_Di-Matteo
@A.DiMatteo target\classes is present in the Workspace. So how should I change the following parameter in .bat file so that it builds successfully? I have made the following change, but still same error: set classpath=D:\Learning\Eclipse\Workspace\CabiGroup\target\classesPrabodh Ghosh
but why do you need a bat file on Jenkins? Jenkins can directly execute maven projects without the hard-to-maintain hardcoded classpath issueA_Di-Matteo
@A.DiMatteo The reason is, all the classes I designed, I do not want to execute all. I have xml files each of which contain specific classes defined in it. Actually, it is a Selenium testing project, and running/building the entire project will execute all test cases, which is definitely not desired. Hope I was able to make you understand :) Also, if you please direct me to any link which instructs how to run the entire maven project, that will be helpful too! Thanks.Prabodh Ghosh
Well, that was an easy google query :) cloudbees.com/blog/painless-maven-builds-jenkins moreover, for your specific purpose, you can still avoid scripting (.bat) via a Maven profile maven.apache.org/guides/introduction/…A_Di-Matteo

1 Answers

1
votes

The compiled code for the maven testng code will be available under target\classes. In case of a normal Java project, testng will create its compiled code under bin folder, hence we have this confusion.

Request you to kindly use the below commands

  1. Navigate to the path of the project

    cd F:\Automation\Workspace\testngproject
    
  2. Set the classpath

    set classpath=F:\Automation\Workspace\testngproject\target\classes;F:\Automation\Workspace\testngproject\lib\*
    
  3. Run the testng.xml using the below command

    java org.testng.TestNG testng.xml