Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.Before(function (scenario, callback) {
var world = this;
var task_id = parseInt(process.env.TASK_ID || 0);
var caps = config.capabilities[task_id];
caps['browserstack.user'] = username;
caps['browserstack.key'] = accessKey;
if(caps["browserstack.local"]){
// Code to start browserstack local before start of test and stop browserstack local after end of test
bs_local = new browserstack.Local();
bs_local.start({'key': accessKey }, function(error) {
if (error) return console.log(error.red);
world.driver = createBrowserStackSession(config, caps);
callback();
});
}
else {
world.driver = createBrowserStackSession(config, caps);
callback();
}
});
protected setupDriverEnv(): Promise {
this.config_.capabilities['browserstack.user'] = this.config_.browserstackUser;
this.config_.capabilities['browserstack.key'] = this.config_.browserstackKey;
this.config_.seleniumAddress = 'http://hub.browserstack.com/wd/hub';
// Append filename to capabilities.name so that it's easier to identify
// tests.
if (this.config_.capabilities.name && this.config_.capabilities.shardTestFiles) {
this.config_.capabilities.name +=
(':' + this.config_.specs.toString().replace(/^.*[\\\/]/, ''));
}
logger.info('Using BrowserStack selenium server at ' + this.config_.seleniumAddress);
return Promise.resolve();
}
}
function (capabilities) {
capabilities['browserstack.user'] = BROWSERSTACK_USER;
capabilities['browserstack.key'] = BROWSERSTACK_KEY;
capabilities['browserstack.local'] = true;
// Selenium 3.6.0 does not work great with IE11
if (capabilities.browserName !== 'internet explorer') {
capabilities['browserstack.selenium_version'] = '3.4.0';
}
capabilities.project = pkg.name;
capabilities.build = env.BROWSERSTACK_BUILD || pkg.version;
if (capabilities.browserName === 'internet explorer') {
capabilities.ignoreProtectedModeSettings = true;
}
return capabilities;
}
function createCapabilities (capabilities, tags) {
capabilities['browserstack.user'] = env.BROWSERSTACK_USER || env.BS_USERNAME;
capabilities['browserstack.key'] = env.BROWSERSTACK_KEY || env.BS_AUTHKEY;
capabilities['browserstack.local'] = true;
// Selenium 3.4.0 does not work great with IE11
if (capabilities.browserName !== 'internet explorer') {
capabilities['browserstack.selenium_version'] = '3.4.0';
}
capabilities.project = pkg.name;
capabilities.build = env.BROWSERSTACK_BUILD || pkg.version;
capabilities.cucumberOpts = {
format: 'json:./test/reports/' + composeReportName(capabilities) + '.json'
};
if (tags) {
capabilities.cucumberOpts.tags = tags;
return new Promise(function (resolve, reject) {
exports.bs_local = new browserstack.Local();
exports.bs_local.start({'key': config.capabilities['browserstack.key'] }, function (error) {
if (error) return reject(error);
console.log('BrowserStack Connected. Now testing...');
psnode.lookup({command: 'BrowserStackLocal'}, function (err, list) {
exports.bs_local_processes = list;
resolve();
});
});
})
};
before(function(done) {
bsLocal = new browserstack.Local();
bsLocal.start({
'key': caps['browserstack.key']
}, function(error) {
if (error) done(error);
driver = buildDriver(caps);
done();
});
});
beforeEach : function(browser, done) {
console.log("Connecting local");
bs_local = new browserstack.Local();
bs_local.start({'key': browser.options.desiredCapabilities['browserstack.key'] }, function(error) {
if (error) return done(error);
console.log('Connected. Now testing...');
done();
});
},
get accessKey() {
return this.settings.desiredCapabilities['browserstack.key'];
}
return new Promise((resolve, reject) => {
exports.bs_local = new browserstack.Local();
exports.bs_local.start({'key': exports.config.commonCapabilities['browserstack.key'] }, (error) => {
if (error) {
return reject(error);
};
resolve();
});
});
},
adaptSettings() {
this.settings.webdriver.start_process = false;
this.settings.webdriver.port = Number(this.settings.webdriver.port);
if (this.settings.webdriver.port === 443) {
this.settings.webdriver.ssl = true;
}
if (!this.accessKey && process.env.BROWSERSTACK_KEY) {
this.settings.desiredCapabilities['browserstack.key'] = process.env.BROWSERSTACK_KEY;
}
if (!this.username && process.env.BROWSERSTACK_USER) {
this.settings.desiredCapabilities['browserstack.user'] = process.env.BROWSERSTACK_USER;
}
if (!this.build) {
this.settings.desiredCapabilities.build = 'nightwatch-test-build';
}
}