tomation 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.vite/manifest.json +1 -1
- package/dist/main.cjs +1 -1
- package/dist/main.d.ts +1 -5
- package/dist/main.js +1280 -1562
- package/dist/{actions.d.ts → src/dom/actions.d.ts} +2 -43
- package/dist/src/dsl/actions.d.ts +53 -0
- package/dist/src/dsl/task.d.ts +2 -0
- package/dist/src/dsl/test.d.ts +4 -0
- package/dist/src/dsl/ui-element-filters.d.ts +12 -0
- package/dist/{ui-element-builder.d.ts → src/dsl/ui-element.d.ts} +6 -18
- package/dist/src/engine/compiler.d.ts +8 -0
- package/dist/src/engine/events.d.ts +27 -0
- package/dist/src/engine/runner.d.ts +49 -0
- package/dist/src/feedback/logger.d.ts +7 -0
- package/dist/src/main.d.ts +13 -0
- package/dist/src/tomation.d.ts +9 -0
- package/package.json +13 -17
- package/dist/automation.d.ts +0 -137
- /package/dist/{ui-utils.d.ts → src/feedback/ui-utils.d.ts} +0 -0
- /package/dist/{date-utils.d.ts → src/utils/date-utils.d.ts} +0 -0
package/dist/.vite/manifest.json
CHANGED
package/dist/main.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var at=Object.defineProperty;var ct=(e,t,n)=>t in e?at(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var i=(e,t,n)=>(ct(e,typeof t!="symbol"?t+"":t,n),n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class z{constructor(t,n,s,o){i(this,"name");i(this,"selector");i(this,"parent");i(this,"postProcess");this.name=t,this.selector=n,this.parent=s||null,this.postProcess=o}getElementName(){let t="";return this.parent&&(t=" in "+this.parent.getElementName()),`${this.name}${t}`}}let V;const lt=e=>{V=e},W=(e,t)=>(s=V,o)=>{s=s||V,console.log("Searching elem from Root = ",s);const a=[];s.querySelectorAll(e).forEach(c=>{c.style.display!=="none"&&a.push(c)});let r;return t?(console.log("Applying filter ",t),console.log(" -- to "+a.length+"elements: ",a),r=a.filter((c,E,x)=>{console.log("Apply filter to item "+E+": ",c);const m=t(c,E,x);return console.log(` -> Item ${E} ${m?"Match":"Discarded"}`),m})[0]):r=a[0],r&&o&&(console.log("Apply post process to = ",r),r=o(r)),console.log("Return elem = ",r),r},L=(e,t,n)=>({as:s=>new z(s,e,t,n)}),ut=(e,t)=>({...L(e,t),postProcess:n=>({...L(e,t,n)})}),G=e=>({...L(e,null),childOf:t=>({...ut(e,t)}),postProcess:t=>({...L(e,null,t)})}),N=e=>({where:t=>G(W(e,t))}),ht=N("div"),dt=N("button"),pt=N("input"),mt=N("textarea"),gt=e=>G(W("#"+e)),yt=e=>N(e);let Q=!1;const Et=e=>{Q=e},w=(...e)=>{Q&&console.log("[UIElement Filter]",...e)},At=e=>t=>{const n=t.className==e;return w(`classIs('${e}') on`,t,"=>",n),n},wt=e=>t=>{const n=t.className.split(" ").includes(e);return w(`classIncludes('${e}') on`,t,"=>",n),n},ft=e=>t=>{var s;const n=((s=t.textContent)==null?void 0:s.trim())==e;return w(`innerTextIs('${e}') on`,t,"=>",n),n},xt=e=>t=>{const n=t.innerText.trim().includes(e);return w(`innerTextContains('${e}') on`,t,"=>",n),n},Ct=e=>t=>{const n=t.title==e;return w(`titleIs('${e}') on`,t,"=>",n),n},St=e=>t=>{const n=t.placeholder===e;return w(`placeholderIs('${e}') on`,t,"=>",n),n},Tt=()=>(e,t)=>{const n=t===0;return w("isFirstElement on",e,"index",t,"=>",n),n},It=e=>(t,n)=>{const s=n===e;return w(`elementIndexIs(${e}) on`,t,"elemIndex",n,"=>",s),s},kt=e=>t=>{const n=(t==null?void 0:t.firstChild).innerText.trim()===e;return w(`firstChildTextIs('${e}') on`,t,"=>",n),n},vt=e=>(t,n)=>{const s=e.every((o,a)=>{const r=o(t,n);return w(`and condition[${a}] on`,t,"elemIndex",n,"=>",r),r});return w("and final result on",t,"elemIndex",n,"=>",s),s},Nt={DIV:ht,BUTTON:dt,INPUT:pt,TEXTAREA:mt,ELEMENT:yt,identifiedBy:gt};let O;const bt=new Uint8Array(16);function Ot(){if(!O&&(O=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!O))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return O(bt)}const p=[];for(let e=0;e<256;++e)p.push((e+256).toString(16).slice(1));function Dt(e,t=0){return(p[e[t+0]]+p[e[t+1]]+p[e[t+2]]+p[e[t+3]]+"-"+p[e[t+4]]+p[e[t+5]]+"-"+p[e[t+6]]+p[e[t+7]]+"-"+p[e[t+8]]+p[e[t+9]]+"-"+p[e[t+10]]+p[e[t+11]]+p[e[t+12]]+p[e[t+13]]+p[e[t+14]]+p[e[t+15]]).toLowerCase()}const Pt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),H={randomUUID:Pt};function Z(e,t,n){if(H.randomUUID&&!t&&!e)return H.randomUUID();e=e||{};const s=e.random||(e.rng||Ot)();if(s[6]=s[6]&15|64,s[8]=s[8]&63|128,t){n=n||0;for(let o=0;o<16;++o)t[n+o]=s[o];return t}return Dt(s)}const A=(e=2e3)=>new Promise(t=>{setTimeout(()=>{t(null)},e)}),f=(e,t)=>{Object.entries(t).map(([s,o])=>({key:s,value:o})).forEach(s=>{const{key:o,value:a}=s;e.style[o]=a})};class Lt{constructor(t){i(this,"window");i(this,"document");i(this,"devToolsMessageContainer");i(this,"devToolsCheckElementContainer");i(this,"darkLayerLeft");i(this,"darkLayerTop");i(this,"darkLayerRight");i(this,"darkLayerBottom");i(this,"currentCheckElem");i(this,"contextViewerContainer");i(this,"devToolsAlertContainer");this.document=t.document,this.window=t,this.devToolsMessageContainer=this.createElement("DIV",{id:"dev-tools-message-container",styles:{width:"500px",backgroundColor:"rgba(0, 0, 0, 0.5)",color:"white",position:"fixed",bottom:"10px",right:"10px",fontFamily:"monospace",zIndex:"9999"},parent:this.document.body}),this.devToolsAlertContainer=this.createElement("DIV",{id:"dev-tools-alert-container",styles:{width:"100%",height:"30px",backgroundColor:"#b00",color:"white",position:"absolute ",top:0,fontFamily:"monospace",zIndex:"9999",display:"none",alignItems:"center",justifyContent:"center",padding:"5px"},parent:this.document.body}),this.devToolsCheckElementContainer=this.createElement("DIV",{id:"dev-tools-check-element-container",styles:{width:"100%",height:this.document.body.clientHeight+"px",position:"absolute",top:"0px",left:"0px",zIndex:"9990",display:"none",opacity:"0",transition:"opacity .2s"},parent:this.document.body});const n={zIndex:"9991",backgroundColor:"rgba(0,0,0,0.3)",position:"absolute"};this.darkLayerLeft=this.createElement("DIV",{id:"dark-layer-left",styles:n,parent:this.devToolsCheckElementContainer}),this.darkLayerTop=this.createElement("DIV",{id:"dark-layer-top",styles:n,parent:this.devToolsCheckElementContainer}),this.darkLayerRight=this.createElement("DIV",{id:"dark-layer-right",styles:n,parent:this.devToolsCheckElementContainer}),this.darkLayerBottom=this.createElement("DIV",{id:"dark-layer-bottom",styles:n,parent:this.devToolsCheckElementContainer}),this.currentCheckElem=this.createElement("DIV",{id:"current-check-elem",parent:this.devToolsCheckElementContainer}),this.contextViewerContainer=this.createElement("DIV",{id:"context-viewer-container",styles:{width:"100%",height:this.document.body.clientHeight+"px",position:"absolute",top:"0px",left:"0px",zIndex:"10000",display:"none"},parent:this.document.body})}createElement(t,n){const s=this.document.createElement(t);return n&&(n.id&&(s.id=n==null?void 0:n.id),n.styles&&f(s,n.styles),n.parent&&n.parent.appendChild(s)),s}async logAction(t){const n=exports.AutomationInstance.document.createElement("DIV");n.innerText=t,f(n,{padding:"3px 10px",opacity:"1",transition:"opacity 1s"}),this.devToolsMessageContainer.appendChild(n),await A(4e3),n.style.opacity="0",await A(4e3),this.devToolsMessageContainer.removeChild(n),await A(1e3)}async checkElement(t,n){if(!t)return;const s=t.getBoundingClientRect(),o=this.document.body.getBoundingClientRect();this.darkLayerLeft.style.left="0px",this.darkLayerLeft.style.top=s.top+"px",this.darkLayerLeft.style.width=this.window.scrollX+s.left+"px",this.darkLayerLeft.style.height=s.height+"px",this.darkLayerTop.style.left=this.window.scrollX+"px",this.darkLayerTop.style.top="0px",this.darkLayerTop.style.width="100%",this.darkLayerTop.style.height=s.top+"px",this.darkLayerRight.style.left=this.window.scrollX+s.left+s.width+"px",this.darkLayerRight.style.top=s.top+"px",this.darkLayerRight.style.width=o.width-(s.left+s.width)+"px",this.darkLayerRight.style.height=s.height+"px",this.darkLayerBottom.style.left=this.window.scrollX+"px",this.darkLayerBottom.style.top=s.top+s.height+"px",this.darkLayerBottom.style.width="100%",this.darkLayerBottom.style.height=o.height-(s.top+s.height)+"px",this.currentCheckElem.id=`dev-tools-current-check-elem-${n}`,this.currentCheckElem.style.top=s.top+"px",this.currentCheckElem.style.left=this.window.scrollX+s.left+"px",this.currentCheckElem.style.height=s.height+"px",this.currentCheckElem.style.width=s.width+"px",this.currentCheckElem.style.boxShadow="0px 0px 5px 2px lightgreen",this.currentCheckElem.style.position="absolute",this.currentCheckElem.style.zIndex="9992",this.devToolsCheckElementContainer.style.display="block",this.devToolsCheckElementContainer.style.opacity="1",await A(200)}async showAlert(t){const n=exports.AutomationInstance.document.createElement("DIV"),s=exports.AutomationInstance.document.body;n.innerText=t,f(s,{paddingTop:"30px"}),f(this.devToolsAlertContainer,{display:"flex"}),this.devToolsAlertContainer.appendChild(n)}async hideAlert(){f(this.devToolsAlertContainer,{display:"none"});const t=exports.AutomationInstance.document.body;f(t,{paddingTop:"0"}),this.devToolsAlertContainer.firstChild&&this.devToolsAlertContainer.removeChild(this.devToolsAlertContainer.firstChild)}async hideCheckElementContainer(){this.devToolsCheckElementContainer.style.opacity="0",await A(200),this.devToolsCheckElementContainer.style.display="none"}displayContext(t){f(this.contextViewerContainer,{display:"flex","background-color":"white",position:"absolute",top:"0px",left:"0px","z-index":"9999"});const n=this.document.createElement("DIV");n.id="context-viewer-before",f(n,{flex:"50%",width:"100%",height:"auto",border:"2px solid orange"});const s=this.document.createElement("DIV");s.id="context-viewer-after",f(s,{flex:"50%",width:"100%",height:"auto",border:"2px solid green"});const o=this.document.createElement("DIV");o.innerHTML=t.beforeHTML,j(o,t.beforeInputValues);const a=this.document.createElement("DIV");a.innerHTML=t.afterHTML,j(a,t.afterInputValues),this.contextViewerContainer.appendChild(n),n.appendChild(o),setTimeout(()=>{this.contextViewerContainer.removeChild(n),this.contextViewerContainer.appendChild(s),s.appendChild(a),setTimeout(()=>{this.contextViewerContainer.removeChild(s),f(this.contextViewerContainer,{display:"none"})},2e3)},2e3)}}const j=(e,t)=>{e.querySelectorAll("input").forEach(n=>{const s=n.getAttribute("input-id")||"";n.value=t[s]})},F=null,D=async(e,t,n,s=1e3,o=0,a=10,r=!1)=>{if(console.log("Automation Status: ",exports.AutomationInstance.status),exports.AutomationInstance.isPaused)return new Promise((c,E)=>{exports.AutomationInstance.saveCurrentAction(async x=>{if(x.status=="skipped")return c(null);try{const m=await D(x,t,n,s,o,a,r);c(m)}catch(m){E(m)}},e)});if(exports.AutomationInstance.isStopped)throw new Error("Test stopped manually");if(console.groupCollapsed(`tries ${o}/${a}`),e&&(e.updateTries(o),await y.notifyActionUpdated(e)),o===a)throw console.groupEnd(),r?new Error(`UI Element ${t.getElementName()||"UNKNOWN"} still present after 10 tries`):new Error(`UI Element ${t.getElementName()||"UNKNOWN"} not found after 10 tries`);{const c=t.selector(n,t.postProcess);return console.groupEnd(),c?r?(await A(s),await D(e,t,n,s,++o,a,r)):(console.log("Element found = ",c),c):r?(console.log("Element removed."),F):(await A(s),await D(e,t,n,s,++o,a,r))}},U=async(e,t,n=1e3,s=10,o=!1)=>{const a=t==null?void 0:t.getElementName();console.group("Looking for Element: "+a);let r=null;if(t.parent)try{console.groupCollapsed("Look for Parent ",t.parent.getElementName()),r=await U(e,t.parent,n,s,o),console.groupEnd()}catch(c){if(console.groupEnd(),o&&c.message.includes("not found"))return console.log("Parent not found, so element was removed"),console.groupEnd(),F;throw console.groupEnd(),c}try{console.log("Using parent element: ",r);const c=await D(e,t,r,n,0,s,o);return console.groupEnd(),c}catch(c){if(o&&c.message.includes("not found"))return console.log("Parent not found, so element was removed"),console.groupEnd(),F;throw console.groupEnd(),c}};var B=(e=>(e.WAITING="waiting",e.RUNNING="running",e.STOPPED="stopped",e.PAUSED="paused",e.SUCCESS="success",e.ERROR="error",e.SKIPPED="skipped",e))(B||{});class y{constructor(){i(this,"status");i(this,"error");i(this,"id");i(this,"context");this.status="waiting",this.error="",this.id=Z(),this.context={beforeHTML:"",beforeInputValues:{},afterInputValues:{},afterHTML:"",url:"",startTimestamp:"",endTimestamp:""}}getJSON(){return{id:this.id,description:this.getDescription(),context:this.context,status:this.status,error:this.error}}reset(){this.status="waiting",this.error="",this.resetAction()}getInputValuesFromPage(){const t={};return exports.AutomationInstance.document.querySelectorAll("input").forEach((s,o)=>{const a=`value-id-${o}`;s.setAttribute("input-id",a),t[a]=s.value}),t}async execute(){try{this.status="running",this.context.beforeInputValues=this.getInputValuesFromPage(),this.context.beforeHTML=exports.AutomationInstance.document.body.innerHTML,await y.notifyActionUpdated(this),console.log("Action: ",this.getDescription()),await this.executeAction(),this.status="success",this.error="",exports.AutomationInstance.isStepByStepMode&&exports.AutomationInstance.pause()}catch(t){if(this.status="error",this.error=t.message,t.message=="Test stopped manually")throw Error("Error in Action "+this.getDescription()+". Message: "+t.message);this.status="paused",exports.AutomationInstance.pause()}finally{this.context.afterInputValues=this.getInputValuesFromPage(),this.context.afterHTML=exports.AutomationInstance.document.body.innerHTML,await y.notifyActionUpdated(this)}}static async notifyActionUpdated(t){h.dispatch(S.ACTION_UPDATE,{action:t.getJSON()})}}class Y extends y{constructor(n,s){super();i(this,"name");i(this,"stepsFn");i(this,"steps");i(this,"params");i(this,"index");this.name=n,this.stepsFn=s,this.steps=[],this.index=0}getDescription(){return this.name}compileSteps(){super.reset(),this.stepsFn(this.params)}stepsToJSON(){return this.steps.reduce((n,s)=>(n.push(s.getJSON()),n),[])}getJSON(){return{...super.getJSON(),type:"Action",params:this.params,steps:this.stepsToJSON()}}resetAction(){this.steps.length=0,this.index=0}async handlePause(){return new Promise((n,s)=>{exports.AutomationInstance.saveCurrentAction(async o=>{if(o.status==="skipped"){n();return}try{await this.continue(),n()}catch(a){s(a)}},this)})}async continue(){for(;this.index<this.steps.length;){if(exports.AutomationInstance.isStopped)throw new Error("Test stopped manually");const n=this.steps[this.index];try{if(await A(exports.AutomationInstance.speed),await n.execute(),exports.AutomationInstance.isPaused){if(await this.handlePause(),n.status==="skipped"){this.index++;continue}}else this.index++}catch(s){throw h.dispatch(S.ACTION_ERROR,{action:this.getJSON(),step:n,error:s.message,index:this.index}),s}}}async executeAction(){this.index=0,await this.continue()}setParams(n){this.params=n}addStep(n){this.steps.push(n)}}class d extends y{constructor(n){super();i(this,"uiElement");i(this,"element");i(this,"tries");this.uiElement=n,this.element=null,this.tries=0}getElementName(){var n;return(n=this.uiElement)==null?void 0:n.getElementName()}updateTries(n){this.tries=n}resetTries(){this.tries=0}getJSON(){return{id:this.id,element:this.getElementName(),description:this.getDescription(),status:this.status,error:this.error,context:this.context,tries:this.tries}}static waitForElement(n,s,o=1e3,a=10,r=!1){const c=s.getElementName();return new Promise(async(E,x)=>{var I;const m=async(C,b=1e3,k=0,v=!1)=>{if(console.groupCollapsed(`tries ${k}/${a}`),n.updateTries(k),await y.notifyActionUpdated(n),k===a)throw console.groupEnd(),v?new Error(`UI Element ${c||"UNKNOWN"} still present after 10 tries`):new Error(`UI Element ${c||"UNKNOWN"} not found after 10 tries`);{const K=s.selector(C,s.postProcess);return console.groupEnd(),K?v?(await A(b),await m(C,b,++k,v)):(console.log("Element found = ",K),K):v?(console.log("Element removed."),null):(await A(b),await m(C,b,++k,v))}};console.group("[Action On Element] Looking for Element: "+c);let T=null,J=!0;if(s.parent){console.groupCollapsed("Look for Parent ",s.parent.getElementName());try{T=await d.waitForElement(n,s.parent,o,a,r)}catch{J=!1}finally{console.groupEnd()}}if(J){console.log("using parent element: ",T);try{const C=await m(T,o,0,r);console.groupEnd(),E(C)}catch(C){console.groupEnd(),x(new Error(C.message))}}else console.groupEnd(),x(new Error(`Parent ${(I=s.parent)==null?void 0:I.getElementName()} of UI Element ${s.name||"UNKNOWN"} not found`))})}async executeAction(){var n;try{this.element=await U(this,this.uiElement),(n=this.element)==null||n.setAttribute("test-id",this.getElementName()),await exports.AutomationInstance.uiUtils.checkElement(this.element,this.getElementName()),this.executeActionOnElement(),await exports.AutomationInstance.uiUtils.hideCheckElementContainer()}catch(s){throw Error(s.message)}}resetAction(){this.element=null,this.resetTries()}}class $t extends d{constructor(t){super(t)}executeActionOnElement(){var t;return(t=this.element)==null?void 0:t.click()}getDescription(){return"Click in "+this.getElementName()}getJSON(){return{...super.getJSON(),type:"Click"}}}class Ut extends d{constructor(n,s){super(n);i(this,"text");this.text=s}executeActionOnElement(){var s;if(!(((s=this.element)==null?void 0:s.innerText)===this.text))throw new Error(`Text in element ${this.getElementName()} is not '${this.text}'`)}getDescription(){return`Assert that text in ${this.getElementName()} is '${this.text}'`}getJSON(){return{...super.getJSON(),type:"AssertTextIsAction",value:this.text}}}class Rt extends d{constructor(n,s){super(n);i(this,"text");this.text=s}executeActionOnElement(){var s;if(!((s=this.element)==null?void 0:s.innerText.includes(this.text)))throw new Error(`Text in element ${this.getElementName()} doesn't contain '${this.text}'`)}getDescription(){return`Assert that ${this.getElementName()} contains '${this.text}'`}getJSON(){return{...super.getJSON(),type:"AssertContainsText",value:this.text}}}class Jt extends d{constructor(n,s){super(n);i(this,"value");this.value=s}executeActionOnElement(){if(!(this.element.value===this.value))throw new Error(`Value in element ${this.getElementName()} is not '${this.value}'`)}getDescription(){return`Assert that value in ${this.getElementName()} is '${this.value}'`}getJSON(){return{...super.getJSON(),type:"AssertValueIsAction",value:this.value}}}class Kt extends d{constructor(t){super(t)}executeActionOnElement(){if(!!!this.element)throw new Error(`Element ${this.getElementName()} doesn't exist`)}getDescription(){return`Assert that ${this.getElementName()} exists`}getJSON(){return{...super.getJSON(),type:"AssertExistsAction"}}}class Vt extends d{constructor(t){super(t)}async executeAction(){var t;try{this.element=await U(this,this.uiElement,1e3,5,!0),(t=this.element)==null||t.setAttribute("test-id",this.getElementName()),await exports.AutomationInstance.uiUtils.checkElement(this.element,this.getElementName()),this.executeActionOnElement(),await exports.AutomationInstance.uiUtils.hideCheckElementContainer()}catch(n){throw Error(n.message)}}executeActionOnElement(){if(!!this.element)throw new Error(`Element ${this.getElementName()} was not expected to exist`)}getDescription(){return`Assert that ${this.getElementName()} doesn't exist`}getJSON(){return{...super.getJSON(),type:"AssertNotExistsAction"}}}class Ft extends d{constructor(n,s){super(n);i(this,"value");this.value=s}executeActionOnElement(){var s,o,a,r;let n=this.element;if(((s=this.element)==null?void 0:s.tagName)!=="INPUT"&&((o=this.element)==null?void 0:o.tagName)!=="SELECT"&&((a=this.element)==null?void 0:a.tagName)!=="TEXTAREA"&&(n=(r=this.element)==null?void 0:r.querySelectorAll("input")[0],!n))throw new Error("Input element not found. Not able to type value in element "+this.getElementName());n.value=this.value,n.dispatchEvent(new Event("change"))}getDescription(){return`Select value '${this.value}' in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:"Select",value:this.value}}}class _ extends d{constructor(n,s){super(n);i(this,"value");this.value=s}executeActionOnElement(){var s,o,a,r;let n=this.element;if(((s=this.element)==null?void 0:s.tagName)!=="INPUT"&&((o=this.element)==null?void 0:o.tagName)!=="SELECT"&&((a=this.element)==null?void 0:a.tagName)!=="TEXTAREA"&&(n=(r=this.element)==null?void 0:r.querySelectorAll("input")[0],!n))throw new Error("Input element not found. Not able to type value in element "+this.getElementName());n.value=this.value,n.dispatchEvent(new Event("change")),n.dispatchEvent(new Event("keyup",{bubbles:!0})),n.dispatchEvent(new Event("input",{bubbles:!0}))}getDescription(){return`Type value '${this.value}' in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:"Type",value:this.value}}}class Mt extends d{constructor(n,s){super(n);i(this,"value");this.value=s}executeActionOnElement(){var s,o,a,r;let n=this.element;if(((s=this.element)==null?void 0:s.tagName)!=="INPUT"&&((o=this.element)==null?void 0:o.tagName)!=="SELECT"&&((a=this.element)==null?void 0:a.tagName)!=="TEXTAREA"&&(n=(r=this.element)==null?void 0:r.querySelectorAll("input")[0],!n))throw new Error("Input element not found. Not able to type value in element "+this.getElementName());n.value=this.value,n.dispatchEvent(new Event("change")),n.dispatchEvent(new Event("keyup",{bubbles:!0})),n.dispatchEvent(new Event("input",{bubbles:!0}))}getDescription(){return`Type a password in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:"TypePassword",value:this.value}}}class Wt extends d{constructor(t){super(t)}executeActionOnElement(){var t;(t=this.element)==null||t.dispatchEvent(new KeyboardEvent("keydown",{altKey:!1,code:"Escape",ctrlKey:!1,isComposing:!1,key:"Escape",location:0,metaKey:!1,repeat:!1,shiftKey:!1,which:27,charCode:0,keyCode:27}))}getDescription(){return`Press Esc key in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:"PressEscKey"}}}class Bt extends d{constructor(t){super(t)}executeActionOnElement(){var t;(t=this.element)==null||t.dispatchEvent(new KeyboardEvent("keyup",{altKey:!1,code:"Down",ctrlKey:!1,isComposing:!1,key:"Down",location:0,metaKey:!1,repeat:!1,shiftKey:!1,which:40,charCode:0,keyCode:40}))}getDescription(){return`Press Down key in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:"PressDownKey"}}}class qt extends d{constructor(t){super(t)}executeActionOnElement(){var t;(t=this.element)==null||t.dispatchEvent(new KeyboardEvent("keydown",{altKey:!1,code:"Tab",ctrlKey:!1,isComposing:!1,key:"Tab",location:0,metaKey:!1,repeat:!1,shiftKey:!1,which:9,charCode:0,keyCode:9}))}getDescription(){return`Press Tab key in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:"PressTabKey"}}}class Ht extends d{constructor(t){super(t)}executeActionOnElement(){var t;(t=this.element)==null||t.dispatchEvent(new KeyboardEvent("keydown",{altKey:!1,code:"Enter",ctrlKey:!1,isComposing:!1,key:"Enter",location:0,metaKey:!1,repeat:!1,shiftKey:!1,which:13,charCode:0,keyCode:13}))}getDescription(){return`Press Enter key in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:"PressEnterKey"}}}var tt=(e=>(e.ESCAPE="Escape",e.ENTER="Enter",e.TAB="Tab",e.ARROW_DOWN="ArrowDown",e.ARROW_UP="ArrowUp",e.ARROW_LEFT="ArrowLeft",e.ARROW_RIGHT="ArrowRight",e.BACKSPACE="Backspace",e.DELETE="Delete",e.SHIFT="Shift",e.CONTROL="Control",e.ALT="Alt",e.META="Meta",e))(tt||{});const X={Escape:27,Enter:13,Tab:9,ArrowDown:40,ArrowUp:38,ArrowLeft:37,ArrowRight:39,Backspace:8,Delete:46,Shift:16,Control:17,Alt:18,Meta:91};class jt extends d{constructor(n,s){super(n);i(this,"key");this.key=s}executeActionOnElement(){var n;(n=this.element)==null||n.dispatchEvent(new KeyboardEvent("keydown",{key:this.key,code:this.key,keyCode:X[this.key],charCode:0,which:X[this.key],altKey:!1,ctrlKey:!1,metaKey:!1,shiftKey:!1,isComposing:!1,location:0,repeat:!1}))}getDescription(){return`Press ${this.key} key in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:"PressKey",key:this.key}}}class Xt extends d{constructor(n,s){super(n);i(this,"file");this.file=s}executeActionOnElement(){const n=this.element,s=new DataTransfer;s.items.add(this.file);const o=s.files;n.files=o,n.dispatchEvent(new Event("change"));function a(c){var E;return c!=null&&c.parentElement?((E=c.parentElement)==null?void 0:E.tagName.toLowerCase())==="form"?c.parentElement:a(c.parentElement):null}const r=a(n);r&&r.dispatchEvent(new Event("change"))}getDescription(){return`Upload file in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:"UploadFile"}}}class zt extends d{constructor(n,s){super(n);i(this,"memorySlotName");this.memorySlotName=s}executeActionOnElement(){var s,o,a,r;let n=this.element;if(((s=this.element)==null?void 0:s.tagName)!=="INPUT"&&((o=this.element)==null?void 0:o.tagName)!=="SELECT"&&((a=this.element)==null?void 0:a.tagName)!=="TEXTAREA"&&(n=(r=this.element)==null?void 0:r.querySelectorAll("input")[0],!n))throw new Error("Input element not found. Not able to save value from element "+this.getElementName());h.dispatch(S.SAVE_VALUE,{memorySlotName:this.memorySlotName,value:n.value})}getDescription(){return`Save value of ${this.getElementName()} in ${this.memorySlotName}`}getJSON(){return{...super.getJSON(),type:"SaveValue",memorySlotName:this.memorySlotName}}}class Gt extends y{constructor(n){super();i(this,"miliseconds");this.miliseconds=n}getDescription(){return"Wait "+this.miliseconds+" miliseconds"}getJSON(){return{...super.getJSON(),type:"Wait"}}async executeAction(){await A(this.miliseconds)}resetAction(){}}class Qt extends y{constructor(n){super();i(this,"uiElement");i(this,"tries");this.uiElement=n,this.tries=0}updateTries(n){this.tries=n}resetAction(){this.tries=0}getElementName(){var n;return(n=this.uiElement)==null?void 0:n.getElementName()}async executeAction(){await U(this,this.uiElement,1e3,10,!0)}getDescription(){return"Wait until "+this.getElementName()+" is removed"}getJSON(){return{...super.getJSON(),type:"WaitUntilElementRemoved"}}}class Zt extends y{constructor(){super()}getDescription(){return"Paused"}getJSON(){return{...super.getJSON(),type:"Pause"}}async executeAction(){await exports.AutomationInstance.pause()}resetAction(){}}class Yt extends y{constructor(n){super();i(this,"description");this.description=n}getDescription(){return"Manual Step: "+this.description}getJSON(){return{...super.getJSON(),type:"ManualStep"}}async executeAction(){return await exports.AutomationInstance.uiUtils.showAlert("Waiting manual step..."),new Promise((n,s)=>{h.on(S.USER_ACCEPT,async()=>(await exports.AutomationInstance.uiUtils.hideAlert(),n(!0))),h.on(S.USER_REJECT,async()=>(await exports.AutomationInstance.uiUtils.hideAlert(),s()))})}resetAction(){}}class _t extends y{constructor(){super()}getDescription(){return"Reload page"}getJSON(){return{...super.getJSON(),type:"ReloadPage"}}async executeAction(){await location.reload()}resetAction(){}}class te extends y{constructor(n,s,o,a="condition"){super();i(this,"condition");i(this,"ifAction");i(this,"elseAction");i(this,"conditionDescription");this.condition=n,this.ifAction=s,this.elseAction=o,this.conditionDescription=a}getDescription(){const n=this.elseAction?`, else ${this.elseAction.getDescription()}`:"";return`If ${this.conditionDescription}, then ${this.ifAction.getDescription()}${n}`}getJSON(){var n;return{...super.getJSON(),type:"If",conditionDescription:this.conditionDescription,ifAction:this.ifAction.getJSON(),elseAction:(n=this.elseAction)==null?void 0:n.getJSON()}}async executeAction(){try{await this.condition(),await this.ifAction.execute()}catch{this.elseAction&&await this.elseAction.execute()}}resetAction(){var n;this.ifAction.reset(),(n=this.elseAction)==null||n.reset()}compileSteps(){var n;this.ifAction.compileSteps(),(n=this.elseAction)==null||n.compileSteps()}}const $=e=>e.toLocaleDateString("en-US",{year:"numeric",month:"2-digit",day:"2-digit"}),R=e=>{const t=new Date;return $(new Date(t.setDate(t.getDate()+e)))},et=e=>{const t=new Date;return $(new Date(t.setMonth(t.getMonth()+e)))},ee=R(1),ne=R(-1),se=R(7),oe=R(-7),ie=et(1),re=et(-1),ae={formatDate:$,today:$(new Date),tomorrow:ee,nextWeek:se,nextMonth:ie,yesterday:ne,lastWeek:oe,lastMonth:re};class ce{constructor(){i(this,"enabled",!1)}setEnabled(t){this.enabled=t}log(...t){this.enabled&&console.log("[tomation]",...t)}groupCollapsed(...t){this.enabled&&console.groupCollapsed("[tomation]",...t)}groupEnd(){this.enabled&&console.groupEnd()}error(...t){this.enabled&&console.error("[tomation]",...t)}}const l=new ce,nt=e=>{l.setEnabled(e)},g=class g{static compileAction(t){const n=g.currentAction;g.currentAction=t,t.compileSteps(),g.currentAction=n}static compileConditionalAction(t){const n=g.currentAction;g.currentAction=t,t.compileSteps(),g.currentAction=n}static addAction(t){l.log("Add action: ",t.getDescription()),g.currentAction.addStep(t)}static init(t){g.currentAction=t,g.isCompiling=!0,l.groupCollapsed("Compile: "+t.getDescription()),t.compileSteps(),g.isCompiling=!1,l.log("Compilation finished"),l.groupEnd()}};i(g,"currentAction"),i(g,"isCompiling");let u=g;var S=(e=>(e.ACTION_UPDATE="tomation-action-update",e.SAVE_VALUE="tomation-save-value",e.REGISTER_TEST="tomation-register-test",e.TEST_STARTED="tomation-test-started",e.TEST_PASSED="tomation-test-passed",e.TEST_FAILED="tomation-test-failed",e.TEST_END="tomation-test-end",e.TEST_STOP="tomation-test-stop",e.TEST_PAUSE="tomation-test-pause",e.TEST_PLAY="tomation-test-play",e.USER_ACCEPT="tomation-user-accept",e.USER_REJECT="tomation-user-reject",e.SESSION_INIT="tomation-session-init",e.ACTION_ERROR="tomation-action-error",e))(S||{});class le{constructor(){i(this,"events");this.events=new Map}on(t,n){var s;this.events.has(t)||this.events.set(t,[]),(s=this.events.get(t))==null||s.push(n)}off(t,n){var s;this.events.has(t)&&this.events.set(t,((s=this.events.get(t))==null?void 0:s.filter(o=>o!==n))||[])}dispatch(t,n){var s;this.events.has(t)&&((s=this.events.get(t))==null||s.forEach(o=>{console.log(`Dispatch Event ${t}:`,n),o(n)}))}}const h=new le;var q=(e=>(e[e.SLOW=2e3]="SLOW",e[e.NORMAL=1e3]="NORMAL",e[e.FAST=200]="FAST",e))(q||{});class st{static async start(t){if(exports.AutomationInstance.status!=="Stopped")throw l.error("Not able to run test while other test is running."),new Error("Not able to run test while other test is running.");exports.AutomationInstance.status="Playing",exports.AutomationInstance.runMode="Normal",l.groupCollapsed("Start Action: ",t.getDescription()),h.dispatch("tomation-test-started",{action:t==null?void 0:t.getJSON()});try{await(t==null?void 0:t.execute()),h.dispatch("tomation-test-passed",{id:t.name}),exports.AutomationInstance.status="Stopped"}catch(n){throw h.dispatch("tomation-test-failed",{id:t.name}),exports.AutomationInstance.uiUtils.hideCheckElementContainer(),l.error(`🤖 Error running task ${t.getDescription()}. Reason: ${n.message}`),exports.AutomationInstance.status="Paused",n}finally{l.groupEnd(),h.dispatch("tomation-test-end",{action:t==null?void 0:t.getJSON()})}}}const P={},ue=(e,t)=>{console.log(`Registering Test: ${e}...`);const n=new Y(e,t);h.dispatch("tomation-register-test",{id:e}),console.log(`Registered Test: ${e} in TestsMap`),P[e]=()=>{l.log(`Compilation of Test ${e} starts...`),u.init(n),l.log(`Compilation of Test ${e} Finished.`),l.log(`Start running Test ${e}...`),st.start(n)}},ot=e=>{if(P[e])P[e]();else throw console.log("Available Tests:",Object.keys(P)),new Error(`Test with id ${e} not found.`)},he=(e,t)=>async n=>{const s=new Y(e,t);if(s.setParams(n),exports.AutomationInstance.status=="Stopped"&&!u.isCompiling)try{l.log(`Compilation of Task ${e} starts...`),u.init(s),l.log(`Compilation of Task ${e} Finished.`),l.log(`Start running Task ${e}...`),await st.start(s),l.log(`End of Task ${e}: SUCCESS`)}catch(o){l.error("Error running task "+e+". "+o.message)}else l.log(`Adding action ${e} to compilation stack`),u.addAction(s),u.compileAction(s)},de=e=>{const t=new $t(e);u.addAction(t)},pe=e=>({textIs:t=>{u.addAction(new Ut(e,t))},containsText:t=>{u.addAction(new Rt(e,t))},valueIs:t=>{u.addAction(new Jt(e,t))},exists:()=>{u.addAction(new Kt(e))},notExists:()=>{u.addAction(new Vt(e))}}),me=e=>({in:t=>{const n=new Ft(t,e);u.addAction(n)}}),ge=e=>({in:t=>{const n=new _(t,e);u.addAction(n)}}),ye=()=>({in:e=>{const t=new _(e,"");u.addAction(t)}}),Ee=()=>({in:e=>{u.addAction(new Wt(e))}}),Ae=()=>({in:e=>{u.addAction(new Bt(e))}}),we=()=>({in:e=>{u.addAction(new qt(e))}}),fe=()=>({in:e=>{u.addAction(new Ht(e))}}),xe=e=>({in:t=>{u.addAction(new jt(t,e))}}),Ce=e=>({in:t=>{const n=new Mt(t,e);u.addAction(n)}}),Se=e=>({in:t=>{const n=new Xt(t,e);u.addAction(n)}}),Te=e=>({in:t=>{const n=new zt(e,t);u.addAction(n)}}),it=e=>{u.addAction(new Gt(e))};it.untilElement=e=>({isRemoved:()=>{u.addAction(new Qt(e))}});const Ie=()=>{u.addAction(new Zt)},ke=e=>{u.addAction(new Yt(e))},ve=()=>{u.addAction(new _t)},Ne=(e,t)=>({then:n=>({else:s=>{const o=new te(t,n,s,e);u.addAction(o)}})});class be{constructor(t){i(this,"_document");i(this,"debug");i(this,"_uiUtils");i(this,"speed");i(this,"status");i(this,"runMode");i(this,"currentActionCallback");i(this,"currentAction");this._document=t.document,this.debug=!0,this._uiUtils=new Lt(t),this.speed=1e3,this.status="Stopped",this.runMode="Normal"}get document(){return this._document}get uiUtils(){return this._uiUtils}get isStepByStepMode(){return this.runMode=="Step By Step"}get isStopped(){return this.status=="Stopped"}get isPlaying(){return this.status=="Playing"}get isPaused(){return this.status=="Paused"}pause(){l.log("Pause Test"),this.status="Paused",h.dispatch("tomation-test-pause")}continue(){l.log("Continue Test"),this.status="Playing",this.runMode="Normal",h.dispatch("tomation-test-play"),this.currentActionCallback&&this.currentAction&&(l.log("Continue: Executing current action callback"),this.currentActionCallback(this.currentAction),this.currentActionCallback=void 0)}next(){l.log("Continue Test to Next Step..."),this.status="Paused",this.runMode="Step By Step",this.currentActionCallback&&this.currentAction&&(l.log("Next: Executing current action callback"),this.currentActionCallback(this.currentAction),this.currentActionCallback=void 0)}stop(){l.log("Stop Test"),this.status="Stopped",this.currentActionCallback&&this.currentAction&&(l.log("Stop: Executing current action callback"),this.currentActionCallback(this.currentAction),this.currentActionCallback=void 0),h.dispatch("tomation-test-stop")}retryAction(){l.log("Retry current step"),this.status="Playing",h.dispatch("tomation-test-play"),this.currentActionCallback&&this.currentAction&&(this.currentAction.resetTries&&(l.log("Retry: Resetting tries for current action"),this.currentAction.resetTries()),l.log("Retry: Executing current action callback"),this.currentActionCallback(this.currentAction),this.currentActionCallback=void 0)}skipAction(){l.log("Skip current step"),this.status="Playing",this.currentActionCallback&&this.currentAction&&(this.currentAction.status=B.SKIPPED,l.log("Skip: Marked current action as SKIPPED"),y.notifyActionUpdated(this.currentAction),l.log("Skip: Executing current action callback"),this.currentActionCallback(this.currentAction),this.currentActionCallback=void 0)}saveCurrentAction(t,n){l.log("Save current action"),this.currentActionCallback=t,this.currentAction=n}setDebug(t){nt(t)}}exports.AutomationInstance=void 0;const M=(e,t)=>(exports.AutomationInstance=new be(e),lt(exports.AutomationInstance.document),t==null||t.forEach(n=>n()),exports.AutomationInstance);function rt(e){const{matches:t,tests:n=[],speed:s="NORMAL",debug:o=!1}=e;if(!(typeof t=="string"?document.location.href.includes(t):!!document.location.href.match(t))){console.log(`[tomation] URL "${document.location.href}" does not match "${t}"`);return}try{console.log("[tomation] Setting up messaging bridge with extension..."),Object.values(S).forEach(r=>{console.log(`[tomation] Setting up listener for event "${r}"`),h.on(r,c=>{console.log(`[tomation] Dispatching event "${r}" to extension`,c),window.postMessage({message:"injectedScript-to-contentScript",sender:"tomation",payload:{cmd:r,params:c}})})}),window.addEventListener("message",r=>{try{console.log("[tomation] Received message from extension:",r.data);const{message:c,sender:E,payload:x}=r.data||{},{cmd:m,params:T}=x||{};if(E!=="web-extension")return;if(c==="contentScript-to-injectedScript"){const I={"run-test-request":()=>ot(T==null?void 0:T.testId),"reload-tests-request":()=>M(window,n||[]),"pause-test-request":()=>exports.AutomationInstance.pause(),"stop-test-request":()=>exports.AutomationInstance.stop(),"continue-test-request":()=>exports.AutomationInstance.continue(),"next-step-request":()=>exports.AutomationInstance.next(),"retry-action-request":()=>exports.AutomationInstance.retryAction(),"skip-action-request":()=>exports.AutomationInstance.skipAction(),"user-accept-request":()=>h.dispatch("tomation-user-accept"),"user-reject-request":()=>h.dispatch("tomation-user-reject")}[m];I?(console.log(`[tomation] Executing command "${m}" from extension`),I()):console.warn(`[tomation] Unknown command "${m}" from extension`);return}}catch(c){console.error("[tomation] Error handling message from extension:",c)}}),window.postMessage({message:"injectedScript-to-contentScript",sender:"tomation",payload:{cmd:"tomation-session-init",params:{sessionId:Z()}}}),M(window,n),exports.AutomationInstance.setDebug(o),exports.AutomationInstance.speed=q[s],console.log("[tomation] Ready ✓")}catch(r){console.error("[tomation] Initialization failed:",r)}}exports.ACTION_STATUS=B;exports.Assert=pe;exports.AutomationEvents=h;exports.ClearValue=ye;exports.Click=de;exports.DateUtils=ae;exports.EVENT_NAMES=S;exports.If=Ne;exports.KEY_MAP=tt;exports.ManualTask=ke;exports.Pause=Ie;exports.PressDownKey=Ae;exports.PressEnterKey=fe;exports.PressEscKey=Ee;exports.PressKey=xe;exports.PressTabKey=we;exports.ReloadPage=ve;exports.RunTest=ot;exports.SaveValue=Te;exports.Select=me;exports.SelectorBuilder=W;exports.Setup=M;exports.Task=he;exports.Test=ue;exports.TestSpeed=q;exports.Type=ge;exports.TypePassword=Ce;exports.UIElement=z;exports.UploadFile=Se;exports.Wait=it;exports.and=vt;exports.classIncludes=wt;exports.classIs=At;exports.default=rt;exports.elementIndexIs=It;exports.firstChildTextIs=kt;exports.innerTextContains=xt;exports.innerTextIs=ft;exports.is=Nt;exports.isFirstElement=Tt;exports.placeholderIs=St;exports.setAutomationLogs=nt;exports.setFilterLogs=Et;exports.titleIs=Ct;exports.tomation=rt;exports.wait=A;
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=!1,t=(...t)=>{e&&console.log(`[UIElement Filter]`,...t)},n=e=>n=>{let r=n.className==e;return t(`classIs('${e}') on`,n,`=>`,r),r},r=e=>n=>{let r=n.className.split(` `).includes(e);return t(`classIncludes('${e}') on`,n,`=>`,r),r},i=e=>n=>{let r=n.textContent?.trim()==e;return t(`innerTextIs('${e}') on`,n,`=>`,r),r},a=e=>n=>{let r=n.innerText.trim().includes(e);return t(`innerTextContains('${e}') on`,n,`=>`,r),r},o=e=>n=>{let r=n.title==e;return t(`titleIs('${e}') on`,n,`=>`,r),r},s=e=>n=>{let r=n.placeholder===e;return t(`placeholderIs('${e}') on`,n,`=>`,r),r},c=()=>(e,n)=>{let r=n===0;return t(`isFirstElement on`,e,`index`,n,`=>`,r),r},l=e=>(n,r)=>{let i=r===e;return t(`elementIndexIs(${e}) on`,n,`elemIndex`,r,`=>`,i),i},u=e=>n=>{let r=(n?.firstChild).innerText.trim()===e;return t(`firstChildTextIs('${e}') on`,n,`=>`,r),r},d=e=>(n,r)=>{let i=e.every((e,i)=>{let a=e(n,r);return t(`and condition[${i}] on`,n,`elemIndex`,r,`=>`,a),a});return t(`and final result on`,n,`elemIndex`,r,`=>`,i),i},f=class{name;selector;parent;postProcess;constructor(e,t,n,r){this.name=e,this.selector=t,this.parent=n||null,this.postProcess=r}getElementName(){let e=``;return this.parent&&(e=` in `+this.parent.getElementName()),`${this.name}${e}`}},p,ee=e=>{p=e},m=(e,t)=>(n=p,r)=>{n||=p,console.log(`Searching elem from Root = `,n);let i=[];n.querySelectorAll(e).forEach(e=>{e.style.display!==`none`&&i.push(e)});let a;return t?(console.log(`Applying filter `,t),console.log(` -- to `+i.length+`elements: `,i),a=i.filter((e,n,r)=>{console.log(`Apply filter to item `+n+`: `,e);let i=t(e,n,r);return console.log(` -> Item ${n} ${i?`Match`:`Discarded`}`),i})[0]):a=i[0],a&&r&&(console.log(`Apply post process to = `,a),a=r(a)),console.log(`Return elem = `,a),a},h=(e,t,n)=>({as:r=>new f(r,e,t,n)}),te=(e,t)=>({...h(e,t),postProcess:n=>({...h(e,t,n)})}),g=e=>({...h(e,null),childOf:t=>({...te(e,t)}),postProcess:t=>({...h(e,null,t)})}),_=e=>({where:t=>g(m(e,t))}),ne={DIV:_(`div`),BUTTON:_(`button`),INPUT:_(`input`),TEXTAREA:_(`textarea`),ELEMENT:e=>_(e),identifiedBy:e=>g(m(`#`+e))},v=function(e){return e.ACTION_UPDATE=`tomation-action-update`,e.SAVE_VALUE=`tomation-save-value`,e.REGISTER_TEST=`tomation-register-test`,e.TEST_STARTED=`tomation-test-started`,e.TEST_PASSED=`tomation-test-passed`,e.TEST_FAILED=`tomation-test-failed`,e.TEST_END=`tomation-test-end`,e.TEST_STOP=`tomation-test-stop`,e.TEST_PAUSE=`tomation-test-pause`,e.TEST_PLAY=`tomation-test-play`,e.USER_ACCEPT=`tomation-user-accept`,e.USER_REJECT=`tomation-user-reject`,e.SESSION_INIT=`tomation-session-init`,e.URL_MISMATCH=`tomation-url-mismatch`,e.SESSION_CONNECTED=`tomation-session-connected`,e}(v||{}),y=new class{events;constructor(){this.events=new Map}on(e,t){this.events.has(e)||this.events.set(e,[]),this.events.get(e)?.push(t)}off(e,t){this.events.has(e)&&this.events.set(e,this.events.get(e)?.filter(e=>e!==t)||[])}dispatch(e,t){this.events.has(e)&&this.events.get(e)?.forEach(n=>{console.log(`Dispatch Event ${e}:`,t),n(t)})}},b=!1,x={setEnabled(e){b=e},log(...e){b&&console.log(`[tomation]`,...e)},groupCollapsed(...e){b&&console.groupCollapsed(`[tomation]`,...e)},groupEnd(){b&&console.groupEnd()},error(...e){b&&console.error(`[tomation]`,...e)}},S=(e=2e3)=>new Promise(t=>{setTimeout(()=>{t(null)},e)}),C=(e,t)=>{Object.entries(t).map(([e,t])=>({key:e,value:t})).forEach(t=>{let{key:n,value:r}=t;e.style[n]=r})},re=class{window;document;devToolsMessageContainer;devToolsCheckElementContainer;darkLayerLeft;darkLayerTop;darkLayerRight;darkLayerBottom;currentCheckElem;contextViewerContainer;devToolsAlertContainer;constructor(e){this.document=e.document,this.window=e,this.devToolsMessageContainer=this.createElement(`DIV`,{id:`dev-tools-message-container`,styles:{width:`500px`,backgroundColor:`rgba(0, 0, 0, 0.5)`,color:`white`,position:`fixed`,bottom:`10px`,right:`10px`,fontFamily:`monospace`,zIndex:`9999`},parent:this.document.body}),this.devToolsAlertContainer=this.createElement(`DIV`,{id:`dev-tools-alert-container`,styles:{width:`100%`,height:`30px`,backgroundColor:`#b00`,color:`white`,position:`absolute `,top:0,fontFamily:`monospace`,zIndex:`9999`,display:`none`,alignItems:`center`,justifyContent:`center`,padding:`5px`},parent:this.document.body}),this.devToolsCheckElementContainer=this.createElement(`DIV`,{id:`dev-tools-check-element-container`,styles:{width:`100%`,height:this.document.body.clientHeight+`px`,position:`absolute`,top:`0px`,left:`0px`,zIndex:`9990`,display:`none`,opacity:`0`,transition:`opacity .2s`},parent:this.document.body});let t={zIndex:`9991`,backgroundColor:`rgba(0,0,0,0.3)`,position:`absolute`};this.darkLayerLeft=this.createElement(`DIV`,{id:`dark-layer-left`,styles:t,parent:this.devToolsCheckElementContainer}),this.darkLayerTop=this.createElement(`DIV`,{id:`dark-layer-top`,styles:t,parent:this.devToolsCheckElementContainer}),this.darkLayerRight=this.createElement(`DIV`,{id:`dark-layer-right`,styles:t,parent:this.devToolsCheckElementContainer}),this.darkLayerBottom=this.createElement(`DIV`,{id:`dark-layer-bottom`,styles:t,parent:this.devToolsCheckElementContainer}),this.currentCheckElem=this.createElement(`DIV`,{id:`current-check-elem`,parent:this.devToolsCheckElementContainer}),this.contextViewerContainer=this.createElement(`DIV`,{id:`context-viewer-container`,styles:{width:`100%`,height:this.document.body.clientHeight+`px`,position:`absolute`,top:`0px`,left:`0px`,zIndex:`10000`,display:`none`},parent:this.document.body})}createElement(e,t){let n=this.document.createElement(e);return t&&(t.id&&(n.id=t?.id),t.styles&&C(n,t.styles),t.parent&&t.parent.appendChild(n)),n}async logAction(e){let t=O.document.createElement(`DIV`);t.innerText=e,C(t,{padding:`3px 10px`,opacity:`1`,transition:`opacity 1s`}),this.devToolsMessageContainer.appendChild(t),await S(4e3),t.style.opacity=`0`,await S(4e3),this.devToolsMessageContainer.removeChild(t),await S(1e3)}async checkElement(e,t){if(!e)return;let n=e.getBoundingClientRect(),r=this.document.body.getBoundingClientRect();this.darkLayerLeft.style.left=`0px`,this.darkLayerLeft.style.top=n.top+`px`,this.darkLayerLeft.style.width=this.window.scrollX+n.left+`px`,this.darkLayerLeft.style.height=n.height+`px`,this.darkLayerTop.style.left=this.window.scrollX+`px`,this.darkLayerTop.style.top=`0px`,this.darkLayerTop.style.width=`100%`,this.darkLayerTop.style.height=n.top+`px`,this.darkLayerRight.style.left=this.window.scrollX+n.left+n.width+`px`,this.darkLayerRight.style.top=n.top+`px`,this.darkLayerRight.style.width=r.width-(n.left+n.width)+`px`,this.darkLayerRight.style.height=n.height+`px`,this.darkLayerBottom.style.left=this.window.scrollX+`px`,this.darkLayerBottom.style.top=n.top+n.height+`px`,this.darkLayerBottom.style.width=`100%`,this.darkLayerBottom.style.height=r.height-(n.top+n.height)+`px`,this.currentCheckElem.id=`dev-tools-current-check-elem-${t}`,this.currentCheckElem.style.top=n.top+`px`,this.currentCheckElem.style.left=this.window.scrollX+n.left+`px`,this.currentCheckElem.style.height=n.height+`px`,this.currentCheckElem.style.width=n.width+`px`,this.currentCheckElem.style.boxShadow=`0px 0px 5px 2px lightgreen`,this.currentCheckElem.style.position=`absolute`,this.currentCheckElem.style.zIndex=`9992`,this.devToolsCheckElementContainer.style.display=`block`,this.devToolsCheckElementContainer.style.opacity=`1`,await S(200)}async showAlert(e){let t=O.document.createElement(`DIV`),n=O.document.body;t.innerText=e,C(n,{paddingTop:`30px`}),C(this.devToolsAlertContainer,{display:`flex`}),this.devToolsAlertContainer.appendChild(t)}async hideAlert(){C(this.devToolsAlertContainer,{display:`none`});let e=O.document.body;C(e,{paddingTop:`0`}),this.devToolsAlertContainer.firstChild&&this.devToolsAlertContainer.removeChild(this.devToolsAlertContainer.firstChild)}async hideCheckElementContainer(){this.devToolsCheckElementContainer.style.opacity=`0`,await S(200),this.devToolsCheckElementContainer.style.display=`none`}displayContext(e){C(this.contextViewerContainer,{display:`flex`,"background-color":`white`,position:`absolute`,top:`0px`,left:`0px`,"z-index":`9999`});let t=this.document.createElement(`DIV`);t.id=`context-viewer-before`,C(t,{flex:`50%`,width:`100%`,height:`auto`,border:`2px solid orange`});let n=this.document.createElement(`DIV`);n.id=`context-viewer-after`,C(n,{flex:`50%`,width:`100%`,height:`auto`,border:`2px solid green`});let r=this.document.createElement(`DIV`);r.innerHTML=e.beforeHTML,w(r,e.beforeInputValues);let i=this.document.createElement(`DIV`);i.innerHTML=e.afterHTML,w(i,e.afterInputValues),this.contextViewerContainer.appendChild(t),t.appendChild(r),setTimeout(()=>{this.contextViewerContainer.removeChild(t),this.contextViewerContainer.appendChild(n),n.appendChild(i),setTimeout(()=>{this.contextViewerContainer.removeChild(n),C(this.contextViewerContainer,{display:`none`})},2e3)},2e3)}},w=(e,t)=>{e.querySelectorAll(`input`).forEach(e=>{e.value=t[e.getAttribute(`input-id`)||``]})},T=function(e){return e[e.SLOW=2e3]=`SLOW`,e[e.NORMAL=1e3]=`NORMAL`,e[e.FAST=200]=`FAST`,e}(T||{}),E=function(e){return e.PLAYING=`Playing`,e.STOPPED=`Stopped`,e.PAUSED=`Paused`,e}(E||{}),D=function(e){return e.NORMAL=`Normal`,e.STEPBYSTEP=`Step By Step`,e}(D||{}),ie=class{_document;debug;_uiUtils;speed;status;runMode;currentActionCallback;currentAction;constructor(e){this._document=e.document,this.debug=!0,this._uiUtils=new re(e),this.speed=T.NORMAL,this.status=E.STOPPED,this.runMode=D.NORMAL}get document(){return this._document}get uiUtils(){return this._uiUtils}get isStepByStepMode(){return this.runMode==D.STEPBYSTEP}get isStopped(){return this.status==E.STOPPED}get isPlaying(){return this.status==E.PLAYING}get isPaused(){return this.status==E.PAUSED}pause(){x.log(`Pause Test`),this.status=E.PAUSED,y.dispatch(v.TEST_PAUSE)}continue(){x.log(`Continue Test`),this.status=E.PLAYING,this.runMode=D.NORMAL,y.dispatch(v.TEST_PLAY),this.currentActionCallback&&this.currentAction&&(x.log(`Continue: Executing current action callback`),this.currentActionCallback(this.currentAction),this.currentActionCallback=void 0)}next(){x.log(`Continue Test to Next Step...`),this.status=E.PLAYING,this.runMode=D.STEPBYSTEP,y.dispatch(v.TEST_PLAY),this.currentActionCallback&&this.currentAction&&(x.log(`Next: Executing current action callback`),this.currentActionCallback(this.currentAction),this.currentActionCallback=void 0)}stop(){x.log(`Stop Test`),this.status=E.STOPPED,this.currentActionCallback&&this.currentAction&&(x.log(`Stop: Executing current action callback`),this.currentActionCallback(this.currentAction),this.currentActionCallback=void 0),y.dispatch(v.TEST_STOP)}retryAction(){x.log(`Retry current step`),this.status=E.PLAYING,y.dispatch(v.TEST_PLAY),this.currentActionCallback&&this.currentAction&&(this.currentAction.resetTries&&(x.log(`Retry: Resetting tries for current action`),this.currentAction.resetTries()),x.log(`Retry: Executing current action callback`),this.currentActionCallback(this.currentAction),this.currentActionCallback=void 0)}skipAction(){x.log(`Skip current step`),this.status=E.PLAYING,this.currentActionCallback&&this.currentAction&&(this.currentAction.status=L.SKIPPED,x.log(`Skip: Marked current action as SKIPPED`),R.notifyActionUpdated(this.currentAction),x.log(`Skip: Executing current action callback`),this.currentActionCallback(this.currentAction),this.currentActionCallback=void 0)}saveCurrentAction(e,t){x.log(`Save current action`),this.currentActionCallback=e,this.currentAction=t}setDebug(e){x.setEnabled(e)}},O,k=(e,t)=>(O=new ie(e),ee(O.document),t?.forEach(e=>e()),O),A=!1;async function ae(e){if(A)throw x.error(`Not able to run test while other test is running.`),Error(`Not able to run test while other test is running.`);A=!0,O.status=E.PLAYING,O.runMode=D.NORMAL,x.groupCollapsed(`Start Action: `,e.getDescription()),y.dispatch(v.TEST_STARTED,{action:e?.getJSON()});try{await e?.execute(),y.dispatch(v.TEST_PASSED,{id:e.name})}catch(t){throw y.dispatch(v.TEST_FAILED,{id:e.name}),O.uiUtils.hideCheckElementContainer(),x.error(`🤖 Error running task ${e.getDescription()}. Reason: ${t.message}`),t}finally{x.groupEnd(),A=!1,y.dispatch(v.TEST_END,{action:e?.getJSON()})}}var j={start:ae,get running(){return A}},M=[];for(let e=0;e<256;++e)M.push((e+256).toString(16).slice(1));function oe(e,t=0){return(M[e[t+0]]+M[e[t+1]]+M[e[t+2]]+M[e[t+3]]+`-`+M[e[t+4]]+M[e[t+5]]+`-`+M[e[t+6]]+M[e[t+7]]+`-`+M[e[t+8]]+M[e[t+9]]+`-`+M[e[t+10]]+M[e[t+11]]+M[e[t+12]]+M[e[t+13]]+M[e[t+14]]+M[e[t+15]]).toLowerCase()}var se=new Uint8Array(16);function ce(){return crypto.getRandomValues(se)}function N(e,t,n){return!t&&!e&&crypto.randomUUID?crypto.randomUUID():le(e,t,n)}function le(e,t,n){e||={};let r=e.random??e.rng?.()??ce();if(r.length<16)throw Error(`Random bytes length must be >= 16`);if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){if(n||=0,n<0||n+16>t.length)throw RangeError(`UUID byte range ${n}:${n+15} is out of buffer bounds`);for(let e=0;e<16;++e)t[n+e]=r[e];return t}return oe(r)}var P=null,F=async(e,t,n,r=1e3,i=0,a=10,o=!1)=>{if(console.log(`Automation Status: `,O.status),O.isPaused)return new Promise((s,c)=>{O.saveCurrentAction(async e=>{if(e.status==L.SKIPPED)return s(null);try{s(await F(e,t,n,r,i,a,o))}catch(e){c(e)}},e)});if(O.isStopped)throw Error(`Test stopped manually`);if(console.groupCollapsed(`tries ${i}/${a}`),e&&(e.updateTries(i),await R.notifyActionUpdated(e)),i===a)throw console.groupEnd(),Error(o?`UI Element ${t.getElementName()||`UNKNOWN`} still present after 10 tries`:`UI Element ${t.getElementName()||`UNKNOWN`} not found after 10 tries`);{let s=t.selector(n,t.postProcess);return console.groupEnd(),s?o?(await S(r),await F(e,t,n,r,++i,a,o)):(console.log(`Element found = `,s),s):o?(console.log(`Element removed.`),P):(await S(r),await F(e,t,n,r,++i,a,o))}},I=async(e,t,n=1e3,r=10,i=!1)=>{let a=t?.getElementName();console.group(`Looking for Element: `+a);let o=null;if(t.parent)try{console.groupCollapsed(`Look for Parent `,t.parent.getElementName()),o=await I(e,t.parent,n,r,i),console.groupEnd()}catch(e){if(console.groupEnd(),i&&e.message.includes(`not found`))return console.log(`Parent not found, so element was removed`),console.groupEnd(),P;throw console.groupEnd(),e}try{console.log(`Using parent element: `,o);let a=await F(e,t,o,n,0,r,i);return console.groupEnd(),a}catch(e){if(i&&e.message.includes(`not found`))return console.log(`Parent not found, so element was removed`),console.groupEnd(),P;throw console.groupEnd(),e}},L=function(e){return e.WAITING=`waiting`,e.RUNNING=`running`,e.STOPPED=`stopped`,e.PAUSED=`paused`,e.SUCCESS=`success`,e.ERROR=`error`,e.SKIPPED=`skipped`,e}(L||{}),R=class e{status;error;id;context;constructor(){this.status=L.WAITING,this.error=``,this.id=N(),this.context={beforeHTML:``,beforeInputValues:{},afterInputValues:{},afterHTML:``,url:``,startTimestamp:``,endTimestamp:``}}getJSON(){return{id:this.id,description:this.getDescription(),context:this.context,status:this.status,error:this.error}}reset(){this.status=L.WAITING,this.error=``,this.resetAction()}getInputValuesFromPage(){let e={};return O.document.querySelectorAll(`input`).forEach((t,n)=>{let r=`value-id-${n}`;t.setAttribute(`input-id`,r),e[r]=t.value}),e}async execute(){try{this.status=L.RUNNING,this.context.beforeInputValues=this.getInputValuesFromPage(),this.context.beforeHTML=O.document.body.innerHTML,await e.notifyActionUpdated(this),console.log(`Action: `,this.getDescription()),await this.executeAction(),this.status=L.SUCCESS,this.error=``,O.isStepByStepMode&&O.pause()}catch(e){if(this.status=L.ERROR,this.error=e.message,e.message==`Test stopped manually`)throw Error(`Error in Action `+this.getDescription()+`. Message: `+e.message);this.status=L.PAUSED,O.pause()}finally{this.context.afterInputValues=this.getInputValuesFromPage(),this.context.afterHTML=O.document.body.innerHTML,await e.notifyActionUpdated(this)}}static async notifyActionUpdated(e){y.dispatch(v.ACTION_UPDATE,{action:e.getJSON()})}},z=class extends R{name;stepsFn;steps;params;index;constructor(e,t){super(),this.name=e,this.stepsFn=t,this.steps=[],this.index=0}getDescription(){return this.name}compileSteps(){super.reset(),this.stepsFn(this.params)}stepsToJSON(){return this.steps.reduce((e,t)=>(e.push(t.getJSON()),e),[])}getJSON(){return{...super.getJSON(),type:`Action`,params:this.params,steps:this.stepsToJSON()}}resetAction(){this.steps.length=0,this.index=0}async continue(){if(O.isPaused)return new Promise((e,t)=>{O.saveCurrentAction(async n=>{if(n.status==L.SKIPPED)return e();try{await n.continue(),e()}catch(e){t(e)}},this)});if(O.isStopped)throw Error(`Test stopped manually`);if(this.index<this.steps.length){let e=this.steps[this.index];try{if(await S(O.speed),await e.execute(),!O.isPaused)this.index++,await this.continue();else return new Promise((t,n)=>{O.saveCurrentAction(async r=>{if(r.status==L.SKIPPED)return this.index++,await R.notifyActionUpdated(e),await this.continue(),t();try{await r.continue(),t()}catch(e){n(e)}},e)})}catch(e){throw e}}}async executeAction(){this.index=0,await this.continue()}setParams(e){this.params=e}addStep(e){this.steps.push(e)}},B=class e extends R{uiElement;element;tries;constructor(e){super(),this.uiElement=e,this.element=null,this.tries=0}getElementName(){return this.uiElement?.getElementName()}updateTries(e){this.tries=e}resetTries(){this.tries=0}getJSON(){return{id:this.id,element:this.getElementName(),description:this.getDescription(),status:this.status,error:this.error,context:this.context,tries:this.tries}}static waitForElement(t,n,r=1e3,i=10,a=!1){let o=n.getElementName();return new Promise(async(s,c)=>{let l=async(e,r=1e3,a=0,s=!1)=>{if(console.groupCollapsed(`tries ${a}/${i}`),t.updateTries(a),await R.notifyActionUpdated(t),a===i)throw console.groupEnd(),Error(s?`UI Element ${o||`UNKNOWN`} still present after 10 tries`:`UI Element ${o||`UNKNOWN`} not found after 10 tries`);{let t=n.selector(e,n.postProcess);return console.groupEnd(),t?s?(await S(r),await l(e,r,++a,s)):(console.log(`Element found = `,t),t):s?(console.log(`Element removed.`),null):(await S(r),await l(e,r,++a,s))}};console.group(`[Action On Element] Looking for Element: `+o);let u=null,d=!0;if(n.parent){console.groupCollapsed(`Look for Parent `,n.parent.getElementName());try{u=await e.waitForElement(t,n.parent,r,i,a)}catch{d=!1}finally{console.groupEnd()}}if(d){console.log(`using parent element: `,u);try{let e=await l(u,r,0,a);console.groupEnd(),s(e)}catch(e){console.groupEnd(),c(Error(e.message))}}else console.groupEnd(),c(Error(`Parent ${n.parent?.getElementName()} of UI Element ${n.name||`UNKNOWN`} not found`))})}async executeAction(){try{this.element=await I(this,this.uiElement),this.element?.setAttribute(`test-id`,this.getElementName()),await O.uiUtils.checkElement(this.element,this.getElementName()),this.executeActionOnElement(),await O.uiUtils.hideCheckElementContainer()}catch(e){throw Error(e.message)}}resetAction(){this.element=null,this.resetTries()}},ue=class extends B{constructor(e){super(e)}executeActionOnElement(){return this.element?.click()}getDescription(){return`Click in `+this.getElementName()}getJSON(){return{...super.getJSON(),type:`Click`}}},de=class extends B{text;constructor(e,t){super(e),this.text=t}executeActionOnElement(){if(this.element?.innerText!==this.text)throw Error(`Text in element ${this.getElementName()} is not '${this.text}'`)}getDescription(){return`Assert that text in ${this.getElementName()} is '${this.text}'`}getJSON(){return{...super.getJSON(),type:`AssertTextIsAction`,value:this.text}}},fe=class extends B{text;constructor(e,t){super(e),this.text=t}executeActionOnElement(){if(!this.element?.innerText.includes(this.text))throw Error(`Text in element ${this.getElementName()} doesn't contain '${this.text}'`)}getDescription(){return`Assert that ${this.getElementName()} contains '${this.text}'`}getJSON(){return{...super.getJSON(),type:`AssertContainsText`,value:this.text}}},pe=class extends B{value;constructor(e,t){super(e),this.value=t}executeActionOnElement(){if(this.element.value!==this.value)throw Error(`Value in element ${this.getElementName()} is not '${this.value}'`)}getDescription(){return`Assert that value in ${this.getElementName()} is '${this.value}'`}getJSON(){return{...super.getJSON(),type:`AssertValueIsAction`,value:this.value}}},me=class extends B{constructor(e){super(e)}executeActionOnElement(){if(!this.element)throw Error(`Element ${this.getElementName()} doesn't exist`)}getDescription(){return`Assert that ${this.getElementName()} exists`}getJSON(){return{...super.getJSON(),type:`AssertExistsAction`}}},he=class extends B{constructor(e){super(e)}async executeAction(){try{this.element=await I(this,this.uiElement,1e3,5,!0),this.element?.setAttribute(`test-id`,this.getElementName()),await O.uiUtils.checkElement(this.element,this.getElementName()),this.executeActionOnElement(),await O.uiUtils.hideCheckElementContainer()}catch(e){throw Error(e.message)}}executeActionOnElement(){if(this.element)throw Error(`Element ${this.getElementName()} was not expected to exist`)}getDescription(){return`Assert that ${this.getElementName()} doesn't exist`}getJSON(){return{...super.getJSON(),type:`AssertNotExistsAction`}}},ge=class extends B{value;constructor(e,t){super(e),this.value=t}executeActionOnElement(){let e=this.element;if(this.element?.tagName!==`INPUT`&&this.element?.tagName!==`SELECT`&&this.element?.tagName!==`TEXTAREA`&&(e=this.element?.querySelectorAll(`input`)[0],!e))throw Error(`Input element not found. Not able to type value in element `+this.getElementName());e.value=this.value,e.dispatchEvent(new Event(`change`))}getDescription(){return`Select value '${this.value}' in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:`Select`,value:this.value}}},V=class extends B{value;constructor(e,t){super(e),this.value=t}executeActionOnElement(){let e=this.element;if(this.element?.tagName!==`INPUT`&&this.element?.tagName!==`SELECT`&&this.element?.tagName!==`TEXTAREA`&&(e=this.element?.querySelectorAll(`input`)[0],!e))throw Error(`Input element not found. Not able to type value in element `+this.getElementName());e.value=this.value,e.dispatchEvent(new Event(`change`)),e.dispatchEvent(new Event(`keyup`,{bubbles:!0})),e.dispatchEvent(new Event(`input`,{bubbles:!0}))}getDescription(){return`Type value '${this.value}' in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:`Type`,value:this.value}}},_e=class extends B{value;constructor(e,t){super(e),this.value=t}executeActionOnElement(){let e=this.element;if(this.element?.tagName!==`INPUT`&&this.element?.tagName!==`SELECT`&&this.element?.tagName!==`TEXTAREA`&&(e=this.element?.querySelectorAll(`input`)[0],!e))throw Error(`Input element not found. Not able to type value in element `+this.getElementName());e.value=this.value,e.dispatchEvent(new Event(`change`)),e.dispatchEvent(new Event(`keyup`,{bubbles:!0})),e.dispatchEvent(new Event(`input`,{bubbles:!0}))}getDescription(){return`Type a password in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:`TypePassword`,value:this.value}}},ve=class extends B{constructor(e){super(e)}executeActionOnElement(){this.element?.dispatchEvent(new KeyboardEvent(`keydown`,{altKey:!1,code:`Escape`,ctrlKey:!1,isComposing:!1,key:`Escape`,location:0,metaKey:!1,repeat:!1,shiftKey:!1,which:27,charCode:0,keyCode:27}))}getDescription(){return`Press Esc key in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:`PressEscKey`}}},ye=class extends B{constructor(e){super(e)}executeActionOnElement(){this.element?.dispatchEvent(new KeyboardEvent(`keyup`,{altKey:!1,code:`Down`,ctrlKey:!1,isComposing:!1,key:`Down`,location:0,metaKey:!1,repeat:!1,shiftKey:!1,which:40,charCode:0,keyCode:40}))}getDescription(){return`Press Down key in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:`PressDownKey`}}},be=class extends B{constructor(e){super(e)}executeActionOnElement(){this.element?.dispatchEvent(new KeyboardEvent(`keydown`,{altKey:!1,code:`Tab`,ctrlKey:!1,isComposing:!1,key:`Tab`,location:0,metaKey:!1,repeat:!1,shiftKey:!1,which:9,charCode:0,keyCode:9}))}getDescription(){return`Press Tab key in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:`PressTabKey`}}},xe=class extends B{constructor(e){super(e)}executeActionOnElement(){this.element?.dispatchEvent(new KeyboardEvent(`keydown`,{altKey:!1,code:`Enter`,ctrlKey:!1,isComposing:!1,key:`Enter`,location:0,metaKey:!1,repeat:!1,shiftKey:!1,which:13,charCode:0,keyCode:13}))}getDescription(){return`Press Enter key in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:`PressEnterKey`}}},H=function(e){return e.ESCAPE=`Escape`,e.ENTER=`Enter`,e.TAB=`Tab`,e.ARROW_DOWN=`ArrowDown`,e.ARROW_UP=`ArrowUp`,e.ARROW_LEFT=`ArrowLeft`,e.ARROW_RIGHT=`ArrowRight`,e.BACKSPACE=`Backspace`,e.DELETE=`Delete`,e.SHIFT=`Shift`,e.CONTROL=`Control`,e.ALT=`Alt`,e.META=`Meta`,e}(H||{}),U={[H.ESCAPE]:27,[H.ENTER]:13,[H.TAB]:9,[H.ARROW_DOWN]:40,[H.ARROW_UP]:38,[H.ARROW_LEFT]:37,[H.ARROW_RIGHT]:39,[H.BACKSPACE]:8,[H.DELETE]:46,[H.SHIFT]:16,[H.CONTROL]:17,[H.ALT]:18,[H.META]:91},Se=class extends B{key;constructor(e,t){super(e),this.key=t}executeActionOnElement(){this.element?.dispatchEvent(new KeyboardEvent(`keydown`,{key:this.key,code:this.key,keyCode:U[this.key],charCode:0,which:U[this.key],altKey:!1,ctrlKey:!1,metaKey:!1,shiftKey:!1,isComposing:!1,location:0,repeat:!1}))}getDescription(){return`Press ${this.key} key in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:`PressKey`,key:this.key}}},Ce=class extends B{file;constructor(e,t){super(e),this.file=t}executeActionOnElement(){let e=this.element,t=new DataTransfer;t.items.add(this.file),e.files=t.files,e.dispatchEvent(new Event(`change`));function n(e){return e?.parentElement?e.parentElement?.tagName.toLowerCase()===`form`?e.parentElement:n(e.parentElement):null}let r=n(e);r&&r.dispatchEvent(new Event(`change`))}getDescription(){return`Upload file in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:`UploadFile`}}},we=class extends B{memorySlotName;constructor(e,t){super(e),this.memorySlotName=t}executeActionOnElement(){let e=this.element;if(this.element?.tagName!==`INPUT`&&this.element?.tagName!==`SELECT`&&this.element?.tagName!==`TEXTAREA`&&(e=this.element?.querySelectorAll(`input`)[0],!e))throw Error(`Input element not found. Not able to save value from element `+this.getElementName());y.dispatch(v.SAVE_VALUE,{memorySlotName:this.memorySlotName,value:e.value})}getDescription(){return`Save value of ${this.getElementName()} in ${this.memorySlotName}`}getJSON(){return{...super.getJSON(),type:`SaveValue`,memorySlotName:this.memorySlotName}}},Te=class extends R{miliseconds;constructor(e){super(),this.miliseconds=e}getDescription(){return`Wait `+this.miliseconds+` miliseconds`}getJSON(){return{...super.getJSON(),type:`Wait`}}async executeAction(){await S(this.miliseconds)}resetAction(){}},Ee=class extends R{uiElement;tries;constructor(e){super(),this.uiElement=e,this.tries=0}updateTries(e){this.tries=e}resetAction(){this.tries=0}getElementName(){return this.uiElement?.getElementName()}async executeAction(){await I(this,this.uiElement,1e3,10,!0)}getDescription(){return`Wait until `+this.getElementName()+` is removed`}getJSON(){return{...super.getJSON(),type:`WaitUntilElementRemoved`}}},De=class extends R{constructor(){super()}getDescription(){return`Paused`}getJSON(){return{...super.getJSON(),type:`Pause`}}async executeAction(){await O.pause()}resetAction(){}},Oe=class extends R{description;constructor(e){super(),this.description=e}getDescription(){return`Manual Step: `+this.description}getJSON(){return{...super.getJSON(),type:`ManualStep`}}async executeAction(){return await O.uiUtils.showAlert(`Waiting manual step...`),new Promise((e,t)=>{y.on(v.USER_ACCEPT,async()=>(await O.uiUtils.hideAlert(),e(!0))),y.on(v.USER_REJECT,async()=>(await O.uiUtils.hideAlert(),t()))})}resetAction(){}},ke=class extends R{constructor(){super()}getDescription(){return`Reload page`}getJSON(){return{...super.getJSON(),type:`ReloadPage`}}async executeAction(){await location.reload()}resetAction(){}},W,G,K={init:e=>{W=e,G=!0,x.groupCollapsed(`Compile: `+e.getDescription()),e.compileSteps(),G=!1,x.log(`Compilation finished`),x.groupEnd()},addAction:e=>{x.log(`Add action: `,e.getDescription()),W.addStep(e)},compileAction:e=>{let t=W;W=e,e.compileSteps(),W=t},getCurrentAction:()=>W,getIsCompiling:()=>G},q={},Ae=e=>{if(q[e])q[e]();else throw console.log(`Available Tests:`,Object.keys(q)),Error(`Test with id ${e} not found.`)},je=(e,t)=>{console.log(`Registering Test: ${e}...`);let n=new z(e,t);K.init(n),console.log(`Compiled Test: ${e}`),y.dispatch(v.REGISTER_TEST,{id:e,action:n.getJSON()}),console.log(`Registered Test: ${e} in TestsMap`),q[e]=()=>{j.start(n)}};function J(e){let{matches:t,tests:n=[],speed:r=`NORMAL`,debug:i=!1}=e,a=N();if(console.log(`[tomation] Initializing on URL: ${document.location.href} with session ID: ${a}`),window.postMessage({message:`injectedScript-to-contentScript`,sender:`tomation`,payload:{cmd:v.SESSION_INIT,params:{sessionId:a}}}),!(typeof t==`string`?document.location.href.includes(t):document.location.href.match(t))){console.log(`[tomation] URL "${document.location.href}" does not match "${t}"`),window.postMessage({message:`injectedScript-to-contentScript`,sender:`tomation`,payload:{cmd:v.URL_MISMATCH,params:{sessionId:a,matches:t,url:document.location.href}}});return}try{console.log(`[tomation] Setting up messaging bridge with extension...`),Object.values(v).forEach(e=>{console.log(`[tomation] Setting up listener for event "${e}"`),y.on(e,t=>{let n={cmd:e,params:{...t,sessionId:a}};console.log(`[tomation] Dispatching event "${e}" to extension: `,n),window.postMessage({message:`injectedScript-to-contentScript`,sender:`tomation`,payload:n})})}),window.addEventListener(`message`,e=>{try{console.log(`[tomation] Received message from extension:`,e.data);let{message:t,sender:r,payload:i}=e.data||{},{cmd:a,params:o}=i||{};if(r!==`web-extension`)return;if(t===`contentScript-to-injectedScript`){let e={"run-test-request":()=>Ae(o?.testId),"reload-tests-request":()=>k(window,n||[]),"pause-test-request":()=>O.pause(),"stop-test-request":()=>O.stop(),"continue-test-request":()=>O.continue(),"next-step-request":()=>O.next(),"retry-action-request":()=>O.retryAction(),"skip-action-request":()=>O.skipAction(),"user-accept-request":()=>y.dispatch(v.USER_ACCEPT),"user-reject-request":()=>y.dispatch(v.USER_REJECT)}[a];e?(console.log(`[tomation] Executing command "${a}" from extension`),e()):console.warn(`[tomation] Unknown command "${a}" from extension`);return}}catch(e){console.error(`[tomation] Error handling message from extension:`,e)}}),k(window,n),O.setDebug(i),O.speed=T[r],window.postMessage({message:`injectedScript-to-contentScript`,sender:`tomation`,payload:{cmd:v.SESSION_CONNECTED,params:{speed:O.speed,sessionId:a}}}),console.log(`[tomation] Ready ✓`)}catch(e){console.error(`[tomation] Initialization failed:`,e)}}var Me=(e,t)=>async n=>{let r=new z(e,t);if(r.setParams(n),!j.running&&!K.getIsCompiling())try{x.log(`Compilation of Task ${e} starts...`),K.init(r),x.log(`Compilation of Task ${e} Finished.`),x.log(`Start running Task ${e}...`),await j.start(r),x.log(`End of Task ${e}: SUCCESS`)}catch(t){x.error(`Error running task `+e+`. `+t.message)}else x.log(`Adding action ${e} to compilation stack`),K.addAction(r),K.compileAction(r)},Ne=e=>{let t=new ue(e);K.addAction(t)},Pe=e=>({textIs:t=>{K.addAction(new de(e,t))},containsText:t=>{K.addAction(new fe(e,t))},valueIs:t=>{K.addAction(new pe(e,t))},exists:()=>{K.addAction(new me(e))},notExists:()=>{K.addAction(new he(e))}}),Fe=e=>({in:t=>{let n=new ge(t,e);K.addAction(n)}}),Ie=e=>({in:t=>{let n=new V(t,e);K.addAction(n)}}),Le=()=>({in:e=>{let t=new V(e,``);K.addAction(t)}}),Re=()=>({in:e=>{K.addAction(new ve(e))}}),ze=()=>({in:e=>{K.addAction(new ye(e))}}),Be=()=>({in:e=>{K.addAction(new be(e))}}),Ve=()=>({in:e=>{K.addAction(new xe(e))}}),He=e=>({in:t=>{K.addAction(new Se(t,e))}}),Ue=e=>({in:t=>{let n=new _e(t,e);K.addAction(n)}}),We=e=>({in:t=>{let n=new Ce(t,e);K.addAction(n)}}),Ge=e=>({in:t=>{let n=new we(e,t);K.addAction(n)}}),Y=e=>{K.addAction(new Te(e))};Y.untilElement=e=>({isRemoved:()=>{K.addAction(new Ee(e))}});var Ke=()=>{K.addAction(new De)},qe=e=>{K.addAction(new Oe(e))},X=()=>{K.addAction(new ke)},Z=e=>e.toLocaleDateString(`en-US`,{year:`numeric`,month:`2-digit`,day:`2-digit`}),Q=e=>{let t=new Date;return Z(new Date(t.setDate(t.getDate()+e)))},$=e=>{let t=new Date;return Z(new Date(t.setMonth(t.getMonth()+e)))},Je=Q(1),Ye=Q(-1),Xe=Q(7),Ze=Q(-7),Qe=$(1),$e=$(-1),et={formatDate:Z,today:Z(new Date),tomorrow:Je,nextWeek:Xe,nextMonth:Qe,yesterday:Ye,lastWeek:Ze,lastMonth:$e},tt=J;exports.ACTION_STATUS=L,exports.Assert=Pe,exports.AutomationEvents=y,Object.defineProperty(exports,`AutomationInstance`,{enumerable:!0,get:function(){return O}}),exports.ClearValue=Le,exports.Click=Ne,exports.DateUtils=et,exports.EVENT_NAMES=v,exports.KEY_MAP=H,exports.ManualTask=qe,exports.Pause=Ke,exports.PressDownKey=ze,exports.PressEnterKey=Ve,exports.PressEscKey=Re,exports.PressKey=He,exports.PressTabKey=Be,exports.ReloadPage=X,exports.SaveValue=Ge,exports.Select=Fe,exports.Setup=k,exports.Task=Me,exports.Test=je,exports.TestSpeed=T,exports.Type=Ie,exports.TypePassword=Ue,exports.UIElement=f,exports.UploadFile=We,exports.Wait=Y,exports.and=d,exports.classIncludes=r,exports.classIs=n,exports.default=tt,exports.elementIndexIs=l,exports.firstChildTextIs=u,exports.innerTextContains=a,exports.innerTextIs=i,exports.is=ne,exports.isFirstElement=c,exports.placeholderIs=s,exports.titleIs=o,exports.tomation=J,exports.wait=S;
|
package/dist/main.d.ts
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { Setup, Test, RunTest, Task, Click, Assert, Select, Type, TypePassword, ClearValue, PressEscKey, PressDownKey, PressTabKey, PressEnterKey, PressKey, KEY_MAP, UploadFile, SaveValue, Wait, ManualTask, Pause, DateUtils, AutomationEvents, AutomationInstance, EVENT_NAMES, TestSpeed, ReloadPage, If, ACTION_STATUS, setAutomationLogs, tomation } from './automation';
|
|
3
|
-
import { wait } from './ui-utils';
|
|
4
|
-
export default tomation;
|
|
5
|
-
export { tomation, SelectorBuilder, UIElement, is, classIs, classIncludes, innerTextIs, innerTextContains, titleIs, placeholderIs, isFirstElement, elementIndexIs, firstChildTextIs, and, setFilterLogs, Setup, Test, RunTest, Task, Click, Assert, Select, Type, TypePassword, ClearValue, PressEscKey, PressDownKey, PressTabKey, PressKey, PressEnterKey, KEY_MAP, UploadFile, SaveValue, Wait, Pause, ManualTask, ReloadPage, If, DateUtils, AutomationEvents, AutomationInstance, EVENT_NAMES, TestSpeed, wait, ACTION_STATUS, setAutomationLogs, };
|
|
1
|
+
export {}
|