This question is not similar to the questions answered for the related issue.
I'm running a project in office.My build.xml run perfect with using testng.xml and testng.xml alone.
On my laptop(home) I'm able to run the project using testng.xml but eclipse displays error when i run build.xml(using same task for testng) error " [testng] Cannot instantiate class".
I have kept the build.xml simple as this is new to me.Also the jar file path is updated.I doubt if this is a jar file issue as my all .java files are compiled successfully.
Below is my 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 result
Test Case Class
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();
}
}
}
When running testng.xml alone it run successfully.Any help appreciated thanks!