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 18, 2016
1 parent 05a53d1 commit 213a1df
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 5 deletions.
11 changes: 6 additions & 5 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,8 +77,8 @@ DirectDriverProvider.prototype.getNewDriver = function() {
driver = new firefox.Driver(this.config_.capabilities);
break;
default:
throw new Error('browserName ' + this.config_.capabilities.browserName +
'is not supported with directConnect.');
throw new BrowserError('browserName ' + this.config_.capabilities.browserName +
' is not supported with directConnect.');
}
this.drivers_.push(driver);
return driver;
Expand Down
13 changes: 13 additions & 0 deletions lib/exitCodes.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import {Logger} from './logger2';


const CONFIG_ERROR_CODE = 105;
const BROWSER_ERROR_CODE = 135;

export class ProtractorError {
error: Error;
description: string;
code: number;
stack: string;

constructor(logger: Logger, description: string, code: number) {
this.error = new Error();
this.description = description;
Expand All @@ -26,3 +29,13 @@ export class ConfigError extends ProtractorError {
super(logger, description, ConfigError.CODE);
}
}

/**
* Browser errors including getting a driver session, direct connect, etc.
*/
export class BrowserError extends ProtractorError {
static CODE = BROWSER_ERROR_CODE;
constructor(logger: Logger, msg: string) {
super(logger, msg, BrowserError.CODE);
}
}
69 changes: 69 additions & 0 deletions spec/unit/driverProviders/direct_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

var path = require('path');
var fs = require('fs');
var BrowserError = require('../../../built/exitCodes').BrowserError;

var removeSeleniumFolder = 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) { }
};

describe('direct connect', function() {
describe('without the selenium driver', function() {
beforeEach(function() {
removeSeleniumFolder();
});

it('should throw an error if no drivers are present', 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);
});
});

describe('with selenium drivers', function() {
beforeEach(function() {
// add files to selenium folder
var directory = path.resolve('selenium');
fs.mkdirSync(directory);
var file = 'chromedriver_' + require('../../../config.json').webdriverVersions.chromedriver;
fs.openSync(path.resolve(directory, file), 'w');
});

afterEach(function() {
removeSeleniumFolder();
});

it('should throw an error if the driver cannot be used', function() {
var config = {
directConnect: true,
capabilities: { browserName: 'foobar explorer' }
};
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);
});
});
});

0 comments on commit 213a1df

Please sign in to comment.