This repository has been archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(exitCodes): adding exit code for browser connect errors
- Loading branch information
Showing
9 changed files
with
267 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,75 @@ | ||
import {Logger} from './logger2'; | ||
|
||
const CONFIG_ERROR_CODE = 105; | ||
const BROWSER_ERROR_CODE = 135; | ||
|
||
export class ProtractorError extends Error { | ||
static ERR_MSGS: string[]; | ||
static DEFAULT_MSG = 'protractor encountered an error'; | ||
|
||
export class ProtractorError { | ||
error: Error; | ||
description: string; | ||
code: number; | ||
stack: string; | ||
constructor(logger: Logger, description: string, code: number) { | ||
super(); | ||
this.error = new Error(); | ||
this.description = description; | ||
this.code = code; | ||
this.description = description; | ||
this.stack = this.error.stack; | ||
this.logError(logger); | ||
} | ||
|
||
logError(logger: Logger) { | ||
logger.error('error code: ' + this.code); | ||
logger.error('description: ' + this.description); | ||
this.stack = this.error.stack; | ||
logger.error(this.stack); | ||
} | ||
} | ||
|
||
/** | ||
* Configuration file error | ||
*/ | ||
export class ConfigError extends ProtractorError { | ||
static DEFAULT_MSG = 'configuration error'; | ||
static CODE = CONFIG_ERROR_CODE; | ||
constructor(logger: Logger, description: string) { | ||
super(logger, description, ConfigError.CODE); | ||
constructor(logger: Logger, opt_msg?: string) { | ||
super(logger, opt_msg || ConfigError.DEFAULT_MSG, ConfigError.CODE); | ||
} | ||
} | ||
|
||
/** | ||
* Browser errors including getting a driver session, direct connect, etc. | ||
*/ | ||
export class BrowserError extends ProtractorError { | ||
static DEFAULT_MSG = 'browser error'; | ||
static CODE = BROWSER_ERROR_CODE; | ||
static ERR_MSGS = | ||
['ECONNREFUSED connect ECONNREFUSED', 'Sauce Labs Authentication Error']; | ||
constructor(logger: Logger, opt_msg?: string) { | ||
super(logger, opt_msg || BrowserError.DEFAULT_MSG, BrowserError.CODE); | ||
} | ||
} | ||
|
||
export class ErrorHandler { | ||
static isError(errMsgs: string[], e: Error): boolean { | ||
if (errMsgs && errMsgs.length > 0) { | ||
for (let errPos in errMsgs) { | ||
let errMsg = errMsgs[errPos]; | ||
if (e.message.indexOf(errMsg) !== -1) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
static parseError(e: Error): number { | ||
if (ErrorHandler.isError(ConfigError.ERR_MSGS, e)) { | ||
return ConfigError.CODE; | ||
} | ||
if (ErrorHandler.isError(BrowserError.ERR_MSGS, e)) { | ||
return BrowserError.CODE; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
var spawn = require('child_process').spawnSync; | ||
var runProtractor, output, messages; | ||
var checkLogs = function(output, messages) { | ||
for (var pos in messages) { | ||
var message = messages[pos]; | ||
if (output.indexOf(message) === -1) { | ||
throw new Error('does not exist in logs: ' + message); | ||
} | ||
} | ||
}; | ||
|
||
/****************************** | ||
*Below are exit failure tests* | ||
******************************/ | ||
|
||
// assert authentication error for sauce labs | ||
runProtractor = spawn('node', | ||
['bin/protractor', 'spec/errorTest/sauceLabNotAvailable.js']); | ||
output = runProtractor.stdout.toString(); | ||
messages = ['WebDriverError: Sauce Labs Authentication Error.', | ||
'Process exited with error code 135']; | ||
checkLogs(output, messages); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var env = require('../environment.js'); | ||
|
||
exports.config = { | ||
sauceUser: 'foobar', | ||
sauceKey: process.env.SAUCE_ACCESS_KEY, | ||
|
||
framework: 'jasmine', | ||
|
||
specs: [ | ||
'../../example/example_spec.js' | ||
], | ||
|
||
capabilities: { | ||
'browserName': 'chrome' | ||
}, | ||
|
||
baseUrl: env.baseUrl + '/ng1/', | ||
|
||
jasmineNodeOpts: { | ||
defaultTimeoutInterval: 90000 | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
var fs = require('fs'), | ||
os = require('os'), | ||
path = require('path'); | ||
var BrowserError = require('../../../built/exitCodes').BrowserError, | ||
Logger = require('../../../built/logger2').Logger, | ||
WriteTo = require('../../../built/logger2').WriteTo; | ||
|
||
describe('direct connect', function() { | ||
beforeEach(function() { | ||
Logger.setWrite(WriteTo.NONE); | ||
}); | ||
|
||
afterEach(function() { | ||
Logger.setWrite(WriteTo.CONSOLE); | ||
}); | ||
|
||
describe('without the chrome driver', function() { | ||
it('should throw an error if no drivers are present', function() { | ||
var config = { | ||
directConnect: true, | ||
capabilities: { browserName: 'chrome' }, | ||
chromeDriver: '/foo/bar/chromedriver' | ||
}; | ||
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 chromedriver drivers', function() { | ||
var chromedriver = ''; | ||
beforeEach(function() { | ||
// add files to selenium folder | ||
file = 'chromedriver'; | ||
chromedriver = path.resolve(os.tmpdir(), file); | ||
fs.openSync(chromedriver, 'w'); | ||
}); | ||
|
||
afterEach(function() { | ||
try { | ||
fs.unlinkSync(chromedriver); | ||
} catch(e) { | ||
} | ||
}); | ||
it('should throw an error if the driver cannot be used', function() { | ||
var config = { | ||
directConnect: true, | ||
capabilities: { browserName: 'foobar explorer' }, | ||
chromeDriver: chromedriver | ||
}; | ||
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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
var fs = require('fs'), | ||
os = require('os'), | ||
path = require('path'); | ||
var BrowserError = require('../../../built/exitCodes').BrowserError, | ||
Logger = require('../../../built/logger2').Logger, | ||
WriteTo = require('../../../built/logger2').WriteTo; | ||
|
||
describe('local connect', function() { | ||
beforeEach(function() { | ||
Logger.setWrite(WriteTo.NONE); | ||
}); | ||
|
||
afterEach(function() { | ||
Logger.setWrite(WriteTo.CONSOLE); | ||
}); | ||
|
||
describe('without the selenium standalone jar', function() { | ||
it('should throw an error jar file is not present', function() { | ||
var config = { | ||
directConnect: true, | ||
capabilities: { browserName: 'chrome' }, | ||
seleniumServerJar: '/foo/bar/selenium.jar' | ||
}; | ||
var errorFound = false; | ||
try { | ||
webdriver = require('../../../built/driverProviders/local')(config); | ||
webdriver.setupEnv(); | ||
} catch(e) { | ||
errorFound = true; | ||
expect(e.code).toBe(BrowserError.CODE); | ||
} | ||
expect(errorFound).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('with the selenium standalone jar', function() { | ||
it('should throw an error if the jar file does not work', function() { | ||
var jarFile = ''; | ||
beforeEach(function() { | ||
// add files to selenium folder | ||
file = 'selenium.jar'; | ||
jarFile = path.resolve(os.tmpdir(), file); | ||
fs.openSync(jarFile, 'w'); | ||
}); | ||
|
||
afterEach(function() { | ||
try { | ||
fs.unlinkSync(jarFile); | ||
} catch(e) { | ||
} | ||
}); | ||
|
||
it('should throw an error if the selenium sever jar cannot be used', function() { | ||
var config = { | ||
directConnect: true, | ||
capabilities: { browserName: 'foobar explorer' }, | ||
seleniumServerJar: jarFile | ||
}; | ||
var errorFound = false; | ||
try { | ||
webdriver = require('../../../built/driverProviders/local')(config); | ||
webdriver.getNewDriver(); | ||
} catch(e) { | ||
errorFound = true; | ||
expect(e.code).toBe(BrowserError.CODE); | ||
} | ||
expect(errorFound).toBe(true); | ||
}); | ||
}); | ||
}); | ||
}); |