tomation 0.0.1

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/main.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";var nt=Object.defineProperty;var st=(e,t,n)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var o=(e,t,n)=>(st(e,typeof t!="symbol"?t+"":t,n),n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class z{constructor(t,n,s,i){o(this,"name");o(this,"selector");o(this,"parent");o(this,"postProcess");this.name=t,this.selector=n,this.parent=s||null,this.postProcess=i}getElementName(){let t="";return this.parent&&(t=" in "+this.parent.getElementName()),`${this.name}${t}`}}let R;const it=e=>{R=e},F=(e,t)=>(s=R,i)=>{s=s||R,console.log("Searching elem from Root = ",s);const r=[];s.querySelectorAll(e).forEach(c=>{c.style.display!=="none"&&r.push(c)});let a;return t?(console.log("Applying filter ",t),console.log(" -- to "+r.length+"elements: ",r),a=r.filter((c,w,C)=>{console.log("Apply filter to item "+w+": ",c);const A=t(c,w,C);return console.log(` -> Item ${w} ${A?"Match":"Discarded"}`),A})[0]):a=r[0],a&&i&&(console.log("Apply post process to = ",a),a=i(a)),console.log("Return elem = ",a),a},O=(e,t,n)=>({as:s=>new z(s,e,t,n)}),ot=(e,t)=>({...O(e,t),postProcess:n=>({...O(e,t,n)})}),j=e=>({...O(e,null),childOf:t=>({...ot(e,t)}),postProcess:t=>({...O(e,null,t)})}),v=e=>({where:t=>j(F(e,t))}),rt=v("div"),at=v("button"),ct=v("input"),lt=v("textarea"),ut=e=>j(F("#"+e)),ht=e=>v(e);let G=!1;const dt=e=>{G=e},E=(...e)=>{G&&console.log("[UIElement Filter]",...e)},pt=e=>t=>{const n=t.className==e;return E(`classIs('${e}') on`,t,"=>",n),n},mt=e=>t=>{const n=t.className.split(" ").includes(e);return E(`classIncludes('${e}') on`,t,"=>",n),n},gt=e=>t=>{var s;const n=((s=t.textContent)==null?void 0:s.trim())==e;return E(`innerTextIs('${e}') on`,t,"=>",n),n},yt=e=>t=>{const n=t.innerText.trim().includes(e);return E(`innerTextContains('${e}') on`,t,"=>",n),n},Et=e=>t=>{const n=t.title==e;return E(`titleIs('${e}') on`,t,"=>",n),n},wt=e=>t=>{const n=t.placeholder===e;return E(`placeholderIs('${e}') on`,t,"=>",n),n},At=()=>(e,t)=>{const n=t===0;return E("isFirstElement on",e,"index",t,"=>",n),n},ft=e=>(t,n)=>{const s=n===e;return E(`elementIndexIs(${e}) on`,t,"elemIndex",n,"=>",s),s},xt=e=>t=>{const n=(t==null?void 0:t.firstChild).innerText.trim()===e;return E(`firstChildTextIs('${e}') on`,t,"=>",n),n},Ct=e=>(t,n)=>{let s=!0,i=0;for(;s&&i<e.length;){const r=e[i](t,n);E(`and condition[${i}] on`,t,"elemIndex",n,"=>",r),s=s&&r,i++}return E("and final result on",t,"elemIndex",n,"=>",s),s},Tt={DIV:rt,BUTTON:at,INPUT:ct,TEXTAREA:lt,ELEMENT:ht,identifiedBy:ut};let D;const Nt=new Uint8Array(16);function kt(){if(!D&&(D=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!D))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return D(Nt)}const h=[];for(let e=0;e<256;++e)h.push((e+256).toString(16).slice(1));function It(e,t=0){return(h[e[t+0]]+h[e[t+1]]+h[e[t+2]]+h[e[t+3]]+"-"+h[e[t+4]]+h[e[t+5]]+"-"+h[e[t+6]]+h[e[t+7]]+"-"+h[e[t+8]]+h[e[t+9]]+"-"+h[e[t+10]]+h[e[t+11]]+h[e[t+12]]+h[e[t+13]]+h[e[t+14]]+h[e[t+15]]).toLowerCase()}const St=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),q={randomUUID:St};function vt(e,t,n){if(q.randomUUID&&!t&&!e)return q.randomUUID();e=e||{};const s=e.random||(e.rng||kt)();if(s[6]=s[6]&15|64,s[8]=s[8]&63|128,t){n=n||0;for(let i=0;i<16;++i)t[n+i]=s[i];return t}return It(s)}const m=(e=2e3)=>new Promise(t=>{setTimeout(()=>{t(null)},e)}),f=(e,t)=>{Object.entries(t).map(([s,i])=>({key:s,value:i})).forEach(s=>{const{key:i,value:r}=s;e.style[i]=r})};class bt{constructor(t){o(this,"window");o(this,"document");o(this,"devToolsMessageContainer");o(this,"devToolsCheckElementContainer");o(this,"darkLayerLeft");o(this,"darkLayerTop");o(this,"darkLayerRight");o(this,"darkLayerBottom");o(this,"currentCheckElem");o(this,"contextViewerContainer");o(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 m(4e3),n.style.opacity="0",await m(4e3),this.devToolsMessageContainer.removeChild(n),await m(1e3)}async checkElement(t,n){if(!t)return;const s=t.getBoundingClientRect(),i=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=i.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=i.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 m(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 m(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 i=this.document.createElement("DIV");i.innerHTML=t.beforeHTML,X(i,t.beforeInputValues);const r=this.document.createElement("DIV");r.innerHTML=t.afterHTML,X(r,t.afterInputValues),this.contextViewerContainer.appendChild(n),n.appendChild(i),setTimeout(()=>{this.contextViewerContainer.removeChild(n),this.contextViewerContainer.appendChild(s),s.appendChild(r),setTimeout(()=>{this.contextViewerContainer.removeChild(s),f(this.contextViewerContainer,{display:"none"})},2e3)},2e3)}}const X=(e,t)=>{e.querySelectorAll("input").forEach(n=>{const s=n.getAttribute("input-id")||"";n.value=t[s]})},M=null,P=async(e,t,n,s=1e3,i=0,r=10,a=!1)=>{if(console.log("Automation Status: ",exports.AutomationInstance.status),exports.AutomationInstance.isPaused)return new Promise((c,w)=>{exports.AutomationInstance.saveCurrentAction(async C=>{if(C.status=="skipped")return c(null);try{const A=await P(C,t,n,s,i,r,a);c(A)}catch(A){w(A)}},e)});if(exports.AutomationInstance.isStopped)throw new Error("Test stopped manually");if(console.groupCollapsed(`tries ${i}/${r}`),e&&(e.updateTries(i),await p.notifyActionUpdated(e)),i===r)throw console.groupEnd(),a?new Error(`UI Element ${t.getElementName()||"UNKNNOWN"} still present after 10 tries`):new Error(`UI Element ${t.getElementName()||"UNKNNOWN"} not found after 10 tries`);{const c=t.selector(n,t.postProcess);return console.groupEnd(),c?a?(await m(s),await P(e,t,n,s,++i,r,a)):(console.log("Element found = ",c),c):a?(console.log("Element removed."),M):(await m(s),await P(e,t,n,s,++i,r,a))}},U=async(e,t,n=1e3,s=10,i=!1)=>{const r=t==null?void 0:t.getElementName();console.group("Looking for Element: "+r);let a=null;if(t.parent)try{console.groupCollapsed("Look for Parent ",t.parent.getElementName()),a=await U(e,t.parent,n,s,i),console.groupEnd()}catch(c){if(console.groupEnd(),i&&c.message.includes("not found"))return console.log("Parent not found, so element was removed"),console.groupEnd(),M;throw console.groupEnd(),c}try{console.log("Using parent element: ",a);const c=await P(e,t,a,n,0,s,i);return console.groupEnd(),c}catch(c){if(i&&c.message.includes("not found"))return console.log("Parent not found, so element was removed"),console.groupEnd(),M;throw console.groupEnd(),c}};var W=(e=>(e.WAITING="waiting",e.RUNNING="running",e.STOPPED="stopped",e.PAUSED="paused",e.SUCCESS="success",e.ERROR="error",e.SKIPPED="skipped",e))(W||{});class p{constructor(){o(this,"status");o(this,"error");o(this,"id");o(this,"context");this.status="waiting",this.error="",this.id=vt(),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,i)=>{const r=`value-id-${i}`;s.setAttribute("input-id",r),t[r]=s.value}),t}async execute(){try{this.status="running",this.context.beforeInputValues=this.getInputValuesFromPage(),this.context.beforeHTML=exports.AutomationInstance.document.body.innerHTML,await p.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 p.notifyActionUpdated(this)}}static async notifyActionUpdated(t){g.dispatch(T.ACTION_UPDATE,{action:t.getJSON()})}}class Q extends p{constructor(n,s){super();o(this,"name");o(this,"stepsFn");o(this,"steps");o(this,"params");o(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 continue(){if(exports.AutomationInstance.isPaused)return new Promise((n,s)=>{exports.AutomationInstance.saveCurrentAction(async i=>{if(i.status=="skipped")return n();try{await i.continue(),n()}catch(r){s(r)}},this)});if(exports.AutomationInstance.isStopped)throw new Error("Test stopped manually");if(this.index<this.steps.length){const n=this.steps[this.index];try{if(await m(exports.AutomationInstance.speed),await n.execute(),!exports.AutomationInstance.isPaused)this.index++,await this.continue();else return new Promise((s,i)=>{exports.AutomationInstance.saveCurrentAction(async r=>{if(r.status=="skipped")return this.index++,await p.notifyActionUpdated(n),await this.continue(),s();try{await r.continue(),s()}catch(a){i(a)}},n)})}catch(s){throw s}}}async executeAction(){this.index=0,await this.continue()}setParams(n){this.params=n}addStep(n){this.steps.push(n)}}class d extends p{constructor(n){super();o(this,"uiElement");o(this,"element");o(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,i=1e3,r=10,a=!1){const c=s.getElementName();return new Promise(async(w,C)=>{var H;const A=async(x,b=1e3,k=0,I=!1)=>{if(console.groupCollapsed(`tries ${k}/${r}`),n.updateTries(k),await p.notifyActionUpdated(n),k===r)throw console.groupEnd(),I?new Error(`UI Element ${c||"UNKNNOWN"} still present after 10 tries`):new Error(`UI Element ${c||"UNKNNOWN"} not found after 10 tries`);{const V=s.selector(x,s.postProcess);return console.groupEnd(),V?I?(await m(b),await A(x,b,++k,I)):(console.log("Element found = ",V),V):I?(console.log("Element removed."),null):(await m(b),await A(x,b,++k,I))}};console.group("[Action On Element] Looking for Element: "+c);let J=null,B=!0;if(s.parent){console.groupCollapsed("Look for Parent ",s.parent.getElementName());try{J=await d.waitForElement(n,s.parent,i,r,a)}catch{B=!1}finally{console.groupEnd()}}if(B){console.log("using parent element: ",J);try{const x=await A(J,i,0,a);console.groupEnd(),w(x)}catch(x){console.groupEnd(),C(new Error(x.message))}}else console.groupEnd(),C(new Error(`Parent ${(H=s.parent)==null?void 0:H.getElementName()} of UI Element ${s.name||"UNKNNOWN"} 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 Dt 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 Pt extends d{constructor(n,s){super(n);o(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 Ot extends d{constructor(n,s){super(n);o(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 Lt extends d{constructor(n,s){super(n);o(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 Ut 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 $t 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 Jt extends d{constructor(n,s){super(n);o(this,"value");this.value=s}executeActionOnElement(){var s,i,r,a;let n=this.element;if(((s=this.element)==null?void 0:s.tagName)!=="INPUT"&&((i=this.element)==null?void 0:i.tagName)!=="SELECT"&&((r=this.element)==null?void 0:r.tagName)!=="TEXTAREA"&&(n=(a=this.element)==null?void 0:a.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 Y extends d{constructor(n,s){super(n);o(this,"value");this.value=s}executeActionOnElement(){var s,i,r,a;let n=this.element;if(((s=this.element)==null?void 0:s.tagName)!=="INPUT"&&((i=this.element)==null?void 0:i.tagName)!=="SELECT"&&((r=this.element)==null?void 0:r.tagName)!=="TEXTAREA"&&(n=(a=this.element)==null?void 0:a.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"))}getDescription(){return`Type value '${this.value}' in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:"Type",value:this.value}}}class Vt extends d{constructor(n,s){super(n);o(this,"value");this.value=s}executeActionOnElement(){var s,i,r,a;let n=this.element;if(((s=this.element)==null?void 0:s.tagName)!=="INPUT"&&((i=this.element)==null?void 0:i.tagName)!=="SELECT"&&((r=this.element)==null?void 0:r.tagName)!=="TEXTAREA"&&(n=(a=this.element)==null?void 0:a.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`Type a password in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:"TypePassword",value:this.value}}}class Rt 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 Mt 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 Kt 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 Ft extends d{constructor(n,s){super(n);o(this,"file");this.file=s}executeActionOnElement(){const n=this.element,s=new DataTransfer;s.items.add(this.file);const i=s.files;n.files=i,n.dispatchEvent(new Event("change"));function r(c){var w;return c!=null&&c.parentElement?((w=c.parentElement)==null?void 0:w.tagName.toLowerCase())==="form"?c.parentElement:r(c.parentElement):null}const a=r(n);a&&a.dispatchEvent(new Event("change"))}getDescription(){return`Upload file in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:"UploadFile"}}}class Wt extends d{constructor(n,s){super(n);o(this,"memorySlotName");this.memorySlotName=s}executeActionOnElement(){var s,i,r,a;let n=this.element;if(((s=this.element)==null?void 0:s.tagName)!=="INPUT"&&((i=this.element)==null?void 0:i.tagName)!=="SELECT"&&((r=this.element)==null?void 0:r.tagName)!=="TEXTAREA"&&(n=(a=this.element)==null?void 0:a.querySelectorAll("input")[0],!n))throw new Error("Input element not found. Not able to save value from element "+this.getElementName());g.dispatch(T.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 Bt extends p{constructor(n){super();o(this,"miliseconds");this.miliseconds=n}getDescription(){return"Wait "+this.miliseconds+" miliseconds"}getJSON(){return{...super.getJSON(),type:"Wait"}}async executeAction(){await m(this.miliseconds)}resetAction(){}}class Ht extends p{constructor(n){super();o(this,"uiElement");o(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 qt extends p{constructor(){super()}getDescription(){return"Paused"}getJSON(){return{...super.getJSON(),type:"Pause"}}async executeAction(){await exports.AutomationInstance.pause()}resetAction(){}}class Xt extends p{constructor(n){super();o(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)=>{g.on(T.USER_ACCEPT,async()=>(await exports.AutomationInstance.uiUtils.hideAlert(),n(!0))),g.on(T.USER_REJECT,async()=>(await exports.AutomationInstance.uiUtils.hideAlert(),s()))})}resetAction(){}}class zt extends p{constructor(){super()}getDescription(){return"Reload page"}getJSON(){return{...super.getJSON(),type:"ReloadPage"}}async executeAction(){await location.reload()}resetAction(){}}const L=e=>e.toLocaleDateString("en-US",{year:"numeric",month:"2-digit",day:"2-digit"}),$=e=>{const t=new Date;return L(new Date(t.setDate(t.getDate()+e)))},Z=e=>{const t=new Date;return L(new Date(t.setMonth(t.getMonth()+e)))},jt=$(1),Gt=$(-1),Qt=$(7),Yt=$(-7),Zt=Z(1),_t=Z(-1),te={formatDate:L,today:L(new Date),tomorrow:jt,nextWeek:Qt,nextMonth:Zt,yesterday:Gt,lastWeek:Yt,lastMonth:_t};class ee{constructor(){o(this,"enabled",!1)}setEnabled(t){this.enabled=t}log(...t){this.enabled&&console.log("[Automation]",...t)}groupCollapsed(...t){this.enabled&&console.groupCollapsed("[Automation]",...t)}groupEnd(){this.enabled&&console.groupEnd()}error(...t){this.enabled&&console.error("[Automation]",...t)}}const l=new ee,_=e=>{l.setEnabled(e)},y=class y{static compileAction(t){const n=y.currentAction;y.currentAction=t,t.compileSteps(),y.currentAction=n}static addAction(t){l.log("Add action: ",t.getDescription()),y.currentAction.addStep(t)}static init(t){y.currentAction=t,y.isCompiling=!0,l.groupCollapsed("Compile: "+t.getDescription()),t.compileSteps(),y.isCompiling=!1,l.log("Compilation finished"),l.groupEnd()}};o(y,"currentAction"),o(y,"isCompiling");let u=y;var T=(e=>(e.START="start",e.END="end",e.ACTION_UPDATE="action-update",e.SAVE_VALUE="save-value",e.REGISTER_TEST="register-test",e.TEST_STARTED="test-started",e.TEST_PASSED="test-passed",e.TEST_FAILED="test-failed",e.TEST_END="test-end",e.USER_ACCEPT="user-accept",e.USER_REJECT="user-reject",e))(T||{});class ne{constructor(){o(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(i=>i!==n))||[])}dispatch(t,n){var s;this.events.has(t)&&((s=this.events.get(t))==null||s.forEach(i=>{console.log(`Dispatch Event ${t}:`,n),i(n)}))}}const g=new ne;var tt=(e=>(e[e.SLOW=2e3]="SLOW",e[e.NORMAL=1e3]="NORMAL",e[e.FAST=200]="FAST",e))(tt||{});const S=class S{static async start(t){S.running=!0,exports.AutomationInstance.status="Playing",exports.AutomationInstance.runMode="Normal",l.groupCollapsed("Start Action: ",t.getDescription()),g.dispatch("start",{action:t==null?void 0:t.getJSON()});try{await(t==null?void 0:t.execute())}catch(n){throw exports.AutomationInstance.uiUtils.hideCheckElementContainer(),l.error(`🤖 Error running task ${t.getDescription()}. Reason: ${n.message}`),n}finally{l.groupEnd(),S.running=!1,g.dispatch("end",{action:t==null?void 0:t.getJSON()})}}};o(S,"running",!1);let N=S;const K={},se=(e,t)=>{const n=new Q(e,t);u.init(n);const s=async()=>{if(N.running)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.");try{g.dispatch("test-started",{action:n.getJSON()}),await N.start(n),g.dispatch("test-passed",{id:e})}catch{g.dispatch("test-failed",{id:e})}finally{g.dispatch("test-end",{id:e})}};g.dispatch("register-test",{id:e,action:n.getJSON()}),K[e]=s},ie=e=>{if(K[e])K[e]();else throw new Error(`Test with id ${e} not found.`)},oe=(e,t)=>async n=>{const s=new Q(e,t);if(s.setParams(n),!N.running&&!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 N.start(s),l.log(`End of Task ${e}: SUCCESS`)}catch(i){l.error("Error running task "+e+". "+i.message)}else l.log(`Adding action ${e} to compilation stack`),u.addAction(s),u.compileAction(s)},re=e=>{const t=new Dt(e);u.addAction(t)},ae=e=>({textIs:t=>{u.addAction(new Pt(e,t))},containsText:t=>{u.addAction(new Ot(e,t))},valueIs:t=>{u.addAction(new Lt(e,t))},exists:()=>{u.addAction(new Ut(e))},notExists:()=>{u.addAction(new $t(e))}}),ce=e=>({in:t=>{const n=new Jt(t,e);u.addAction(n)}}),le=e=>({in:t=>{const n=new Y(t,e);u.addAction(n)}}),ue=()=>({in:e=>{const t=new Y(e,"");u.addAction(t)}}),he=()=>({in:e=>{u.addAction(new Rt(e))}}),de=()=>({in:e=>{u.addAction(new Mt(e))}}),pe=()=>({in:e=>{u.addAction(new Kt(e))}}),me=e=>({in:t=>{const n=new Vt(t,e);u.addAction(n)}}),ge=e=>({in:t=>{const n=new Ft(t,e);u.addAction(n)}}),ye=e=>({in:t=>{const n=new Wt(e,t);u.addAction(n)}}),et=e=>{u.addAction(new Bt(e))};et.untilElement=e=>({isRemoved:()=>{u.addAction(new Ht(e))}});const Ee=()=>{u.addAction(new qt)},we=e=>{u.addAction(new Xt(e))},Ae=()=>{u.addAction(new zt)};class fe{constructor(t){o(this,"_document");o(this,"debug");o(this,"_uiUtils");o(this,"speed");o(this,"status");o(this,"runMode");o(this,"currentActionCallback");o(this,"currentAction");this._document=t.document,this.debug=!0,this._uiUtils=new bt(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"}continue(){l.log("Continue Test"),this.status="Playing",this.runMode="Normal",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="Playing",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)}retryAction(){l.log("Retry current step"),this.status="Playing",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=W.SKIPPED,l.log("Skip: Marked current action as SKIPPED"),p.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){_(t)}}exports.AutomationInstance=void 0;const xe=(e,t)=>(exports.AutomationInstance=new fe(e),it(exports.AutomationInstance.document),t==null||t.forEach(n=>n()),exports.AutomationInstance);exports.ACTION_STATUS=W;exports.Assert=ae;exports.AutomationEvents=g;exports.ClearValue=ue;exports.Click=re;exports.DateUtils=te;exports.EVENT_NAMES=T;exports.ManualTask=we;exports.Pause=Ee;exports.PressDownKey=de;exports.PressEscKey=he;exports.PressTabKey=pe;exports.ReloadPage=Ae;exports.RunTest=ie;exports.SaveValue=ye;exports.Select=ce;exports.SelectorBuilder=F;exports.Setup=xe;exports.Task=oe;exports.Test=se;exports.TestSpeed=tt;exports.Type=le;exports.TypePassword=me;exports.UIElement=z;exports.UploadFile=ge;exports.Wait=et;exports.and=Ct;exports.classIncludes=mt;exports.classIs=pt;exports.elementIndexIs=ft;exports.firstChildTextIs=xt;exports.innerTextContains=yt;exports.innerTextIs=gt;exports.is=Tt;exports.isFirstElement=At;exports.placeholderIs=wt;exports.setAutomationLogs=_;exports.setFilterLogs=dt;exports.titleIs=Et;exports.wait=m;
package/dist/main.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { SelectorBuilder, UIElement, is, classIs, classIncludes, innerTextIs, innerTextContains, titleIs, placeholderIs, isFirstElement, elementIndexIs, firstChildTextIs, and, setFilterLogs } from './ui-element-builder';
2
+ import { Setup, Test, RunTest, Task, Click, Assert, Select, Type, TypePassword, ClearValue, PressEscKey, PressDownKey, PressTabKey, UploadFile, SaveValue, Wait, ManualTask, Pause, DateUtils, AutomationEvents, AutomationInstance, EVENT_NAMES, TestSpeed, ReloadPage, ACTION_STATUS, setAutomationLogs } from './automation';
3
+ import { wait } from './ui-utils';
4
+ export { 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, UploadFile, SaveValue, Wait, Pause, ManualTask, ReloadPage, DateUtils, AutomationEvents, AutomationInstance, EVENT_NAMES, TestSpeed, wait, ACTION_STATUS, setAutomationLogs, };