这个问题与相关问题的答案不相似。
我在办公室里运行一个项目。我的build.xml运行完美,仅使用testng.xml和testng.xml。
在我的笔记本电脑(家庭)上,我能够使用testng.xml运行项目,但是当我运行build.xml时eclipse显示错误(对testng使用相同的任务) 错误" [testng]无法实例化类"。
我保持build.xml简单,因为这对我来说是新的。还更新了jar文件路径。我怀疑这是否是一个jar文件问题,因为我的所有.java文件都已成功编译。
下面是我的build.xml。
<target name="DeleteDir">
<delete dir="bin" />
<delete dir="src" />
<delete dir="test-output" />
<echo>Build is Clean.</echo>
</target>
<path id="Classpath">
<fileset dir="E:\XAP_Automate_Lib" includes="*.jar" />
<pathelement location="C:\Users\dhillon\git\XAP_Automate\Ant\build\bin" />
</path>
<target name="CreateDir" depends="DeleteDir">
<mkdir dir="bin" />
<mkdir dir="src" />
<mkdir dir="test-output" />
<echo>New Directory is created.</echo>
</target>
<path id="srcfiles">
<fileset dir="C:\Users\dhillon\git\XAP_Automate\src" includes="**/*.java">
</fileset>
</path>
<target name="Copy" depends="CreateDir">
<copydir src="C:\Users\dhillon\git\XAP_Automate\src" includes="**/*.java" dest="C:\Users\dhillon\git\XAP_Automate\Ant\build\src">
</copydir>
<echo>The Copy Target is completed.</echo>
</target>
<target name="Compile" depends="Copy">
<javac classpathref="Classpath" includeantruntime="true"
srcdir="C:\Users\dhillon\git\XAP_Automate\Ant\build\src"
destdir="C:\Users\dhillon\git\XAP_Automate\Ant\build\bin" includes="**/*.java">
</javac>
<echo>All dot class files are copied in the Bin Directory</echo>
</target>
<taskdef resource="testngtasks" classpath="E:\XAP_Automate_Lib\testng-6.11.jar"/>
<!--<taskdef name="testng" classname="org.testng.TestNGAntTask" classpath=""/>-->
<target name="testng-execution" depends="Compile">
<testng outputdir="${testng-report-dir}" classpathref="Classpath" useDefaultListeners="false">
<xmlfileset dir="C:/Users/Dhillon/git/XAP_Automate/ant/build/" includes="testng.xml" />
</testng>
</target>
Build.xml结果
测试用例类
package com.legacyTest.test;
import org.testng.annotations.Test;
import org.testng.Assert;
import java.util.Hashtable;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.DataProvider;
import com.legacyTeam.TestBase.TestBase;
import com.legacyTeam.dashboard.ToDoListFunctions;
import com.legacyTeam.loginPage.loginPage;
public class TC09_Add_ToDoList extends TestBase {
public Assert asrt;
@Test(dataProvider = "getData")
public void Add_ToDoList(Hashtable<String, String> data) {
logger = extent.createTest(" TC09_Add_ToDoList " + data);
logger.info("********** Starting Test Case **********");
start(prop.getProperty("browser"), prop.getProperty("URL"));
loginPage lp = new loginPage(driver);
lp.login(prop.getProperty("username"), prop.getProperty("password"));
String text = lp.validateLogin();
if (text.contains("Success")) {
asrt.assertEquals(text, "Login Successfully");
logger.pass("login Successfull");
} else {
asrt.fail();
asrt.fail("Login Failed");
}
fluentWait("DashboardWaiting_xpath");
waitinSec(2);
ToDoListFunctions td = new ToDoListFunctions(driver);
int yearNumber = Integer.parseInt(data.get("YearNumber"));
int date = Integer.parseInt(data.get("Date"));
td.addlist(data.get("MonthName"), date, yearNumber,
data.get("TextArea"));
td.selectTab("Upcoming");
waitinSec(1);
fluentWait("wait_id");
boolean b = td.VerifyToDoList(data.get("VerifyText"));
if (b == true) {
logger.pass("Test Case is Passed,Able to verify added String in the list : "
+ data.get("VerifyText"));
} else {
logger.fail("Test Case is Failed,Not Able to verify added String in the list : "
+ data.get("VerifyText"));
}
boolean validateLogOut = lp.logout();
if (validateLogOut == true) {
logger.pass("Logout successfull");
}
asrt.assertEquals(validateLogOut, true);
logger.info("********** Ending Test Case **********");
}
@DataProvider
public Object[][] getData() {
Object[][] data = com.leagacyTeam.readExcel.DataUtil.getData(reader,
"Add_ToDoList");
return data;
}
@AfterMethod
public void quite() {
if (extent != null) {
logger.info(" Closing Driver ");
extent.flush();
driver.quit();
}
}
@BeforeSuite
public void init() {
if (prop == null) {
TestBase tb = new TestBase();
tb.init();
}
}
}
单独运行testng.xml时,它运行成功。任何帮助表示感谢!