tomation 0.0.2 → 0.0.4
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/actions.d.ts +48 -1
- package/dist/automation.d.ts +18 -13
- package/dist/main.cjs +1 -1
- package/dist/main.d.ts +2 -2
- package/dist/main.js +488 -386
- package/package.json +1 -1
package/dist/.vite/manifest.json
CHANGED
package/dist/actions.d.ts
CHANGED
|
@@ -284,6 +284,53 @@ declare class PressTabKeyAction extends ActionOnElement {
|
|
|
284
284
|
tries: number;
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
|
+
declare class PressEnterKeyAction extends ActionOnElement {
|
|
288
|
+
constructor(uiElement: UIElement);
|
|
289
|
+
protected executeActionOnElement(): void;
|
|
290
|
+
getDescription(): string;
|
|
291
|
+
getJSON(): {
|
|
292
|
+
type: string;
|
|
293
|
+
id: string;
|
|
294
|
+
element: string;
|
|
295
|
+
description: string;
|
|
296
|
+
status: ACTION_STATUS;
|
|
297
|
+
error: string;
|
|
298
|
+
context: ActionContext;
|
|
299
|
+
tries: number;
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
declare enum KEY_MAP {
|
|
303
|
+
ESCAPE = "Escape",
|
|
304
|
+
ENTER = "Enter",
|
|
305
|
+
TAB = "Tab",
|
|
306
|
+
ARROW_DOWN = "ArrowDown",
|
|
307
|
+
ARROW_UP = "ArrowUp",
|
|
308
|
+
ARROW_LEFT = "ArrowLeft",
|
|
309
|
+
ARROW_RIGHT = "ArrowRight",
|
|
310
|
+
BACKSPACE = "Backspace",
|
|
311
|
+
DELETE = "Delete",
|
|
312
|
+
SHIFT = "Shift",
|
|
313
|
+
CONTROL = "Control",
|
|
314
|
+
ALT = "Alt",
|
|
315
|
+
META = "Meta"
|
|
316
|
+
}
|
|
317
|
+
declare class PressKeyAction extends ActionOnElement {
|
|
318
|
+
key: KEY_MAP;
|
|
319
|
+
constructor(uiElement: UIElement, key: KEY_MAP);
|
|
320
|
+
protected executeActionOnElement(): void;
|
|
321
|
+
getDescription(): string;
|
|
322
|
+
getJSON(): {
|
|
323
|
+
type: string;
|
|
324
|
+
key: KEY_MAP;
|
|
325
|
+
id: string;
|
|
326
|
+
element: string;
|
|
327
|
+
description: string;
|
|
328
|
+
status: ACTION_STATUS;
|
|
329
|
+
error: string;
|
|
330
|
+
context: ActionContext;
|
|
331
|
+
tries: number;
|
|
332
|
+
};
|
|
333
|
+
}
|
|
287
334
|
declare class UploadFileAction extends ActionOnElement {
|
|
288
335
|
file: File;
|
|
289
336
|
constructor(uiElement: UIElement, file: File);
|
|
@@ -393,4 +440,4 @@ declare class ReloadPageAction extends AbstractAction {
|
|
|
393
440
|
executeAction(): Promise<void>;
|
|
394
441
|
resetAction(): void;
|
|
395
442
|
}
|
|
396
|
-
export { AbstractAction, Action, ActionOnElement, ClickAction, SelectAction, TypeAction, TypePasswordAction, PressEscKeyAction, PressDownKeyAction, PressTabKeyAction, UploadFileAction, AssertTextIsAction, AssertContainsTextAction, AssertValueIsAction, AssertExistsAction, AssertNotExistsAction, SaveValueAction, WaitAction, WaitUntilElementRemovedAction, PauseAction, ManualAction, ReloadPageAction, ACTION_STATUS, };
|
|
443
|
+
export { AbstractAction, Action, ActionOnElement, ClickAction, SelectAction, TypeAction, TypePasswordAction, PressEscKeyAction, PressDownKeyAction, PressTabKeyAction, PressKeyAction, KEY_MAP, PressEnterKeyAction, UploadFileAction, AssertTextIsAction, AssertContainsTextAction, AssertValueIsAction, AssertExistsAction, AssertNotExistsAction, SaveValueAction, WaitAction, WaitUntilElementRemovedAction, PauseAction, ManualAction, ReloadPageAction, ACTION_STATUS, };
|
package/dist/automation.d.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import { AbstractAction, ACTION_STATUS } from './actions';
|
|
1
|
+
import { AbstractAction, KEY_MAP, ACTION_STATUS } from './actions';
|
|
2
2
|
import { UIUtils } from "./ui-utils";
|
|
3
3
|
import { UIElement } from './ui-element-builder';
|
|
4
4
|
import DateUtils from './date-utils';
|
|
5
5
|
declare const setAutomationLogs: (enabled: boolean) => void;
|
|
6
6
|
declare enum EVENT_NAMES {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
USER_REJECT = "user-reject"
|
|
7
|
+
ACTION_UPDATE = "tomation-action-update",
|
|
8
|
+
SAVE_VALUE = "tomation-save-value",
|
|
9
|
+
REGISTER_TEST = "tomation-register-test",
|
|
10
|
+
TEST_STARTED = "tomation-test-started",
|
|
11
|
+
TEST_PASSED = "tomation-test-passed",
|
|
12
|
+
TEST_FAILED = "tomation-test-failed",
|
|
13
|
+
TEST_END = "tomation-test-end",
|
|
14
|
+
TEST_STOP = "tomation-test-stop",
|
|
15
|
+
USER_ACCEPT = "tomation-user-accept",
|
|
16
|
+
USER_REJECT = "tomation-user-reject"
|
|
18
17
|
}
|
|
19
18
|
type AutomationEventHandlerType = ((action?: any) => void);
|
|
20
19
|
declare class EventDispatcher {
|
|
@@ -68,6 +67,12 @@ declare const PressDownKey: () => {
|
|
|
68
67
|
declare const PressTabKey: () => {
|
|
69
68
|
in: (uiElement: UIElement) => void;
|
|
70
69
|
};
|
|
70
|
+
declare const PressEnterKey: () => {
|
|
71
|
+
in: (uiElement: UIElement) => void;
|
|
72
|
+
};
|
|
73
|
+
declare const PressKey: (key: KEY_MAP) => {
|
|
74
|
+
in: (uiElement: UIElement) => void;
|
|
75
|
+
};
|
|
71
76
|
declare const TypePassword: (value: string) => {
|
|
72
77
|
in: (uiElement: UIElement) => void;
|
|
73
78
|
};
|
|
@@ -120,4 +125,4 @@ interface TomationOptions {
|
|
|
120
125
|
debug?: boolean;
|
|
121
126
|
}
|
|
122
127
|
export declare function tomation(options: TomationOptions): void;
|
|
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, };
|
|
128
|
+
export { Setup, AutomationInstance, Test, RunTest, Task, Click, Assert, Select, Type, TypePassword, ClearValue, PressEscKey, PressDownKey, PressTabKey, PressKey, PressEnterKey, KEY_MAP, 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 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;
|
|
1
|
+
"use strict";var ae=Object.defineProperty;var ce=(t,e,n)=>e in t?ae(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var i=(t,e,n)=>(ce(t,typeof e!="symbol"?e+"":e,n),n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});class Q{constructor(e,n,s,o){i(this,"name");i(this,"selector");i(this,"parent");i(this,"postProcess");this.name=e,this.selector=n,this.parent=s||null,this.postProcess=o}getElementName(){let e="";return this.parent&&(e=" in "+this.parent.getElementName()),`${this.name}${e}`}}let F;const le=t=>{F=t},q=(t,e)=>(s=F,o)=>{s=s||F,console.log("Searching elem from Root = ",s);const r=[];s.querySelectorAll(t).forEach(c=>{c.style.display!=="none"&&r.push(c)});let a;return e?(console.log("Applying filter ",e),console.log(" -- to "+r.length+"elements: ",r),a=r.filter((c,y,x)=>{console.log("Apply filter to item "+y+": ",c);const p=e(c,y,x);return console.log(` -> Item ${y} ${p?"Match":"Discarded"}`),p})[0]):a=r[0],a&&o&&(console.log("Apply post process to = ",a),a=o(a)),console.log("Return elem = ",a),a},$=(t,e,n)=>({as:s=>new Q(s,t,e,n)}),ue=(t,e)=>({...$(t,e),postProcess:n=>({...$(t,e,n)})}),Z=t=>({...$(t,null),childOf:e=>({...ue(t,e)}),postProcess:e=>({...$(t,null,e)})}),D=t=>({where:e=>Z(q(t,e))}),he=D("div"),de=D("button"),pe=D("input"),me=D("textarea"),ge=t=>Z(q("#"+t)),ye=t=>D(t);let Y=!1;const Ee=t=>{Y=t},f=(...t)=>{Y&&console.log("[UIElement Filter]",...t)},we=t=>e=>{const n=e.className==t;return f(`classIs('${t}') on`,e,"=>",n),n},fe=t=>e=>{const n=e.className.split(" ").includes(t);return f(`classIncludes('${t}') on`,e,"=>",n),n},Ae=t=>e=>{var s;const n=((s=e.textContent)==null?void 0:s.trim())==t;return f(`innerTextIs('${t}') on`,e,"=>",n),n},xe=t=>e=>{const n=e.innerText.trim().includes(t);return f(`innerTextContains('${t}') on`,e,"=>",n),n},Ce=t=>e=>{const n=e.title==t;return f(`titleIs('${t}') on`,e,"=>",n),n},Te=t=>e=>{const n=e.placeholder===t;return f(`placeholderIs('${t}') on`,e,"=>",n),n},ke=()=>(t,e)=>{const n=e===0;return f("isFirstElement on",t,"index",e,"=>",n),n},Se=t=>(e,n)=>{const s=n===t;return f(`elementIndexIs(${t}) on`,e,"elemIndex",n,"=>",s),s},Ie=t=>e=>{const n=(e==null?void 0:e.firstChild).innerText.trim()===t;return f(`firstChildTextIs('${t}') on`,e,"=>",n),n},ve=t=>(e,n)=>{let s=!0,o=0;for(;s&&o<t.length;){const r=t[o](e,n);f(`and condition[${o}] on`,e,"elemIndex",n,"=>",r),s=s&&r,o++}return f("and final result on",e,"elemIndex",n,"=>",s),s},Ne={DIV:he,BUTTON:de,INPUT:pe,TEXTAREA:me,ELEMENT:ye,identifiedBy:ge};let P;const be=new Uint8Array(16);function De(){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(be)}const d=[];for(let t=0;t<256;++t)d.push((t+256).toString(16).slice(1));function Oe(t,e=0){return(d[t[e+0]]+d[t[e+1]]+d[t[e+2]]+d[t[e+3]]+"-"+d[t[e+4]]+d[t[e+5]]+"-"+d[t[e+6]]+d[t[e+7]]+"-"+d[t[e+8]]+d[t[e+9]]+"-"+d[t[e+10]]+d[t[e+11]]+d[t[e+12]]+d[t[e+13]]+d[t[e+14]]+d[t[e+15]]).toLowerCase()}const Pe=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),X={randomUUID:Pe};function Le(t,e,n){if(X.randomUUID&&!e&&!t)return X.randomUUID();t=t||{};const s=t.random||(t.rng||De)();if(s[6]=s[6]&15|64,s[8]=s[8]&63|128,e){n=n||0;for(let o=0;o<16;++o)e[n+o]=s[o];return e}return Oe(s)}const E=(t=2e3)=>new Promise(e=>{setTimeout(()=>{e(null)},t)}),A=(t,e)=>{Object.entries(e).map(([s,o])=>({key:s,value:o})).forEach(s=>{const{key:o,value:r}=s;t.style[o]=r})};class Ue{constructor(e){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=e.document,this.window=e,this.devToolsMessageContainer=this.createElement("DIV",{id:"dev-tools-message-container",styles:{width:"500px",backgroundColor:"rgba(0, 0, 0, 0.5)",color:"white",position:"fixed",bottom:"10px",right:"10px",fontFamily:"monospace",zIndex:"9999"},parent:this.document.body}),this.devToolsAlertContainer=this.createElement("DIV",{id:"dev-tools-alert-container",styles:{width:"100%",height:"30px",backgroundColor:"#b00",color:"white",position:"absolute ",top:0,fontFamily:"monospace",zIndex:"9999",display:"none",alignItems:"center",justifyContent:"center",padding:"5px"},parent:this.document.body}),this.devToolsCheckElementContainer=this.createElement("DIV",{id:"dev-tools-check-element-container",styles:{width:"100%",height:this.document.body.clientHeight+"px",position:"absolute",top:"0px",left:"0px",zIndex:"9990",display:"none",opacity:"0",transition:"opacity .2s"},parent:this.document.body});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(e,n){const s=this.document.createElement(e);return n&&(n.id&&(s.id=n==null?void 0:n.id),n.styles&&A(s,n.styles),n.parent&&n.parent.appendChild(s)),s}async logAction(e){const n=exports.AutomationInstance.document.createElement("DIV");n.innerText=e,A(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(e,n){if(!e)return;const s=e.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(e){const n=exports.AutomationInstance.document.createElement("DIV"),s=exports.AutomationInstance.document.body;n.innerText=e,A(s,{paddingTop:"30px"}),A(this.devToolsAlertContainer,{display:"flex"}),this.devToolsAlertContainer.appendChild(n)}async hideAlert(){A(this.devToolsAlertContainer,{display:"none"});const e=exports.AutomationInstance.document.body;A(e,{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(e){A(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",A(n,{flex:"50%",width:"100%",height:"auto",border:"2px solid orange"});const s=this.document.createElement("DIV");s.id="context-viewer-after",A(s,{flex:"50%",width:"100%",height:"auto",border:"2px solid green"});const o=this.document.createElement("DIV");o.innerHTML=e.beforeHTML,z(o,e.beforeInputValues);const r=this.document.createElement("DIV");r.innerHTML=e.afterHTML,z(r,e.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),A(this.contextViewerContainer,{display:"none"})},2e3)},2e3)}}const z=(t,e)=>{t.querySelectorAll("input").forEach(n=>{const s=n.getAttribute("input-id")||"";n.value=e[s]})},W=null,L=async(t,e,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 x=>{if(x.status=="skipped")return c(null);try{const p=await L(x,e,n,s,o,r,a);c(p)}catch(p){y(p)}},t)});if(exports.AutomationInstance.isStopped)throw new Error("Test stopped manually");if(console.groupCollapsed(`tries ${o}/${r}`),t&&(t.updateTries(o),await g.notifyActionUpdated(t)),o===r)throw console.groupEnd(),a?new Error(`UI Element ${e.getElementName()||"UNKNOWN"} still present after 10 tries`):new Error(`UI Element ${e.getElementName()||"UNKNOWN"} not found after 10 tries`);{const c=e.selector(n,e.postProcess);return console.groupEnd(),c?a?(await E(s),await L(t,e,n,s,++o,r,a)):(console.log("Element found = ",c),c):a?(console.log("Element removed."),W):(await E(s),await L(t,e,n,s,++o,r,a))}},J=async(t,e,n=1e3,s=10,o=!1)=>{const r=e==null?void 0:e.getElementName();console.group("Looking for Element: "+r);let a=null;if(e.parent)try{console.groupCollapsed("Look for Parent ",e.parent.getElementName()),a=await J(t,e.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(),W;throw console.groupEnd(),c}try{console.log("Using parent element: ",a);const c=await L(t,e,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(),W;throw console.groupEnd(),c}};var H=(t=>(t.WAITING="waiting",t.RUNNING="running",t.STOPPED="stopped",t.PAUSED="paused",t.SUCCESS="success",t.ERROR="error",t.SKIPPED="skipped",t))(H||{});class g{constructor(){i(this,"status");i(this,"error");i(this,"id");i(this,"context");this.status="waiting",this.error="",this.id=Le(),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 e={};return exports.AutomationInstance.document.querySelectorAll("input").forEach((s,o)=>{const r=`value-id-${o}`;s.setAttribute("input-id",r),e[r]=s.value}),e}async execute(){try{this.status="running",this.context.beforeInputValues=this.getInputValuesFromPage(),this.context.beforeHTML=exports.AutomationInstance.document.body.innerHTML,await g.notifyActionUpdated(this),console.log("Action: ",this.getDescription()),await this.executeAction(),this.status="success",this.error="",exports.AutomationInstance.isStepByStepMode&&exports.AutomationInstance.pause()}catch(e){if(this.status="error",this.error=e.message,e.message=="Test stopped manually")throw Error("Error in Action "+this.getDescription()+". Message: "+e.message);this.status="paused",exports.AutomationInstance.pause()}finally{this.context.afterInputValues=this.getInputValuesFromPage(),this.context.afterHTML=exports.AutomationInstance.document.body.innerHTML,await g.notifyActionUpdated(this)}}static async notifyActionUpdated(e){m.dispatch(k.ACTION_UPDATE,{action:e.getJSON()})}}class _ extends g{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 g.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 h extends g{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,x)=>{var I;const p=async(C,O=1e3,v=0,N=!1)=>{if(console.groupCollapsed(`tries ${v}/${r}`),n.updateTries(v),await g.notifyActionUpdated(n),v===r)throw console.groupEnd(),N?new Error(`UI Element ${c||"UNKNOWN"} still present after 10 tries`):new Error(`UI Element ${c||"UNKNOWN"} not found after 10 tries`);{const M=s.selector(C,s.postProcess);return console.groupEnd(),M?N?(await E(O),await p(C,O,++v,N)):(console.log("Element found = ",M),M):N?(console.log("Element removed."),null):(await E(O),await p(C,O,++v,N))}};console.group("[Action On Element] Looking for Element: "+c);let T=null,K=!0;if(s.parent){console.groupCollapsed("Look for Parent ",s.parent.getElementName());try{T=await h.waitForElement(n,s.parent,o,r,a)}catch{K=!1}finally{console.groupEnd()}}if(K){console.log("using parent element: ",T);try{const C=await p(T,o,0,a);console.groupEnd(),y(C)}catch(C){console.groupEnd(),x(new Error(C.message))}}else console.groupEnd(),x(new Error(`Parent ${(I=s.parent)==null?void 0:I.getElementName()} of UI Element ${s.name||"UNKNOWN"} not found`))})}async executeAction(){var n;try{this.element=await J(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 $e extends h{constructor(e){super(e)}executeActionOnElement(){var e;return(e=this.element)==null?void 0:e.click()}getDescription(){return"Click in "+this.getElementName()}getJSON(){return{...super.getJSON(),type:"Click"}}}class Re extends h{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 Je extends h{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 Ve extends h{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 Ke extends h{constructor(e){super(e)}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 Me extends h{constructor(e){super(e)}async executeAction(){var e;try{this.element=await J(this,this.uiElement,1e3,5,!0),(e=this.element)==null||e.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 Fe extends h{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 ee extends h{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",{bubbles:!0})),n.dispatchEvent(new Event("input",{bubbles:!0}))}getDescription(){return`Type value '${this.value}' in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:"Type",value:this.value}}}class We extends h{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",{bubbles:!0})),n.dispatchEvent(new Event("input",{bubbles:!0}))}getDescription(){return`Type a password in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:"TypePassword",value:this.value}}}class Be extends h{constructor(e){super(e)}executeActionOnElement(){var e;(e=this.element)==null||e.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 qe extends h{constructor(e){super(e)}executeActionOnElement(){var e;(e=this.element)==null||e.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 He extends h{constructor(e){super(e)}executeActionOnElement(){var e;(e=this.element)==null||e.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 je extends h{constructor(e){super(e)}executeActionOnElement(){var e;(e=this.element)==null||e.dispatchEvent(new KeyboardEvent("keydown",{altKey:!1,code:"Enter",ctrlKey:!1,isComposing:!1,key:"Enter",location:0,metaKey:!1,repeat:!1,shiftKey:!1,which:13,charCode:0,keyCode:13}))}getDescription(){return`Press Enter key in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:"PressEnterKey"}}}var te=(t=>(t.ESCAPE="Escape",t.ENTER="Enter",t.TAB="Tab",t.ARROW_DOWN="ArrowDown",t.ARROW_UP="ArrowUp",t.ARROW_LEFT="ArrowLeft",t.ARROW_RIGHT="ArrowRight",t.BACKSPACE="Backspace",t.DELETE="Delete",t.SHIFT="Shift",t.CONTROL="Control",t.ALT="Alt",t.META="Meta",t))(te||{});const G={Escape:27,Enter:13,Tab:9,ArrowDown:40,ArrowUp:38,ArrowLeft:37,ArrowRight:39,Backspace:8,Delete:46,Shift:16,Control:17,Alt:18,Meta:91};class Xe extends h{constructor(n,s){super(n);i(this,"key");this.key=s}executeActionOnElement(){var n;(n=this.element)==null||n.dispatchEvent(new KeyboardEvent("keydown",{key:this.key,code:this.key,keyCode:G[this.key],charCode:0,which:G[this.key],altKey:!1,ctrlKey:!1,metaKey:!1,shiftKey:!1,isComposing:!1,location:0,repeat:!1}))}getDescription(){return`Press ${this.key} key in ${this.getElementName()}`}getJSON(){return{...super.getJSON(),type:"PressKey",key:this.key}}}class ze extends h{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 Ge extends h{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());m.dispatch(k.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 Qe extends g{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 Ze extends g{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 J(this,this.uiElement,1e3,10,!0)}getDescription(){return"Wait until "+this.getElementName()+" is removed"}getJSON(){return{...super.getJSON(),type:"WaitUntilElementRemoved"}}}class Ye extends g{constructor(){super()}getDescription(){return"Paused"}getJSON(){return{...super.getJSON(),type:"Pause"}}async executeAction(){await exports.AutomationInstance.pause()}resetAction(){}}class _e extends g{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)=>{m.on(k.USER_ACCEPT,async()=>(await exports.AutomationInstance.uiUtils.hideAlert(),n(!0))),m.on(k.USER_REJECT,async()=>(await exports.AutomationInstance.uiUtils.hideAlert(),s()))})}resetAction(){}}class et extends g{constructor(){super()}getDescription(){return"Reload page"}getJSON(){return{...super.getJSON(),type:"ReloadPage"}}async executeAction(){await location.reload()}resetAction(){}}const R=t=>t.toLocaleDateString("en-US",{year:"numeric",month:"2-digit",day:"2-digit"}),V=t=>{const e=new Date;return R(new Date(e.setDate(e.getDate()+t)))},ne=t=>{const e=new Date;return R(new Date(e.setMonth(e.getMonth()+t)))},tt=V(1),nt=V(-1),st=V(7),ot=V(-7),it=ne(1),rt=ne(-1),at={formatDate:R,today:R(new Date),tomorrow:tt,nextWeek:st,nextMonth:it,yesterday:nt,lastWeek:ot,lastMonth:rt};class ct{constructor(){i(this,"enabled",!1)}setEnabled(e){this.enabled=e}log(...e){this.enabled&&console.log("[tomation]",...e)}groupCollapsed(...e){this.enabled&&console.groupCollapsed("[tomation]",...e)}groupEnd(){this.enabled&&console.groupEnd()}error(...e){this.enabled&&console.error("[tomation]",...e)}}const l=new ct,se=t=>{l.setEnabled(t)},w=class w{static compileAction(e){const n=w.currentAction;w.currentAction=e,e.compileSteps(),w.currentAction=n}static addAction(e){l.log("Add action: ",e.getDescription()),w.currentAction.addStep(e)}static init(e){w.currentAction=e,w.isCompiling=!0,l.groupCollapsed("Compile: "+e.getDescription()),e.compileSteps(),w.isCompiling=!1,l.log("Compilation finished"),l.groupEnd()}};i(w,"currentAction"),i(w,"isCompiling");let u=w;var k=(t=>(t.ACTION_UPDATE="tomation-action-update",t.SAVE_VALUE="tomation-save-value",t.REGISTER_TEST="tomation-register-test",t.TEST_STARTED="tomation-test-started",t.TEST_PASSED="tomation-test-passed",t.TEST_FAILED="tomation-test-failed",t.TEST_END="tomation-test-end",t.TEST_STOP="tomation-test-stop",t.USER_ACCEPT="tomation-user-accept",t.USER_REJECT="tomation-user-reject",t))(k||{});class lt{constructor(){i(this,"events");this.events=new Map}on(e,n){var s;this.events.has(e)||this.events.set(e,[]),(s=this.events.get(e))==null||s.push(n)}off(e,n){var s;this.events.has(e)&&this.events.set(e,((s=this.events.get(e))==null?void 0:s.filter(o=>o!==n))||[])}dispatch(e,n){var s;this.events.has(e)&&((s=this.events.get(e))==null||s.forEach(o=>{console.log(`Dispatch Event ${e}:`,n),o(n)}))}}const m=new lt;var j=(t=>(t[t.SLOW=2e3]="SLOW",t[t.NORMAL=1e3]="NORMAL",t[t.FAST=200]="FAST",t))(j||{});const S=class S{static async start(e){if(S.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.");S.running=!0,exports.AutomationInstance.status="Playing",exports.AutomationInstance.runMode="Normal",l.groupCollapsed("Start Action: ",e.getDescription()),m.dispatch("tomation-test-started",{action:e==null?void 0:e.getJSON()});try{await(e==null?void 0:e.execute()),m.dispatch("tomation-test-passed",{id:e.name})}catch(n){throw m.dispatch("tomation-test-failed",{id:e.name}),exports.AutomationInstance.uiUtils.hideCheckElementContainer(),l.error(`🤖 Error running task ${e.getDescription()}. Reason: ${n.message}`),n}finally{l.groupEnd(),S.running=!1,m.dispatch("tomation-test-end",{action:e==null?void 0:e.getJSON()})}}};i(S,"running",!1);let b=S;const U={},ut=(t,e)=>{console.log(`Registering Test: ${t}...`);const n=new _(t,e);u.init(n),console.log(`Compiled Test: ${t}`),m.dispatch("tomation-register-test",{id:t,action:n.getJSON()}),console.log(`Registered Test: ${t} in TestsMap`),U[t]=()=>{b.start(n)}},oe=t=>{if(U[t])U[t]();else throw console.log("Available Tests:",Object.keys(U)),new Error(`Test with id ${t} not found.`)},ht=(t,e)=>async n=>{const s=new _(t,e);if(s.setParams(n),!b.running&&!u.isCompiling)try{l.log(`Compilation of Task ${t} starts...`),u.init(s),l.log(`Compilation of Task ${t} Finished.`),l.log(`Start running Task ${t}...`),await b.start(s),l.log(`End of Task ${t}: SUCCESS`)}catch(o){l.error("Error running task "+t+". "+o.message)}else l.log(`Adding action ${t} to compilation stack`),u.addAction(s),u.compileAction(s)},dt=t=>{const e=new $e(t);u.addAction(e)},pt=t=>({textIs:e=>{u.addAction(new Re(t,e))},containsText:e=>{u.addAction(new Je(t,e))},valueIs:e=>{u.addAction(new Ve(t,e))},exists:()=>{u.addAction(new Ke(t))},notExists:()=>{u.addAction(new Me(t))}}),mt=t=>({in:e=>{const n=new Fe(e,t);u.addAction(n)}}),gt=t=>({in:e=>{const n=new ee(e,t);u.addAction(n)}}),yt=()=>({in:t=>{const e=new ee(t,"");u.addAction(e)}}),Et=()=>({in:t=>{u.addAction(new Be(t))}}),wt=()=>({in:t=>{u.addAction(new qe(t))}}),ft=()=>({in:t=>{u.addAction(new He(t))}}),At=()=>({in:t=>{u.addAction(new je(t))}}),xt=t=>({in:e=>{u.addAction(new Xe(e,t))}}),Ct=t=>({in:e=>{const n=new We(e,t);u.addAction(n)}}),Tt=t=>({in:e=>{const n=new ze(e,t);u.addAction(n)}}),kt=t=>({in:e=>{const n=new Ge(t,e);u.addAction(n)}}),ie=t=>{u.addAction(new Qe(t))};ie.untilElement=t=>({isRemoved:()=>{u.addAction(new Ze(t))}});const St=()=>{u.addAction(new Ye)},It=t=>{u.addAction(new _e(t))},vt=()=>{u.addAction(new et)};class Nt{constructor(e){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=e.document,this.debug=!0,this._uiUtils=new Ue(e),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),m.dispatch("tomation-test-stop")}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=H.SKIPPED,l.log("Skip: Marked current action as SKIPPED"),g.notifyActionUpdated(this.currentAction),l.log("Skip: Executing current action callback"),this.currentActionCallback(this.currentAction),this.currentActionCallback=void 0)}saveCurrentAction(e,n){l.log("Save current action"),this.currentActionCallback=e,this.currentAction=n}setDebug(e){se(e)}}exports.AutomationInstance=void 0;const B=(t,e)=>(exports.AutomationInstance=new Nt(t),le(exports.AutomationInstance.document),e==null||e.forEach(n=>n()),exports.AutomationInstance);function re(t){const{matches:e,tests:n=[],speed:s="NORMAL",debug:o=!1}=t;if(!(typeof e=="string"?document.location.href.includes(e):!!document.location.href.match(e))){console.log(`[tomation] URL "${document.location.href}" does not match "${e}"`);return}try{console.log("[tomation] Setting up messaging bridge with extension..."),Object.values(k).forEach(a=>{console.log(`[tomation] Setting up listener for event "${a}"`),m.on(a,c=>{console.log(`[tomation] Dispatching event "${a}" to extension`,c),window.postMessage({message:"injectedScript-to-contentScript",sender:"tomation",payload:{cmd:a,params:c}})})}),window.addEventListener("message",a=>{try{console.log("[tomation] Received message from extension:",a.data);const{message:c,sender:y,payload:x}=a.data||{},{cmd:p,params:T}=x||{};if(y!=="web-extension")return;if(c==="contentScript-to-injectedScript"){const I={"run-test-request":()=>oe(T==null?void 0:T.testId),"reload-tests-request":()=>B(window,n||[]),"pause-test-request":()=>exports.AutomationInstance.pause(),"stop-test-request":()=>exports.AutomationInstance.stop(),"continue-test-request":()=>exports.AutomationInstance.continue(),"next-step-request":()=>exports.AutomationInstance.next(),"retry-action-request":()=>exports.AutomationInstance.retryAction(),"skip-action-request":()=>exports.AutomationInstance.skipAction(),"user-accept-request":()=>m.dispatch("tomation-user-accept"),"user-reject-request":()=>m.dispatch("tomation-user-reject")}[p];I?(console.log(`[tomation] Executing command "${p}" from extension`),I()):console.warn(`[tomation] Unknown command "${p}" from extension`);return}}catch(c){console.error("[tomation] Error handling message from extension:",c)}}),B(window,n),exports.AutomationInstance.setDebug(o),exports.AutomationInstance.speed=j[s],console.log("[tomation] Ready ✓")}catch(a){console.error("[tomation] Initialization failed:",a)}}exports.ACTION_STATUS=H;exports.Assert=pt;exports.AutomationEvents=m;exports.ClearValue=yt;exports.Click=dt;exports.DateUtils=at;exports.EVENT_NAMES=k;exports.KEY_MAP=te;exports.ManualTask=It;exports.Pause=St;exports.PressDownKey=wt;exports.PressEnterKey=At;exports.PressEscKey=Et;exports.PressKey=xt;exports.PressTabKey=ft;exports.ReloadPage=vt;exports.RunTest=oe;exports.SaveValue=kt;exports.Select=mt;exports.SelectorBuilder=q;exports.Setup=B;exports.Task=ht;exports.Test=ut;exports.TestSpeed=j;exports.Type=gt;exports.TypePassword=Ct;exports.UIElement=Q;exports.UploadFile=Tt;exports.Wait=ie;exports.and=ve;exports.classIncludes=fe;exports.classIs=we;exports.default=re;exports.elementIndexIs=Se;exports.firstChildTextIs=Ie;exports.innerTextContains=xe;exports.innerTextIs=Ae;exports.is=Ne;exports.isFirstElement=ke;exports.placeholderIs=Te;exports.setAutomationLogs=se;exports.setFilterLogs=Ee;exports.titleIs=Ce;exports.tomation=re;exports.wait=E;
|
package/dist/main.d.ts
CHANGED
|
@@ -1,5 +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, tomation } from './automation';
|
|
2
|
+
import { Setup, Test, RunTest, Task, Click, Assert, Select, Type, TypePassword, ClearValue, PressEscKey, PressDownKey, PressTabKey, PressEnterKey, PressKey, KEY_MAP, UploadFile, SaveValue, Wait, ManualTask, Pause, DateUtils, AutomationEvents, AutomationInstance, EVENT_NAMES, TestSpeed, ReloadPage, ACTION_STATUS, setAutomationLogs, tomation } from './automation';
|
|
3
3
|
import { wait } from './ui-utils';
|
|
4
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, };
|
|
5
|
+
export { tomation, SelectorBuilder, UIElement, is, classIs, classIncludes, innerTextIs, innerTextContains, titleIs, placeholderIs, isFirstElement, elementIndexIs, firstChildTextIs, and, setFilterLogs, Setup, Test, RunTest, Task, Click, Assert, Select, Type, TypePassword, ClearValue, PressEscKey, PressDownKey, PressTabKey, PressKey, PressEnterKey, KEY_MAP, UploadFile, SaveValue, Wait, Pause, ManualTask, ReloadPage, DateUtils, AutomationEvents, AutomationInstance, EVENT_NAMES, TestSpeed, wait, ACTION_STATUS, setAutomationLogs, };
|