diff --git a/example/chromeOnlyConf.js b/example/chromeOnlyConf.js index 6b2bab582..5c59c56a5 100644 --- a/example/chromeOnlyConf.js +++ b/example/chromeOnlyConf.js @@ -2,7 +2,7 @@ exports.config = { // Do not start a Selenium Standalone sever - only run this using chrome. chromeOnly: true, - chromeDriver: './selenium/chromedriver', + chromeDriver: '../selenium/chromedriver', // Capabilities to be passed to the webdriver instance. capabilities: { diff --git a/lib/cli.js b/lib/cli.js index 9890f3954..2fe52ba07 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -42,10 +42,6 @@ var argv = require('optimist'). }). argv; - -var configPath; - - var printVersion = function () { util.puts('Version ' + JSON.parse( fs.readFileSync(__dirname + '/../package.json', 'utf8')).version); @@ -56,18 +52,25 @@ if (argv.version) { printVersion(); } +// Any file names should be resolved relative to the current working directory. if (argv.specs) { argv.specs = argv.specs.split(','); argv.specs.forEach(function(spec, index, arr) { arr[index] = path.resolve(process.cwd(), spec); }); } +['seleniumServerJar', 'chromeDriver', 'onPrepare'].forEach(function(name) { + if (argv[name]) { + argv[name] = path.resolve(process.cwd(), argv[name]); + } +}); var configFilename = argv._[0]; if (configFilename) { - configPath = path.resolve(process.cwd(), configFilename); - runner.addConfig(require(configPath).config); - runner.addConfig({specFileBase: path.dirname(configPath)}) + var configPath = path.resolve(process.cwd(), configFilename); + config = require(configPath).config; + config.configDir = path.dirname(configPath); + runner.addConfig(config); } runner.addConfig(argv); diff --git a/lib/runner.js b/lib/runner.js index b9c187d8d..32e97e600 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -17,7 +17,7 @@ var sauceAccount; // Default configuration. var config = { - specFileBase: './', + configDir: './', seleniumServerJar: null, seleniumArgs: [], seleniumPort: null, @@ -60,6 +60,15 @@ var merge = function(into, from) { * @param {Object} additionalConfig */ var addConfig = function(additionalConfig) { + // All filepaths should be kept relative to the current config location. + // This will not affect absolute paths. + ['seleniumServerJar', 'chromeDriver', 'onPrepare'].forEach(function(name) { + if (additionalConfig[name] && additionalConfig.configDir && + typeof additionalConfig[name] == 'string') { + additionalConfig[name] = + path.resolve(additionalConfig.configDir, additionalConfig[name]); + } + }) merge(config, additionalConfig); }; @@ -183,12 +192,12 @@ var runJasmineTests = function() { } var resolvedSpecs = []; for (var i = 0; i < specs.length; ++i) { - var matches = glob.sync(specs[i], {cwd: config.specFileBase}); + var matches = glob.sync(specs[i], {cwd: config.configDir}); if (!matches.length) { util.puts('Warning: pattern ' + specs[i] + ' did not match any files.'); } for (var j = 0; j < matches.length; ++j) { - resolvedSpecs.push(path.resolve(config.specFileBase, matches[j])); + resolvedSpecs.push(path.resolve(config.configDir, matches[j])); } } if (!resolvedSpecs.length) { @@ -245,7 +254,7 @@ var runJasmineTests = function() { if (typeof config.onPrepare == 'function') { config.onPrepare(); } else if (typeof config.onPrepare == 'string') { - require(path.resolve(config.specFileBase, config.onPrepare)); + require(path.resolve(config.configDir, config.onPrepare)); } else { throw 'config.onPrepare must be a string or function'; } diff --git a/referenceConf.js b/referenceConf.js index 0109610a7..4b2d4d3de 100644 --- a/referenceConf.js +++ b/referenceConf.js @@ -14,7 +14,8 @@ exports.config = { // and chromeDriver will be used directly (from the location specified in // chromeDriver) - // The location of the selenium standalone server .jar file. + // The location of the selenium standalone server .jar file, relative + // to the location of this config. seleniumServerJar: './selenium/selenium-server-standalone-2.37.0.jar', // The port to start the selenium server on, or null if the server should // find its own unused port. diff --git a/spec/altRootConf.js b/spec/altRootConf.js index 92b02b8c2..4eac7d4ca 100644 --- a/spec/altRootConf.js +++ b/spec/altRootConf.js @@ -1,7 +1,7 @@ // Tests for an Angular app where ng-app is not on the body. exports.config = { - seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar', - chromeDriver: './selenium/chromedriver', + seleniumServerJar: '../selenium/selenium-server-standalone-2.37.0.jar', + chromeDriver: '../selenium/chromedriver', seleniumAddress: 'http://localhost:4444/wd/hub', diff --git a/spec/basicConf.js b/spec/basicConf.js index 09db2bc03..277d0bf64 100644 --- a/spec/basicConf.js +++ b/spec/basicConf.js @@ -1,7 +1,7 @@ // The main suite of Protractor tests. exports.config = { - seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar', - chromeDriver: './selenium/chromedriver', + seleniumServerJar: '../selenium/selenium-server-standalone-2.37.0.jar', + chromeDriver: '../selenium/chromedriver', seleniumAddress: 'http://localhost:4444/wd/hub', diff --git a/spec/junitOutputConf.js b/spec/junitOutputConf.js index b217d0cb5..a51ea9b3a 100644 --- a/spec/junitOutputConf.js +++ b/spec/junitOutputConf.js @@ -5,8 +5,8 @@ require('jasmine-reporters'); // The main suite of Protractor tests. exports.config = { - seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar', - chromeDriver: './selenium/chromedriver', + seleniumServerJar: '../selenium/selenium-server-standalone-2.35.0.jar', + chromeDriver: '../selenium/chromedriver', seleniumAddress: 'http://localhost:4444/wd/hub', diff --git a/spec/onPrepareConf.js b/spec/onPrepareConf.js index c3695c367..63acedf5f 100644 --- a/spec/onPrepareConf.js +++ b/spec/onPrepareConf.js @@ -1,7 +1,7 @@ // The main suite of Protractor tests. exports.config = { - seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar', - chromeDriver: './selenium/chromedriver', + seleniumServerJar: '../selenium/selenium-server-standalone-2.35.0.jar', + chromeDriver: '../selenium/chromedriver', seleniumAddress: 'http://localhost:4444/wd/hub', diff --git a/spec/onPrepareStringConf.js b/spec/onPrepareStringConf.js index 67b0e3760..d51f0497d 100644 --- a/spec/onPrepareStringConf.js +++ b/spec/onPrepareStringConf.js @@ -1,8 +1,8 @@ // Configuration using a string in onPrepare to load a file with code to // execute once before tests. exports.config = { - seleniumServerJar: './selenium/selenium-server-standalone-2.35.0.jar', - chromeDriver: './selenium/chromedriver', + seleniumServerJar: '../selenium/selenium-server-standalone-2.35.0.jar', + chromeDriver: '../selenium/chromedriver', seleniumAddress: 'http://localhost:4444/wd/hub',