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

时间:2015-04-04 21:01:18

标签: testing phantomjs cucumberjs

cucumber-js page中展示了Zombie的一个例子:

// 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的例子吗?

感谢。

1 个答案:

答案 0 :(得分:4)

最后我找到了解决方案:

// 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

<强> Chromedriver

你也可以按照以下方式使用chromedriver:

npm install chromedriver

请记住将驱动程序更改为:

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