我正在与 Mink 合作/Sahi为我的网站编写功能测试套件。
我使用 Firefox 和 Chrome 进行了一系列测试,对此我很满意。它们每晚都在我们的 Jenkins 盒子上运行,并且运行良好。
但是,因为我们的 Jenkins 盒子是服务器,而 Chrome/Firefox 是 GUI 应用程序,所以我必须在我的台式电脑上运行测试。这很痛苦,因为这意味着我必须每晚都打开它,这对环境和成本来说都是不利的。另外,如果电源、网络或软件出现任何问题,测试就会失败。
所以我想要一些关于将测试切换为在 Jenkins 盒子本身上使用 headless 浏览器的建议。
看来我有三个选择:Goutte、Zombie 和 Phantom(当然,除非有人可以推荐另一个)。以下总结了我迄今为止的进展:
Goutte:这是 PHP 驱动的,因此可以在 Mink 内部运行,无需 Sahi。这听起来很棒,因为 Jenkins 盒子的资源有限,所以我需要安装和运行的东西越少越好。但是,我需要运行 JS 代码作为测试的一部分,并且我知道 Goutte 无法做到这一点。这是否排除了这种可能性?
Zombie:在 Node.js 下运行。不幸的是,我根本无法完成这项工作。我已经安装了 Node、NPM 和 Zombie,但我无法让 Mink 识别它们。任何人都可以给我一些比 Mink 网站更清晰的说明来说明如何运行它吗?
Phantom:不幸的是,Mink 没有 Phantom 的驱动程序,所以我必须通过 Sahi 运行它。正如我所说,我不想在 Jenkins 服务器上安装 Sahi,特别是因为它还需要作为服务器持续运行。但这是迄今为止我唯一取得成功的一次。在 Sahi 下运行它,我可以让我的测试成功运行(尽管不一致,这是一个担心 - 它似乎随机超时,大约三分之一)。任何人都可以建议一种无需安装 Sahi (或任何其他中间层服务器)即可运行此程序的方法吗?或者,如果我确实需要 Sahi,谁能告诉我如何配置 Jenkins 在测试套件开始时启动 Sahi 并在结束时停止它?
我非常感谢任何关于如何继续的建议。由于这样或那样的原因,这些选择似乎都没有明显的胜利。但功能测试很重要,所以这一定是一个已解决的问题。对我来说最好的解决方案是什么?
(我知道还可以选择用 Javascript 重写我的脚本来直接与 Zombie 或 Phantom 对话。我不想这样做,因为当它们失败时,我仍然需要看到它们在 Firefox 中运行看看出了什么问题,所以像 Mink 这样的跨浏览器界面是理想的 - 更不用说我已经用 PHP 编写了所有测试!)
感谢您的任何建议。 :)
最佳答案
这个答案专门针对
can anyone tell me how to configure Jenkins to start Sahi at the begining of the test suite and stop it at the end?
使用 ant,您可以使用以下目标启动 Sahi
<target name="sahitests" description="start the server and run sahi tests">
<parallel>
<antcall target="start"/>
<sequential>
<waitfor maxwait="3" maxwaitunit="minute" checkevery="100">
<http url="http://${urlbase}/demo/index.htm"/>
</waitfor>
<antcall target="runietests"/>
<antcall target="stopsahi"/>
</sequential>
</parallel>
</target>
<target name="start" description="starts proxy">
<java classname="net.sf.sahi.Proxy" fork="true">
<classpath location="lib/sahi.jar">
<pathelement location="extlib/rhino/js.jar"/>
<pathelement location="extlib/apc/commons-codec-1.3.jar"/>
<pathelement location="extlib/license/truelicense.jar"/>
<pathelement location="extlib/license/truexml.jar"/>
<pathelement location="extlib/db/h2.jar" />
<pathelement location="extlib/poi/dom4j-1.6.1.jar"/>
<pathelement location="extlib/poi/excelpoi.jar"/>
<pathelement location="extlib/poi/poi-3.7-20101029.jar"/>
<pathelement location="extlib/poi/poi-ooxml-3.7-20101029.jar"/>
<pathelement location="extlib/poi/poi-ooxml-schemas-3.7-20101029.jar"/>
<pathelement location="extlib/poi/xmlbeans-2.3.0.jar"/>
<fileset dir="extlib" includes="*.jar"/>
</classpath>
<arg value="." id="basePath"/>
<arg value="userdata" id="userdataPath"/>
</java>
</target>
<target name="runietests">
<antcall target="clean-tests">
</antcall>
<sahi suite="../userdata/scripts/demo/demo.suite"
browserType="ie"
baseurl="http://${urlbase}/demo/"
sahihost="localhost"
sahiport="9999"
failureproperty="sahi.failed"
haltonfailure="false"
threads="6"
>
<report type="html"/>
<report type="junit" logdir="${userdata.dir}/temp/junit/tests"/>
</sahi>
<antcall target="report-gen" />
<antcall target="failsahi"/>
</target>
<target name="report-gen">
<delete dir="${userdata.dir}/temp/junit/reports">
</delete>
<mkdir dir="${userdata.dir}/temp/junit/reports"/>
<junitreport todir="${userdata.dir}/temp/junit/reports">
<fileset dir="${userdata.dir}/temp/junit/tests">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${userdata.dir}/temp/junit/reports/sahi-html" />
</junitreport>
</target>
<target name="failsahi" if="sahi.failed">
<antcall target="stopsahi"/>
<fail message="Sahi tests failed!"/>
</target>
<target name="stopsahi" description="stop sahi server">
<sahi stop="true" sahihost="localhost" sahiport="9999"/>
</target>
重要的部分是
- “sahitests”目标启动 Sahi 并运行测试 平行。
- “start”目标,在没有仪表板的情况下启动 Sahi。
您可以将Sahi+PhantomJS中的随机失败问题发布到Sahi论坛上寻求解答。
Sahi 作为代理服务器的开销/占用空间相当小。
关于phantomjs - 我们网站的功能测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11721116/