【问题标题】:Functional testing for our site我们网站的功能测试
【发布时间】:2012-07-28 02:21:39
【问题描述】:

我正在与 Mink / Sahi 合作为我的网站编写功能测试套件。

我在 Firefox 和 Chrome 上进行了一组测试,对此我很满意。它们每晚都在我们的 Jenkins 机器上运行,并且运行良好。

但是,因为我们的 Jenkins 机器是服务器,而 Chrome/Firefox 是 GUI 应用程序,所以我不得不让测试在我的台式电脑上运行。这很痛苦,因为这意味着我必须每晚都打开它,这不利于环境和成本。另外,如果它在电源、网络或软件方面有任何问题,那么测试就会失败。

所以我想要一些关于切换测试以在 Jenkins 机器上使用无头浏览器的建议。

似乎我有三个选择:Goutte、Zombie 和 Phantom(当然,除非有人可以推荐另一个)。以下总结了我到目前为止的进展:

  • Goutte:这是 PHP 驱动的,因此可以在 Mink 内部运行,无需 Sahi。这听起来很棒,因为 Jenkins 盒子的资源有限,所以我需要安装和运行的越少越好。但是,我需要运行 JS 代码作为测试的一部分,我知道 Goutte 无法做到这一点。这排除了它吗?

  • 僵尸:在 Node.js 下运行。不幸的是,我根本无法完成这项工作。我已经安装了 Node、NPM 和 Zombie,但我无法让 Mink 识别它。谁能给我一些比 Mink 网站更清晰的说明来告诉我如何运行它?

  • Phantom:不幸的是,Mink 没有 Phantom 的驱动程序,所以我必须通过 Sahi 运行它。正如我所说,我宁愿不必在 Jenkins 服务器上安装 Sahi,尤其是因为它还需要作为服务器连续运行。但这是迄今为止我唯一成功的。在 Sahi 下运行它,我可以让我的测试成功运行(虽然不是一致的,这是一个令人担心的问题 - 它似乎随机超时,大约三分之一)。任何人都可以建议一种无需安装 Sahi(或任何其他中间层服务器)即可运行它的方法吗?或者如果我确实需要 Sahi,谁能告诉我如何配置 Jenkins 以在测试套件开始时启动 Sahi,并在结束时停止它?

我非常感谢有关如何进行的任何建议。出于某种原因,这些选择似乎都没有明显的胜利。但是功能测试很重要,所以这一定是一个已解决的问题。对我来说最好的解决方案是什么?

(我知道还可以选择用 Javascript 重写我的脚本以直接与 Zombie 或 Phantom 对话。我不想这样做,因为当它们失败时,我仍然需要看到它们在 Firefox 中运行看看出了什么问题,所以像 Mink 这样的跨浏览器界面是理想的——更不用说我已经用 PHP 编写了所有测试!)

感谢您的任何建议。 :)

【问题讨论】:

    标签: phantomjs zombie.js sahi mink goutte


    【解决方案1】:

    这个答案是专门为

    谁能告诉我如何配置 Jenkins 以在 测试套件的开始并在最后停止?

    使用 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>
    

    重要的是

    1. “sahitests”目标启动 Sahi 并在其中运行测试 并行。
    2. “start”目标在没有仪表板的情况下启动 Sahi。

    您可以在 Sahi 论坛上发布 Sahi+PhantomJS 中的随机故障问题以获得答案。

    Sahi 作为代理服务器的开销/足迹相当小。

    【讨论】:

    • 感谢您的回答。非常感谢。我会试试你的想法;它们听起来很有趣。我现在也将接受答案,甚至在我尝试之前,因为它看起来应该是我正在寻找的东西,即使它对我不起作用,它肯定会教我一些东西!谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多