Skip to content

Instantly share code, notes, and snippets.

@jdewit
Last active March 24, 2016 23:39
Show Gist options
  • Save jdewit/8422507 to your computer and use it in GitHub Desktop.
Save jdewit/8422507 to your computer and use it in GitHub Desktop.
world.js file for cucumberjs using phantomjs and protractor.
var assert = require('chai').assert,
path = require('path'),
browserName = process.env.browser || 'chrome',
protractor = require('protractor'),
webdriver = require('selenium-webdriver'),
exec = require('child_process').exec,
util = require('util')
;
var driver = new webdriver.Builder().usingServer('http://localhost:4444/wd/hub').withCapabilities(webdriver.Capabilities[browserName]()).build();
driver.manage().timeouts().setScriptTimeout(100000);
var browser = protractor.wrapDriver(driver);
module.exports = function() {
this.registerHandler('AfterFeatures', function (e, done) {
browser.quit();
if (browserName === 'chrome') {
exec('pkill chromedriver');
} else if (browserName === 'phantomjs') {
exec('pkill phantomjs');
}
setTimeout(function() {
done();
}, 500);
});
};
module.exports.World = function World(callback) {
this.browser = browser;
this.By = protractor.By;
this.p = protractor;
this.assert = assert;
this.baseUrl = 'http://www.wardelladvisor.com';
callback();
};
@anilreddy
Copy link

Hi jdewit,

How can i use this world.js with protractor + cucumberjs. Can u please provide me an example. like defining step definitions and execution.

Please do the need full.

Thanks,
Anil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment