简体   繁体   中英

testng.xml is not executed from batch file

I've read many tutorials and threads, but cannot resolve my problem. I'm getting "Could not find or load main class org.testng.TestNG" error all the time and can't find solution.

That's how my project structure looks like:

That's my .xml file code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="false">
<test name="Test">
<classes>
  <class name="olatest_2.rejestracja"/>
  <class name="olatest_2.logowanie"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->

I've tried different ways of composing my .bat file, but none of them works.

set projectLocation=C:\ENVIRONMENT\eclipse\WORKSPACE\PZW_2
cd %projectLocation%
set classpath=%projectLocation%\bin
java org.testng.TestNG %projectLocation%\testng.xml
pause

Should I add some paths in system directories?

Here is the whole error content:

C:\\ENVIRONMENT\\eclipse\\WORKSPACE\\PZW_2>java org.testng.TestNG C:\\ENVIRONMENT\\eclipse\\WORKSPACE\\PZW_2\\testng.xml [TestNGClassFinder] Warning: Can't link and determine methods of class olatest_2.rejestracja [TestNGClassFinder] Warning: Can't link and determine methods of class olatest_2.logowanie [[TestNGClassFinder]] Unable to read methods on class olatest_2.rejestracja - unable to resolve class reference org/openqa/selenium/WebDriver [[TestNGClassFinder]] Unable to read methods on class olatest_2.logowanie - unable to resolve class reference org/openqa/selenium/WebDriver [TestNG] Running: C:\\ENVIRONMENT\\eclipse\\WORKSPACE\\PZW_2\\testng.xml

Try setting the TESTNG_HOME and add it to the classpath like below.

SET TESTNG_HOME=C:\PREPARATION\TESTNG
SET CLASSPATH=%CLASSPATH%;%TESTNG_HOME%\testng-6.8.jar;%TESTNG_HOME%\jcommander-1.5.jar;

Also set JAVA_HOME if you did not set it.

SET PATH=%PATH%;%JAVA_HOME%\bin;

Hope this helps:)

Ok, I solved it. Needed to add selenium-standalone-server.jar path.

set projectLocation=C:\ENVIRONMENT\eclipse\WORKSPACE\PZW_2
cd %projectLocation%
set classpath=%projectLocation%\bin
SET TESTNG_HOME=C:\ENVIRONMENT\java
SET PATH=%PATH%;%JAVA_HOME%\bin;
SET CLASSPATH=%CLASSPATH%;%TESTNG_HOME%\testng- 6.9.9.jar;%TESTNG_HOME%\jcommander-1.27.jar;C:\ENVIRONMENT\java\selenium-server-   standalone-2.53.0.jar
java org.testng.TestNG %projectLocation%\testng.xml
pause

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM