2015-04-04 107 views
1

cucumber-js page世界构造例子显示出与僵尸的例子:黄瓜-JS:与phantomjs

// 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而不是僵尸?

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

谢谢。

回答

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() 
+0

请你帮我出https://stackoverflow.com/questions/48297950/cucumberjs-how-to-use-worldconstructor-across-different-features – Valay 2018-01-17 11:12:57

+0

@Valay对不起,但我没有用了两年。 – drinor 2018-01-18 09:15:14