【问题标题】:phantomjs and run-jasmine.js timeoutsphantomjs 和 run-jasmine.js 超时
【发布时间】:2012-03-11 21:17:23
【问题描述】:

所以我有一个奇怪的问题。

我在 localhost:8080/test/runner.html 的机器上本地运行了一个 Jasmine 测试运行程序

当我在网络浏览器中打开它时,它运行良好。

我想自动执行此操作,因此我使用了 phantomjs(从 brew 安装——我在 Mac 上),并且我正在使用代码中的示例 run-jasmine.js 文件。

但是,每当我针对 URL 运行它时,我都会得到:

phantomjs war/test/spec/run_jasmine.js http://localhost:8080/test/runner.html
'waitFor()' timeout

所以我写了一个非常简单的脚本来看看我是否遗漏了什么:

var page = require('webpage').create();

page.open(phantom.args[0],
function(status) {
    if (status !== "success") {
        console.log("Unable to access network");
        phantom.exit();
    } else {
        if (document.body.querySelector('#hello')) {
            console.log('hi');
        }
    }
});

并创建了一个新的 HTML 文件:

<!DOCTYPE html>
<html>
<head>
    <title>hi</title>
</head>
<body>
    <div id="hi"></div>
</body>
</html>

这件事仍然永远挂着。

我在这里遗漏了什么吗?我知道页面正在加载,但看起来 phantomjs 从未解析过它。

【问题讨论】:

  • 这听起来很傻,但是如果你用 127.0.0.1 替换 localhost 呢?有什么区别吗?
  • 这并不傻,但遗憾的是不起作用。但是让我开始思考——如果我尝试 telnet 到端口 8080 并执行GET /test/runner.html HTTP/1.1 会发生什么。低头看 - HTTP/1.1 400 Bad Request Connection: close Server: Jetty(6.1.x) 就像,服务器有问题......(它是 GAE 的本地服务器)
  • 哦,鸭子。服务器正在抛出一个请求登录凭据的页面。我现在必须把它编码进去。并处理饼干。或者只是移动到不同的子目录...

标签: javascript unit-testing jasmine phantomjs


【解决方案1】:

我觉得自己很笨。

/test/ 需要身份验证。

【讨论】:

  • 哈哈,在使用我们的 .net 解决方案实现 phantomjs 时,我犯了完全相同的错误。我们就是这样学习的!
  • 加一个让你感觉很笨:)
猜你喜欢
  • 1970-01-01
  • 2013-05-27
  • 1970-01-01
  • 2015-01-12
  • 2017-04-16
  • 2021-06-12
  • 2017-07-20
  • 1970-01-01
  • 2014-02-09
相关资源
最近更新 更多