2

我一直在尝试创建一系列功能单元测试,以便在使用 PhantomJS 作为浏览器的 Node.js Web 服务器上运行,在另一个站点上测试功能。过去我曾成功使用 FuncUnit 从目标站点本身运行功能测试,但为了测试规模,我创建了一个 Node 项目来执行此操作,在 Heroku 实例上运行。

我使用 Bower 安装了 JQuery、Jasmine(我正在使用的测试运行程序)和 FuncUnit。我被告知 FuncUnit 不支持最新版本的 Jasmine,所以它的版本是 1.3.1 - 所有其他包都是最新版本。Phantom 已安装 NPM,并打开以下页面:

<html>
<head>
<title>Functional Testing</title>

<script type="text/javascript" src="bower_components/jquery/dist/jquery.js"></script>
<script type="text/javascript" src="bower_components/syn/dist/syn.js"></script>
<script type="text/javascript" src="bower_components/jasmine-core/lib/jasmine-core/jasmine.js"></script>
<script type="text/javascript" src="bower_components/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
<script type="text/javascript" src="bower_components/jasmine-core/lib/jasmine-core/json2.js"></script>
<script type="text/javascript" src="bower_components/funcunit/dist/funcunit.js"></script>

<script type="text/javascript" src="testSpec.js"></script>

<script type="text/javascript">
   // Standard Jasmine 1.3 boot script from examples
</script>

</head>

<body>
</body>
</html>

测试运行开始后,我几乎立即遇到错误。下面的部分似乎会导致崩溃,尽管我很难确定哪一行与堆栈跟踪已被证明难以导航完全一致。

F.attach(jasmine);

F.speed = 100;

describe("Demo Script", function() {
    "use strict";

    it("should login to the website", function() {

        F.open("http://example.site/login");

        if (F('h2:contains("ALL PROJECTS")').size() === 0) {
            // Not logged in

            F('#Email').visible().type("a@b.com");
        }
    });
});

这会产生以下描述的错误:

TypeError: 'undefined' is not an object (evaluating 'off.left') 
    file:///app/bower_components/funcunit/dist/funcunit.js:290
    file:///app/bower_components/funcunit/dist/funcunit.js:473
    file:///app/bower_components/funcunit/dist/funcunit.js:120 
    file:///app/bower_components/funcunit/dist/funcunit.js:91           
    file:///app/bower_components/funcunit/dist/funcunit.js:2852            
    file:///app/bower_components/funcunit/dist/funcunit.js:3240

此堆栈跟踪的第一行指向以下函数:

//syn.helpers.addOffset
addOffset: function (options, el) {
    var jq = syn.jquery(el), off;
    if (typeof options === 'object' && options.clientX === undefined && options.clientY === undefined && options.pageX === undefined && options.pageY === undefined && jq) {
        el = jq(el);
        off = el.offset();
        options.pageX = off.left + el.width() / 2;
        options.pageY = off.top + el.height() / 2;
    }
}

似乎它el作为 传递给了这个函数undefined,但是试图调查这个调用的来源让我很困惑。如果有人可以看到缺少的脚本引用或我的测试规范有任何错误可能导致这种情况,我们将不胜感激。谢谢!

编辑

我刚刚注意到,如果我让它继续运行,这个错误每隔 30 秒左右就会重新出现一次。

4

0 回答 0