Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
chore(exitCodes): adding exit code for direct connect errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cnishina committed Apr 16, 2016
1 parent 5fa94db commit 8793992
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
9 changes: 5 additions & 4 deletions lib/driverProviders/direct.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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() {});
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion lib/exitCodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
}
39 changes: 39 additions & 0 deletions spec/unit/driverProviders/direct_test.js
Original file line number Diff line number Diff line change
@@ -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() {
// ;
// });
});
});

0 comments on commit 8793992

Please sign in to comment.