2015-04-04 09:53:59 -07:00
|
|
|
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
|
// distributed with this work for additional information
|
|
|
|
|
// regarding copyright ownership. The SFC licenses this file
|
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
|
// "License"); you may not use this file except in compliance
|
|
|
|
|
// with the License. You may obtain a copy of the License at
|
2014-11-12 19:33:37 +00:00
|
|
|
//
|
2015-04-04 09:53:59 -07:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2014-11-12 19:33:37 +00:00
|
|
|
//
|
2015-04-04 09:53:59 -07:00
|
|
|
// Unless required by applicable law or agreed to in writing,
|
|
|
|
|
// software distributed under the License is distributed on an
|
|
|
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
|
// KIND, either express or implied. See the License for the
|
|
|
|
|
// specific language governing permissions and limitations
|
|
|
|
|
// under the License.
|
2010-07-25 21:06:09 +00:00
|
|
|
|
2010-07-19 11:24:30 +00:00
|
|
|
/**
|
|
|
|
|
* @fileoverview Utilities for working with errors as defined by WebDriver's
|
2015-03-17 19:15:20 -04:00
|
|
|
* wire protocol: https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol
|
2010-07-19 11:24:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
goog.provide('bot.Error');
|
|
|
|
|
goog.provide('bot.ErrorCode');
|
|
|
|
|
|
|
|
|
|
|
2015-04-09 13:52:53 +01:00
|
|
|
/**
|
|
|
|
|
* Error codes from the Selenium WebDriver protocol:
|
2015-03-17 19:15:20 -04:00
|
|
|
* https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol#response-status-codes
|
2010-07-19 11:24:30 +00:00
|
|
|
*
|
|
|
|
|
* @enum {number}
|
2018-11-25 13:21:40 +00:00
|
|
|
* @suppress {lintChecks}
|
2010-07-19 11:24:30 +00:00
|
|
|
*/
|
|
|
|
|
bot.ErrorCode = {
|
|
|
|
|
SUCCESS: 0, // Included for completeness
|
|
|
|
|
|
|
|
|
|
NO_SUCH_ELEMENT: 7,
|
|
|
|
|
NO_SUCH_FRAME: 8,
|
|
|
|
|
UNKNOWN_COMMAND: 9,
|
|
|
|
|
UNSUPPORTED_OPERATION: 9, // Alias.
|
|
|
|
|
STALE_ELEMENT_REFERENCE: 10,
|
|
|
|
|
ELEMENT_NOT_VISIBLE: 11,
|
|
|
|
|
INVALID_ELEMENT_STATE: 12,
|
|
|
|
|
UNKNOWN_ERROR: 13,
|
|
|
|
|
ELEMENT_NOT_SELECTABLE: 15,
|
2011-07-26 17:09:52 +00:00
|
|
|
JAVASCRIPT_ERROR: 17,
|
2010-07-19 11:24:30 +00:00
|
|
|
XPATH_LOOKUP_ERROR: 19,
|
2011-08-05 11:08:14 +00:00
|
|
|
TIMEOUT: 21,
|
2010-07-19 11:24:30 +00:00
|
|
|
NO_SUCH_WINDOW: 23,
|
|
|
|
|
INVALID_COOKIE_DOMAIN: 24,
|
2010-12-01 19:01:54 +00:00
|
|
|
UNABLE_TO_SET_COOKIE: 25,
|
2014-07-31 16:21:12 -07:00
|
|
|
UNEXPECTED_ALERT_OPEN: 26,
|
|
|
|
|
NO_SUCH_ALERT: 27,
|
2011-07-26 19:15:24 +00:00
|
|
|
SCRIPT_TIMEOUT: 28,
|
2011-08-05 11:01:18 +00:00
|
|
|
INVALID_ELEMENT_COORDINATES: 29,
|
2012-09-14 12:26:12 +00:00
|
|
|
IME_NOT_AVAILABLE: 30,
|
|
|
|
|
IME_ENGINE_ACTIVATION_FAILED: 31,
|
2011-09-01 00:38:53 +00:00
|
|
|
INVALID_SELECTOR_ERROR: 32,
|
2012-09-14 12:26:12 +00:00
|
|
|
SESSION_NOT_CREATED: 33,
|
2011-09-22 19:20:25 +00:00
|
|
|
MOVE_TARGET_OUT_OF_BOUNDS: 34,
|
2013-04-28 10:02:43 -07:00
|
|
|
SQL_DATABASE_ERROR: 35,
|
|
|
|
|
INVALID_XPATH_SELECTOR: 51,
|
|
|
|
|
INVALID_XPATH_SELECTOR_RETURN_TYPE: 52,
|
2017-03-17 12:37:34 +00:00
|
|
|
INVALID_ARGUMENT: 61,
|
2013-04-28 10:02:43 -07:00
|
|
|
// The following error codes are derived straight from HTTP return codes.
|
|
|
|
|
METHOD_NOT_ALLOWED: 405
|
2010-07-19 11:24:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2015-04-09 13:52:53 +01:00
|
|
|
* Represents an error returned from a WebDriver command request.
|
2010-07-19 11:24:30 +00:00
|
|
|
*
|
|
|
|
|
* @param {!bot.ErrorCode} code The error's status code.
|
2011-09-14 16:58:31 +00:00
|
|
|
* @param {string=} opt_message Optional error message.
|
2010-07-19 11:24:30 +00:00
|
|
|
* @constructor
|
2012-01-13 17:10:50 +00:00
|
|
|
* @extends {Error}
|
2010-07-19 11:24:30 +00:00
|
|
|
*/
|
2020-11-27 15:46:30 +00:00
|
|
|
bot.Error = function (code, opt_message) {
|
2010-07-19 11:24:30 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This error's status code.
|
|
|
|
|
* @type {!bot.ErrorCode}
|
|
|
|
|
*/
|
|
|
|
|
this.code = code;
|
|
|
|
|
|
2013-04-28 10:02:43 -07:00
|
|
|
/** @type {string} */
|
|
|
|
|
this.state =
|
2020-11-27 15:46:30 +00:00
|
|
|
bot.Error.CODE_TO_STATE_[code] || bot.Error.State.UNKNOWN_ERROR;
|
2013-04-28 10:02:43 -07:00
|
|
|
|
2012-01-13 17:10:50 +00:00
|
|
|
/** @override */
|
|
|
|
|
this.message = opt_message || '';
|
|
|
|
|
|
2020-11-27 15:46:30 +00:00
|
|
|
var name = this.state.replace(/((?:^|\s+)[a-z])/g, function (str) {
|
2013-04-30 12:50:56 -07:00
|
|
|
// IE<9 does not support String#trim(). Also, IE does not include 0xa0
|
|
|
|
|
// (the non-breaking-space) in the \s character class, so we have to
|
|
|
|
|
// explicitly include it.
|
|
|
|
|
return str.toUpperCase().replace(/^[\s\xa0]+/g, '');
|
2013-04-28 10:02:43 -07:00
|
|
|
});
|
2013-06-14 07:31:01 -07:00
|
|
|
|
2013-04-28 10:02:43 -07:00
|
|
|
var l = name.length - 'Error'.length;
|
|
|
|
|
if (l < 0 || name.indexOf('Error', l) != l) {
|
|
|
|
|
name += 'Error';
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-13 17:10:50 +00:00
|
|
|
/** @override */
|
2013-04-28 10:02:43 -07:00
|
|
|
this.name = name;
|
2012-01-13 17:10:50 +00:00
|
|
|
|
|
|
|
|
// Generate a stacktrace for our custom error; ensure the error has our
|
|
|
|
|
// custom name and message so the stack prints correctly in all browsers.
|
|
|
|
|
var template = new Error(this.message);
|
|
|
|
|
template.name = this.name;
|
|
|
|
|
|
|
|
|
|
/** @override */
|
|
|
|
|
this.stack = template.stack || '';
|
2010-07-19 11:24:30 +00:00
|
|
|
};
|
2012-01-13 17:10:50 +00:00
|
|
|
goog.inherits(bot.Error, Error);
|
2010-07-19 11:24:30 +00:00
|
|
|
|
|
|
|
|
|
2015-04-14 23:40:37 +03:00
|
|
|
/**
|
|
|
|
|
* Status strings enumerated in the W3C WebDriver protocol.
|
|
|
|
|
* @enum {string}
|
|
|
|
|
* @see https://w3c.github.io/webdriver/webdriver-spec.html#handling-errors
|
|
|
|
|
*/
|
|
|
|
|
bot.Error.State = {
|
|
|
|
|
ELEMENT_NOT_SELECTABLE: 'element not selectable',
|
|
|
|
|
ELEMENT_NOT_VISIBLE: 'element not visible',
|
|
|
|
|
INVALID_ARGUMENT: 'invalid argument',
|
|
|
|
|
INVALID_COOKIE_DOMAIN: 'invalid cookie domain',
|
|
|
|
|
INVALID_ELEMENT_COORDINATES: 'invalid element coordinates',
|
|
|
|
|
INVALID_ELEMENT_STATE: 'invalid element state',
|
|
|
|
|
INVALID_SELECTOR: 'invalid selector',
|
|
|
|
|
INVALID_SESSION_ID: 'invalid session id',
|
|
|
|
|
JAVASCRIPT_ERROR: 'javascript error',
|
|
|
|
|
MOVE_TARGET_OUT_OF_BOUNDS: 'move target out of bounds',
|
|
|
|
|
NO_SUCH_ALERT: 'no such alert',
|
|
|
|
|
NO_SUCH_ELEMENT: 'no such element',
|
|
|
|
|
NO_SUCH_FRAME: 'no such frame',
|
|
|
|
|
NO_SUCH_WINDOW: 'no such window',
|
|
|
|
|
SCRIPT_TIMEOUT: 'script timeout',
|
|
|
|
|
SESSION_NOT_CREATED: 'session not created',
|
|
|
|
|
STALE_ELEMENT_REFERENCE: 'stale element reference',
|
|
|
|
|
TIMEOUT: 'timeout',
|
|
|
|
|
UNABLE_TO_SET_COOKIE: 'unable to set cookie',
|
|
|
|
|
UNEXPECTED_ALERT_OPEN: 'unexpected alert open',
|
|
|
|
|
UNKNOWN_COMMAND: 'unknown command',
|
|
|
|
|
UNKNOWN_ERROR: 'unknown error',
|
|
|
|
|
UNKNOWN_METHOD: 'unknown method',
|
|
|
|
|
UNSUPPORTED_OPERATION: 'unsupported operation'
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2013-04-28 10:02:43 -07:00
|
|
|
/**
|
|
|
|
|
* A map of error codes to state string.
|
|
|
|
|
* @private {!Object.<bot.ErrorCode, bot.Error.State>}
|
2010-07-19 11:24:30 +00:00
|
|
|
*/
|
2013-04-28 10:02:43 -07:00
|
|
|
bot.Error.CODE_TO_STATE_ = {};
|
2020-11-27 15:46:30 +00:00
|
|
|
goog.scope(function () {
|
2013-04-28 10:02:43 -07:00
|
|
|
var map = bot.Error.CODE_TO_STATE_;
|
|
|
|
|
var code = bot.ErrorCode;
|
|
|
|
|
var state = bot.Error.State;
|
|
|
|
|
|
|
|
|
|
map[code.ELEMENT_NOT_SELECTABLE] = state.ELEMENT_NOT_SELECTABLE;
|
|
|
|
|
map[code.ELEMENT_NOT_VISIBLE] = state.ELEMENT_NOT_VISIBLE;
|
2015-04-09 13:49:33 +01:00
|
|
|
map[code.IME_ENGINE_ACTIVATION_FAILED] = state.UNKNOWN_ERROR;
|
|
|
|
|
map[code.IME_NOT_AVAILABLE] = state.UNKNOWN_ERROR;
|
2013-04-28 10:02:43 -07:00
|
|
|
map[code.INVALID_COOKIE_DOMAIN] = state.INVALID_COOKIE_DOMAIN;
|
|
|
|
|
map[code.INVALID_ELEMENT_COORDINATES] = state.INVALID_ELEMENT_COORDINATES;
|
|
|
|
|
map[code.INVALID_ELEMENT_STATE] = state.INVALID_ELEMENT_STATE;
|
|
|
|
|
map[code.INVALID_SELECTOR_ERROR] = state.INVALID_SELECTOR;
|
|
|
|
|
map[code.INVALID_XPATH_SELECTOR] = state.INVALID_SELECTOR;
|
|
|
|
|
map[code.INVALID_XPATH_SELECTOR_RETURN_TYPE] = state.INVALID_SELECTOR;
|
|
|
|
|
map[code.JAVASCRIPT_ERROR] = state.JAVASCRIPT_ERROR;
|
|
|
|
|
map[code.METHOD_NOT_ALLOWED] = state.UNSUPPORTED_OPERATION;
|
|
|
|
|
map[code.MOVE_TARGET_OUT_OF_BOUNDS] = state.MOVE_TARGET_OUT_OF_BOUNDS;
|
2014-07-31 16:21:12 -07:00
|
|
|
map[code.NO_SUCH_ALERT] = state.NO_SUCH_ALERT;
|
2013-04-28 10:02:43 -07:00
|
|
|
map[code.NO_SUCH_ELEMENT] = state.NO_SUCH_ELEMENT;
|
|
|
|
|
map[code.NO_SUCH_FRAME] = state.NO_SUCH_FRAME;
|
|
|
|
|
map[code.NO_SUCH_WINDOW] = state.NO_SUCH_WINDOW;
|
|
|
|
|
map[code.SCRIPT_TIMEOUT] = state.SCRIPT_TIMEOUT;
|
|
|
|
|
map[code.SESSION_NOT_CREATED] = state.SESSION_NOT_CREATED;
|
|
|
|
|
map[code.STALE_ELEMENT_REFERENCE] = state.STALE_ELEMENT_REFERENCE;
|
|
|
|
|
map[code.TIMEOUT] = state.TIMEOUT;
|
|
|
|
|
map[code.UNABLE_TO_SET_COOKIE] = state.UNABLE_TO_SET_COOKIE;
|
2018-11-25 13:21:40 +00:00
|
|
|
map[code.UNEXPECTED_ALERT_OPEN] = state.UNEXPECTED_ALERT_OPEN;
|
2013-04-28 10:02:43 -07:00
|
|
|
map[code.UNKNOWN_ERROR] = state.UNKNOWN_ERROR;
|
|
|
|
|
map[code.UNSUPPORTED_OPERATION] = state.UNKNOWN_COMMAND;
|
|
|
|
|
}); // goog.scope
|
2010-07-19 11:24:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Flag used for duck-typing when this code is embedded in a Firefox extension.
|
2011-08-15 04:24:29 +00:00
|
|
|
* This is required since an Error thrown in one component and then reported
|
2010-07-19 11:24:30 +00:00
|
|
|
* to another will fail instanceof checks in the second component.
|
|
|
|
|
* @type {boolean}
|
|
|
|
|
*/
|
|
|
|
|
bot.Error.prototype.isAutomationError = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (goog.DEBUG) {
|
2018-11-25 13:21:40 +00:00
|
|
|
/**
|
|
|
|
|
* @override
|
|
|
|
|
* @return {string} The string representation of this error.
|
|
|
|
|
*/
|
2020-11-27 15:46:30 +00:00
|
|
|
bot.Error.prototype.toString = function () {
|
2012-10-22 22:58:53 +00:00
|
|
|
return this.name + ': ' + this.message;
|
2011-07-26 17:09:52 +00:00
|
|
|
};
|
2010-07-19 11:24:30 +00:00
|
|
|
}
|