【发布时间】:2016-04-29 23:16:35
【问题描述】:
我正在尝试让 Phantom.js 运行一套用 Jasmine 编写的 JavaScript 测试。以下是重现我正在做的事情的步骤:
获取最新版 Jasmine 框架的latest standalone release(压缩包)
存档包含几个 javascript 文件的示例规范和可以在浏览器中运行这些规范的
SpecRunner.html文件安装phantom.js并从phantom.js项目的example文件夹下载jasmine 2 runner
-
尝试使用 phantom.js 运行
SpecRunner.html:phantomjs ./phantom/run-jasmine2.js ./jasmine/SpecRunner.html
(其中./phantom/run-jasmine2.js 是 phantom.js 的 jasmine2 runner 的路径,./jasmine/SpecRunner.html 是 jasmine 文件夹中带有示例规范的规范 runner 的路径)
我收到以下错误
TypeError: null is not an object (evaluating 'document.body.querySelector('.description').innerText')
Blocked a frame with origin "file://" from accessing a frame with origin "null". The frame requesting access has a protocol of "file", the frame being accessed has a protocol of "about". Protocols must match.
因此,Phantom 似乎不高兴将规范运行程序直接作为磁盘中的文件提供给它,而不是作为由本地服务器提供的文件 (localhost:8080/SpecRunner.html)。您能否建议一种方法让 Phantom 使用规范运行程序文件而不启动服务器?如果可能的话,也不要使用 Karma。
【问题讨论】:
-
你使用的是什么版本的 PhantomJS?
标签: javascript jasmine phantomjs