1

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

enter image description here

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!

balvinder dhillon
  • 109
  • 1
  • 2
  • 10
  • Any chance [setting the verbose flag](https://stackoverflow.com/questions/5232168/is-there-a-way-to-set-ant-verbose-inside-build-xml) gives you more detail on the error? – mrfreester Nov 14 '17 at 18:45
  • ' [testng] 'org.testng.TestNG' [testng] '@C:\Users\Dhillon\AppData\Local\Temp\testng717942493110842561' [testng] [testng] The ' characters around the executable and arguments are [testng] not part of the command. [testng] [TestNG] [ERROR] [testng] Cannot instantiate class com.legacyTest.test.TC09_Add_ToDoList [testng] The tests failed.' – balvinder dhillon Nov 15 '17 at 02:37
  • this does not helped much – balvinder dhillon Nov 15 '17 at 02:37
  • Can you put your `TC09_Add_ToDoList` class in the question? There might be an issue with that even though it works using testng.xml. I would also double check that the `lib` location is what you want in `Classpath`, that looks a little weird. – mrfreester Nov 15 '17 at 15:46
  • Yes I'll do that.Give me some time – balvinder dhillon Nov 15 '17 at 15:47

0 Answers0