Cucumber-js: World constructor example with phantomjs

浪子不回头ぞ 提交于 2019-12-09 23:57:51

问题


In the cucumber-js page is showed an example with 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;

It is possible use Phantomjs instead of Zombie?

Can someone show me an example of world.js with it ?

Thanks.


回答1:


Finally I found the solution:

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

I had to install phantomjs:

npm install phantomjs

Chromedriver

You can also use chromedriver as follows:

npm install chromedriver

Remember to change driver to:

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


来源:https://stackoverflow.com/questions/29451362/cucumber-js-world-constructor-example-with-phantomjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!