0
votes

My build.xml is :

<?xml version="1.0"?>   

<project name="Test" default="test" basedir=".">

   <!-- Define <testng> task -->

<taskdef resource="testngtasks"> 
   <classpath>
      <pathelement location="/lib/testng-6.9.4.jar"/>
   </classpath>
</taskdef>

 <property name="testdir" location="test" />
 <property name="srcdir" location="src" />
 <property name="libdir" location="lib" />
 <property name="full-compile" value="true" />

 <path id="classpath.base"/>
 <path id="classpath.test">   
   <fileset dir="${libdir}">
      <include name="**/*.jar" />
   </fileset>  
    <pathelement location="${testdir}" />
    <pathelement location="${srcdir}" />   
    <path refid="classpath.base" />
 </path>

 <target name="clean" >
    <delete verbose="${full-compile}">
      <fileset dir="${testdir}" includes="**/*.class" />
    </delete>
   <echo>Cleaned Successfully.</echo>
 </target>

 <target name="compile" depends="clean">
  <echo>Compiling</echo>
    <javac srcdir="${srcdir}" destdir="${testdir}" verbose="${full-compile}">
       <classpath refid="classpath.test"/>
    </javac>
  <echo>Java file compiled Successfully.</echo>
 </target>

 <target name="test" depends="compile">     
    <testng outputdir="${testdir}" classpathref="classpath.test"> 
      <xmlfileset dir="${srcdir}" includes="TestNG.xml"/> 
    </testng>
 </target>   
</project>

I am getting the below errors :

BUILD FAILED
`Path\build.xml:44: Problem: failed to create task or type testng
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.

I have had this issue in future, below is link : ANT: Build Failed: failed to create task or type testng:

I followed all the steps but it has again started giving error.

Please help!!

Changing to solved first problem

But I have received another issue that while running using ant, .properties file are not being read which contains URL, credentials and all.

I have used testNG and am reading URL from a .properties file. By running directly from eclipse, each and everything works properly and it can be seen but executing using ant is just opeing the browser but not navigating to URL which has been specifed in .properties file.

I can see in the logs the method names but none of them can run as no URL opens. Please suggest what to do in this scenario.

1

1 Answers

1
votes

BUILD FAILED `Path\build.xml:44: Problem: failed to create task or type testng Cause: The name is undefined. Action: Check the spelling. Action: Check that any custom tasks/types have been declared. Action: Check that any / declarations have taken place.

<taskdef resource="testngtasks"> 
   <classpath>
      <pathelement location="/lib/testng-6.9.4.jar"/>
   </classpath>
</taskdef>

The above error is occurring because ant cannot find your TestNg jar file .Replace the taskdef tag above with the one below

  <taskdef name="testng" classpath="${test.classpath}"
                   classname="org.testng.TestNGAntTask" />

Hope this heps you...kindly get back if you have any problem