phantom 没有方法 'create'

phantom has no method 'create'

我正在尝试将 phamtom 用于 node express 应用程序。

出于测试目的,我写了这个测试

'use strict' ;

var buster = require("buster"),
  phantom = require('phantom'),
  server="http://localhost:3000";
buster.spec.expose();
describe("get index page", function () {
it("is accessable", function(phantom) {
  phantom.create(function (error,ph) {
    ph.createPage(function (page) {
      ... ...
            ph.exit();
          }
        });
    });
  });
console.log('phatom.create.done') ;
});
});

但是当使用

进行测试时
node test/node-test-index.js

对象幻影没有创建方法

TypeError: Object function (fn) {
              if (typeof fn !== "function") { return resolve("resolve"); }
              return function () {
                  try {
                      var retVal = fn.apply(this, arguments);
                      resolve("resolve");
                      return retVal;
                  } catch (up) {
                      resolve("reject", up);
                  }
              };
          } has no method 'create'
      at Object.<anonymous>     (/home/hebus/Documents/git/system/nodejs/searchEs/test/node-test-index.js:25:15)

如果 it 回调,您将覆盖局部范围内的变量引用。不要重复使用变量名!

it("is accessable", function(done) {

您的代码的另一个错误是 phantom.create() 回调的错误参数。

如果你真的在使用phantom模块,那么你需要改变

phantom.create(function (error,ph) {

phantom.create(function (ph) {

如果没有,那么你应该使用

var phantom = require('node-phantom');

这是 node.js 和 PhantomJS 之间非常相似的桥梁。