UNPKG

tia

Version:

Time is All (logs driven test engine with ExtJs support)

121 lines 4.11 kB
"use strict"; // import {gT} from '../../../types'; Object.defineProperty(exports, "__esModule", { value: true }); const tiaErrorPropName = 'TIA_ERR'; async function queryAndAction(args) { const { tEQ, action, idForLog, enableLog } = args; // Waiting for all ExtJs inner processes are finished and component is ready to work with. await gT.e.wait.ajaxRequestsFinish(undefined, false); // await gT.e.wait.idle(undefined, false); return gIn.wrap({ msg: `Searching ExtJs cmp ${idForLog ? `${idForLog} ` : ''}by TEQ: ${tEQ} ... `, enableLog, act: async () => { // eslint-disable-next-line no-undef-init let result = undefined; let errorStr = 'Error Stub'; try { await gT.sOrig.driver.wait(async () => { const escapedTEQ = tEQ.replace(/\\/g, '\\\\'); const res = await gT.s.browser.executeScriptWrapper(`const { cmp, cmpInfo, tiaErr } = tiaEJ.searchAndWrap.byTeq('${escapedTEQ}', true);` + `if (tiaErr) return {${tiaErrorPropName}: tiaErr};` + `${action};`); if (typeof res === 'object' && res !== null && res[tiaErrorPropName]) { errorStr = res[tiaErrorPropName]; return false; } result = res; errorStr = ''; return true; }, gT.engineConsts.timeoutForSearchByTEQ); return result; } catch (err) { if (err.name !== 'TimeoutError') { throw err; } throw new Error(errorStr); } }, }); } exports.queryAndAction = queryAndAction; /** * Returns and object with component info. * TODO: create type for this object. */ async function queryCmpInfo(args) { const newArgs = { ...args, action: 'return cmpInfo;', }; return queryAndAction(newArgs); } exports.queryCmpInfo = queryCmpInfo; async function queryCmpId(args) { const newArgs = { ...args, action: 'return cmpInfo.constProps.realId;', }; return queryAndAction(newArgs); } exports.queryCmpId = queryCmpId; async function queryCmpInput(args) { const newArgs = { ...args, action: 'return cmpInfo.constProps.inputEl;', }; return queryAndAction(newArgs); } exports.queryCmpInput = queryCmpInput; async function queryCmpInputId(args) { const newArgs = { ...args, action: 'return cmpInfo.constProps.inputId;', }; return queryAndAction(newArgs); } exports.queryCmpInputId = queryCmpInputId; async function queryCmpTrigger(args) { const newArgs = { ...args, action: 'return cmpInfo.constProps.triggerEl;', }; return queryAndAction(newArgs); } exports.queryCmpTrigger = queryCmpTrigger; async function setFakeId(args) { const { tEQ, idForLog, enableLog, fakeId } = args; const idForLogStr = idForLog ? `, idForLog: ${idForLog}` : ''; return gIn.wrap({ msg: `Setting fakeId "${fakeId}" for TEQ: ${tEQ}${idForLogStr} ... `, enableLog, act: async () => queryAndAction({ tEQ, action: `tiaEJ.idMap.add('${fakeId}', cmpInfo.constProps.realId);`, enableLog: false, }), }); } exports.setFakeId = setFakeId; async function removeAllFakeIds(enableLog) { return gIn.wrap({ msg: 'Removing fake Ids ... ', enableLog, act: async () => gT.s.browser.executeScriptWrapper('tiaEJ.idMap.removeAll()'), }); } exports.removeAllFakeIds = removeAllFakeIds; /** * Wrap some function with logger and error handling code. */ async function wrap(args) { const { tEQ, compName, idForLog = '', act, actionDesc, enableLog } = args; return gIn.wrap({ msg: `${compName}${idForLog ? ` ${idForLog}` : ''} "${tEQ}": ${actionDesc} ... `, enableLog, act, }); } exports.wrap = wrap; //# sourceMappingURL=tia-extjs-query.js.map