如何创建接受参数的ant目标

时间:2015-02-09 22:22:37

标签: java selenium ant testng

我有selenium testng框架,之前我们有用于启动和停止selenium网格的xml文件,因为它曾用于反映在测试报告中我们已经删除了xmls以启动和停止网格并且倾向于使用ant来实现这一点,因此我正在尝试创建一个接受参数并传递给java函数的目标。

我的功能 -

 public static void main(String[] args) throws Exception {
        if(args.length<1){
            System.err.println("This execution requires arguments such as startGRID or stopGRID");
            log.error("This execution requires argumentr such as startGRID or stopGRID");
        } else if(args[0].equalsIgnoreCase("startGRID")){
            System.out.println("Starting up GRID");
            log.info("Starting up GRID");
            setupSeleniumGrid();
        } else if(args[0].equalsIgnoreCase("stopGRID")){
            System.out.println("Shutting down GRID");
            log.info("Shutting down GRID");
            shutdownSeleniumGrid();
        }else {
            System.err.println("unrecognized arguments, please provide aruments such as startGRID or stopGRID");
            log.error("unrecognized arguments, please provide aruments such as startGRID or stopGRID");
        }
    }

蚂蚁目标 -

   <!-- start Grid -->
    <target name="startGRID" depends="compile">
        <echo>
    Please wait .... GRID is starting up...
    </echo>
        <java classname="foo.bar.framework.selenium.SetupGrid" classpath="${test.dest}" classpathref="${test.c}" />
        <echo>
        GRID Start up complete !
    </echo>
    </target>

在上面的目标中我不确定classpathref="${test.c}在遗留代码中的作用是什么,我们一直在使用它。

如果有人可以通过蚂蚁建议工作目标来完成这项任务。

3 个答案:

答案 0 :(得分:0)

根据文档,必须有一个id =&#34; $ {test.c}&#34;的路径元素。在您的build.xml中。更多信息:http://ant.apache.org/manual/using.html#references

答案 1 :(得分:0)

从stackoverflow Use Ant for running program with command line arguments

中浏览此线程

在你的&#34; java&#34;标记传递&#34; arg&#34;通过从命令行获取参数来标记。用线程中的例子清楚地解释......

答案 2 :(得分:0)

这对我有用 -

  <target name="controlGRID" depends="compile">
                <echo>
            Please wait .... GRID is starting up...
            </echo>
                <java classname="foo.bar.framework.selenium.SetupGrid" classpath="${test.dest}" classpathref="test.c">
                <arg value="${arg}"/>
                </java>
                <echo>
                GRID Start up complete !
            </echo>
            </target>

和命令行

ant -Darg=startGRID controlGRID
相关问题