【问题标题】:PhantomJS error on basic tests基本测试中的 PhantomJS 错误
【发布时间】:2015-08-13 21:26:44
【问题描述】:

我正在使用node-phantom npm 模块,每当我做一个超级简单的测试时,比如

phantom=require('node-phantom');
var phantom=require('node-phantom');
phantom.create(function(err,ph) {
    console.log("testing");
    ph.exit();
});

它会打印以下错误: phantom stdout: console msg:XMLHttpRequest cannot load http://127.0.0.1/socket.io/?EIO=3&transport=polling&t=1439501157936-0. Origin http://127.0.0.1:60689 is not allowed by Access-Control-Allow-Origin.

有人知道这是什么原因吗?

package.json:

{
  "name": "test",
  "version": "0.0.1",
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-contrib-clean": "^0.6.0",
    "grunt-contrib-watch": "^0.6.1",
    "grunt-exec": "^0.4.6",
    "mocha": "^2.2.5",
    "node-phantom": "^0.2.5",
    "phantom": "^0.7.2",
    "phantomjs": "^1.9.18",
  }
}

(幻影有多个版本,因为我一直在尝试)

【问题讨论】:

  • 向我们展示 package.json 和你执行的命令npm test?
  • 尝试phantom 而不是node-phantom。它具有基本相同的 API,但通信设置不同。顺便说一句,你在窗户上吗?
  • @EmilioPlatzer 我直接使用node test.js 运行脚本(我的文件名为test.js)。现在不尝试与测试套件绑定,实际上只是尝试设置我的环境并且没有任何工作。

标签: javascript node.js testing phantomjs


【解决方案1】:

node-phantom.js 文件中将window.location.hostname 更改为window.location.host

【讨论】:

  • 谢谢,是的,我也找到了。这在技术上是可行的,但我希望有更好的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-17
  • 2015-12-03
  • 1970-01-01
  • 2017-03-25
相关资源
最近更新 更多