所以我有一个奇怪的问题。
我有一个 Jasmine 测试运行器在我的机器上本地运行,可在 localhost:8080/test/runner.html
当我在网络浏览器中打开它时,它可以完美运行。
我想自动执行此操作,因此我使用了 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 正在解析它。