我有一个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
我的解决方案
最终,我使用了以下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/