Selenium TestNG代码将在Eclipse中编译,但不会在Jenkins中编译

Selenium TestNG代码将在Eclipse中编译,但不会在Jenkins中编译,selenium,jenkins,testng,Selenium,Jenkins,Testng,我目前正在使用Java、Selenium和TestNG构建一个测试网页的框架。在build.xml中,我引用了测试版本6.8.8。在Eclipse中,我也更新了这个版本。作为测试的一部分,我使用retryAnalyzer重新运行一次失败的测试。然后,我使用TTestListener清理testNG报告,以删除在重新运行时传递的失败测试(删除失败的测试结果)(所有代码如下) 我的问题是这个。在Eclipse中编译和运行我的代码时,一切正常;然而,当我提交并试图通过Jenkins运行时,我遇到了一个

我目前正在使用Java、Selenium和TestNG构建一个测试网页的框架。在build.xml中,我引用了测试版本6.8.8。在Eclipse中,我也更新了这个版本。作为测试的一部分,我使用retryAnalyzer重新运行一次失败的测试。然后,我使用TTestListener清理testNG报告,以删除在重新运行时传递的失败测试(删除失败的测试结果)(所有代码如下)

我的问题是这个。在Eclipse中编译和运行我的代码时,一切正常;然而,当我提交并试图通过Jenkins运行时,我遇到了一个异常,表明ITestNGMethod和ITestResult之间存在不兼容的类型。在testNG 6.8.6之前,removeResult()方法只允许ITestNGMethods使用,但根据文档,它现在包括删除ITestResult的功能(这可以从它在Eclipse[]中运行的事实中得到证明).这几乎就好像Jenkins正在使用差异编译器,或者不知何故没有看到testNG的正确版本

我特别希望通过让Jenkins以与Eclipse实例相同的方式编译代码来帮助解决这个问题

任何方向都很好

谢谢

删除错误失败的测试的粗略代码。由于我只重新运行一次测试,当且仅当它第一次失败时,我可以假设如果一个测试在失败和通过列表中,那么它将通过它的后续尝试,因此可以从失败集中删除

Set<ITestResult> failedSet = context.getFailedTests().getResults(testMethod);
Set<ITestResult> passedSet = context.getPassedTests().getResults(testMethod);       


    for(ITestResult passedTest : passedSet)
    {
        for(ITestResult failedTest : failedSet)
        {
             //parameter[0] is a unique testID
            if(failedTest.getParameters()[0].equals(passedTest.getParameters()[0]))
            {
                context.getFailedTests().removeResult(failedTest);      
            }                   
        }
    }
下面是我的build.xml文件的外观:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
          Any modifications will be overwritten.
          To include a user specific buildfile here, simply create one in the same
          directory with the processing instruction <?eclipse.ant.import?>
          as the first entry and export the buildfile again. --><project basedir="." default="build" name="Automation">
<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id="TestNG.libraryclasspath">
    <pathelement location="../../../../../../eclipse/plugins/org.testng.eclipse_6.8.6.20130517_2218/lib/testng.jar"/>
</path>
<path id="Automation.classpath">
    <pathelement location="bin"/>
    <path refid="TestNG.libraryclasspath"/>
    <pathelement location="../../../../../../selenium/lib/jtds-1.3.0.jar"/>
    <pathelement location="../../../../../../selenium/lib/sqljdbc4-2.0.jar"/>
    <pathelement location="../../../../../../selenium/lib/selenium-server-standalone-2.42.2.jar"/>
    <pathelement location="../../../../../../selenium/lib/testng-6.8.8.jar"/>
    <pathelement location="../../../../../../selenium/lib/reportng-1.1.4.jar"/>
    <pathelement location="../../../../../../selenium/lib/velocity-dep-1.4.jar"/>
    <pathelement location="../../../../../../selenium/lib/guice-3.0.jar"/>
    <pathelement location="../../../../../../selenium/lib/saxon-8.7.jar"/>
</path>
<target name="init">
    <mkdir dir="bin"/>
    <copy includeemptydirs="false" todir="bin">
        <fileset dir="src">
            <exclude name="**/*.java"/>
        </fileset>
    </copy>
</target>
<target name="clean">
    <delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
    <echo message="${ant.project.name}: ${ant.file}"/>
    <javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
        <src path="src"/>
        <classpath refid="Automation.classpath"/>
    </javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
    <copy todir="${ant.library.dir}">
        <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
    </copy>
    <unzip dest="${ant.library.dir}">
        <patternset includes="jdtCompilerAdapter.jar"/>
        <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
    </unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
    <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
    <antcall target="build"/>
</target>

<taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="Automation.classpath" />
    <taskdef resource="testngtasks">
            <classpath>
                <pathelement location="../../../../../selenium/lib/testng-6.8.8.jar"/>
            </classpath>
    </taskdef>

<!-- = = = = = = = = = = = = = = = = =
      macrodef: runTestNG          
     = = = = = = = = = = = = = = = = = -->
<macrodef name="runTestNG">
    <attribute name="xmlFile" default="testng.xml" />
    <sequential>
        <testng classpathref="Automation.classpath" 
                outputdir="test-output" 
                haltonfailure="no" 
                useDefaultListeners="true" 
                listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter">
            <sysproperty key="org.uncommons.reportng.title" value="FOX Test Automation Report"/>
            <sysproperty key="org.uncommons.reportng.escape-output" value="false"/>
            <xmlfileset dir="." includes="@{xmlFile}"/>
        </testng>
        <echo> /* Testng Report generated */ </echo>
    </sequential>
</macrodef>

<macrodef name="runXSLT">
    <sequential>
        <delete dir="${basedir}/testng-xslt"/> 
        <mkdir dir="${basedir}/testng-xslt"/> 
        <xslt in="${basedir}/test-output/testng-results.xml" 
            style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html"> 
            <classpath location="../../../../../../selenium/lib/saxon-8.7.jar" />
            <param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir"/> 
            <param expression="true" name="testNgXslt.sortTestCaseLinks"/> 
            <param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter"/>
            <param expression="true" name="testNgXslt.showRuntimeTotals"/> 
            <classpath refid="Automation.classpath"/> 
        </xslt> 
        <echo> /* XSLT Report generated */ </echo>
    </sequential>
</macrodef>

<target name="firstFile">
    <echo message="Running Hoverbar/Client/Job/Lead tests" />
    <runTestNG xmlFile="testng.xml" />  
</target>
<target name="test" depends="firstFile">
    <runXSLT />
</target>

<target name="secondFile">
        <echo message="Running Hoverbar/Client/Job/Lead tests" />
        <runTestNG xmlFile="testng1.xml" /> 
    </target>
<target name="test1" depends="secondFile">
        <runXSLT />
</target>

<!--target name="test1">
    <echo message="running second test"/>
    <testng classpathref="Automation.classpath" outputdir="testng_output">
         <xmlfileset dir="." includes="testng1.xml"/>
    </testng>
</target -->

<target name="thirdFile">
    <echo message="Running Hoverbar/Client/Job/Lead tests" />
    <runTestNG xmlFile="testng2.xml" /> 
</target>
<target name="provider2" depends="thirdFile">
    <runXSLT />
</target>

<target name="testngAll">
    <echo message="Running all automated tests" />
    <runTestNG xmlFile="testngAll.xml" />
</target>
<target name="AllTests" depends="testngAll">
    <runXSLT />
</target>

<!-- Running Tests and TestNG report generation -->
<!--target name="run">
    <testng classpathref="Automation.classpath" 
            outputdir="test-output" 
            haltonfailure="no" 
            useDefaultListeners="true" 
            listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter">
        <sysproperty key="org.uncommons.reportng.title" value="FOX Test Automation Report"/>
        <sysproperty key="org.uncommons.reportng.escape-output" value="false"/>
        <xmlfileset dir="." includes="testngAll.xml"/>
    </testng>
    <echo> /* Testng Report generated */ </echo>
</target>
<target name="xslt" depends="run"> 
    <delete dir="${basedir}/testng-xslt"/> 
    <mkdir dir="${basedir}/testng-xslt"/> 
    <xslt in="${basedir}/test-output/testng-results.xml" 
        style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html"> 
        <classpath location="../../../../../../selenium/lib/saxon-8.7.jar" />
        <param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir"/> 
        <param expression="true" name="testNgXslt.sortTestCaseLinks"/> 
        <param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter"/>
        <param expression="true" name="testNgXslt.showRuntimeTotals"/> 
        <classpath refid="Automation.classpath"/> 
    </xslt> 
    <echo> /* XSLT Report generated */ </echo>
</target --> 

/*生成的Testng报告*/
/*生成的XSLT报告*/

更多信息: Jenkins正在服务器上运行(并且没有与Ecliplse的连接)


下面是我尝试使用的方法的定义:org.testng.IResultMap.removeResult(ITestResult r)

你的路径有两个testng jar,一个带有插件,另一个来自你的库。你能试着删除插件jar ref吗?非常感谢niharika_neo的快速回复!我会尝试一下,让你知道它是如何运行的。我试着删除插件jar,很抱歉它没有修复它,尽管不管怎样清理它还是很好的。仍然希望如此我想知道更多的想法。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
          Any modifications will be overwritten.
          To include a user specific buildfile here, simply create one in the same
          directory with the processing instruction <?eclipse.ant.import?>
          as the first entry and export the buildfile again. --><project basedir="." default="build" name="Automation">
<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id="TestNG.libraryclasspath">
    <pathelement location="../../../../../../eclipse/plugins/org.testng.eclipse_6.8.6.20130517_2218/lib/testng.jar"/>
</path>
<path id="Automation.classpath">
    <pathelement location="bin"/>
    <path refid="TestNG.libraryclasspath"/>
    <pathelement location="../../../../../../selenium/lib/jtds-1.3.0.jar"/>
    <pathelement location="../../../../../../selenium/lib/sqljdbc4-2.0.jar"/>
    <pathelement location="../../../../../../selenium/lib/selenium-server-standalone-2.42.2.jar"/>
    <pathelement location="../../../../../../selenium/lib/testng-6.8.8.jar"/>
    <pathelement location="../../../../../../selenium/lib/reportng-1.1.4.jar"/>
    <pathelement location="../../../../../../selenium/lib/velocity-dep-1.4.jar"/>
    <pathelement location="../../../../../../selenium/lib/guice-3.0.jar"/>
    <pathelement location="../../../../../../selenium/lib/saxon-8.7.jar"/>
</path>
<target name="init">
    <mkdir dir="bin"/>
    <copy includeemptydirs="false" todir="bin">
        <fileset dir="src">
            <exclude name="**/*.java"/>
        </fileset>
    </copy>
</target>
<target name="clean">
    <delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
    <echo message="${ant.project.name}: ${ant.file}"/>
    <javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
        <src path="src"/>
        <classpath refid="Automation.classpath"/>
    </javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
    <copy todir="${ant.library.dir}">
        <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
    </copy>
    <unzip dest="${ant.library.dir}">
        <patternset includes="jdtCompilerAdapter.jar"/>
        <fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
    </unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
    <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
    <antcall target="build"/>
</target>

<taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="Automation.classpath" />
    <taskdef resource="testngtasks">
            <classpath>
                <pathelement location="../../../../../selenium/lib/testng-6.8.8.jar"/>
            </classpath>
    </taskdef>

<!-- = = = = = = = = = = = = = = = = =
      macrodef: runTestNG          
     = = = = = = = = = = = = = = = = = -->
<macrodef name="runTestNG">
    <attribute name="xmlFile" default="testng.xml" />
    <sequential>
        <testng classpathref="Automation.classpath" 
                outputdir="test-output" 
                haltonfailure="no" 
                useDefaultListeners="true" 
                listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter">
            <sysproperty key="org.uncommons.reportng.title" value="FOX Test Automation Report"/>
            <sysproperty key="org.uncommons.reportng.escape-output" value="false"/>
            <xmlfileset dir="." includes="@{xmlFile}"/>
        </testng>
        <echo> /* Testng Report generated */ </echo>
    </sequential>
</macrodef>

<macrodef name="runXSLT">
    <sequential>
        <delete dir="${basedir}/testng-xslt"/> 
        <mkdir dir="${basedir}/testng-xslt"/> 
        <xslt in="${basedir}/test-output/testng-results.xml" 
            style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html"> 
            <classpath location="../../../../../../selenium/lib/saxon-8.7.jar" />
            <param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir"/> 
            <param expression="true" name="testNgXslt.sortTestCaseLinks"/> 
            <param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter"/>
            <param expression="true" name="testNgXslt.showRuntimeTotals"/> 
            <classpath refid="Automation.classpath"/> 
        </xslt> 
        <echo> /* XSLT Report generated */ </echo>
    </sequential>
</macrodef>

<target name="firstFile">
    <echo message="Running Hoverbar/Client/Job/Lead tests" />
    <runTestNG xmlFile="testng.xml" />  
</target>
<target name="test" depends="firstFile">
    <runXSLT />
</target>

<target name="secondFile">
        <echo message="Running Hoverbar/Client/Job/Lead tests" />
        <runTestNG xmlFile="testng1.xml" /> 
    </target>
<target name="test1" depends="secondFile">
        <runXSLT />
</target>

<!--target name="test1">
    <echo message="running second test"/>
    <testng classpathref="Automation.classpath" outputdir="testng_output">
         <xmlfileset dir="." includes="testng1.xml"/>
    </testng>
</target -->

<target name="thirdFile">
    <echo message="Running Hoverbar/Client/Job/Lead tests" />
    <runTestNG xmlFile="testng2.xml" /> 
</target>
<target name="provider2" depends="thirdFile">
    <runXSLT />
</target>

<target name="testngAll">
    <echo message="Running all automated tests" />
    <runTestNG xmlFile="testngAll.xml" />
</target>
<target name="AllTests" depends="testngAll">
    <runXSLT />
</target>

<!-- Running Tests and TestNG report generation -->
<!--target name="run">
    <testng classpathref="Automation.classpath" 
            outputdir="test-output" 
            haltonfailure="no" 
            useDefaultListeners="true" 
            listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter">
        <sysproperty key="org.uncommons.reportng.title" value="FOX Test Automation Report"/>
        <sysproperty key="org.uncommons.reportng.escape-output" value="false"/>
        <xmlfileset dir="." includes="testngAll.xml"/>
    </testng>
    <echo> /* Testng Report generated */ </echo>
</target>
<target name="xslt" depends="run"> 
    <delete dir="${basedir}/testng-xslt"/> 
    <mkdir dir="${basedir}/testng-xslt"/> 
    <xslt in="${basedir}/test-output/testng-results.xml" 
        style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html"> 
        <classpath location="../../../../../../selenium/lib/saxon-8.7.jar" />
        <param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir"/> 
        <param expression="true" name="testNgXslt.sortTestCaseLinks"/> 
        <param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter"/>
        <param expression="true" name="testNgXslt.showRuntimeTotals"/> 
        <classpath refid="Automation.classpath"/> 
    </xslt> 
    <echo> /* XSLT Report generated */ </echo>
</target -->