gpt4 book ai didi

node.js - 无法连接到本地主机 : Using CasperJS for ExpressJS application test suite

转载 作者:搜寻专家 更新时间:2023-11-01 00:02:48 25 4
gpt4 key购买 nike

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

我创建了一个简单的 Express 应用程序来使用 Express 可执行文件进行测试,例如表达我的应用程序。我使用 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

这是怎么回事?

最佳答案

如果你确定你在本地主机上的端口 3000 上,我会试试这个:

casper.start("http://localhost:3000")

关于node.js - 无法连接到本地主机 : Using CasperJS for ExpressJS application test suite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15983878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com