testng.xml is not executed from batch file

时间:2016-10-20 13:09:55

标签: java xml batch-file selenium-webdriver testng

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

2 个答案:

答案 0 :(得分:0)

尝试设置TESTNG_HOME并将其添加到类路径中,如下所示。

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

如果没有设置JAVA_HOME,也可以设置它。

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

希望这会有所帮助:)

答案 1 :(得分:0)

好的,我解决了。需要添加selenium-standalone-server.jar路径。

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