diff --git a/lib/driverProviders/direct.js b/lib/driverProviders/direct.js index 2c7ee341d..c783d0366 100644 --- a/lib/driverProviders/direct.js +++ b/lib/driverProviders/direct.js @@ -12,7 +12,8 @@ var webdriver = require('selenium-webdriver'), path = require('path'), util = require('util'), DriverProvider = require('./driverProvider'), - log = require('../logger'); + log = require('../logger'), + BrowserError = require('../exitCodes').BrowserError; var DirectDriverProvider = function(config) { DriverProvider.call(this, config); @@ -34,7 +35,7 @@ DirectDriverProvider.prototype.setupEnv = function() { log.puts('Using FirefoxDriver directly...'); break; default: - throw new Error('browserName (' + this.config_.capabilities.browserName + + throw new BrowserError('browserName (' + this.config_.capabilities.browserName + ') is not supported with directConnect.'); } return q.fcall(function() {}); @@ -62,7 +63,7 @@ DirectDriverProvider.prototype.getNewDriver = function() { var chromeDriverFile = this.config_.chromeDriver || defaultChromeDriverPath; if (!fs.existsSync(chromeDriverFile)) { - throw new Error('Could not find chromedriver at ' + chromeDriverFile); + throw new BrowserError('Could not find chromedriver at ' + chromeDriverFile); } var service = new chrome.ServiceBuilder(chromeDriverFile).build(); @@ -76,7 +77,7 @@ DirectDriverProvider.prototype.getNewDriver = function() { driver = new firefox.Driver(this.config_.capabilities); break; default: - throw new Error('browserName ' + this.config_.capabilities.browserName + + throw new BrowserError('browserName ' + this.config_.capabilities.browserName + 'is not supported with directConnect.'); } this.drivers_.push(driver); diff --git a/lib/exitCodes.ts b/lib/exitCodes.ts index 433c9ef17..be3d59a69 100644 --- a/lib/exitCodes.ts +++ b/lib/exitCodes.ts @@ -12,10 +12,20 @@ export class ProtractorError extends Error { } const CONFIG_ERROR_CODE = 105; +const BROWSER_ERROR_CODE = 135; /** * Configuration file error */ export class ConfigError extends ProtractorError { - constructor(msg: string) { super(msg, CONFIG_ERROR_CODE); } + static CODE = CONFIG_ERROR_CODE; + constructor(msg: string) { super(msg, ConfigError.CODE); } } + +/** + * Browser errors including getting a driver session, direct connect, etc. + */ + export class BrowserError extends ProtractorError { + static CODE = BROWSER_ERROR_CODE; + constructor(msg: string) { super(msg, BrowserError.CODE); } + } diff --git a/spec/unit/driverProviders/direct_test.js b/spec/unit/driverProviders/direct_test.js new file mode 100644 index 000000000..bdb98d801 --- /dev/null +++ b/spec/unit/driverProviders/direct_test.js @@ -0,0 +1,39 @@ + +var path = require('path'); +var fs = require('fs'); +var BrowserError = require('../../../built/exitCodes').BrowserError; + +describe('direct connect', function() { + describe('without the selenium driver', function() { + beforeEach(function() { + try { + var directory = path.resolve('selenium'); + var files = fs.readdirSync(directory); + for (var pos = 0; pos < files.length; pos++) { + fs.unlinkSync(path.resolve(directory, files[pos])); + } + fs.rmdirSync(directory); + } catch(e) { } + }); + + it('should do something', function() { + var config = { + directConnect: true, + capabilities: { browserName: 'chrome' } + }; + var errorFound = false; + try { + webdriver = require('../../../built/driverProviders/direct')(config); + webdriver.getNewDriver(); + } catch(e) { + errorFound = true; + expect(e.code).toBe(BrowserError.CODE); + } + expect(errorFound).toBe(true); + }); + + // it('should throw an error', function() { + // ; + // }); + }); +});