我正在与Mink / Sahi合作,为我的网站编写功能测试套件。
我通过Firefox和Chrome进行了一系列测试,我很满意。他们每晚都在Jenkins的盒子上跑步,并且运作良好。
然而,因为我们的Jenkins盒子是服务器而Chrome / Firefox是GUI应用程序,所以我不得不在我的台式PC上运行测试。这是一种痛苦,因为这意味着我必须每晚都打开它,这对于环境和成本原因是不利的。此外,如果电源或网络或软件出现任何问题,则测试失败。
所以我想在切换测试时使用Jenkins盒子上的无头浏览器。
似乎我有三个选择: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编写了所有测试的事实!)
感谢您的任何建议。 :)
答案 0 :(得分:2)
这个答案专门针对
任何人都可以告诉我如何配置Jenkins来启动Sahi 开始测试套件并在结束时停止它?
使用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>
重要的部分是
您可以在Sahi论坛上发布Sahi + PhantomJS中的随机失败问题以获得答案。
Sahi作为代理服务器的开销/占用空间相当小。