如何将参数传递给ant脚本? [英] How to pass parameter to ant scripts?

查看:25
本文介绍了如何将参数传递给ant脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Recently I am working on selenium webdriver 2.0 (developing automation framework). As per requirement for every faiulre the screenshot must be capture (file path and filename: ./screenshots/testcases/ddmmyyyy/scenario_hhmmss.png) however I already capture screenshots. when i run these entire test suite (I want to generate JUNIT report such that the repost must have screenshot link.)Now problem is that the screenshot path is generate dynamically (By selenium java code), and in Junit report i want to establish hyperlink to recently generated screenshots (i already updated frames-report.xslt file using we can create link but it was hardcoded)? Please suggest any way to do so?

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

Here is some part of my build.xml file

<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>

推荐答案

使用 Java 系统属性

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

You can pass a variable as a JVM argument. Assuming you have a variable named "screenShotRoot" defined like this

ant -DscreenShotRoot=/screenshots/testcases

你可以像这样在 build.xml 中读取它

you can read it in your build.xml like this

<property name="screenshot.root" value="${screenShotRoot}" />

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

Your ANT task can then use this root path to generate appropriate paths to your PNG files on the date expected.

请参阅此 Apache ANT 常见问题页面

使用环境变量

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

You can also use Operating System environment variables, by setting them before calling your script. Assuming you have an environment variable named "screenShotRoot" defined like this on Windows

SET screenShotRoot=/screenshots/testcases

你可以像这样在 build.xml 中读取它

you can read it in your build.xml like this

<property environment="env"/>
<property name="screenshot.root" value="${env.screenShotRoot}" />

使用属性文件

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

You could also write your links into a properties file that your ANT script loads, like this

<property file="build.properties"/>

这篇关于如何将参数传递给ant脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆