如何将参数传递给ant脚本?

Pri*_*hah 9 ant

最近我正在研究selenium webdriver 2.0(开发自动化框架).根据每个faiulre的要求,屏幕截图必须被捕获(文件路径和文件名:./ screenshots/testcases/ddmmyyyy/scenario_hhmmss.png)但是我已经捕获了截图.当我运行这些整个测试套件时(我想生成JUNIT报告,以便重新发布必须有截图链接.)现在的问题是截图路径是动态生成的(通过selenium java代码),而在Junit报告中我想建立超链接最近生成的截图(我已经更新了frames-report.xslt文件,我们可以创建链接,但它是硬编码的)?请建议任何方式这样做?

这是我的build.xml文件的一部分

<target name="exec" depends="compile">
        <delete dir="${report}" />
    <mkdir dir="${report}" />
        <mkdir dir="${report}/xml" />
    <junit printsummary="yes" haltonfailure="no">
         <classpath refid="project-classpath" />
        <classpath>
                        <pathelement location="${bin}" />
                        <fileset dir="${lib}">
                            <include name="**/*.jar" />
                        </fileset>
                    </classpath>
        <test name="com.example.tests.NormanTestSuite" haltonfailure="no" todir="${report}/xml" outfile="TEST-result">          
        <formatter type="xml" />
        </test>         
    </junit>
    <junitreport todir="${report}">
            <fileset dir="${report}/xml">
                <include name="TEST*.xml" />
            </fileset>
    <report styledir="C:\apache-ant-1.8.4\custom" format="frames" todir="${report}/html" >          
    </report>
    </junitreport>
</target>
Run Code Online (Sandbox Code Playgroud)

Bra*_*rad 18

使用Java系统属性

您可以将变量作为JVM参数传递.假设你有一个名为"screenShotRoot"的变量,就像这样定义

ant -DscreenShotRoot=/screenshots/testcases
Run Code Online (Sandbox Code Playgroud)

你可以在build.xml中读取它

<property name="screenshot.root" value="${screenShotRoot}" />
Run Code Online (Sandbox Code Playgroud)

然后,您的ANT任务可以使用此根路径在预期的日期生成PNG文件的相应路径.

请参阅此Apache ANT FAQ页面

使用环境变量

您还可以使用操作系统环境变量,方法是在调用脚本之前设置它们.假设您在Windows上定义了一个名为"screenShotRoot"的环境变量

SET screenShotRoot=/screenshots/testcases
Run Code Online (Sandbox Code Playgroud)

你可以在build.xml中读取它

<property environment="env"/>
<property name="screenshot.root" value="${env.screenShotRoot}" />
Run Code Online (Sandbox Code Playgroud)

使用属性文件

您也可以将链接写入ANT脚本加载的属性文件中,如下所示

<property file="build.properties"/>
Run Code Online (Sandbox Code Playgroud)