Skip to content

Instantly share code, notes, and snippets.

@bsandhu
Last active October 12, 2017 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsandhu/c2b22c69a6e6527a8f4f2608c90c8055 to your computer and use it in GitHub Desktop.
Save bsandhu/c2b22c69a6e6527a8f4f2608c90c8055 to your computer and use it in GitHub Desktop.
Protractor config with BrowserStackLocal via Proxy
const path = require('path');
exports.props = {
capabilities: {
browserName: 'chrome',
chromeOptions: {
args: ["show-fps-counter=true"]
}
},
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true // Use colors in the command line report.
},
// Spec patterns are relative to the location of the spec file. They may
// include glob patterns.
suites: {
search: ["target/*.js"]
},
onPrepare: () => {
browser.waitForAngularEnabled(false);
}
};
const browserstack = require('browserstack-local');
const path = require('path');
const process = require('process');
const commonConfig = require('./protractor.common.conf.js');
const _ = require('underscore');
/************************************************/
/* User setup */
/************************************************/
const PROXY_HOST = '10.10.100.10';
const PROXY_PORT = '8080';
// Note: These can be passed via IntelliJ Run configuration for Gulp
const PROXY_USER = process.env.PROXY_USER || undefined;
const PROXY_PASS = process.env.PROXY_PASS || undefined;
const BROWSERSTACK_USER = process.env.BROWSERSTACK_USER || undefined;
const BROWSERSTACK_KEY = process.env.BROWSERSTACK_KEY || undefined;
if (_.isUndefined(PROXY_USER)
|| _.isUndefined(PROXY_PASS)
|| _.isUndefined(BROWSERSTACK_KEY)
|| _.isUndefined(BROWSERSTACK_USER)) {
const msg = `\nPlease specify PROXY and BROWSERSTACK credentials in protractor.browserstack.conf.js \n`;
console.error(msg);
throw msg;
}
/************************************************/
/* BrowserStack/Protractor config */
/************************************************/
let browserstackConfig = {
seleniumAddress: 'http://hub-cloud.browserstack.com/wd/hub',
webDriverProxy: `${PROXY_USER}:${PROXY_PASS}@${PROXY_HOST}:${PROXY_PORT}`,
capabilities: {
'browserstack.user' : BROWSERSTACK_USER,
'browserstack.key' : BROWSERSTACK_KEY,
'browserstack.local': true,
browserName: 'chrome'
},
// Start BrowserStack local process before start of test
// This launches the .exe downloaded from Nexus using the 'browserstack-local' npm pkg
// Since the build machine can't access the www, we put the BrowserStackLocal.exe in Nexus
// and download in as a part of the build
beforeLaunch: function () {
console.log("Connecting local");
return new Promise(function (resolve, reject) {
exports.bs_local = new browserstack.Local();
exports.bs_local.start({
'key' : BROWSERSTACK_KEY,
'proxyHost' : PROXY_HOST,
'proxyPort' : PROXY_PORT,
'proxyUser' : PROXY_USER,
'proxyPass' : PROXY_PASS,
'logFile' : 'target/BrowserStackLocal.log',
'forceLocal' : true,
'binarypath' : path.join(process.cwd(), 'target/binaries/BrowserStackLocal.exe')
},
error => {
if (error) return reject(error);
console.log('Connected. Now testing...');
resolve();
});
});
},
// Stop BrowserStack local after end of test
afterLaunch: function () {
return new Promise(function (resolve, reject) {
exports.bs_local.stop(resolve);
});
}
};
const finalConfig = _.extend(commonConfig.props, browserstackConfig);
console.log(`\n*** Protractor config ***\n`);
console.log(finalConfig);
exports.config = finalConfig;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment