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

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

问题描述

最近我的工作在硒的webdriver 2.0(开发自动化框架)。按规定,每faiulre截图必须是捕获(文件的路径和文件名:./screenshots/testcases/ddmmyyyy/scenario_hhmmss.png),但是我已经捕捉截图。当我运行这些整个测试套件(我想生成JU​​nit的报告使得转贴必须有截图链接)。现在的问题是,截图路径是动态生成(硒的java code),并在Junit的报告,我想建立超链接,最近生成的截图(我已经在使用我们可以创建链接更新框,report.xslt文件,但它是很难codeD)?请建议任何方式这样做呢?

下面是我的build.xml文件的某些部分。

 <目标名称=EXEC依赖=编译>
        <删除DIR =$ {}报告/>
    < MKDIR DIR =$ {}报告/>
        < MKDIR DIR =$ {}报告/ XML/>
    < JUnit的printsummary =YEShaltonfailure =无>
         <类路径REFID =项目的类路径/>
        <&类路径GT;
                        < pathelement位置=$ {}斌/>
                        <文件集DIR =$ {} lib目录>
                            <包括姓名=** / *罐子。/>
                        < /文件集>
                    < /类路径>
        <试验NAME =com.example.tests.NormanTestSuitehaltonfailure =NOtodir =$ {}报告/ XMLOUTFILE =TEST-结果>
        <格式化类型=XML/>
        < /试验>
    < / JUnit的>
    < junitreport todir =$ {}报告>
            <文件集DIR =$ {}报告/ XML>
                <包括姓名=TEST *的.xml/>
            < /文件集>
    <报告styledir =C:\\ Apache的ANT-1.8.4 \\定制格式=帧todir =$ {}报告/ HTML>
    < /报告>
    < / junitreport>
< /目标与GT;


解决方案

使用Java系统属性

您可以传递一个变量作为一个JVM参数。假设你已经这样定义一个名为screenShotRoot变量

 蚂蚁-DscreenShotRoot = /截图/测试用例

你可以在你的build.xml这样读

 <属性名=screenshot.root值=$ {} screenShotRoot/>

您Ant任务可以使用这个根路径产生预期的日期到您的PNG文件的路径适当

请参阅此 Apache Ant的常见问题解答页面

使用环境变量

您也可以使用操作系统环境变量,通过调用你的脚本之前设置它们。假定您已经定义了名为screenShotRoot的环境变量,这样在Windows

  SET screenShotRoot = /截图/测试用例

你可以在你的build.xml这样读

 <物业环境=ENV/>
<属性名=screenshot.root值=$ {} env.screenShotRoot/>

使用属性文件

您也可以写你的链接到一个属性文件Ant脚本加载,这样

 <属性文件=build.properties/>

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?

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>

解决方案

Using Java System Property

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

ant -DscreenShotRoot=/screenshots/testcases

you can read it in your build.xml like this

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

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

See this Apache ANT FAQ page

Using Environment Variables

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

you can read it in your build.xml like this

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

Using Properties Files

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天全站免登陆