Best JavaScript code snippet using appium-base-driver
errors.js
Source:errors.js
1import ES6Error from 'es6-error';2import _ from 'lodash';3import { util, logger } from 'appium-support';4import { StatusCodes as HTTPStatusCodes } from 'http-status-codes';5const mjsonwpLog = logger.getLogger('MJSONWP');6const w3cLog = logger.getLogger('W3C');7const W3C_UNKNOWN_ERROR = 'unknown error';8// base error class for all of our errors9class ProtocolError extends ES6Error {10 constructor (msg, jsonwpCode, w3cStatus, error) {11 super(msg);12 this.jsonwpCode = jsonwpCode;13 this.error = error || W3C_UNKNOWN_ERROR;14 if (this.jsonwpCode === null) {15 this.jsonwpCode = 13;16 }17 this.w3cStatus = w3cStatus || HTTPStatusCodes.BAD_REQUEST;18 this._stacktrace = null;19 }20 get stacktrace () {21 return this._stacktrace || this.stack;22 }23 set stacktrace (value) {24 this._stacktrace = value;25 }26}27// https://github.com/SeleniumHQ/selenium/blob/176b4a9e3082ac1926f2a436eb346760c37a5998/java/client/src/org/openqa/selenium/remote/ErrorCodes.java#L21528// https://github.com/SeleniumHQ/selenium/issues/5562#issuecomment-37037947029// https://w3c.github.io/webdriver/webdriver-spec.html#dfn-error-code30class NoSuchDriverError extends ProtocolError {31 static code () {32 return 6;33 }34 // W3C Error is called InvalidSessionID35 static w3cStatus () {36 return HTTPStatusCodes.NOT_FOUND;37 }38 static error () {39 return 'invalid session id';40 }41 constructor (err) {42 super(err || 'A session is either terminated or not started', NoSuchDriverError.code(),43 NoSuchDriverError.w3cStatus(), NoSuchDriverError.error());44 }45}46class NoSuchElementError extends ProtocolError {47 static code () {48 return 7;49 }50 static w3cStatus () {51 return HTTPStatusCodes.NOT_FOUND;52 }53 static error () {54 return 'no such element';55 }56 constructor (err) {57 super(err || 'An element could not be located on the page using the given ' +58 'search parameters.', NoSuchElementError.code(), NoSuchElementError.w3cStatus(),59 NoSuchElementError.error());60 }61}62class NoSuchFrameError extends ProtocolError {63 static code () {64 return 8;65 }66 static error () {67 return 'no such frame';68 }69 static w3cStatus () {70 return HTTPStatusCodes.NOT_FOUND;71 }72 constructor (err) {73 super(err || 'A request to switch to a frame could not be satisfied because ' +74 'the frame could not be found.', NoSuchFrameError.code(),75 NoSuchFrameError.w3cStatus(), NoSuchFrameError.error());76 }77}78class UnknownCommandError extends ProtocolError {79 static code () {80 return 9;81 }82 static w3cStatus () {83 return HTTPStatusCodes.NOT_FOUND;84 }85 static error () {86 return 'unknown command';87 }88 constructor (err) {89 super(err || 'The requested resource could not be found, or a request was ' +90 'received using an HTTP method that is not supported by the mapped ' +91 'resource.', UnknownCommandError.code(), UnknownCommandError.w3cStatus(), UnknownCommandError.error());92 }93}94class StaleElementReferenceError extends ProtocolError {95 static code () {96 return 10;97 }98 static w3cStatus () {99 return HTTPStatusCodes.NOT_FOUND;100 }101 static error () {102 return 'stale element reference';103 }104 constructor (err) {105 super(err || 'An element command failed because the referenced element is no ' +106 'longer attached to the DOM.', StaleElementReferenceError.code(),107 StaleElementReferenceError.w3cStatus(), StaleElementReferenceError.error());108 }109}110class ElementNotVisibleError extends ProtocolError {111 static code () {112 return 11;113 }114 static w3cStatus () {115 return HTTPStatusCodes.BAD_REQUEST;116 }117 static error () {118 return 'element not visible';119 }120 constructor (err) {121 super(err || 'An element command could not be completed because the element is ' +122 'not visible on the page.', ElementNotVisibleError.code(),123 ElementNotVisibleError.w3cStatus(), ElementNotVisibleError.error());124 }125}126class InvalidElementStateError extends ProtocolError {127 static code () {128 return 12;129 }130 static w3cStatus () {131 return HTTPStatusCodes.BAD_REQUEST;132 }133 static error () {134 return 'invalid element state';135 }136 constructor (err) {137 super(err || 'An element command could not be completed because the element is ' +138 'in an invalid state (e.g. attempting to click a disabled element).',139 InvalidElementStateError.code(), InvalidElementStateError.w3cStatus(),140 InvalidElementStateError.error());141 }142}143class UnknownError extends ProtocolError {144 static code () {145 return 13;146 }147 static w3cStatus () {148 return HTTPStatusCodes.INTERNAL_SERVER_ERROR;149 }150 static error () {151 return W3C_UNKNOWN_ERROR;152 }153 constructor (errorOrMessage) {154 const origMessage = _.isString((errorOrMessage || {}).message)155 ? errorOrMessage.message156 : errorOrMessage;157 const message = 'An unknown server-side error occurred while processing the command.' +158 (origMessage ? ` Original error: ${origMessage}` : '');159 super(message, UnknownError.code(), UnknownError.w3cStatus(), UnknownError.error());160 }161}162class UnknownMethodError extends ProtocolError {163 static code () {164 return 405;165 }166 static w3cStatus () {167 return HTTPStatusCodes.METHOD_NOT_ALLOWED;168 }169 static error () {170 return 'unknown method';171 }172 constructor (err) {173 super(err || 'The requested command matched a known URL but did not match an method for that URL',174 UnknownMethodError.code(), UnknownMethodError.w3cStatus(), UnknownMethodError.error());175 }176}177class UnsupportedOperationError extends ProtocolError {178 static code () {179 return 405;180 }181 static w3cStatus () {182 return HTTPStatusCodes.INTERNAL_SERVER_ERROR;183 }184 static error () {185 return 'unsupported operation';186 }187 constructor (err) {188 super(err || 'A server-side error occurred. Command cannot be supported.',189 UnsupportedOperationError.code(), UnsupportedOperationError.w3cStatus(),190 UnsupportedOperationError.error());191 }192}193class ElementIsNotSelectableError extends ProtocolError {194 static code () {195 return 15;196 }197 static error () {198 return 'element not selectable';199 }200 static w3cStatus () {201 return HTTPStatusCodes.BAD_REQUEST;202 }203 constructor (err) {204 super(err || 'An attempt was made to select an element that cannot be selected.',205 ElementIsNotSelectableError.code(), ElementIsNotSelectableError.w3cStatus(),206 ElementIsNotSelectableError.error());207 }208}209class ElementClickInterceptedError extends ProtocolError {210 static code () {211 return 64;212 }213 static error () {214 return 'element click intercepted';215 }216 static w3cStatus () {217 return HTTPStatusCodes.BAD_REQUEST;218 }219 constructor (err) {220 super(err || 'The Element Click command could not be completed because the element receiving ' +221 'the events is obscuring the element that was requested clicked',222 ElementClickInterceptedError.code(), ElementClickInterceptedError.w3cStatus(),223 ElementClickInterceptedError.error());224 }225}226class ElementNotInteractableError extends ProtocolError {227 static code () {228 return 60;229 }230 static error () {231 return 'element not interactable';232 }233 static w3cStatus () {234 return HTTPStatusCodes.BAD_REQUEST;235 }236 constructor (err) {237 super(err || 'A command could not be completed because the element is not pointer- or keyboard interactable',238 ElementNotInteractableError.code(), ElementNotInteractableError.w3cStatus(),239 ElementNotInteractableError.error());240 }241}242class InsecureCertificateError extends ProtocolError {243 static error () {244 return 'insecure certificate';245 }246 constructor (err) {247 super(err || 'Navigation caused the user agent to hit a certificate warning, which is usually the result of an expired or invalid TLS certificate',248 ElementIsNotSelectableError.code(), null, InsecureCertificateError.error());249 }250}251class JavaScriptError extends ProtocolError {252 static code () {253 return 17;254 }255 static w3cStatus () {256 return HTTPStatusCodes.INTERNAL_SERVER_ERROR;257 }258 static error () {259 return 'javascript error';260 }261 constructor (err) {262 super(err || 'An error occurred while executing user supplied JavaScript.',263 JavaScriptError.code(), JavaScriptError.w3cStatus(), JavaScriptError.error());264 }265}266class XPathLookupError extends ProtocolError {267 static code () {268 return 19;269 }270 static w3cStatus () {271 return HTTPStatusCodes.BAD_REQUEST;272 }273 static error () {274 return 'invalid selector';275 }276 constructor (err) {277 super(err || 'An error occurred while searching for an element by XPath.',278 XPathLookupError.code(), XPathLookupError.w3cStatus(), XPathLookupError.error());279 }280}281class TimeoutError extends ProtocolError {282 static code () {283 return 21;284 }285 static w3cStatus () {286 return HTTPStatusCodes.REQUEST_TIMEOUT;287 }288 static error () {289 return 'timeout';290 }291 constructor (err) {292 super(err || 'An operation did not complete before its timeout expired.',293 TimeoutError.code(), TimeoutError.w3cStatus(), TimeoutError.error());294 }295}296class NoSuchWindowError extends ProtocolError {297 static code () {298 return 23;299 }300 static error () {301 return 'no such window';302 }303 static w3cStatus () {304 return HTTPStatusCodes.NOT_FOUND;305 }306 constructor (err) {307 super(err || 'A request to switch to a different window could not be satisfied ' +308 'because the window could not be found.', NoSuchWindowError.code(),309 NoSuchWindowError.w3cStatus(), NoSuchWindowError.error());310 }311}312class InvalidArgumentError extends ProtocolError {313 static code () {314 return 61;315 }316 static error () {317 return 'invalid argument';318 }319 static w3cStatus () {320 return HTTPStatusCodes.BAD_REQUEST;321 }322 constructor (err) {323 super(err || 'The arguments passed to the command are either invalid or malformed',324 InvalidArgumentError.code(), InvalidArgumentError.w3cStatus(),325 InvalidArgumentError.error());326 }327}328class InvalidCookieDomainError extends ProtocolError {329 static code () {330 return 24;331 }332 static error () {333 return 'invalid cookie domain';334 }335 static w3cStatus () {336 return HTTPStatusCodes.BAD_REQUEST;337 }338 constructor (err) {339 super(err || 'An illegal attempt was made to set a cookie under a different ' +340 'domain than the current page.', InvalidCookieDomainError.code(),341 InvalidCookieDomainError.w3cStatus(), InvalidCookieDomainError.error());342 }343}344class NoSuchCookieError extends ProtocolError {345 static code () {346 return 62;347 }348 static w3cStatus () {349 return HTTPStatusCodes.NOT_FOUND;350 }351 static error () {352 return 'no such cookie';353 }354 constructor (err) {355 super(err || 'No cookie matching the given path name was found amongst the associated cookies of the current browsing contextâs active document',356 NoSuchCookieError.code(), NoSuchCookieError.w3cStatus(), NoSuchCookieError.error());357 }358}359class UnableToSetCookieError extends ProtocolError {360 static code () {361 return 25;362 }363 static w3cStatus () {364 return HTTPStatusCodes.INTERNAL_SERVER_ERROR;365 }366 static error () {367 return 'unable to set cookie';368 }369 constructor (err) {370 super(err || 'A request to set a cookie\'s value could not be satisfied.',371 UnableToSetCookieError.code(), UnableToSetCookieError.w3cStatus(), UnableToSetCookieError.error());372 }373}374class UnexpectedAlertOpenError extends ProtocolError {375 static code () {376 return 26;377 }378 static w3cStatus () {379 return HTTPStatusCodes.INTERNAL_SERVER_ERROR;380 }381 static error () {382 return 'unexpected alert open';383 }384 constructor (err) {385 super(err || 'A modal dialog was open, blocking this operation',386 UnexpectedAlertOpenError.code(), UnexpectedAlertOpenError.w3cStatus(), UnexpectedAlertOpenError.error());387 }388}389class NoAlertOpenError extends ProtocolError {390 static code () {391 return 27;392 }393 static w3cStatus () {394 return HTTPStatusCodes.NOT_FOUND;395 }396 static error () {397 return 'no such alert';398 }399 constructor (err) {400 super(err || 'An attempt was made to operate on a modal dialog when one ' +401 'was not open.', NoAlertOpenError.code(), NoAlertOpenError.w3cStatus(), NoAlertOpenError.error());402 }403}404class NoSuchAlertError extends NoAlertOpenError {}405class ScriptTimeoutError extends ProtocolError {406 static code () {407 return 28;408 }409 static w3cStatus () {410 return HTTPStatusCodes.REQUEST_TIMEOUT;411 }412 static error () {413 return 'script timeout';414 }415 constructor (err) {416 super(err || 'A script did not complete before its timeout expired.',417 ScriptTimeoutError.code(), ScriptTimeoutError.w3cStatus(), ScriptTimeoutError.error());418 }419}420class InvalidElementCoordinatesError extends ProtocolError {421 static code () {422 return 29;423 }424 static w3cStatus () {425 return HTTPStatusCodes.BAD_REQUEST;426 }427 static error () {428 return 'invalid coordinates';429 }430 constructor (err) {431 super(err || 'The coordinates provided to an interactions operation are invalid.',432 InvalidElementCoordinatesError.code(), InvalidElementCoordinatesError.w3cStatus(),433 InvalidElementCoordinatesError.error());434 }435}436class InvalidCoordinatesError extends InvalidElementCoordinatesError {}437class IMENotAvailableError extends ProtocolError {438 static code () {439 return 30;440 }441 static w3cStatus () {442 return HTTPStatusCodes.INTERNAL_SERVER_ERROR;443 }444 static error () {445 return 'unsupported operation';446 }447 constructor (err) {448 super(err || 'IME was not available.', IMENotAvailableError.code(),449 IMENotAvailableError.w3cStatus(), IMENotAvailableError.error());450 }451}452class IMEEngineActivationFailedError extends ProtocolError {453 static code () {454 return 31;455 }456 static w3cStatus () {457 return HTTPStatusCodes.INTERNAL_SERVER_ERROR;458 }459 static error () {460 return 'unsupported operation';461 }462 constructor (err) {463 super(err || 'An IME engine could not be started.',464 IMEEngineActivationFailedError.code(), IMEEngineActivationFailedError.w3cStatus(),465 IMEEngineActivationFailedError.error());466 }467}468class InvalidSelectorError extends ProtocolError {469 static code () {470 return 32;471 }472 static w3cStatus () {473 return HTTPStatusCodes.BAD_REQUEST;474 }475 static error () {476 return 'invalid selector';477 }478 constructor (err) {479 super(err || 'Argument was an invalid selector (e.g. XPath/CSS).',480 InvalidSelectorError.code(), InvalidSelectorError.w3cStatus(),481 InvalidSelectorError.error());482 }483}484class SessionNotCreatedError extends ProtocolError {485 static code () {486 return 33;487 }488 static w3cStatus () {489 return HTTPStatusCodes.INTERNAL_SERVER_ERROR;490 }491 static error () {492 return 'session not created';493 }494 constructor (details) {495 let message = 'A new session could not be created.';496 if (details) {497 message += ` Details: ${details}`;498 }499 super(message, SessionNotCreatedError.code(), SessionNotCreatedError.w3cStatus(), SessionNotCreatedError.error());500 }501}502class MoveTargetOutOfBoundsError extends ProtocolError {503 static code () {504 return 34;505 }506 static w3cStatus () {507 return HTTPStatusCodes.INTERNAL_SERVER_ERROR;508 }509 static error () {510 return 'move target out of bounds';511 }512 constructor (err) {513 super(err || 'Target provided for a move action is out of bounds.',514 MoveTargetOutOfBoundsError.code(), MoveTargetOutOfBoundsError.w3cStatus(), MoveTargetOutOfBoundsError.error());515 }516}517class NoSuchContextError extends ProtocolError {518 static code () {519 return 35;520 }521 constructor (err) {522 super(err || 'No such context found.', NoSuchContextError.code());523 }524}525class InvalidContextError extends ProtocolError {526 static code () {527 return 36;528 }529 constructor (err) {530 super(err || 'That command could not be executed in the current context.',531 InvalidContextError.code());532 }533}534// These are aliases for UnknownMethodError535class NotYetImplementedError extends UnknownMethodError {536 constructor (err) {537 super(err || 'Method has not yet been implemented');538 }539}540class NotImplementedError extends UnknownMethodError {541 constructor (err) {542 super(err || 'Method is not implemented');543 }544}545class UnableToCaptureScreen extends ProtocolError {546 static code () {547 return 63;548 }549 static w3cStatus () {550 return HTTPStatusCodes.INTERNAL_SERVER_ERROR;551 }552 static error () {553 return 'unable to capture screen';554 }555 constructor (err) {556 super(err || 'A screen capture was made impossible',557 UnableToCaptureScreen.code(), UnableToCaptureScreen.w3cStatus(), UnableToCaptureScreen.error());558 }559}560// Equivalent to W3C InvalidArgumentError561class BadParametersError extends ES6Error {562 static error () {563 return 'invalid argument';564 }565 constructor (requiredParams, actualParams, errMessage) {566 let message;567 if (!errMessage) {568 message = `Parameters were incorrect. We wanted ` +569 `${JSON.stringify(requiredParams)} and you ` +570 `sent ${JSON.stringify(actualParams)}`;571 } else {572 message = `Parameters were incorrect. You sent ${JSON.stringify(actualParams)}, ${errMessage}`;573 }574 super(message);575 this.w3cStatus = HTTPStatusCodes.BAD_REQUEST;576 }577}578/**579 * ProxyRequestError is a custom error and will be thrown up on unsuccessful proxy request and580 * will contain information about the proxy failure.581 * In case of ProxyRequestError should fetch the actual error by calling `getActualError()`582 * for proxy failure to generate the client response.583 */584class ProxyRequestError extends ES6Error {585 constructor (err, responseError, httpStatus) {586 let responseErrorObj = util.safeJsonParse(responseError);587 if (!_.isPlainObject(responseErrorObj)) {588 responseErrorObj = {};589 }590 let origMessage = _.isString(responseError) ? responseError : '';591 if (!_.isEmpty(responseErrorObj)) {592 if (_.isString(responseErrorObj.value)) {593 origMessage = responseErrorObj.value;594 } else if (_.isPlainObject(responseErrorObj.value) && _.isString(responseErrorObj.value.message)) {595 origMessage = responseErrorObj.value.message;596 }597 }598 super(_.isEmpty(err) ? `Proxy request unsuccessful. ${origMessage}` : err);599 this.w3cStatus = HTTPStatusCodes.BAD_REQUEST;600 // If the response error is an object and value is an object, it's a W3C error (for JSONWP value is a string)601 if (_.isPlainObject(responseErrorObj.value) && _.has(responseErrorObj.value, 'error')) {602 this.w3c = responseErrorObj.value;603 this.w3cStatus = httpStatus || HTTPStatusCodes.BAD_REQUEST;604 } else {605 this.jsonwp = responseErrorObj;606 }607 }608 getActualError () {609 // If it's MJSONWP error, returns actual error cause for request failure based on `jsonwp.status`610 if (util.hasValue(this.jsonwp) && util.hasValue(this.jsonwp.status) && util.hasValue(this.jsonwp.value)) {611 return errorFromMJSONWPStatusCode(this.jsonwp.status, this.jsonwp.value);612 } else if (util.hasValue(this.w3c) && _.isNumber(this.w3cStatus) && this.w3cStatus >= 300) {613 return errorFromW3CJsonCode(this.w3c.error, this.w3c.message || this.message, this.w3c.stacktrace);614 }615 return new UnknownError(this.message);616 }617}618// map of error class name to error class619const errors = {NotYetImplementedError,620 NotImplementedError,621 BadParametersError,622 InvalidArgumentError,623 NoSuchDriverError,624 NoSuchElementError,625 UnknownCommandError,626 StaleElementReferenceError,627 ElementNotVisibleError,628 InvalidElementStateError,629 UnknownError,630 ElementIsNotSelectableError,631 ElementClickInterceptedError,632 ElementNotInteractableError,633 InsecureCertificateError,634 JavaScriptError,635 XPathLookupError,636 TimeoutError,637 NoSuchWindowError,638 NoSuchCookieError,639 InvalidCookieDomainError,640 InvalidCoordinatesError,641 UnableToSetCookieError,642 UnexpectedAlertOpenError,643 NoAlertOpenError,644 ScriptTimeoutError,645 InvalidElementCoordinatesError,646 IMENotAvailableError,647 IMEEngineActivationFailedError,648 InvalidSelectorError,649 SessionNotCreatedError,650 MoveTargetOutOfBoundsError,651 NoSuchAlertError,652 NoSuchContextError,653 InvalidContextError,654 NoSuchFrameError,655 UnableToCaptureScreen,656 UnknownMethodError,657 UnsupportedOperationError,658 ProxyRequestError};659// map of error code to error class660const jsonwpErrorCodeMap = {};661for (let ErrorClass of _.values(errors)) {662 if (ErrorClass.code) {663 jsonwpErrorCodeMap[ErrorClass.code()] = ErrorClass;664 }665}666const w3cErrorCodeMap = {};667for (let ErrorClass of _.values(errors)) {668 if (ErrorClass.error) {669 w3cErrorCodeMap[ErrorClass.error()] = ErrorClass;670 }671}672function isUnknownError (err) {673 return !err.constructor.name ||674 !_.values(errors).find(function equalNames (error) {675 return error.name === err.constructor.name;676 });677}678function isErrorType (err, type) {679 // `name` property is the constructor name680 if (type.name === ProtocolError.name) {681 // `jsonwpCode` is `0` on success682 return !!err.jsonwpCode;683 } else if (type.name === ProxyRequestError.name) {684 // `status` is `0` on success685 if (err.jsonwp) {686 return !!err.jsonwp.status;687 }688 if (_.isPlainObject(err.w3c)) {689 return _.isNumber(err.w3cStatus) && err.w3cStatus >= 300;690 }691 return false;692 }693 return err.constructor.name === type.name;694}695/**696 * Retrieve an error derived from MJSONWP status697 * @param {number} code JSONWP status code698 * @param {string|Object} value The error message, or an object with a `message` property699 * @return {ProtocolError} The error that is associated with provided JSONWP status code700 */701function errorFromMJSONWPStatusCode (code, value = '') {702 // if `value` is an object, pull message from it, otherwise use the plain703 // value, or default to an empty string, if null704 const message = (value || {}).message || value || '';705 if (code !== UnknownError.code() && jsonwpErrorCodeMap[code]) {706 mjsonwpLog.debug(`Matched JSONWP error code ${code} to ${jsonwpErrorCodeMap[code].name}`);707 return new jsonwpErrorCodeMap[code](message);708 }709 mjsonwpLog.debug(`Matched JSONWP error code ${code} to UnknownError`);710 return new UnknownError(message);711}712/**713 * Retrieve an error derived from W3C JSON Code714 * @param {string} code W3C error string (see https://www.w3.org/TR/webdriver/#handling-errors `JSON Error Code` column)715 * @param {string} message the error message716 * @param {?string} stacktrace an optional error stacktrace717 * @return {ProtocolError} The error that is associated with the W3C error string718 */719function errorFromW3CJsonCode (code, message, stacktrace = null) {720 if (code && w3cErrorCodeMap[code.toLowerCase()]) {721 w3cLog.debug(`Matched W3C error code '${code}' to ${w3cErrorCodeMap[code.toLowerCase()].name}`);722 const resultError = new w3cErrorCodeMap[code.toLowerCase()](message);723 resultError.stacktrace = stacktrace;724 return resultError;725 }726 w3cLog.debug(`Matched W3C error code '${code}' to UnknownError`);727 const resultError = new UnknownError(message);728 resultError.stacktrace = stacktrace;729 return resultError;730}731/**732 * Convert an Appium error to proper W3C HTTP response733 * @param {ProtocolError} err The error that needs to be translated734 */735function getResponseForW3CError (err) {736 let httpStatus;737 // W3C defined error message (https://www.w3.org/TR/webdriver/#dfn-error-code)738 let w3cErrorString;739 if (!err.w3cStatus) {740 err = util.hasValue(err.status)741 // If it's a JSONWP error, find corresponding error742 ? errorFromMJSONWPStatusCode(err.status, err.value)743 : new errors.UnknownError(err.message);744 }745 if (isErrorType(err, errors.BadParametersError)) {746 // respond with a 400 if we have bad parameters747 w3cLog.debug(`Bad parameters: ${err}`);748 w3cErrorString = BadParametersError.error();749 } else {750 w3cErrorString = err.error;751 }752 httpStatus = err.w3cStatus;753 if (!w3cErrorString) {754 w3cErrorString = UnknownError.error();755 }756 let httpResBody = {757 value: {758 error: w3cErrorString,759 message: err.message,760 stacktrace: err.stacktrace || err.stack,761 }762 };763 return [httpStatus, httpResBody];764}765/**766 * Convert an Appium error to a proper JSONWP response767 * @param {ProtocolError} err The error to be converted768 */769function getResponseForJsonwpError (err) {770 if (isUnknownError(err)) {771 err = new errors.UnknownError(err);772 }773 // MJSONWP errors are usually 500 status code so set it to that by default774 let httpStatus = HTTPStatusCodes.INTERNAL_SERVER_ERROR;775 let httpResBody = {776 status: err.jsonwpCode,777 value: {778 message: err.message779 }780 };781 if (isErrorType(err, errors.BadParametersError)) {782 // respond with a 400 if we have bad parameters783 mjsonwpLog.debug(`Bad parameters: ${err}`);784 httpStatus = HTTPStatusCodes.BAD_REQUEST;785 httpResBody = err.message;786 } else if (isErrorType(err, errors.NotYetImplementedError) ||787 isErrorType(err, errors.NotImplementedError)) {788 // respond with a 501 if the method is not implemented789 httpStatus = HTTPStatusCodes.NOT_IMPLEMENTED;790 } else if (isErrorType(err, errors.NoSuchDriverError)) {791 // respond with a 404 if there is no driver for the session792 httpStatus = HTTPStatusCodes.NOT_FOUND;793 }794 return [httpStatus, httpResBody];795}796export {797 ProtocolError, errors, isErrorType, isUnknownError,798 errorFromMJSONWPStatusCode, errorFromW3CJsonCode,799 getResponseForW3CError, getResponseForJsonwpError,...
report.js
Source:report.js
1$(document).ready(function() {var formatter = new CucumberHTML.DOMFormatter($('.cucumber-report'));formatter.uri("file:src/test/resources/features/Editbook.feature");2formatter.feature({3 "name": "Edit book should have following parameters",4 "description": "",5 "keyword": "Feature",6 "tags": [7 {8 "name": "@driver"9 },10 {11 "name": "@wip"12 }13 ]14});15formatter.background({16 "name": "",17 "description": "",18 "keyword": "Background"19});20formatter.before({21 "status": "passed"22});23formatter.step({24 "name": "the librarian logged in the application",25 "keyword": "Given "26});27formatter.match({28 "location": "com.profillo.step_definitions.LoginStepDefs.the_librarian_logged_in_the_application()"29});30formatter.result({31 "error_message": "org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Can\u0027t stop process; it\u0027s not currently running (cmd: \u0027C:\\\\Users\\\\Mehmet\\\\IdeaProjects\\\\CucumberFramework\\\\src\\\\test\\\\resources\\\\chromedriver_win32.zip --url-base\\\u003dwd/hub --port\\\u003d8000 --adb-port\\\u003d5037 --verbose\u0027)\nBuild info: version: \u00273.141.59\u0027, revision: \u0027e82be7d358\u0027, time: \u00272018-11-14T08:17:03\u0027\nSystem info: host: \u0027DESKTOP-GSIE280\u0027, ip: \u0027192.168.0.10\u0027, os.name: \u0027Windows 10\u0027, os.arch: \u0027amd64\u0027, os.version: \u002710.0\u0027, java.version: \u002713.0.1\u0027\nDriver info: driver.version: Driver\nremote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Can\u0027t stop process; it\u0027s not currently running (cmd: \u0027C:\\\\Users\\\\Mehmet\\\\IdeaProjects\\\\CucumberFramework\\\\src\\\\test\\\\resources\\\\chromedriver_win32.zip --url-base\\\u003dwd/hub --port\\\u003d8000 --adb-port\\\u003d5037 --verbose\u0027)\n at getResponseForW3CError (C:\\Program Files\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-base-driver\\lib\\protocol\\errors.js:804:9)\n at asyncHandler (C:\\Program Files\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-base-driver\\lib\\protocol\\protocol.js:380:37)\r\n\tat java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)\r\n\tat java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)\r\n\tat java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)\r\n\tat java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)\r\n\tat java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)\r\n\tat org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)\r\n\tat org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)\r\n\tat org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)\r\n\tat java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)\r\n\tat java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)\r\n\tat java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)\r\n\tat java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)\r\n\tat java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)\r\n\tat java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)\r\n\tat java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)\r\n\tat java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)\r\n\tat java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)\r\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)\r\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)\r\n\tat org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)\r\n\tat org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)\r\n\tat org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)\r\n\tat org.openqa.selenium.remote.RemoteWebDriver.\u003cinit\u003e(RemoteWebDriver.java:131)\r\n\tat org.openqa.selenium.remote.RemoteWebDriver.\u003cinit\u003e(RemoteWebDriver.java:144)\r\n\tat com.profillo.utilities.Driver.get(Driver.java:91)\r\n\tat com.profillo.step_definitions.LoginStepDefs.the_librarian_logged_in_the_application(LoginStepDefs.java:17)\r\n\tat â½.the librarian logged in the application(file:///C:/Users/Mehmet/IdeaProjects/CucumberFramework/src/test/resources/features/Editbook.feature:6)\r\n",32 "status": "failed"33});34formatter.scenario({35 "name": "Librarian can edit books",36 "description": "",37 "keyword": "Scenario",38 "tags": [39 {40 "name": "@driver"41 },42 {43 "name": "@wip"44 },45 {46 "name": "@PROF-231"47 }48 ]49});50formatter.step({51 "name": "user clicks on books module",52 "keyword": "Given "53});54formatter.match({55 "location": "com.profillo.step_definitions.LibrarianStepDefs.user_clicks_on_books_module()"56});57formatter.result({58 "status": "skipped"59});60formatter.step({61 "name": "user clicks on edit book button",62 "keyword": "And "63});64formatter.match({65 "location": "com.profillo.step_definitions.LibrarianStepDefs.user_clicks_on_edit_book_button()"66});67formatter.result({68 "status": "skipped"69});70formatter.step({71 "name": "user fills each component in edit window",72 "keyword": "When "73});74formatter.match({75 "location": "com.profillo.step_definitions.LibrarianStepDefs.user_fills_each_component_in_edit_window()"76});77formatter.result({78 "status": "skipped"79});80formatter.step({81 "name": "user clicks on save changes button",82 "keyword": "And "83});84formatter.match({85 "location": "com.profillo.step_definitions.LibrarianStepDefs.user_clicks_on_save_changes_button()"86});87formatter.result({88 "status": "skipped"89});90formatter.step({91 "name": "New changes will appear on book management page",92 "keyword": "Then "93});94formatter.match({95 "location": "com.profillo.step_definitions.LibrarianStepDefs.new_changes_will_appear_on_book_managament_page()"96});97formatter.result({98 "status": "skipped"99});100formatter.after({101 "error_message": "org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Can\u0027t stop process; it\u0027s not currently running (cmd: \u0027C:\\\\Users\\\\Mehmet\\\\IdeaProjects\\\\CucumberFramework\\\\src\\\\test\\\\resources\\\\chromedriver_win32.zip --url-base\\\u003dwd/hub --port\\\u003d8000 --adb-port\\\u003d5037 --verbose\u0027)\nBuild info: version: \u00273.141.59\u0027, revision: \u0027e82be7d358\u0027, time: \u00272018-11-14T08:17:03\u0027\nSystem info: host: \u0027DESKTOP-GSIE280\u0027, ip: \u0027192.168.0.10\u0027, os.name: \u0027Windows 10\u0027, os.arch: \u0027amd64\u0027, os.version: \u002710.0\u0027, java.version: \u002713.0.1\u0027\nDriver info: driver.version: Driver\nremote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Can\u0027t stop process; it\u0027s not currently running (cmd: \u0027C:\\\\Users\\\\Mehmet\\\\IdeaProjects\\\\CucumberFramework\\\\src\\\\test\\\\resources\\\\chromedriver_win32.zip --url-base\\\u003dwd/hub --port\\\u003d8000 --adb-port\\\u003d5037 --verbose\u0027)\n at getResponseForW3CError (C:\\Program Files\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-base-driver\\lib\\protocol\\errors.js:804:9)\n at asyncHandler (C:\\Program Files\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-base-driver\\lib\\protocol\\protocol.js:380:37)\r\n\tat java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)\r\n\tat java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)\r\n\tat java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)\r\n\tat java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)\r\n\tat java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)\r\n\tat org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)\r\n\tat org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)\r\n\tat org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)\r\n\tat java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)\r\n\tat java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)\r\n\tat java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)\r\n\tat java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)\r\n\tat java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)\r\n\tat java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)\r\n\tat java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)\r\n\tat java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)\r\n\tat java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)\r\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)\r\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)\r\n\tat org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)\r\n\tat org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)\r\n\tat org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)\r\n\tat org.openqa.selenium.remote.RemoteWebDriver.\u003cinit\u003e(RemoteWebDriver.java:131)\r\n\tat org.openqa.selenium.remote.RemoteWebDriver.\u003cinit\u003e(RemoteWebDriver.java:144)\r\n\tat com.profillo.utilities.Driver.get(Driver.java:91)\r\n\tat com.profillo.step_definitions.Hooks.tearDown(Hooks.java:22)\r\n",102 "status": "failed"103});104formatter.background({105 "name": "",106 "description": "",107 "keyword": "Background"108});109formatter.before({110 "status": "passed"111});112formatter.step({113 "name": "the librarian logged in the application",114 "keyword": "Given "115});116formatter.match({117 "location": "com.profillo.step_definitions.LoginStepDefs.the_librarian_logged_in_the_application()"118});119formatter.result({120 "error_message": "org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Can\u0027t stop process; it\u0027s not currently running (cmd: \u0027C:\\\\Users\\\\Mehmet\\\\IdeaProjects\\\\CucumberFramework\\\\src\\\\test\\\\resources\\\\chromedriver_win32.zip --url-base\\\u003dwd/hub --port\\\u003d8000 --adb-port\\\u003d5037 --verbose\u0027)\nBuild info: version: \u00273.141.59\u0027, revision: \u0027e82be7d358\u0027, time: \u00272018-11-14T08:17:03\u0027\nSystem info: host: \u0027DESKTOP-GSIE280\u0027, ip: \u0027192.168.0.10\u0027, os.name: \u0027Windows 10\u0027, os.arch: \u0027amd64\u0027, os.version: \u002710.0\u0027, java.version: \u002713.0.1\u0027\nDriver info: driver.version: Driver\nremote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Can\u0027t stop process; it\u0027s not currently running (cmd: \u0027C:\\\\Users\\\\Mehmet\\\\IdeaProjects\\\\CucumberFramework\\\\src\\\\test\\\\resources\\\\chromedriver_win32.zip --url-base\\\u003dwd/hub --port\\\u003d8000 --adb-port\\\u003d5037 --verbose\u0027)\n at getResponseForW3CError (C:\\Program Files\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-base-driver\\lib\\protocol\\errors.js:804:9)\n at asyncHandler (C:\\Program Files\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-base-driver\\lib\\protocol\\protocol.js:380:37)\r\n\tat java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)\r\n\tat java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)\r\n\tat java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)\r\n\tat java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)\r\n\tat java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)\r\n\tat org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)\r\n\tat org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)\r\n\tat org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)\r\n\tat java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)\r\n\tat java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)\r\n\tat java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)\r\n\tat java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)\r\n\tat java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)\r\n\tat java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)\r\n\tat java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)\r\n\tat java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)\r\n\tat java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)\r\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)\r\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)\r\n\tat org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)\r\n\tat org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)\r\n\tat org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)\r\n\tat org.openqa.selenium.remote.RemoteWebDriver.\u003cinit\u003e(RemoteWebDriver.java:131)\r\n\tat org.openqa.selenium.remote.RemoteWebDriver.\u003cinit\u003e(RemoteWebDriver.java:144)\r\n\tat com.profillo.utilities.Driver.get(Driver.java:91)\r\n\tat com.profillo.step_definitions.LoginStepDefs.the_librarian_logged_in_the_application(LoginStepDefs.java:17)\r\n\tat â½.the librarian logged in the application(file:///C:/Users/Mehmet/IdeaProjects/CucumberFramework/src/test/resources/features/Editbook.feature:6)\r\n",121 "status": "failed"122});123formatter.scenario({124 "name": "Edit book should have following parameters",125 "description": "",126 "keyword": "Scenario",127 "tags": [128 {129 "name": "@driver"130 },131 {132 "name": "@wip"133 },134 {135 "name": "@PROF-265"136 }137 ]138});139formatter.step({140 "name": "user clicks on books module",141 "keyword": "Given "142});143formatter.match({144 "location": "com.profillo.step_definitions.LibrarianStepDefs.user_clicks_on_books_module()"145});146formatter.result({147 "status": "skipped"148});149formatter.step({150 "name": "user clicks on edit book button",151 "keyword": "Then "152});153formatter.match({154 "location": "com.profillo.step_definitions.LibrarianStepDefs.user_clicks_on_edit_book_button()"155});156formatter.result({157 "status": "skipped"158});159formatter.step({160 "name": "user fills each component in edit window",161 "keyword": "When "162});163formatter.match({164 "location": "com.profillo.step_definitions.LibrarianStepDefs.user_fills_each_component_in_edit_window()"165});166formatter.result({167 "status": "skipped"168});169formatter.step({170 "name": "user clicks on save changes button",171 "keyword": "And "172});173formatter.match({174 "location": "com.profillo.step_definitions.LibrarianStepDefs.user_clicks_on_save_changes_button()"175});176formatter.result({177 "status": "skipped"178});179formatter.step({180 "name": "new changes will appear on book management page",181 "keyword": "Then "182});183formatter.match({184 "location": "com.profillo.step_definitions.EditBookStepDefs.new_changes_will_appear_on_book_management_page()"185});186formatter.result({187 "status": "skipped"188});189formatter.after({190 "error_message": "org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Can\u0027t stop process; it\u0027s not currently running (cmd: \u0027C:\\\\Users\\\\Mehmet\\\\IdeaProjects\\\\CucumberFramework\\\\src\\\\test\\\\resources\\\\chromedriver_win32.zip --url-base\\\u003dwd/hub --port\\\u003d8000 --adb-port\\\u003d5037 --verbose\u0027)\nBuild info: version: \u00273.141.59\u0027, revision: \u0027e82be7d358\u0027, time: \u00272018-11-14T08:17:03\u0027\nSystem info: host: \u0027DESKTOP-GSIE280\u0027, ip: \u0027192.168.0.10\u0027, os.name: \u0027Windows 10\u0027, os.arch: \u0027amd64\u0027, os.version: \u002710.0\u0027, java.version: \u002713.0.1\u0027\nDriver info: driver.version: Driver\nremote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Can\u0027t stop process; it\u0027s not currently running (cmd: \u0027C:\\\\Users\\\\Mehmet\\\\IdeaProjects\\\\CucumberFramework\\\\src\\\\test\\\\resources\\\\chromedriver_win32.zip --url-base\\\u003dwd/hub --port\\\u003d8000 --adb-port\\\u003d5037 --verbose\u0027)\n at getResponseForW3CError (C:\\Program Files\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-base-driver\\lib\\protocol\\errors.js:804:9)\n at asyncHandler (C:\\Program Files\\Appium\\resources\\app\\node_modules\\appium\\node_modules\\appium-base-driver\\lib\\protocol\\protocol.js:380:37)\r\n\tat java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)\r\n\tat java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)\r\n\tat java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)\r\n\tat java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)\r\n\tat java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)\r\n\tat org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)\r\n\tat org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)\r\n\tat org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)\r\n\tat java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)\r\n\tat java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)\r\n\tat java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127)\r\n\tat java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502)\r\n\tat java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488)\r\n\tat java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)\r\n\tat java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)\r\n\tat java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)\r\n\tat java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543)\r\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)\r\n\tat org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)\r\n\tat org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)\r\n\tat org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)\r\n\tat org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)\r\n\tat org.openqa.selenium.remote.RemoteWebDriver.\u003cinit\u003e(RemoteWebDriver.java:131)\r\n\tat org.openqa.selenium.remote.RemoteWebDriver.\u003cinit\u003e(RemoteWebDriver.java:144)\r\n\tat com.profillo.utilities.Driver.get(Driver.java:91)\r\n\tat com.profillo.step_definitions.Hooks.tearDown(Hooks.java:22)\r\n",191 "status": "failed"192});193formatter.background({194 "name": "",195 "description": "",196 "keyword": "Background"197});198formatter.before({199 "status": "passed"200});201formatter.step({202 "name": "the librarian logged in the application",203 "keyword": "Given "204});205formatter.match({206 "location": "com.profillo.step_definitions.LoginStepDefs.the_librarian_logged_in_the_application()"...
protocol.js
Source:protocol.js
...329 SESSIONS_CACHE.getLogger(req.params.sessionId || newSessionId, currentProtocol)330 .debug(`Encountered internal error running command: ${errMsg}`);331 }332 if (currentProtocol === PROTOCOLS.W3C) {333 [httpStatus, httpResBody] = getResponseForW3CError(actualErr);334 } else if (currentProtocol === PROTOCOLS.MJSONWP) {335 [httpStatus, httpResBody] = getResponseForJsonwpError(actualErr);336 } else {337 // If it's unknown what the protocol is (like if it's `getStatus` prior to `createSession`), merge the responses338 // together to be protocol-agnostic339 let jsonwpRes = getResponseForJsonwpError(actualErr);340 let w3cRes = getResponseForW3CError(actualErr);341 httpResBody = {342 ...jsonwpRes[1],343 ...w3cRes[1],344 };345 // Use the JSONWP status code (which is usually 500)346 httpStatus = jsonwpRes[0];347 }348 }349 // decode the response, which is either a string or json350 if (_.isString(httpResBody)) {351 res.status(httpStatus).send(httpResBody);352 } else {353 if (newSessionId) {354 if (currentProtocol === PROTOCOLS.W3C) {...
errors-specs.js
Source:errors-specs.js
...332 it('should return an error, message and stacktrace for just a generic exception', function () {333 try {334 throw new Error('Some random error');335 } catch (e) {336 const [httpStatus, httpResponseBody] = getResponseForW3CError(e);337 httpStatus.should.equal(500);338 const {error, message, stacktrace} = httpResponseBody.value;339 message.should.match(/Some random error/);340 error.should.equal('unknown error');341 stacktrace.should.match(/at getResponseForW3CError/);342 stacktrace.should.match(/Some random error/);343 stacktrace.should.match(/errors-specs.js/);344 }345 });346 it('should return an error, message and stacktrace for a NoSuchElementError', function () {347 const noSuchElementError = new errors.NoSuchElementError('specific error message');348 const [httpStatus, httpResponseBody] = getResponseForW3CError(noSuchElementError);349 httpStatus.should.equal(404);350 const {error, message, stacktrace} = httpResponseBody.value;351 error.should.equal('no such element');352 message.should.match(/specific error message/);353 stacktrace.should.match(/errors-specs.js/);354 });355 it('should handle BadParametersError', function () {356 const badParamsError = new errors.BadParametersError('__FOO__', '__BAR__', '__HELLO_WORLD__');357 const [httpStatus, httpResponseBody] = getResponseForW3CError(badParamsError);358 httpStatus.should.equal(400);359 const {error, message, stacktrace} = httpResponseBody.value;360 error.should.equal('invalid argument');361 message.should.match(/__BAR__/);362 message.should.match(/__HELLO_WORLD__/);363 stacktrace.should.match(/errors-specs.js/);364 });365 it('should translate JSONWP errors', function () {366 const [httpStatus, httpResponseBody] = getResponseForW3CError({367 status: 7,368 value: 'My custom message',369 sessionId: 'Fake Session Id',370 });371 httpStatus.should.equal(404);372 const {error, message, stacktrace} = httpResponseBody.value;373 message.should.equal('My custom message');374 error.should.equal('no such element');375 stacktrace.should.exist;376 });377});378describe('.getActualError', function () {379 describe('MJSONWP', function () {380 it('should map a status code 7 no such element error as a NoSuchElementError', function () {...
Using AI Code Generation
1const BaseDriver = require('appium-base-driver');2const W3CError = BaseDriver.errors.W3CError;3const getResponseForW3CError = BaseDriver.errors.getResponseForW3CError;4const BaseDriver = require('appium-base-driver');5const W3CError = BaseDriver.errors.W3CError;6const getResponseForW3CError = BaseDriver.errors.getResponseForW3CError;7const error = new Error('test error');8const w3cError = new W3CError('test error', 400);9const w3cErrorWithoutStatus = new W3CError('test error');10const w3cErrorWithStatus = new W3CError('test error', 400);11const w3cErrorWithMessage = new W3CError('test error', 400, 'message');12const w3cErrorWithEmptyMessage = new W3CError('test error', 400, '');13const w3cErrorWithNullMessage = new W3CError('test error', 400, null);14const w3cErrorWithUndefinedMessage = new W3CError('test error', 400, undefined);15const w3cErrorWithEmptyData = new W3CError('test error', 400, null, {});16const w3cErrorWithData = new W3CError('test error', 400, null, {foo: 'bar'});
Using AI Code Generation
1var appiumBaseDriver = require('appium-base-driver');2var W3CError = appiumBaseDriver.errors.W3CError;3var getResponseForW3CError = appiumBaseDriver.errors.getResponseForW3CError;4var error = new W3CError('Invalid Argument', 'error message');5console.log(getResponseForW3CError(error));6{ status: 400,7 { error: 'invalid argument',8at Object. (/Users/rahul/test.js:8:22)9at Module._compile (module.js:569:30)10at Object.Module._extensions..js (module.js:580:10)11at Module.load (module.js:503:32)12at tryModuleLoad (module.js:466:12)13at Function.Module._load (module.js:458:3)14at Function.Module.runMain (module.js:605:10)15at startup (bootstrap_node.js:158:16)16at bootstrap_node.js:575:3' } }
Using AI Code Generation
1var AppiumBaseDriver = require('appium-base-driver');2var appiumBaseDriver = new AppiumBaseDriver();3var error = new Error('Test Error');4var response = appiumBaseDriver.getResponseForW3CError(error, {});5console.log('Response: ' + JSON.stringify(response));6Response: {"status":13,"value":{"error":"unknown error","message":"Test Error"}}
Using AI Code Generation
1var BaseDriver = require('appium-base-driver').BaseDriver;2var driver = new BaseDriver();3var error = new Error('test error');4var response = driver.getResponseForW3CError(error, {});5console.log(response);6{"status":13,"value":{"error":"unknown error","message":"test error"}}7var AndroidDriver = require('appium-android-driver').AndroidDriver;8var driver = new AndroidDriver();9var error = new Error('test error');10var response = driver.getResponseForW3CError(error, {});11console.log(response);12{"status":13,"value":{"error":"unknown error","message":"test error"}}13var IOSDriver = require('appium-ios-driver').IOSDriver;14var driver = new IOSDriver();15var error = new Error('test error');16var response = driver.getResponseForW3CError(error, {});17console.log(response);18{"status":13,"value":{"error":"unknown error","message":"test error"}}19var WindowsDriver = require('appium-windows-driver').WindowsDriver;20var driver = new WindowsDriver();21var error = new Error('test error');22var response = driver.getResponseForW3CError(error, {});23console.log(response);24{"status":13,"value":{"error":"unknown error","message":"test error"}}25var MacDriver = require('appium-mac-driver').MacDriver;26var driver = new MacDriver();27var error = new Error('test error');28var response = driver.getResponseForW3CError(error, {});29console.log(response);30{"status":13,"value":{"error":"unknown error","message":"test error"}}31var YouiEngineDriver = require('appium-youiengine-driver').YouiEngineDriver;32var driver = new YouiEngineDriver();33var error = new Error('
Using AI Code Generation
1import { getResponseForW3CError } from 'appium-base-driver';2const error = new Error('Some error');3const response = getResponseForW3CError(error);4console.log(response);5import { getResponseForW3CError } from 'appium-base-driver';6const error = new Error('Some error');7const response = getResponseForW3CError(error);8console.log(response);9npm ERR! 404 You should bug the author to publish it (or use the name yourself!)10npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!