4

我有一个 Ant 构建脚本,它当前启动一个服务器,然后等到一个 URL 可以被解析,然后再为我执行一些 Selenium 测试。该任务看起来像这样;

<target name="test.selenium" depends="compile.constants, launch.server" description="Run the Selenium tests">
    <echodesc/>
    <waitfor maxwait="1" maxwaitunit="minute" checkevery="2" checkeveryunit="second">
        <http url="http://127.0.0.1:${product.listenport}/"/>
    </waitfor>
    <exec executable="${deps.python}" spawn="false" failonerror="true" dir="src">
        <arg line="manage.py test --selenium-only" />
    </exec>
</target>

成功之后,我想调用一个 URL 来关闭服务器,但我不确定如何使用 Ant 执行此操作。是否可以让 Ant 打电话127.0.0.1:${product.listenport}/QUIT

我之前是taskkill通过对正在运行的进程的命令来实现这一点的,但这已经开始导致 Windows 错误,并且该 URL 干净地关闭了服务器。

我能找到的最佳解决方案是在浏览器中打开 URL 的宏,但这仍然会给我带来问题,因为我在测试结束时有一个打开的浏览器;http://chris.m0nk3y.net/blog/post/opening-a-url-in-the-default-browser-with-ant

我的解决方案

最终我使用了以下蚂蚁目标;

<target name="shutdown.server" depends="init.properties" description="Shutdown the server">
    <get src="http://127.0.0.1:${product.listenport}/QUIT" dest="NUL"/>
</target>

'NUL' 使我能够使用 get 而无需处理正在创建的新文件,因此这非常适合工作 \o/

4

1 回答 1

3

您可以使用get任务来调用http url。这是更多信息https://ant.apache.org/manual/Tasks/get.html

例如<get src="http://127.0.0.1:${product.listenport}/QUIT" dest="${temp.dir}/quit.res"/>

于 2013-04-09T09:10:06.883 回答