Cucumber-js:使用 phantomjs 的世界构造函数示例

Cucumber-js: World constructor example with phantomjs

cucumber-js page 中显示了一个僵尸示例:

// features/support/world.js
var zombie = require('zombie');
var WorldConstructor = function WorldConstructor(callback) {

  var browser = new zombie();

  var world = {
    browser: browser,                        // this.browser will be available in step definitions
    visit: function(url, callback) {         // this.visit will be available in step definitions
      this.browser.visit(url, callback);
    }
  };

  callback(world); // tell Cucumber we're finished and to use our world object instead of 'this'
};
exports.World = WorldConstructor;

可以用 Phantomjs 代替 Zombie 吗?

有人可以给我看一个 world.js 的例子吗?

谢谢。

终于找到了解决办法:

// features/support/world.js
var webdriver = require("selenium-webdriver");

var WorldConstructor = function WorldConstructor(callback) {
  var world = {
    driver: new webdriver.Builder()
      .withCapabilities(webdriver.Capabilities.phantomjs())
      .build()
  };

  callback(world);
};

exports.World = WorldConstructor;

我必须安装 phantomjs:

npm install phantomjs

Chrome 驱动程序

你也可以使用chromedriver如下:

npm install chromedriver

记得把驱动改成:

driver: new webdriver.Builder()
  .withCapabilities(webdriver.Capabilities.chrome())
  .build()