diff --git a/files/mcloud/node_modules/@appium/base-driver/build/lib/protocol/protocol.js b/files/mcloud/node_modules/@appium/base-driver/build/lib/protocol/protocol.js index 390a2ee..f93376e 100644 --- a/files/mcloud/node_modules/@appium/base-driver/build/lib/protocol/protocol.js +++ b/files/mcloud/node_modules/@appium/base-driver/build/lib/protocol/protocol.js @@ -256,7 +256,7 @@ function routeConfiguringFunction(driver) { for (const [path, methods] of lodash_1.default.toPairs(allMethods)) { for (const [method, spec] of lodash_1.default.toPairs(methods)) { // set up the express route handler - buildHandler(app, method, `${basePath}${path}`, spec, driver, isSessionCommand(/** @type {import('@appium/types').DriverMethodDef} */ (spec).command)); + buildHandler(app, method, `${basePath}${path}`, spec, driver, isSessionCommand(/** @type {import('@appium/types').DriverMethodDef} */(spec).command)); } } }; @@ -393,128 +393,125 @@ function buildHandler(app, method, path, spec, driver, isSessCmd) { } catch (err) { - async function updateDeviceStatus(token, udid, note) { + // token: string - auth token from stf + // udid: string - unique id of device + // note: string - comment with error for device which would shows in stf + // status: string - new status for device if null, update only note + async function updateDevice(token, udid, note, status) { // if token or udid not exist, skip function if (token == "" || udid == "") { - console.log(`[MCLOUD] Device status didi not change in STF`) - return; + return; } - + const url = `${process.env.STF_API_URL}/devices/${udid}`; - + const headers = { - 'Authorization': `Bearer ${token}`, - 'Content-Type': 'application/json' - }; - - const data = { - device: { - status: 'Unhealthy', - note: note - } + 'Authorization': `Bearer ${token}`, + 'Content-Type': 'application/json' }; - + + + const data = status ? { device: { status: status, note: note } } : { device: { note: note } } + try { - const response = await fetch(url, { - method: 'PUT', - headers: headers, - body: JSON.stringify(data) - }); - - if (!response.ok) { - throw new Error(`[MCLOUD] HTTP Error ${response.status}`); - } - - const responseData = await response.json(); - console.log('[MCLOUD] Successful device status change response:', responseData); - - return responseData; + const response = await fetch(url, { + method: 'PUT', + headers: headers, + body: JSON.stringify(data) + }); + + if (!response.ok) { + throw new Error(`[MCLOUD] HTTP Error ${response.status}.`); + } + + const responseData = await response.json(); + console.log('[MCLOUD] Successful device status change response: ', responseData); + + return responseData; } catch (error) { - console.error('[MCLOUD] Request device status change error:', error.message); - throw error; + console.error('[MCLOUD] Request device status change error: ', error.message); + throw error; } - } - - const token = process.env.STF_AUTH_TOKEN - const udid = process.env.DEVICE_UDID + } + + const token = process.env.STF_AUTH_TOKEN + const udid = process.env.DEVICE_UDID + + - // PATCH #2 /node_modules/appium/node_modules/appium-base-driver/build/lib/protocol/protocol.js to return to carina "DEBUG info" about problematic step - if(err.message !== 'An element could not be located on the page using the given search parameters.'){ - err.message = `${err.message}[[[--udid ${process.env.DEVICE_UDID} --name ${process.env.DEVICE_NAME} --sessionId ${process.env.sessionId}]]]`; - } - // handling error with Cannot find any free port in range if (err.message.toLowerCase().includes("cannot find any free port in range")) { - console.log(`[MCLOUD] Cannot find any free port in range. Error message: ${err.message} Appium need restart, exit code 1 `); + console.log(`[MCLOUD] Cannot find any free port in range. Error message: ${err.message} Appium need restart, exit with code 1.`); // Exiting with code 1 to indicate an error // process.exit(1); } - + // handling error with ENOSPC: no space left on device, mkdir '/tmp/ and exit with code 0 - if(err.message.toLowerCase().includes('no space left on device') || err.message.toLowerCase().includes('adb: failed to install')){ - console.log(`[MCLOUD] [BaseDriver] ENOSPC error, no space left on device, Error message:${err.message}. exit code 0. Device is Unhealthy !!! `) + if (err.message.toLowerCase().includes('no space left on device') || err.message.toLowerCase().includes('adb: failed to install')) { // process.exit(0); - updateDeviceStatus(token, udid, err.message) - .then(() => { - console.log(`[MCLOUD] Devices status for device with UDID ${udid} changed to Unhealthy!`) - }) - .catch(error => { - console.log(`[MCLOUD] Error occurated during making device with UDID ${udid} Unhealthy. Error: ${error}`) - }); + updateDevice(token, udid, err.message, 'Unhealthy') // device status will change to Unhealthy + .then(() => { + console.log(`[MCLOUD] Devices status for device with UDID ${udid} changed to Unhealthy!`) + }) + .catch(error => { + console.log(`[MCLOUD] Error occurred during making device with UDID ${udid} Unhealthy. Error: ${error}.`) + }); } - + // Check if the error 'socket hang up' occurred and do exit 0 if (err.message.toLowerCase().includes("socket hang up") && err.message.toLowerCase().includes("could not proxy command to the remote server")) { - console.log(`[MCLOUD] [BaseDriver] Error occurred, socket hang up. Original error: ${err.message}. exit code 0. Device is Unhealthy !!!`); // process.exit(0); - updateDeviceStatus(token, udid, err.message) - .then(() => { - console.log(`[MCLOUD] Devices status for device with UDID ${udid} changed to Unhealthy!`) - }) - .catch(error => { - console.log(`[MCLOUD] Error occurated during making device with UDID ${udid} Unhealthy. Error: ${error}`) - }); + updateDevice(token, udid, err.message) // device status will not change + .then(() => { + console.log(`[MCLOUD] Comment with error details added in STF for device with UDID ${udid}.`) + }) + .catch(error => { + console.log(`[MCLOUD] Error occurred while adding comment for device with UDID in STF ${udid}. Error: ${error}`) + }); } // Check if the error 'device setup is not yet complete' occurred and do exit 1 if (err.message.toLowerCase().includes("device setup is not yet complete")) { - console.log(`[MCLOUD] [BaseDriver] Error occurred, device setup is not yet complete. Original error: ${err.message} exit code 0, Deveice is Unhealthy !!!`); // process.exit(0); - updateDeviceStatus(token, udid, err.message) - .then(() => { - console.log(`[MCLOUD] Devices status for device with UDID ${udid} changed to Unhealthy!`) - }) - .catch(error => { - console.log(`[MCLOUD] Error occurated during making device with UDID ${udid} Unhealthy. Error: ${error}`) - }); - } - - // Check if the error is related to executing the 'am' shell command and do exit code 0 + updateDevice(token, udid, err.message, 'Unhealthy') // device status will change to Unhealthy + .then(() => { + console.log(`[MCLOUD] Devices status for device with UDID ${udid} changed to Unhealthy and error details have been added to the note.`) + }) + .catch(error => { + console.log(`[MCLOUD] Error occurred during making device with UDID ${udid} Unhealthy. Error: ${error}.`) + }); + } + if (err.message.toLowerCase().includes("the session identified by") && err.message.toLowerCase().includes("is not known")) { - console.log(`[MCLOUD] [BaseDriver] Got error: the session identified by [[[--udid ${process.env.DEVICE_UDID} --name ${process.env.DEVICE_NAME} --sessionId ${process.env.sessionId}]]] is not known. Error message: ${err.message}. Exit code 0. Device is Unhealthy !!!`); // process.exit(0); - updateDeviceStatus(token, udid, err.message) - .then(() => { - console.log(`[MCLOUD] Devices status for device with UDID ${udid} changed to Unhealthy!`) - }) - .catch(error => { - console.log(`[MCLOUD] Error occurated during making device with UDID ${udid} Unhealthy. Error: ${error}`) - }); - } - + updateDevice(token, udid, err.message) // device status will not change + .then(() => { + console.log(`[MCLOUD] Comment with Error details added in STF for device with UDID ${udid}.`) + }) + .catch(error => { + console.log(`[MCLOUD] Error occurred while adding comment for device with UDID in STF ${udid}. Error: ${error}.`) + }); + } + + + // Check if the error is related to executing the 'am' shell command and do exit code 0 if (err.message.toLowerCase().includes("сannot execute the 'am' shell command")) { - console.log(`[MCLOUD] [BaseDriver] Got error: Cannot execute the 'am' shell command. Error message: ${err.message}. exit code 0. Device is Unhealthy !!!`); // process.exit(0); - updateDeviceStatus(token, udid, err.message) - .then(() => { - console.log(`[MCLOUD] Devices status for device with UDID ${udid} changed to Unhealthy!`) - }) - .catch(error => { - console.log(`[MCLOUD] Error occurated during making device with UDID ${udid} Unhealthy. Error: ${error}`) - }); + updateDevice(token, udid, err.message, 'Unhealthy') // device status will change to Unhealthy + .then(() => { + console.log(`[MCLOUD] Devices status for device with UDID ${udid} changed to Unhealthy and error details have been added to the note.`) + }) + .catch(error => { + console.log(`[MCLOUD] Error occurred during making device with UDID ${udid} Unhealthy. Error: ${error}.`) + }); + } + + // PATCH #2 /node_modules/appium/node_modules/appium-base-driver/build/lib/protocol/protocol.js to return to carina "DEBUG info" about problematic step + if (err.message !== 'An element could not be located on the page using the given search parameters.') { + err.message = `${err.message}[[[--udid ${process.env.DEVICE_UDID} --name ${process.env.DEVICE_NAME} --sessionId ${process.env.sessionId}]]]`; } let actualErr; diff --git a/files/mcloud/node_modules/appium-2_2_2.diff b/files/mcloud/node_modules/appium-2_2_2.diff index fcc8742..67e2efc 100644 --- a/files/mcloud/node_modules/appium-2_2_2.diff +++ b/files/mcloud/node_modules/appium-2_2_2.diff @@ -564,9 +564,14 @@ index 7eca78cd9..4f8034cad 100644 } catch (err) { -+ async function updateDeviceStatus(token, udid, note) { ++ // token: string - auth token from stf ++ // udid: string - unique id of device ++ // note: string - comment with error for device which would shows in stf ++ // status: string - new status for device if null, update only note + -+ // if token or udid not exist, skip function ++ async function updateDevice(token, udid, note, status) { ++ ++ // if token or udid not exist, skip function + if (token == "" || udid == "") { + return; + } @@ -578,13 +583,8 @@ index 7eca78cd9..4f8034cad 100644 + 'Content-Type': 'application/json' + }; + -+ const data = { -+ device: { -+ status: 'Unhealthy', -+ note: note -+ } -+ }; -+ ++ const data = status ? { device: { status: status, note: note } } : { device: { note: note } } ++ + try { + const response = await fetch(url, { + method: 'PUT', @@ -593,15 +593,15 @@ index 7eca78cd9..4f8034cad 100644 + }); + + if (!response.ok) { -+ throw new Error(`HTTP Error ${response.status}`); ++ throw new Error(`HTTP Error ${response.status}.`); + } + + const responseData = await response.json(); -+ console.log('Successful response:', responseData); ++ console.log('Successful response: ', responseData); + + return responseData; + } catch (error) { -+ console.error('Request error:', error.message); ++ console.error('Request error: ', error.message); + throw error; + } + } @@ -610,87 +610,80 @@ index 7eca78cd9..4f8034cad 100644 + const udid = process.env.DEVICE_UDID + + - - // PATCH #2 /node_modules/appium/node_modules/appium-base-driver/build/lib/protocol/protocol.js to return to carina "DEBUG info" about problematic step -- err.message = `${err.message}[[[--udid ${process.env.DEVICE_UDID} --name ${process.env.DEVICE_NAME} --sessionId ${process.env.sessionId}]]]`; -+ if(err.message !== 'An element could not be located on the page using the given search parameters.'){ -+ err.message = `${err.message}[[[--udid ${process.env.DEVICE_UDID} --name ${process.env.DEVICE_NAME} --sessionId ${process.env.sessionId}]]]`; -+ } + + // handling error with Cannot find any free port in range + if (err.message.toLowerCase().includes("cannot find any free port in range")) { -+ console.log(`[MCLOUD] Cannot find any free port in range. Error message: ${err.message} Appium exit with code 1 `); ++ console.log(`[MCLOUD] Cannot find any free port in range. Error message: ${err.message} Appium exit with code 1.`); + // Exiting with code 1 to indicate an error + process.exit(1); + } + + // handling error with ENOSPC: no space left on device, mkdir '/tmp/ and exit with code 0 -+ if(err.message.toLowerCase().includes('no space left on device') || err.message.toLowerCase().includes('adb: failed to install')){\ -- console.log(`- [BaseDriver] ENOSPC error, no space left on device, Error message:${err.message} Appium need restart, exit code 0`) -+ console.log(`[MCLOUD] [BaseDriver] ENOSPC error, no space left on device, Error message:${err.message}. exit code 0. Device is Unhealthy !!! `) ++ if(err.message.toLowerCase().includes('no space left on device') || err.message.toLowerCase().includes('adb: failed to install')){ ++ console.log(`[MCLOUD] [BaseDriver] ENOSPC error, no space left on device, Error message:${err.message}. exit code 0. Device is Unhealthy.`) + // process.exit(0); -+ updateDeviceStatus(token, udid, err.message) ++ updateDevice(token, udid, err.message, 'Unhealthy') // device status will change to Unhealthy + .then(() => { + console.log(`[MCLOUD] Devices status for device with UDID ${udid} changed to Unhealthy!`) + }) + .catch(error => { -+ console.log(`[MCLOUD] Error occurated during making device with UDID ${udid} Unhealthy. Error: ${error}`) ++ console.log(`[MCLOUD] Error occurated during making device with UDID ${udid} Unhealthy. Error: ${error}.`) + }); + } + + // Check if the error 'socket hang up' occurred and do exit 0 + if (err.message.toLowerCase().includes("socket hang up") && err.message.toLowerCase().includes("could not proxy command to the remote server")) { -- console.log(`- [BaseDriver] Error occurred, socket hang up. Original error: ${err.message} Appium need restart, exit code 0`); -+ console.log(`[MCLOUD] [BaseDriver] Error occurred, socket hang up. Original error: ${err.message}. exit code 0. Device is Unhealthy !!!`); -+ // process.exit(0); -+ updateDeviceStatus(token, udid, err.message) ++ // process.exit(0); ++ updateDevice(token, udid, err.message) // device status will not change + .then(() => { + console.log(`[MCLOUD] Devices status for device with UDID ${udid} changed to Unhealthy!`) + }) + .catch(error => { -+ console.log(`[MCLOUD] Error occurated during making device with UDID ${udid} Unhealthy. Error: ${error}`) ++ console.log(`[MCLOUD] Error occurated during making device with UDID ${udid} Unhealthy. Error: ${error}.`) + }); + } + + // Check if the error 'device setup is not yet complete' occurred and do exit 1 + if (err.message.toLowerCase().includes("device setup is not yet complete")) { -- console.log(`- [BaseDriver] Error occurred, device setup is not yet complete. Original error: ${err.message} Appium need restart, exit code 0`); -+ console.log(`[MCLOUD] [BaseDriver] Error occurred, device setup is not yet complete. Original error: ${err.message} exit code 0, Deveice is Unhealthy !!!`); + // process.exit(0); -+ updateDeviceStatus(token, udid, err.message) ++ updateDevice(token, udid, err.message, 'Unhealthy') // device status will change to Unhealthy + .then(() => { -+ console.log(`[MCLOUD] Devices status for device with UDID ${udid} changed to Unhealthy!`) ++ console.log(`[MCLOUD] Devices status for device with UDID ${udid} changed to Unhealthy and error details have been added to the note.`) + }) + .catch(error => { -+ console.log(`[MCLOUD] Error occurated during making device with UDID ${udid} Unhealthy. Error: ${error}`) ++ console.log(`[MCLOUD] Error occurated during making device with UDID ${udid} Unhealthy. Error: ${error}.`) + }); + } + + // Check if the error is related to executing the 'am' shell command and do exit code 0 + if (err.message.toLowerCase().includes("сannot execute the 'am' shell command")) { -+ console.log(`[MCLOUD] [BaseDriver] Got error: Cannot execute the 'am' shell command. Error message: ${err.message}. exit code 0. Device is Unhealthy !!!`); + // process.exit(0); -+ updateDeviceStatus(token, udid, err.message) ++ updateDevice(token, udid, err.message, 'Unhealthy') // device status will change to Unhealthy + .then(() => { -+ console.log(`[MCLOUD] Devices status for device with UDID ${udid} changed to Unhealthy!`) ++ console.log(`[MCLOUD] Devices status for device with UDID ${udid} changed to Unhealthy and error details have been added to the note.`) + }) + .catch(error => { -+ console.log(`[MCLOUD] Error occurated during making device with UDID ${udid} Unhealthy. Error: ${error}`) ++ console.log(`[MCLOUD] Error occurated during making device with UDID ${udid} Unhealthy. Error: ${error}.`) + }); + } + if (err.message.toLowerCase().includes("the session identified by") && err.message.toLowerCase().includes("is not known")) { -+ console.log(`[MCLOUD] [BaseDriver] Got error: the session identified by [[[--udid ${process.env.DEVICE_UDID} --name ${process.env.DEVICE_NAME} --sessionId ${process.env.sessionId}]]] is not known. Error message: ${err.message}. Exit code 0. Device is Unhealthy !!!`); ++ console.log(`[MCLOUD] [BaseDriver] Got error: the session identified by [[[--udid ${process.env.DEVICE_UDID} --name ${process.env.DEVICE_NAME} --sessionId ${process.env.sessionId}]]] is not known. Error message: ${err.message}. Exit code 0.`); + // process.exit(0); -+ updateDeviceStatus(token, udid, err.message) ++ updateDevice(token, udid, err.message) // device status will not change + .then(() => { -+ console.log(`[MCLOUD] Devices status for device with UDID ${udid} changed to Unhealthy!`) ++ console.log(`[MCLOUD] Comment with Error details added in STF for device with UDID ${udid}.`) + }) + .catch(error => { -+ console.log(`[MCLOUD] Error occurated during making device with UDID ${udid} Unhealthy. Error: ${error}`) ++ console.log(`[MCLOUD] Error occurated while adding comment for device with UDID in STF ${udid}. Error: ${error}.`) + }); + } + ++ // PATCH #2 /node_modules/appium/node_modules/appium-base-driver/build/lib/protocol/protocol.js to return to carina "DEBUG info" about problematic step ++ if(err.message !== 'An element could not be located on the page using the given search parameters.'){ ++ err.message = `${err.message}[[[--udid ${process.env.DEVICE_UDID} --name ${process.env.DEVICE_NAME} --sessionId ${process.env.sessionId}]]]`; ++ } let actualErr;