-1

While running selenium automation using a bat file, it is showing this error

No test suite found. Nothing to run

But TestNG is running properly from Eclipse.

enter image description here

RubioRic
  • 2,442
  • 4
  • 28
  • 35
Vishal
  • 121
  • 1
  • 2
  • 12
  • I think that you're not invoking TestNG properly. Check this answer https://stackoverflow.com/a/11897452/2553194 and change how you execute TestNG. – RubioRic May 02 '18 at 10:27
  • i don't have bin folder created in my peoject, should i created mannually ? – Vishal May 02 '18 at 14:02
  • i think i was doing one mistake. instead of projectLocation while running i was giving ClassPath. now change as "java -cp %classpath% org.testng.TestNG %projectLocation%\testng.xml". Now it is giving error like " D:\Myprogram\Emailsent>java -cp D:\Myprogram\Emailsent\bin;D:\Myprogram\Emailsent\lib\* org.testng.TestNG D:\Myprogram\Emailsent\testng.xml [TestNG] [ERROR] Cannot find class in classpath: SendEmail.ToCheckPage Exception in thread "main" java.lang.NullPointerException at org.testng.TestNG.getStatus(TestNG.java:211) at org.testng.TestNG.main(TestNG.java:1324)" – Vishal May 02 '18 at 14:09
  • You do not have to create a bin folder. You have to set %classpath% with the directory or directories where TestNG can find your classes and their dependences. – RubioRic May 02 '18 at 14:15
  • which class are u talking about? .java ? – Vishal May 03 '18 at 06:14
  • I'm taking about "Cannot find class in classpath: SendEmail". Where is your SendMail.class file? Usually all your .class files should be packaged in a jar file. You are instructing TestNG to look for them in "D:\Myprogram\Emailsent\bin;D:\Myprogram\Emailsent\lib" and it seems that they are not there – RubioRic May 03 '18 at 07:13
  • yes i don't have .class file – Vishal May 03 '18 at 09:34
  • no bin folder created and in lib folder i put all selenium jar files. where would be my .class file – Vishal May 03 '18 at 09:38
  • Wherever you want. It don't have to be in any specific place. You just have to inform TestNG where to look for it. That's the meaning of a classpath. lib folder is a good place – RubioRic May 03 '18 at 09:45
  • we are running testng.xml file, arent we? then what is meaning of giving path of .class file – Vishal May 03 '18 at 09:52
  • Because to run TestNG, you need the compiled classes used to implement TestNG and your own classes that should be tested. You are not running an XML file. You are running a java class org.testng.TestNG included in a jar file. This class need to execute a method in your java class, that should be in another class file. Both should be accesible in the directory that you established as argument. – RubioRic May 03 '18 at 09:55
  • thanks for your reply. i don't have bin folder created, what about that. should i create manually and put some file there? – Vishal May 03 '18 at 10:08
  • Some file? Not just some file, you have to copy there your class file and ALL files imported in your class as well, and files that they use etc. If you have developed your class using an IDE like Eclipse or Netbeans, you should have already a folder with the required jars. You can point to that folder adding it to the arguments. Something like `java -cp "C:\Eclipse\VishalProject\lib;C:\FolderThatIncludesTestNGjar" ...` – RubioRic May 03 '18 at 10:24
  • hi Thanks for every thing. let me clear i don't have bin folder and i don't have any .class file also. i have .classpath and .project file only... now i am going to create one bin folder tell me exactly what files i will paste there. – Vishal May 03 '18 at 12:20
  • How can I tell you "exactly" what files do you need if I haven't programmed your project? If you don't know how java and your IDE work, why are you trying to use advanced tools for testing? – RubioRic May 03 '18 at 12:35
  • hey RubioRic. now this problem got resolved. but test is getting failed don't now why when running with batch file – Vishal May 10 '18 at 12:01

4 Answers4

1

The command used to invoke TestNG is incorrect. Also you can specify classpath with option -cp. So the renewed sample command for you would be

java -cp <classpath> org.testng.TestNG <location of testng.xml>
pranay jain
  • 352
  • 1
  • 2
  • 15
  • thanks for your reply. that is also not working.actually i don't have bin folder created in my project library. will it create any problem. – Vishal May 02 '18 at 12:14
  • this is my batch file content..===> set projectLocation=D:\Myprogram\Emailsent cd %projectLocation% set classpath=%projectLocation%\bin;%projectLocation%\lib\* java -cp %classpath% org.testng.TestNG %classpath%\testng.xml pause – Vishal May 02 '18 at 12:16
  • Are you getting the same error as above ? Is your location of testng.xml correct ? – pranay jain May 02 '18 at 12:20
  • yaa same problem – Vishal May 02 '18 at 13:13
  • doesn't have bin folder will create any problem – Vishal May 02 '18 at 13:13
  • i think i was doing one mistake. instead of projectLocation while running i was giving ClassPath. now change as "java -cp %classpath% org.testng.TestNG %projectLocation%\testng.xml". Now it is giving error like " D:\Myprogram\Emailsent>java -cp D:\Myprogram\Emailsent\bin;D:\Myprogram\Emailsent\lib* org.testng.TestNG D:\Myprogram\Emailsent\testng.xml [TestNG] [ERROR] Cannot find class in classpath: SendEmail.ToCheckPage Exception in thread "main" java.lang.NullPointerException at org.testng.TestNG.getStatus(TestNG.java:211) at org.testng.TestNG.main(TestNG.java:1324)" – Vishal May 02 '18 at 14:09
0

A batch file is nothing but collections of commands. Try to run it from CMD first and then make a batch file. For running TestNG from Command-Line, you might wanna follow these steps.

  1. After adding TestNG to your project library create one folder in your Project names as lib ( name can be anything ) :

  2. Go to "C:\Program Files\Eclipse\your_eclipse_name\eclipse\plugins" location and copy com.beust.jcommander_1.72.0.jar and org.testng_6.14.2.r20180216145.jar file to created folder (lib).

Note : Files are testng.jar and jcommander.jar

Now Launch CMD, and navigate to your project directory and then type :

Java -cp C:\Users\User123\TestNG\lib*;C:\Users\User123\TestNG\bin org.testng.TestNG testng.xml
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
  • thanks but i don't have bin folder created in my project library. – Vishal May 02 '18 at 12:13
  • this is my batch file content..===> set projectLocation=D:\Myprogram\Emailsent cd %projectLocation% set classpath=%projectLocation%\bin;%projectLocation%\lib\* java -cp %classpath% org.testng.TestNG %classpath%\testng.xml pause – Vishal May 02 '18 at 12:17
  • i think i was doing one mistake. instead of projectLocation while running i was giving ClassPath. now change as "java -cp %classpath% org.testng.TestNG %projectLocation%\testng.xml". Now it is giving error like " D:\Myprogram\Emailsent>java -cp D:\Myprogram\Emailsent\bin;D:\Myprogram\Emailsent\lib* org.testng.TestNG D:\Myprogram\Emailsent\testng.xml [TestNG] [ERROR] Cannot find class in classpath: SendEmail.ToCheckPage Exception in thread "main" java.lang.NullPointerException at org.testng.TestNG.getStatus(TestNG.java:211) at org.testng.TestNG.main(TestNG.java:1324)" – Vishal May 02 '18 at 14:10
  • Have you performed the steps given in my answer ? and also tell me which testng you are using ? – cruisepandey May 02 '18 at 14:24
  • ya i follow your step, in lib folder along with the two jar that u mentioned, i put all selenium jar, testng jar and chrome driver. – Vishal May 03 '18 at 06:13
  • No.!! Is there any other method to schedule selenium automation – Vishal May 03 '18 at 08:25
0

I was using maven for this. I simply changed to java project only and got bin folder created as well. And then convert it to maven project. Now everything is fine. Thanks to all.

user2807083
  • 2,962
  • 4
  • 29
  • 37
Vishal
  • 121
  • 1
  • 2
  • 12
0

I saw someone mentioning a cannot find classpath problem, had the same issue. I think TestNG changes the classpath variable and moves all class files to /target/classes directory. But if we try to point this path in cmd, it doesnt work. For bat file to run all class files HAVE to be in bin folder. Do the following

Goto Eclipse -> right click on Project ->Properties -> Source tab

Here, change the output folder to bin. Now run the testng xml from eclipse to make sure everything still works.

Then goto bin folder, your class files should now be here. Then run your testng command, should start working.