【问题标题】:How to create an ant target which accepts arguments如何创建一个接受参数的蚂蚁目标
【发布时间】:2015-02-09 22:22:36
【问题描述】:

我有 selenium testng 框架,之前我们有用于启动和停止 selenium 网格的 xml 文件,因为它曾经反映在测试报告中,我们已经删除了用于启动和停止网格的 xml,并倾向于使用 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} 在旧代码中的作用,我们一直在使用它。

如果有人可以建议通过 ant 完成此任务的工作目标。

【问题讨论】:

标签: java selenium ant testng


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    从stackoverflowUse Ant for running program with command line arguments遍历这个线程

    在您的“java”标签中,通过从命令行获取参数来传递“arg”标签。用线程中的示例清楚地解释...

    【讨论】:

      【解决方案3】:

      这对我有用 -

        <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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-30
        • 2020-06-07
        • 2012-06-13
        相关资源
        最近更新 更多