3

在使用 CasperJS 为基于 ExpressJS 的 Web 应用程序创建功能测试套件时,我似乎遇到了一个非常基本的问题。我似乎无法连接到 t

我创建了一个准系统 Express 应用程序来使用 Express 可执行文件进行测试,例如express myapp. 我用node app.js.

下面是测试脚本,我要做的只是连接到我的 Express 页面并检查标题,应该是“Express”。

var casper = require("casper").create({
        logLevel: "debug"
});

casper.start("localhost:3000/")

casper.then(function() {
        this.test.assertTitle("Express", "Express homepage title is the one expected");
});
casper.run(function() {
        this.exit();
});

当我尝试连接时localhost,如上所述,这是我收到的错误消息。casper 似乎找不到标题。

FAIL Express homepage title is the one expected
#    type: assertTitle
#    subject: ""
#    expected: "Express"

如果我更改为尝试连接到我的服务器的外部域,例如casper.start("http://mydomain.com:3000/"),那么测试通过。

PASS Express homepage title is the one expected

这里发生了什么?

4

1 回答 1

1

如果你确定你在 localhost 的 3000 端口上,我会试试这个:

casper.start("http://localhost:3000")
于 2013-12-07T15:02:58.823 回答