我试图运行使用Java + Selenium + TestNG + Ant构建的Selenium测试。但是,当我运行build.xml
时会抛出以下错误 -
BUILD FAILED
G:\Workspace\AntProject\build.xml:14: taskdef class AntPackage.AntTest cannot be found
using the classloader AntClassLoader[G:\Workspace\AntProject\libs\testng-6.8.jar]
Total time: 645 milliseconds
以下是build.xml
-
<project basedir="." default="runTest" name="Ant file for TestNG">
<property name="src" location="src"/>
<property name="bin" location="bin"/>
<property name="libs" location="libs"/>
<path id="class.path">
<pathelement location="${libs}/testng-6.8.jar"/>
<pathelement location="${libs}/selenium-java-2.40.0-srcs.jar"/>
<pathelement location="${libs}/selenium-java-2.40.0.jar"/>
<pathelement location="${libs}"/>
</path>
<taskdef name="test" classname="AntPackage.AntTest">
<classpath>
<pathelement location="libs/testng-6.8.jar"/>
</classpath>
</taskdef>
<target name="runTest">
<mkdir dir="testng_output"/>
<testng outputdir="testng_output" classpathref="class.path">
<xmlfileset dir="." includes="testng.xml"/>
</testng>
</target>
</project>
以下是testng.xml
-
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="Test">
<classes>
<class name="AntPackage.AntTest"/>
</classes>
</test>
</suite>
班级AntTest
位于AntPackage
。
我根据The taskdef ant task cannot be found的答案对build.xml
进行了更改,但它仍然无效。
答案 0 :(得分:4)
不要指定classname="AntPackage.AntTest"
,而是根据文档添加taskdef <taskdef resource="testngtasks" classpath="${libs.dir}/testng-6.8.jar" />
http://testng.org/doc/ant.html
`<taskdef />` is needed to specify path to testng.jar but not your test classes
答案 1 :(得分:1)
在build.xml中,替换...
<taskdef name="test" classname="AntPackage.AntTest">
<classpath>
<pathelement location="libs/testng-6.8.jar"/>
</classpath>
</taskdef>
...与...
<taskdef resource="testngtasks" classpath="${libs}/testng-6.8.jar"/>