質問

I'm pretty new with this setup. And having issue to call my project with TestNG by ant.

I can run the testng.xml without any problem in Eclipse but I alway receive Cannot find class in classpath by ant.

Build.xml

<project basedir="." default="runTest" name="Ant file for TestNG">

<property name="src" location="src" />
<property name="bin" location="bin" />
<property name="telus" location="C:\ESP_Testware\ESP_Projects\Selenium\telus-pharma-integration-tests\src\test\resources\suite\local" />
<property name="libs" location="lib" />

<path id="class.path">
     <pathelement location="${libs}/testng-6.4.jar" />
     <pathelement location="${libs}/selenium-java-client-driver.jar" />
     <pathelement location="${libs}/selenium-server-standalone-2.39.0.jar" />
     <pathelement location="${bin}"/>
     <pathelement location="${telus}"/>

     </path>

<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="${libs}/testng-6.4.jar"/>
</classpath>
</taskdef>

<target name="runTest">

     <echo message="mkdir"/>

 <mkdir dir="testng_output"/><!-- Create the output directory. -->
     <echo message= "TestNg Start"/>
  <testng outputdir="testng_output" classpathref="class.path"> 
     <xmlfileset dir="${telus}" includes="testng.xml"/> 
    <!--    <xmlfileset dir="." includes="TestNG2.xml"/> -->
   </testng>

</target>
 </project> 

Testng.xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Bolt harness QA" verbose="1">
    <parameter name="test.env" value="qa" />
    <parameter name="selenium.url" value="https://www.google.com" />
    <!-- Valid values for browser: FF, IE, Chrome -->
    <parameter name="selenium.browser" value="Chrome" />

    <listeners>
        <listener class-name="com.gdo.test.integration.listener.SoftAssertTestListener" />
    </listeners>

    <test name="Test_MS_Website" preserve-order="true">
        <classes>

            <class name="com.gdo.telus.SC006">
                <methods>
                    <include name="Web_InvalidPassword" />
                    <exclude name="Web_LockedAccount" />
                </methods>
            </class>

        </classes>
    </test>
</suite>

My Class are at this path :

C:\ESP_Testware\ESP_Projects\Selenium\telus-pharma-integration-tests\src\test\java\com\gdo\telus

Thanks for your help.

役に立ちましたか?

解決 2

I've found my answer on this site. I need to use maven to call my solution.

http://rationaleemotions.wordpress.com/2012/05/14/continuous-integration-with-selenium/

but thanx anyway for your help

他のヒント

Try my build.xml file, I did add the ReportNG plugin into this build.xml file to generate better looking reports instead of the default TestNG reports. You can just download the jar file for ReportNG and place it into your lib folder and it should still work fine:

<project name="Some Bullshit Goes Here" default="clean" basedir=".">

    <!-- Initilization properties -->
        <!-- <property name="lib.dir" value="${basedir}/lib"/> -->

<!-- using the ${basedir} allows you to use relative paths. It will use the working directory and add folders that you specify -->

    <property name="build.dir" value="${basedir}/build"/>
    <property name="lib.dir" value="hardcoded value can go here"/>
    <property name="src.dir" value="${basedir}/src"/>
    <property name="bin.dir" value="${basedir}/bin"/>
    <property name="output.dir" value="${basedir}/output"/>


<!-- I chose to hardcode the location where my jar library files will be, it will be used for compilation. Again you can set relative path if you wish.-->
<path id="assloadoflibs">
    <fileset dir="/automated/tests/library">
        <include name="*.jar"/>
    </fileset>
    <pathelement path="${basedir}/bin"/>
</path>

    <!-- setting libraries -->
    <target name="setClassPath">
        <path id="classpath_jars">
            <pathelement path="${basedir}/"/>
        <fileset dir="/automated/tests/library" includes="*.jar"/>
        </path>

    <!-- Convert jar collection from a given reference into one list, storing the result into a given property, separated by colon -->

    <pathconvert pathsep=":" property="test.classpath" refid="classpath_jars"/>
</target>


<target name="loadTestNG" depends="setClassPath"> 
<!-- Creating task definition for TestNG task -->
    <taskdef resource="testngtasks" classpath="${test.classpath}"/> 

    </target>  

    <target name="init">
    <!-- Creating build directory structure used by compile -->
        <mkdir dir="${build.dir}"/>
    </target>

    <target name="clean">
        <echo message="deleting existing build directory"/>
        <delete dir="${build.dir}"/>
    </target>

    <!-- In compile target dependency is given over clean target followed by init,
    this order makes sure that build directory gets created before compile takes place
    This is how a clean complile is achieved.
    -->

    <target name="compile" depends="clean,init,setClassPath,loadTestNG">
        <echo message="classpath:${test.classpath}"/>
        <echo message="compiling..."/>
        <javac destdir="${build.dir}" srcdir="${src.dir}" classpath="${test.classpath}"/>


    </target>

    <target name="run" depends="compile">

        <!-- testng classpath has been provided reference of jar files and compiled classes
        this will generate report NG report.
        -->

    <testng classpath="${test.classpath}:${build.dir}" outputdir="${basedir}/output" haltonfailure="false" useDefaultListeners="true" listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter" classpathref="reportnglibs">
<xmlfileset dir="${basedir}" includes="testng.xml"/>

<!-- This value here will show the title of the report --> 
<sysproperty key="org.uncommons.reportng.title" value="Example Test Report"/>
        </testng>
    </target>
</project>

Here is my TestNG.xml file:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

<suite name="Example Test Suite">

<test name ="Example TestCase Name">
    <classes>
        <class name="packageName.JavaFilename"></class>
    </classes>
</test>
</suite>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top