tomation 0.0.1 → 0.0.2
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 +2 -2
- package/dist/automation.d.ts +7 -0
- package/dist/main.cjs +1 -1
- package/dist/main.d.ts +3 -2
- package/dist/main.js +323 -272
- package/package.json +1 -1
package/dist/.vite/manifest.json
CHANGED
package/dist/automation.d.ts
CHANGED
|
@@ -113,4 +113,11 @@ declare class Automation {
|
|
|
113
113
|
}
|
|
114
114
|
declare let AutomationInstance: Automation;
|
|
115
115
|
declare const Setup: (window: Window, tests?: Array<any>) => Automation;
|
|
116
|
+
interface TomationOptions {
|
|
117
|
+
matches: string | RegExp;
|
|
118
|
+
tests: any[];
|
|
119
|
+
speed?: keyof typeof TestSpeed;
|
|
120
|
+
debug?: boolean;
|
|
121
|
+
}
|
|
122
|
+
export declare function tomation(options: TomationOptions): void;
|
|
116
123
|
export { Setup, AutomationInstance, Test, RunTest, Task, Click, Assert, Select, Type, TypePassword, ClearValue, PressEscKey, PressDownKey, PressTabKey, UploadFile, SaveValue, Wait, Pause, ManualTask, ReloadPage, DateUtils, AutomationEvents, EVENT_NAMES, TestSpeed, ACTION_STATUS, setAutomationLogs, };
|
package/dist/main.cjs
CHANGED
|
@@ -1 +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;
|
|
1
|
+
"use strict";var it=Object.defineProperty;var rt=(e,t,n)=>t in e?it(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var i=(e,t,n)=>(rt(e,typeof t!="symbol"?t+"":t,n),n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class G{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 M;const at=e=>{M=e},W=(e,t)=>(s=M,o)=>{s=s||M,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,y,f)=>{console.log("Apply filter to item "+y+": ",c);const g=t(c,y,f);return console.log(` -> Item ${y} ${g?"Match":"Discarded"}`),g})[0]):a=r[0],a&&o&&(console.log("Apply post process to = ",a),a=o(a)),console.log("Return elem = ",a),a},L=(e,t,n)=>({as:s=>new G(s,e,t,n)}),ct=(e,t)=>({...L(e,t),postProcess:n=>({...L(e,t,n)})}),Q=e=>({...L(e,null),childOf:t=>({...ct(e,t)}),postProcess:t=>({...L(e,null,t)})}),b=e=>({where:t=>Q(W(e,t))}),lt=b("div"),ut=b("button"),ht=b("input"),dt=b("textarea"),pt=e=>Q(W("#"+e)),mt=e=>b(e);let Y=!1;const gt=e=>{Y=e},A=(...e)=>{Y&&console.log("[UIElement Filter]",...e)},yt=e=>t=>{const n=t.className==e;return A(`classIs('${e}') on`,t,"=>",n),n},Et=e=>t=>{const n=t.className.split(" ").includes(e);return A(`classIncludes('${e}') on`,t,"=>",n),n},wt=e=>t=>{var s;const n=((s=t.textContent)==null?void 0:s.trim())==e;return A(`innerTextIs('${e}') on`,t,"=>",n),n},At=e=>t=>{const n=t.innerText.trim().includes(e);return A(`innerTextContains('${e}') on`,t,"=>",n),n},ft=e=>t=>{const n=t.title==e;return A(`titleIs('${e}') on`,t,"=>",n),n},xt=e=>t=>{const n=t.placeholder===e;return A(`placeholderIs('${e}') on`,t,"=>",n),n},Ct=()=>(e,t)=>{const n=t===0;return A("isFirstElement on",e,"index",t,"=>",n),n},Tt=e=>(t,n)=>{const s=n===e;return A(`elementIndexIs(${e}) on`,t,"elemIndex",n,"=>",s),s},It=e=>t=>{const n=(t==null?void 0:t.firstChild).innerText.trim()===e;return A(`firstChildTextIs('${e}') on`,t,"=>",n),n},Nt=e=>(t,n)=>{let s=!0,o=0;for(;s&&o<e.length;){const r=e[o](t,n);A(`and condition[${o}] on`,t,"elemIndex",n,"=>",r),s=s&&r,o++}return A("and final result on",t,"elemIndex",n,"=>",s),s},kt={DIV:lt,BUTTON:ut,INPUT:ht,TEXTAREA:dt,ELEMENT:mt,identifiedBy:pt};let P;const St=new Uint8Array(16);function vt(){if(!P&&(P=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!P))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return P(St)}const h=[];for(let e=0;e<256;++e)h.push((e+256).toString(16).slice(1));function bt(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 Dt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),j={randomUUID:Dt};function Pt(e,t,n){if(j.randomUUID&&!t&&!e)return j.randomUUID();e=e||{};const s=e.random||(e.rng||vt)();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 bt(s)}const E=(e=2e3)=>new Promise(t=>{setTimeout(()=>{t(null)},e)}),x=(e,t)=>{Object.entries(t).map(([s,o])=>({key:s,value:o})).forEach(s=>{const{key:o,value:r}=s;e.style[o]=r})};class Ot{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&&x(s,n.styles),n.parent&&n.parent.appendChild(s)),s}async logAction(t){const n=exports.AutomationInstance.document.createElement("DIV");n.innerText=t,x(n,{padding:"3px 10px",opacity:"1",transition:"opacity 1s"}),this.devToolsMessageContainer.appendChild(n),await E(4e3),n.style.opacity="0",await E(4e3),this.devToolsMessageContainer.removeChild(n),await E(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 E(200)}async showAlert(t){const n=exports.AutomationInstance.document.createElement("DIV"),s=exports.AutomationInstance.document.body;n.innerText=t,x(s,{paddingTop:"30px"}),x(this.devToolsAlertContainer,{display:"flex"}),this.devToolsAlertContainer.appendChild(n)}async hideAlert(){x(this.devToolsAlertContainer,{display:"none"});const t=exports.AutomationInstance.document.body;x(t,{paddingTop:"0"}),this.devToolsAlertContainer.firstChild&&this.devToolsAlertContainer.removeChild(this.devToolsAlertContainer.firstChild)}async hideCheckElementContainer(){this.devToolsCheckElementContainer.style.opacity="0",await E(200),this.devToolsCheckElementContainer.style.display="none"}displayContext(t){x(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",x(n,{flex:"50%",width:"100%",height:"auto",border:"2px solid orange"});const s=this.document.createElement("DIV");s.id="context-viewer-after",x(s,{flex:"50%",width:"100%",height:"auto",border:"2px solid green"});const o=this.document.createElement("DIV");o.innerHTML=t.beforeHTML,z(o,t.beforeInputValues);const r=this.document.createElement("DIV");r.innerHTML=t.afterHTML,z(r,t.afterInputValues),this.contextViewerContainer.appendChild(n),n.appendChild(o),setTimeout(()=>{this.contextViewerContainer.removeChild(n),this.contextViewerContainer.appendChild(s),s.appendChild(r),setTimeout(()=>{this.contextViewerContainer.removeChild(s),x(this.contextViewerContainer,{display:"none"})},2e3)},2e3)}}const z=(e,t)=>{e.querySelectorAll("input").forEach(n=>{const s=n.getAttribute("input-id")||"";n.value=t[s]})},K=null,O=async(e,t,n,s=1e3,o=0,r=10,a=!1)=>{if(console.log("Automation Status: ",exports.AutomationInstance.status),exports.AutomationInstance.isPaused)return new Promise((c,y)=>{exports.AutomationInstance.saveCurrentAction(async f=>{if(f.status=="skipped")return c(null);try{const g=await O(f,t,n,s,o,r,a);c(g)}catch(g){y(g)}},e)});if(exports.AutomationInstance.isStopped)throw new Error("Test stopped manually");if(console.groupCollapsed(`tries ${o}/${r}`),e&&(e.updateTries(o),await m.notifyActionUpdated(e)),o===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 E(s),await O(e,t,n,s,++o,r,a)):(console.log("Element found = ",c),c):a?(console.log("Element removed."),K):(await E(s),await O(e,t,n,s,++o,r,a))}},$=async(e,t,n=1e3,s=10,o=!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 $(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(),K;throw console.groupEnd(),c}try{console.log("Using parent element: ",a);const c=await O(e,t,a,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(),K;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 m{constructor(){i(this,"status");i(this,"error");i(this,"id");i(this,"context");this.status="waiting",this.error="",this.id=Pt(),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 r=`value-id-${o}`;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 m.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 m.notifyActionUpdated(this)}}static async notifyActionUpdated(t){p.dispatch(T.ACTION_UPDATE,{action:t.getJSON()})}}class Z extends m{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 continue(){if(exports.AutomationInstance.isPaused)return new Promise((n,s)=>{exports.AutomationInstance.saveCurrentAction(async o=>{if(o.status=="skipped")return n();try{await o.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 E(exports.AutomationInstance.speed),await n.execute(),!exports.AutomationInstance.isPaused)this.index++,await this.continue();else return new Promise((s,o)=>{exports.AutomationInstance.saveCurrentAction(async r=>{if(r.status=="skipped")return this.index++,await m.notifyActionUpdated(n),await this.continue(),s();try{await r.continue(),s()}catch(a){o(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 m{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,r=10,a=!1){const c=s.getElementName();return new Promise(async(y,f)=>{var X;const g=async(C,D=1e3,N=0,k=!1)=>{if(console.groupCollapsed(`tries ${N}/${r}`),n.updateTries(N),await m.notifyActionUpdated(n),N===r)throw console.groupEnd(),k?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(C,s.postProcess);return console.groupEnd(),V?k?(await E(D),await g(C,D,++N,k)):(console.log("Element found = ",V),V):k?(console.log("Element removed."),null):(await E(D),await g(C,D,++N,k))}};console.group("[Action On Element] Looking for Element: "+c);let R=null,q=!0;if(s.parent){console.groupCollapsed("Look for Parent ",s.parent.getElementName());try{R=await d.waitForElement(n,s.parent,o,r,a)}catch{q=!1}finally{console.groupEnd()}}if(q){console.log("using parent element: ",R);try{const C=await g(R,o,0,a);console.groupEnd(),y(C)}catch(C){console.groupEnd(),f(new Error(C.message))}}else console.groupEnd(),f(new Error(`Parent ${(X=s.parent)==null?void 0:X.getElementName()} of UI Element ${s.name||"UNKNNOWN"} not found`))})}async executeAction(){var n;try{this.element=await $(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 Lt 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 $t 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 Rt 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 $(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 Mt extends d{constructor(n,s){super(n);i(this,"value");this.value=s}executeActionOnElement(){var s,o,r,a;let n=this.element;if(((s=this.element)==null?void 0:s.tagName)!=="INPUT"&&((o=this.element)==null?void 0:o.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 _ extends d{constructor(n,s){super(n);i(this,"value");this.value=s}executeActionOnElement(){var s,o,r,a;let n=this.element;if(((s=this.element)==null?void 0:s.tagName)!=="INPUT"&&((o=this.element)==null?void 0:o.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 Kt extends d{constructor(n,s){super(n);i(this,"value");this.value=s}executeActionOnElement(){var s,o,r,a;let n=this.element;if(((s=this.element)==null?void 0:s.tagName)!=="INPUT"&&((o=this.element)==null?void 0:o.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 Ft 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 Wt 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 Bt 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(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 r(c){var y;return c!=null&&c.parentElement?((y=c.parentElement)==null?void 0:y.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 qt extends d{constructor(n,s){super(n);i(this,"memorySlotName");this.memorySlotName=s}executeActionOnElement(){var s,o,r,a;let n=this.element;if(((s=this.element)==null?void 0:s.tagName)!=="INPUT"&&((o=this.element)==null?void 0:o.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());p.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 Xt extends m{constructor(n){super();i(this,"miliseconds");this.miliseconds=n}getDescription(){return"Wait "+this.miliseconds+" miliseconds"}getJSON(){return{...super.getJSON(),type:"Wait"}}async executeAction(){await E(this.miliseconds)}resetAction(){}}class jt extends m{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 $(this,this.uiElement,1e3,10,!0)}getDescription(){return"Wait until "+this.getElementName()+" is removed"}getJSON(){return{...super.getJSON(),type:"WaitUntilElementRemoved"}}}class zt extends m{constructor(){super()}getDescription(){return"Paused"}getJSON(){return{...super.getJSON(),type:"Pause"}}async executeAction(){await exports.AutomationInstance.pause()}resetAction(){}}class Gt extends m{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)=>{p.on(T.USER_ACCEPT,async()=>(await exports.AutomationInstance.uiUtils.hideAlert(),n(!0))),p.on(T.USER_REJECT,async()=>(await exports.AutomationInstance.uiUtils.hideAlert(),s()))})}resetAction(){}}class Qt extends m{constructor(){super()}getDescription(){return"Reload page"}getJSON(){return{...super.getJSON(),type:"ReloadPage"}}async executeAction(){await location.reload()}resetAction(){}}const U=e=>e.toLocaleDateString("en-US",{year:"numeric",month:"2-digit",day:"2-digit"}),J=e=>{const t=new Date;return U(new Date(t.setDate(t.getDate()+e)))},tt=e=>{const t=new Date;return U(new Date(t.setMonth(t.getMonth()+e)))},Yt=J(1),Zt=J(-1),_t=J(7),te=J(-7),ee=tt(1),ne=tt(-1),se={formatDate:U,today:U(new Date),tomorrow:Yt,nextWeek:_t,nextMonth:ee,yesterday:Zt,lastWeek:te,lastMonth:ne};class oe{constructor(){i(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 oe,et=e=>{l.setEnabled(e)},w=class w{static compileAction(t){const n=w.currentAction;w.currentAction=t,t.compileSteps(),w.currentAction=n}static addAction(t){l.log("Add action: ",t.getDescription()),w.currentAction.addStep(t)}static init(t){w.currentAction=t,w.isCompiling=!0,l.groupCollapsed("Compile: "+t.getDescription()),t.compileSteps(),w.isCompiling=!1,l.log("Compilation finished"),l.groupEnd()}};i(w,"currentAction"),i(w,"isCompiling");let u=w;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 ie{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 p=new ie;var H=(e=>(e[e.SLOW=2e3]="SLOW",e[e.NORMAL=1e3]="NORMAL",e[e.FAST=200]="FAST",e))(H||{});const v=class v{static async start(t){v.running=!0,exports.AutomationInstance.status="Playing",exports.AutomationInstance.runMode="Normal",l.groupCollapsed("Start Action: ",t.getDescription()),p.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(),v.running=!1,p.dispatch("end",{action:t==null?void 0:t.getJSON()})}}};i(v,"running",!1);let I=v;const S={},re=(e,t)=>{console.log(`Registering Test: ${e}...`);const n=new Z(e,t);u.init(n),console.log(`Compiled Test: ${e}`);const s=async()=>{if(I.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{p.dispatch("test-started",{action:n.getJSON()}),await I.start(n),p.dispatch("test-passed",{id:e})}catch{p.dispatch("test-failed",{id:e})}finally{p.dispatch("test-end",{id:e})}};p.dispatch("register-test",{id:e,action:n.getJSON()}),console.log(`Registered Test: ${e} in TestsMap`),S[e]=s,console.log({TestsMap:S})},nt=e=>{if(S[e])S[e]();else throw console.log("Available Tests:",Object.keys(S)),new Error(`Test with id ${e} not found.`)},ae=(e,t)=>async n=>{const s=new Z(e,t);if(s.setParams(n),!I.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 I.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)},ce=e=>{const t=new Lt(e);u.addAction(t)},le=e=>({textIs:t=>{u.addAction(new Ut(e,t))},containsText:t=>{u.addAction(new $t(e,t))},valueIs:t=>{u.addAction(new Jt(e,t))},exists:()=>{u.addAction(new Rt(e))},notExists:()=>{u.addAction(new Vt(e))}}),ue=e=>({in:t=>{const n=new Mt(t,e);u.addAction(n)}}),he=e=>({in:t=>{const n=new _(t,e);u.addAction(n)}}),de=()=>({in:e=>{const t=new _(e,"");u.addAction(t)}}),pe=()=>({in:e=>{u.addAction(new Ft(e))}}),me=()=>({in:e=>{u.addAction(new Wt(e))}}),ge=()=>({in:e=>{u.addAction(new Bt(e))}}),ye=e=>({in:t=>{const n=new Kt(t,e);u.addAction(n)}}),Ee=e=>({in:t=>{const n=new Ht(t,e);u.addAction(n)}}),we=e=>({in:t=>{const n=new qt(e,t);u.addAction(n)}}),st=e=>{u.addAction(new Xt(e))};st.untilElement=e=>({isRemoved:()=>{u.addAction(new jt(e))}});const Ae=()=>{u.addAction(new zt)},fe=e=>{u.addAction(new Gt(e))},xe=()=>{u.addAction(new Qt)};class Ce{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 Ot(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=B.SKIPPED,l.log("Skip: Marked current action as SKIPPED"),m.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){et(t)}}exports.AutomationInstance=void 0;const F=(e,t)=>(exports.AutomationInstance=new Ce(e),at(exports.AutomationInstance.document),t==null||t.forEach(n=>n()),exports.AutomationInstance);function ot(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{Object.values(T).forEach(a=>{p.on(a,c=>{window.postMessage({sender:"tomation",eventId:a,data:c})})}),window.addEventListener("message",a=>{var g;if(a.source!==window||((g=a.data)==null?void 0:g.sender)!=="web-extension")return;const{cmd:c,args:y}=a.data||{},f={"run-test":()=>nt(y.id),"reload-tests":()=>F(window,n||[]),"pause-test":()=>exports.AutomationInstance.pause(),"stop-test":()=>exports.AutomationInstance.stop(),"continue-test":()=>exports.AutomationInstance.continue(),"next-test":()=>exports.AutomationInstance.next(),"retry-action":()=>exports.AutomationInstance.retryAction(),"skip-action":()=>exports.AutomationInstance.skipAction(),"user-accept":()=>p.dispatch("user-accept"),"user-reject":()=>p.dispatch("user-reject")};f[c]&&f[c]()}),F(window,n),exports.AutomationInstance.setDebug(o),exports.AutomationInstance.speed=H[s],console.log("[tomation] Ready ✓")}catch(a){console.error("[tomation] Initialization failed:",a)}}exports.ACTION_STATUS=B;exports.Assert=le;exports.AutomationEvents=p;exports.ClearValue=de;exports.Click=ce;exports.DateUtils=se;exports.EVENT_NAMES=T;exports.ManualTask=fe;exports.Pause=Ae;exports.PressDownKey=me;exports.PressEscKey=pe;exports.PressTabKey=ge;exports.ReloadPage=xe;exports.RunTest=nt;exports.SaveValue=we;exports.Select=ue;exports.SelectorBuilder=W;exports.Setup=F;exports.Task=ae;exports.Test=re;exports.TestSpeed=H;exports.Type=he;exports.TypePassword=ye;exports.UIElement=G;exports.UploadFile=Ee;exports.Wait=st;exports.and=Nt;exports.classIncludes=Et;exports.classIs=yt;exports.default=ot;exports.elementIndexIs=Tt;exports.firstChildTextIs=It;exports.innerTextContains=At;exports.innerTextIs=wt;exports.is=kt;exports.isFirstElement=Ct;exports.placeholderIs=xt;exports.setAutomationLogs=et;exports.setFilterLogs=gt;exports.titleIs=ft;exports.tomation=ot;exports.wait=E;
|
package/dist/main.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
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';
|
|
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, tomation } from './automation';
|
|
3
3
|
import { wait } from './ui-utils';
|
|
4
|
-
export
|
|
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, UploadFile, SaveValue, Wait, Pause, ManualTask, ReloadPage, DateUtils, AutomationEvents, AutomationInstance, EVENT_NAMES, TestSpeed, wait, ACTION_STATUS, setAutomationLogs, };
|