Java 数据驱动的excel-ant通过命令行(testng ant webdriver)
我可以通过IDE中的Ant运行测试 但是,当我试图从命令行运行它时,它失败了,因为无法从资源中找到Excel 我补充说:Java 数据驱动的excel-ant通过命令行(testng ant webdriver),java,selenium,ant,Java,Selenium,Ant,我可以通过IDE中的Ant运行测试 但是,当我试图从命令行运行它时,它失败了,因为无法从资源中找到Excel 我补充说: `<copy todir="test/Resources/Data"> <fileset dir="${Resources}/Data"> <exclude name="**/*.java"/> </fileset> </copy>` ` ` 文件已复制,但仍然失败。 看起来代码看起来不在
`<copy todir="test/Resources/Data">
<fileset dir="${Resources}/Data">
<exclude name="**/*.java"/>
</fileset>
</copy>`
`
`
文件已复制,但仍然失败。
看起来代码看起来不在正确的位置。。
有什么想法吗
full build.xml:
<project name="TestNGTest" default="test" basedir=".">
<!-- Define <testng> task -->
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="lib/testng-6.8.5.jar"/>
</classpath>
</taskdef>
<property name="testdir" location="test" />
<property name="srcdir" location="src" />
<property name="libdir" location="lib" />
<property name="full-compile" value="true" />
<property name="Resources" location="Resources"/>
<copy todir="test/Resources/Data">
<fileset dir="${Resources}/Data">
<exclude name="**/*.java"/>
</fileset>
</copy>
<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>
</target>
<target name="compile" depends="clean">
<javac srcdir="${srcdir}" destdir="${testdir}"
verbose="${full-compile}">
<classpath refid="classpath.test"/>
</javac>
</target>
<target name="test" depends="compile">
<testng outputdir=".test-output" classpathref="classpath.test"
useDefaultListeners="false"
listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter">
<xmlfileset dir="." includes="testng.xml"/>
</testng>
</target>
</project>'
'
我发现了问题。
在代码中,我使用System.getProperty(“user.dir”),当从ant运行时,它会找到我的“user”文件夹。
所以我可以手动将excel ant放在那里,它可以正常工作。
现在,我需要找到将System.getProperty(“user.dir”)更改为指向项目根目录的方法您可以通过xml文件进行详细描述吗?我在我的代码中添加了build.xml:
公共字符串ExcelFilePath=System.getProperty(“user.dir”)+“/Resources/Data/TestDataCandex.xls”代码>可能是问题所在-编译后他找不到文件?替换为|试试这个,让我知道嗨,现在它甚至没有复制文件。可能代码中的引用应该是另一个?