tomation 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1,1570 +1,1288 @@
1
- var ne = Object.defineProperty;
2
- var se = (t, e, n) => e in t ? ne(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
3
- var i = (t, e, n) => (se(t, typeof e != "symbol" ? e + "" : e, n), n);
4
- class oe {
5
- constructor(e, n, s, o) {
6
- i(this, "name");
7
- i(this, "selector");
8
- i(this, "parent");
9
- i(this, "postProcess");
10
- this.name = e, this.selector = n, this.parent = s || null, this.postProcess = o;
11
- }
12
- getElementName() {
13
- let e = "";
14
- return this.parent && (e = " in " + this.parent.getElementName()), `${this.name}${e}`;
15
- }
1
+ //#region src/dsl/ui-element-filters.ts
2
+ var e = !1, t = (...t) => {
3
+ e && console.log("[UIElement Filter]", ...t);
4
+ }, n = (e) => (n) => {
5
+ let r = n.className == e;
6
+ return t(`classIs('${e}') on`, n, "=>", r), r;
7
+ }, r = (e) => (n) => {
8
+ let r = n.className.split(" ").includes(e);
9
+ return t(`classIncludes('${e}') on`, n, "=>", r), r;
10
+ }, i = (e) => (n) => {
11
+ let r = n.textContent?.trim() == e;
12
+ return t(`innerTextIs('${e}') on`, n, "=>", r), r;
13
+ }, a = (e) => (n) => {
14
+ let r = n.innerText.trim().includes(e);
15
+ return t(`innerTextContains('${e}') on`, n, "=>", r), r;
16
+ }, o = (e) => (n) => {
17
+ let r = n.title == e;
18
+ return t(`titleIs('${e}') on`, n, "=>", r), r;
19
+ }, s = (e) => (n) => {
20
+ let r = n.placeholder === e;
21
+ return t(`placeholderIs('${e}') on`, n, "=>", r), r;
22
+ }, c = () => (e, n) => {
23
+ let r = n === 0;
24
+ return t("isFirstElement on", e, "index", n, "=>", r), r;
25
+ }, l = (e) => (n, r) => {
26
+ let i = r === e;
27
+ return t(`elementIndexIs(${e}) on`, n, "elemIndex", r, "=>", i), i;
28
+ }, u = (e) => (n) => {
29
+ let r = (n?.firstChild).innerText.trim() === e;
30
+ return t(`firstChildTextIs('${e}') on`, n, "=>", r), r;
31
+ }, d = (e) => (n, r) => {
32
+ let i = e.every((e, i) => {
33
+ let a = e(n, r);
34
+ return t(`and condition[${i}] on`, n, "elemIndex", r, "=>", a), a;
35
+ });
36
+ return t("and final result on", n, "elemIndex", r, "=>", i), i;
37
+ }, f = class {
38
+ name;
39
+ selector;
40
+ parent;
41
+ postProcess;
42
+ constructor(e, t, n, r) {
43
+ this.name = e, this.selector = t, this.parent = n || null, this.postProcess = r;
44
+ }
45
+ getElementName() {
46
+ let e = "";
47
+ return this.parent && (e = " in " + this.parent.getElementName()), `${this.name}${e}`;
48
+ }
49
+ }, p, ee = (e) => {
50
+ p = e;
51
+ }, m = (e, t) => (n = p, r) => {
52
+ n ||= p, console.log("Searching elem from Root = ", n);
53
+ let i = [];
54
+ n.querySelectorAll(e).forEach((e) => {
55
+ e.style.display !== "none" && i.push(e);
56
+ });
57
+ let a;
58
+ return t ? (console.log("Applying filter ", t), console.log(" -- to " + i.length + "elements: ", i), a = i.filter((e, n, r) => {
59
+ console.log("Apply filter to item " + n + ": ", e);
60
+ let i = t(e, n, r);
61
+ return console.log(` -> Item ${n} ${i ? "Match" : "Discarded"}`), i;
62
+ })[0]) : a = i[0], a && r && (console.log("Apply post process to = ", a), a = r(a)), console.log("Return elem = ", a), a;
63
+ }, h = (e, t, n) => ({ as: (r) => new f(r, e, t, n) }), te = (e, t) => ({
64
+ ...h(e, t),
65
+ postProcess: (n) => ({ ...h(e, t, n) })
66
+ }), g = (e) => ({
67
+ ...h(e, null),
68
+ childOf: (t) => ({ ...te(e, t) }),
69
+ postProcess: (t) => ({ ...h(e, null, t) })
70
+ }), _ = (e) => ({ where: (t) => g(m(e, t)) }), ne = {
71
+ DIV: _("div"),
72
+ BUTTON: _("button"),
73
+ INPUT: _("input"),
74
+ TEXTAREA: _("textarea"),
75
+ ELEMENT: (e) => _(e),
76
+ identifiedBy: (e) => g(m("#" + e))
77
+ }, v = /* @__PURE__ */ function(e) {
78
+ return e.ACTION_UPDATE = "tomation-action-update", e.SAVE_VALUE = "tomation-save-value", e.REGISTER_TEST = "tomation-register-test", e.TEST_STARTED = "tomation-test-started", e.TEST_PASSED = "tomation-test-passed", e.TEST_FAILED = "tomation-test-failed", e.TEST_END = "tomation-test-end", e.TEST_STOP = "tomation-test-stop", e.TEST_PAUSE = "tomation-test-pause", e.TEST_PLAY = "tomation-test-play", e.USER_ACCEPT = "tomation-user-accept", e.USER_REJECT = "tomation-user-reject", e.SESSION_INIT = "tomation-session-init", e.URL_MISMATCH = "tomation-url-mismatch", e.SESSION_CONNECTED = "tomation-session-connected", e;
79
+ }(v || {}), y = new class {
80
+ events;
81
+ constructor() {
82
+ this.events = /* @__PURE__ */ new Map();
83
+ }
84
+ on(e, t) {
85
+ this.events.has(e) || this.events.set(e, []), this.events.get(e)?.push(t);
86
+ }
87
+ off(e, t) {
88
+ this.events.has(e) && this.events.set(e, this.events.get(e)?.filter((e) => e !== t) || []);
89
+ }
90
+ dispatch(e, t) {
91
+ this.events.has(e) && this.events.get(e)?.forEach((n) => {
92
+ console.log(`Dispatch Event ${e}:`, t), n(t);
93
+ });
94
+ }
95
+ }(), b = !1, x = {
96
+ setEnabled(e) {
97
+ b = e;
98
+ },
99
+ log(...e) {
100
+ b && console.log("[tomation]", ...e);
101
+ },
102
+ groupCollapsed(...e) {
103
+ b && console.groupCollapsed("[tomation]", ...e);
104
+ },
105
+ groupEnd() {
106
+ b && console.groupEnd();
107
+ },
108
+ error(...e) {
109
+ b && console.error("[tomation]", ...e);
110
+ }
111
+ }, S = (e = 2e3) => new Promise((t) => {
112
+ setTimeout(() => {
113
+ t(null);
114
+ }, e);
115
+ }), C = (e, t) => {
116
+ Object.entries(t).map(([e, t]) => ({
117
+ key: e,
118
+ value: t
119
+ })).forEach((t) => {
120
+ let { key: n, value: r } = t;
121
+ e.style[n] = r;
122
+ });
123
+ }, re = class {
124
+ window;
125
+ document;
126
+ devToolsMessageContainer;
127
+ devToolsCheckElementContainer;
128
+ darkLayerLeft;
129
+ darkLayerTop;
130
+ darkLayerRight;
131
+ darkLayerBottom;
132
+ currentCheckElem;
133
+ contextViewerContainer;
134
+ devToolsAlertContainer;
135
+ constructor(e) {
136
+ this.document = e.document, this.window = e, this.devToolsMessageContainer = this.createElement("DIV", {
137
+ id: "dev-tools-message-container",
138
+ styles: {
139
+ width: "500px",
140
+ backgroundColor: "rgba(0, 0, 0, 0.5)",
141
+ color: "white",
142
+ position: "fixed",
143
+ bottom: "10px",
144
+ right: "10px",
145
+ fontFamily: "monospace",
146
+ zIndex: "9999"
147
+ },
148
+ parent: this.document.body
149
+ }), this.devToolsAlertContainer = this.createElement("DIV", {
150
+ id: "dev-tools-alert-container",
151
+ styles: {
152
+ width: "100%",
153
+ height: "30px",
154
+ backgroundColor: "#b00",
155
+ color: "white",
156
+ position: "absolute ",
157
+ top: 0,
158
+ fontFamily: "monospace",
159
+ zIndex: "9999",
160
+ display: "none",
161
+ alignItems: "center",
162
+ justifyContent: "center",
163
+ padding: "5px"
164
+ },
165
+ parent: this.document.body
166
+ }), this.devToolsCheckElementContainer = this.createElement("DIV", {
167
+ id: "dev-tools-check-element-container",
168
+ styles: {
169
+ width: "100%",
170
+ height: this.document.body.clientHeight + "px",
171
+ position: "absolute",
172
+ top: "0px",
173
+ left: "0px",
174
+ zIndex: "9990",
175
+ display: "none",
176
+ opacity: "0",
177
+ transition: "opacity .2s"
178
+ },
179
+ parent: this.document.body
180
+ });
181
+ let t = {
182
+ zIndex: "9991",
183
+ backgroundColor: "rgba(0,0,0,0.3)",
184
+ position: "absolute"
185
+ };
186
+ this.darkLayerLeft = this.createElement("DIV", {
187
+ id: "dark-layer-left",
188
+ styles: t,
189
+ parent: this.devToolsCheckElementContainer
190
+ }), this.darkLayerTop = this.createElement("DIV", {
191
+ id: "dark-layer-top",
192
+ styles: t,
193
+ parent: this.devToolsCheckElementContainer
194
+ }), this.darkLayerRight = this.createElement("DIV", {
195
+ id: "dark-layer-right",
196
+ styles: t,
197
+ parent: this.devToolsCheckElementContainer
198
+ }), this.darkLayerBottom = this.createElement("DIV", {
199
+ id: "dark-layer-bottom",
200
+ styles: t,
201
+ parent: this.devToolsCheckElementContainer
202
+ }), this.currentCheckElem = this.createElement("DIV", {
203
+ id: "current-check-elem",
204
+ parent: this.devToolsCheckElementContainer
205
+ }), this.contextViewerContainer = this.createElement("DIV", {
206
+ id: "context-viewer-container",
207
+ styles: {
208
+ width: "100%",
209
+ height: this.document.body.clientHeight + "px",
210
+ position: "absolute",
211
+ top: "0px",
212
+ left: "0px",
213
+ zIndex: "10000",
214
+ display: "none"
215
+ },
216
+ parent: this.document.body
217
+ });
218
+ }
219
+ createElement(e, t) {
220
+ let n = this.document.createElement(e);
221
+ return t && (t.id && (n.id = t?.id), t.styles && C(n, t.styles), t.parent && t.parent.appendChild(n)), n;
222
+ }
223
+ async logAction(e) {
224
+ let t = O.document.createElement("DIV");
225
+ t.innerText = e, C(t, {
226
+ padding: "3px 10px",
227
+ opacity: "1",
228
+ transition: "opacity 1s"
229
+ }), this.devToolsMessageContainer.appendChild(t), await S(4e3), t.style.opacity = "0", await S(4e3), this.devToolsMessageContainer.removeChild(t), await S(1e3);
230
+ }
231
+ async checkElement(e, t) {
232
+ if (!e) return;
233
+ let n = e.getBoundingClientRect(), r = this.document.body.getBoundingClientRect();
234
+ this.darkLayerLeft.style.left = "0px", this.darkLayerLeft.style.top = n.top + "px", this.darkLayerLeft.style.width = this.window.scrollX + n.left + "px", this.darkLayerLeft.style.height = n.height + "px", this.darkLayerTop.style.left = this.window.scrollX + "px", this.darkLayerTop.style.top = "0px", this.darkLayerTop.style.width = "100%", this.darkLayerTop.style.height = n.top + "px", this.darkLayerRight.style.left = this.window.scrollX + n.left + n.width + "px", this.darkLayerRight.style.top = n.top + "px", this.darkLayerRight.style.width = r.width - (n.left + n.width) + "px", this.darkLayerRight.style.height = n.height + "px", this.darkLayerBottom.style.left = this.window.scrollX + "px", this.darkLayerBottom.style.top = n.top + n.height + "px", this.darkLayerBottom.style.width = "100%", this.darkLayerBottom.style.height = r.height - (n.top + n.height) + "px", this.currentCheckElem.id = `dev-tools-current-check-elem-${t}`, this.currentCheckElem.style.top = n.top + "px", this.currentCheckElem.style.left = this.window.scrollX + n.left + "px", this.currentCheckElem.style.height = n.height + "px", this.currentCheckElem.style.width = n.width + "px", this.currentCheckElem.style.boxShadow = "0px 0px 5px 2px lightgreen", this.currentCheckElem.style.position = "absolute", this.currentCheckElem.style.zIndex = "9992", this.devToolsCheckElementContainer.style.display = "block", this.devToolsCheckElementContainer.style.opacity = "1", await S(200);
235
+ }
236
+ async showAlert(e) {
237
+ let t = O.document.createElement("DIV"), n = O.document.body;
238
+ t.innerText = e, C(n, { paddingTop: "30px" }), C(this.devToolsAlertContainer, { display: "flex" }), this.devToolsAlertContainer.appendChild(t);
239
+ }
240
+ async hideAlert() {
241
+ C(this.devToolsAlertContainer, { display: "none" });
242
+ let e = O.document.body;
243
+ C(e, { paddingTop: "0" }), this.devToolsAlertContainer.firstChild && this.devToolsAlertContainer.removeChild(this.devToolsAlertContainer.firstChild);
244
+ }
245
+ async hideCheckElementContainer() {
246
+ this.devToolsCheckElementContainer.style.opacity = "0", await S(200), this.devToolsCheckElementContainer.style.display = "none";
247
+ }
248
+ displayContext(e) {
249
+ C(this.contextViewerContainer, {
250
+ display: "flex",
251
+ "background-color": "white",
252
+ position: "absolute",
253
+ top: "0px",
254
+ left: "0px",
255
+ "z-index": "9999"
256
+ });
257
+ let t = this.document.createElement("DIV");
258
+ t.id = "context-viewer-before", C(t, {
259
+ flex: "50%",
260
+ width: "100%",
261
+ height: "auto",
262
+ border: "2px solid orange"
263
+ });
264
+ let n = this.document.createElement("DIV");
265
+ n.id = "context-viewer-after", C(n, {
266
+ flex: "50%",
267
+ width: "100%",
268
+ height: "auto",
269
+ border: "2px solid green"
270
+ });
271
+ let r = this.document.createElement("DIV");
272
+ r.innerHTML = e.beforeHTML, w(r, e.beforeInputValues);
273
+ let i = this.document.createElement("DIV");
274
+ i.innerHTML = e.afterHTML, w(i, e.afterInputValues), this.contextViewerContainer.appendChild(t), t.appendChild(r), setTimeout(() => {
275
+ this.contextViewerContainer.removeChild(t), this.contextViewerContainer.appendChild(n), n.appendChild(i), setTimeout(() => {
276
+ this.contextViewerContainer.removeChild(n), C(this.contextViewerContainer, { display: "none" });
277
+ }, 2e3);
278
+ }, 2e3);
279
+ }
280
+ }, w = (e, t) => {
281
+ e.querySelectorAll("input").forEach((e) => {
282
+ e.value = t[e.getAttribute("input-id") || ""];
283
+ });
284
+ }, T = /* @__PURE__ */ function(e) {
285
+ return e[e.SLOW = 2e3] = "SLOW", e[e.NORMAL = 1e3] = "NORMAL", e[e.FAST = 200] = "FAST", e;
286
+ }(T || {}), E = /* @__PURE__ */ function(e) {
287
+ return e.PLAYING = "Playing", e.STOPPED = "Stopped", e.PAUSED = "Paused", e;
288
+ }(E || {}), D = /* @__PURE__ */ function(e) {
289
+ return e.NORMAL = "Normal", e.STEPBYSTEP = "Step By Step", e;
290
+ }(D || {}), ie = class {
291
+ _document;
292
+ debug;
293
+ _uiUtils;
294
+ speed;
295
+ status;
296
+ runMode;
297
+ currentActionCallback;
298
+ currentAction;
299
+ constructor(e) {
300
+ this._document = e.document, this.debug = !0, this._uiUtils = new re(e), this.speed = T.NORMAL, this.status = E.STOPPED, this.runMode = D.NORMAL;
301
+ }
302
+ get document() {
303
+ return this._document;
304
+ }
305
+ get uiUtils() {
306
+ return this._uiUtils;
307
+ }
308
+ get isStepByStepMode() {
309
+ return this.runMode == D.STEPBYSTEP;
310
+ }
311
+ get isStopped() {
312
+ return this.status == E.STOPPED;
313
+ }
314
+ get isPlaying() {
315
+ return this.status == E.PLAYING;
316
+ }
317
+ get isPaused() {
318
+ return this.status == E.PAUSED;
319
+ }
320
+ pause() {
321
+ x.log("Pause Test"), this.status = E.PAUSED, y.dispatch(v.TEST_PAUSE);
322
+ }
323
+ continue() {
324
+ x.log("Continue Test"), this.status = E.PLAYING, this.runMode = D.NORMAL, y.dispatch(v.TEST_PLAY), this.currentActionCallback && this.currentAction && (x.log("Continue: Executing current action callback"), this.currentActionCallback(this.currentAction), this.currentActionCallback = void 0);
325
+ }
326
+ next() {
327
+ x.log("Continue Test to Next Step..."), this.status = E.PLAYING, this.runMode = D.STEPBYSTEP, y.dispatch(v.TEST_PLAY), this.currentActionCallback && this.currentAction && (x.log("Next: Executing current action callback"), this.currentActionCallback(this.currentAction), this.currentActionCallback = void 0);
328
+ }
329
+ stop() {
330
+ x.log("Stop Test"), this.status = E.STOPPED, this.currentActionCallback && this.currentAction && (x.log("Stop: Executing current action callback"), this.currentActionCallback(this.currentAction), this.currentActionCallback = void 0), y.dispatch(v.TEST_STOP);
331
+ }
332
+ retryAction() {
333
+ x.log("Retry current step"), this.status = E.PLAYING, y.dispatch(v.TEST_PLAY), this.currentActionCallback && this.currentAction && (this.currentAction.resetTries && (x.log("Retry: Resetting tries for current action"), this.currentAction.resetTries()), x.log("Retry: Executing current action callback"), this.currentActionCallback(this.currentAction), this.currentActionCallback = void 0);
334
+ }
335
+ skipAction() {
336
+ x.log("Skip current step"), this.status = E.PLAYING, this.currentActionCallback && this.currentAction && (this.currentAction.status = L.SKIPPED, x.log("Skip: Marked current action as SKIPPED"), R.notifyActionUpdated(this.currentAction), x.log("Skip: Executing current action callback"), this.currentActionCallback(this.currentAction), this.currentActionCallback = void 0);
337
+ }
338
+ saveCurrentAction(e, t) {
339
+ x.log("Save current action"), this.currentActionCallback = e, this.currentAction = t;
340
+ }
341
+ setDebug(e) {
342
+ x.setEnabled(e);
343
+ }
344
+ }, O, k = (e, t) => (O = new ie(e), ee(O.document), t?.forEach((e) => e()), O), A = !1;
345
+ async function ae(e) {
346
+ if (A) throw x.error("Not able to run test while other test is running."), Error("Not able to run test while other test is running.");
347
+ A = !0, O.status = E.PLAYING, O.runMode = D.NORMAL, x.groupCollapsed("Start Action: ", e.getDescription()), y.dispatch(v.TEST_STARTED, { action: e?.getJSON() });
348
+ try {
349
+ await e?.execute(), y.dispatch(v.TEST_PASSED, { id: e.name });
350
+ } catch (t) {
351
+ throw y.dispatch(v.TEST_FAILED, { id: e.name }), O.uiUtils.hideCheckElementContainer(), x.error(`🤖 Error running task ${e.getDescription()}. Reason: ${t.message}`), t;
352
+ } finally {
353
+ x.groupEnd(), A = !1, y.dispatch(v.TEST_END, { action: e?.getJSON() });
354
+ }
16
355
  }
17
- let F;
18
- const ie = (t) => {
19
- F = t;
20
- }, j = (t, e) => (s = F, o) => {
21
- s = s || F, console.log("Searching elem from Root = ", s);
22
- const a = [];
23
- s.querySelectorAll(t).forEach((l) => {
24
- l.style.display !== "none" && a.push(l);
25
- });
26
- let r;
27
- return e ? (console.log("Applying filter ", e), console.log(" -- to " + a.length + "elements: ", a), r = a.filter((l, w, C) => {
28
- console.log("Apply filter to item " + w + ": ", l);
29
- const g = e(l, w, C);
30
- return console.log(` -> Item ${w} ${g ? "Match" : "Discarded"}`), g;
31
- })[0]) : r = a[0], r && o && (console.log("Apply post process to = ", r), r = o(r)), console.log("Return elem = ", r), r;
32
- }, $ = (t, e, n) => ({
33
- /**
34
- * Sets the UI element identifier
35
- * @param uiElementId
36
- * @returns
37
- */
38
- as: (s) => new oe(s, t, e, n)
39
- }), re = (t, e) => ({
40
- ...$(t, e),
41
- /**
42
- * Tansform the UI element that will be returned
43
- * @param postProcessFn
44
- * @returns
45
- */
46
- postProcess: (n) => ({
47
- ...$(t, e, n)
48
- })
49
- }), X = (t) => ({
50
- ...$(t, null),
51
- childOf: (e) => ({
52
- ...re(t, e)
53
- }),
54
- /**
55
- * Tansform the UI element that will be returned
56
- * @param postProcessFn
57
- * @returns
58
- */
59
- postProcess: (e) => ({
60
- ...$(t, null, e)
61
- })
62
- }), O = (t) => ({
63
- where: (e) => X(j(t, e))
64
- }), ae = O("div"), ce = O("button"), le = O("input"), ue = O("textarea"), he = (t) => X(j("#" + t)), de = (t) => O(t);
65
- let z = !1;
66
- const _e = (t) => {
67
- z = t;
68
- }, A = (...t) => {
69
- z && console.log("[UIElement Filter]", ...t);
70
- }, et = (t) => (e) => {
71
- const n = e.className == t;
72
- return A(`classIs('${t}') on`, e, "=>", n), n;
73
- }, tt = (t) => (e) => {
74
- const n = e.className.split(" ").includes(t);
75
- return A(`classIncludes('${t}') on`, e, "=>", n), n;
76
- }, nt = (t) => (e) => {
77
- var s;
78
- const n = ((s = e.textContent) == null ? void 0 : s.trim()) == t;
79
- return A(`innerTextIs('${t}') on`, e, "=>", n), n;
80
- }, st = (t) => (e) => {
81
- const n = e.innerText.trim().includes(t);
82
- return A(`innerTextContains('${t}') on`, e, "=>", n), n;
83
- }, ot = (t) => (e) => {
84
- const n = e.title == t;
85
- return A(`titleIs('${t}') on`, e, "=>", n), n;
86
- }, it = (t) => (e) => {
87
- const n = e.placeholder === t;
88
- return A(`placeholderIs('${t}') on`, e, "=>", n), n;
89
- }, rt = () => (t, e) => {
90
- const n = e === 0;
91
- return A("isFirstElement on", t, "index", e, "=>", n), n;
92
- }, at = (t) => (e, n) => {
93
- const s = n === t;
94
- return A(`elementIndexIs(${t}) on`, e, "elemIndex", n, "=>", s), s;
95
- }, ct = (t) => (e) => {
96
- const n = (e == null ? void 0 : e.firstChild).innerText.trim() === t;
97
- return A(`firstChildTextIs('${t}') on`, e, "=>", n), n;
98
- }, lt = (t) => (e, n) => {
99
- const s = t.every((o, a) => {
100
- const r = o(e, n);
101
- return A(`and condition[${a}] on`, e, "elemIndex", n, "=>", r), r;
102
- });
103
- return A("and final result on", e, "elemIndex", n, "=>", s), s;
104
- }, ut = {
105
- DIV: ae,
106
- BUTTON: ce,
107
- INPUT: le,
108
- TEXTAREA: ue,
109
- ELEMENT: de,
110
- identifiedBy: he
111
- };
112
- let I;
113
- const pe = new Uint8Array(16);
114
- function me() {
115
- if (!I && (I = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !I))
116
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
117
- return I(pe);
118
- }
119
- const p = [];
120
- for (let t = 0; t < 256; ++t)
121
- p.push((t + 256).toString(16).slice(1));
122
- function ge(t, e = 0) {
123
- return (p[t[e + 0]] + p[t[e + 1]] + p[t[e + 2]] + p[t[e + 3]] + "-" + p[t[e + 4]] + p[t[e + 5]] + "-" + p[t[e + 6]] + p[t[e + 7]] + "-" + p[t[e + 8]] + p[t[e + 9]] + "-" + p[t[e + 10]] + p[t[e + 11]] + p[t[e + 12]] + p[t[e + 13]] + p[t[e + 14]] + p[t[e + 15]]).toLowerCase();
124
- }
125
- const ye = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), W = {
126
- randomUUID: ye
127
- };
128
- function G(t, e, n) {
129
- if (W.randomUUID && !e && !t)
130
- return W.randomUUID();
131
- t = t || {};
132
- const s = t.random || (t.rng || me)();
133
- if (s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128, e) {
134
- n = n || 0;
135
- for (let o = 0; o < 16; ++o)
136
- e[n + o] = s[o];
137
- return e;
138
- }
139
- return ge(s);
140
- }
141
- const f = (t = 2e3) => new Promise((e) => {
142
- setTimeout(() => {
143
- e(null);
144
- }, t);
145
- }), x = (t, e) => {
146
- Object.entries(e).map(([s, o]) => ({
147
- key: s,
148
- value: o
149
- })).forEach((s) => {
150
- const { key: o, value: a } = s;
151
- t.style[o] = a;
152
- });
153
- };
154
- class Ee {
155
- constructor(e) {
156
- i(this, "window");
157
- i(this, "document");
158
- i(this, "devToolsMessageContainer");
159
- i(this, "devToolsCheckElementContainer");
160
- i(this, "darkLayerLeft");
161
- i(this, "darkLayerTop");
162
- i(this, "darkLayerRight");
163
- i(this, "darkLayerBottom");
164
- i(this, "currentCheckElem");
165
- i(this, "contextViewerContainer");
166
- i(this, "devToolsAlertContainer");
167
- this.document = e.document, this.window = e, this.devToolsMessageContainer = this.createElement("DIV", {
168
- id: "dev-tools-message-container",
169
- styles: {
170
- width: "500px",
171
- backgroundColor: "rgba(0, 0, 0, 0.5)",
172
- color: "white",
173
- position: "fixed",
174
- bottom: "10px",
175
- right: "10px",
176
- fontFamily: "monospace",
177
- zIndex: "9999"
178
- },
179
- parent: this.document.body
180
- }), this.devToolsAlertContainer = this.createElement("DIV", {
181
- id: "dev-tools-alert-container",
182
- styles: {
183
- width: "100%",
184
- height: "30px",
185
- backgroundColor: "#b00",
186
- color: "white",
187
- position: "absolute ",
188
- top: 0,
189
- fontFamily: "monospace",
190
- zIndex: "9999",
191
- display: "none",
192
- alignItems: "center",
193
- justifyContent: "center",
194
- padding: "5px"
195
- },
196
- parent: this.document.body
197
- }), this.devToolsCheckElementContainer = this.createElement("DIV", {
198
- id: "dev-tools-check-element-container",
199
- styles: {
200
- width: "100%",
201
- height: this.document.body.clientHeight + "px",
202
- position: "absolute",
203
- top: "0px",
204
- left: "0px",
205
- zIndex: "9990",
206
- display: "none",
207
- opacity: "0",
208
- transition: "opacity .2s"
209
- },
210
- parent: this.document.body
211
- });
212
- const n = {
213
- zIndex: "9991",
214
- backgroundColor: "rgba(0,0,0,0.3)",
215
- position: "absolute"
216
- };
217
- this.darkLayerLeft = this.createElement("DIV", {
218
- id: "dark-layer-left",
219
- styles: n,
220
- parent: this.devToolsCheckElementContainer
221
- }), this.darkLayerTop = this.createElement("DIV", {
222
- id: "dark-layer-top",
223
- styles: n,
224
- parent: this.devToolsCheckElementContainer
225
- }), this.darkLayerRight = this.createElement("DIV", {
226
- id: "dark-layer-right",
227
- styles: n,
228
- parent: this.devToolsCheckElementContainer
229
- }), this.darkLayerBottom = this.createElement("DIV", {
230
- id: "dark-layer-bottom",
231
- styles: n,
232
- parent: this.devToolsCheckElementContainer
233
- }), this.currentCheckElem = this.createElement("DIV", {
234
- id: "current-check-elem",
235
- parent: this.devToolsCheckElementContainer
236
- }), this.contextViewerContainer = this.createElement("DIV", {
237
- id: "context-viewer-container",
238
- styles: {
239
- width: "100%",
240
- height: this.document.body.clientHeight + "px",
241
- position: "absolute",
242
- top: "0px",
243
- left: "0px",
244
- zIndex: "10000",
245
- display: "none"
246
- },
247
- parent: this.document.body
248
- });
249
- }
250
- createElement(e, n) {
251
- const s = this.document.createElement(e);
252
- 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;
253
- }
254
- /**
255
- *
256
- * @param message @deprecated
257
- */
258
- async logAction(e) {
259
- const n = c.document.createElement("DIV");
260
- n.innerText = e, x(n, {
261
- padding: "3px 10px",
262
- opacity: "1",
263
- transition: "opacity 1s"
264
- }), this.devToolsMessageContainer.appendChild(n), await f(4e3), n.style.opacity = "0", await f(4e3), this.devToolsMessageContainer.removeChild(n), await f(1e3);
265
- }
266
- async checkElement(e, n) {
267
- if (!e)
268
- return;
269
- const s = e.getBoundingClientRect(), o = this.document.body.getBoundingClientRect();
270
- 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 f(200);
271
- }
272
- async showAlert(e) {
273
- const n = c.document.createElement("DIV"), s = c.document.body;
274
- n.innerText = e, x(s, {
275
- paddingTop: "30px"
276
- }), x(this.devToolsAlertContainer, {
277
- display: "flex"
278
- }), this.devToolsAlertContainer.appendChild(n);
279
- }
280
- async hideAlert() {
281
- x(this.devToolsAlertContainer, {
282
- display: "none"
283
- });
284
- const e = c.document.body;
285
- x(e, {
286
- paddingTop: "0"
287
- }), this.devToolsAlertContainer.firstChild && this.devToolsAlertContainer.removeChild(this.devToolsAlertContainer.firstChild);
288
- }
289
- async hideCheckElementContainer() {
290
- this.devToolsCheckElementContainer.style.opacity = "0", await f(200), this.devToolsCheckElementContainer.style.display = "none";
291
- }
292
- displayContext(e) {
293
- x(this.contextViewerContainer, {
294
- display: "flex",
295
- "background-color": "white",
296
- position: "absolute",
297
- top: "0px",
298
- left: "0px",
299
- "z-index": "9999"
300
- });
301
- const n = this.document.createElement("DIV");
302
- n.id = "context-viewer-before", x(n, {
303
- flex: "50%",
304
- width: "100%",
305
- height: "auto",
306
- border: "2px solid orange"
307
- });
308
- const s = this.document.createElement("DIV");
309
- s.id = "context-viewer-after", x(s, {
310
- flex: "50%",
311
- width: "100%",
312
- height: "auto",
313
- border: "2px solid green"
314
- });
315
- const o = this.document.createElement("DIV");
316
- o.innerHTML = e.beforeHTML, q(o, e.beforeInputValues);
317
- const a = this.document.createElement("DIV");
318
- a.innerHTML = e.afterHTML, q(a, e.afterInputValues), this.contextViewerContainer.appendChild(n), n.appendChild(o), setTimeout(() => {
319
- this.contextViewerContainer.removeChild(n), this.contextViewerContainer.appendChild(s), s.appendChild(a), setTimeout(() => {
320
- this.contextViewerContainer.removeChild(s), x(this.contextViewerContainer, { display: "none" });
321
- }, 2e3);
322
- }, 2e3);
323
- }
324
- }
325
- const q = (t, e) => {
326
- t.querySelectorAll("input").forEach((n) => {
327
- const s = n.getAttribute("input-id") || "";
328
- n.value = e[s];
329
- });
330
- }, M = null, L = async (t, e, n, s = 1e3, o = 0, a = 10, r = !1) => {
331
- if (console.log("Automation Status: ", c.status), c.isPaused)
332
- return new Promise((l, w) => {
333
- c.saveCurrentAction(async (C) => {
334
- if (C.status == "skipped")
335
- return l(null);
336
- try {
337
- const g = await L(C, e, n, s, o, a, r);
338
- l(g);
339
- } catch (g) {
340
- w(g);
341
- }
342
- }, t);
343
- });
344
- if (c.isStopped)
345
- throw new Error("Test stopped manually");
346
- if (console.groupCollapsed(`tries ${o}/${a}`), t && (t.updateTries(o), await E.notifyActionUpdated(t)), o === a)
347
- throw console.groupEnd(), r ? new Error(`UI Element ${e.getElementName() || "UNKNOWN"} still present after 10 tries`) : new Error(`UI Element ${e.getElementName() || "UNKNOWN"} not found after 10 tries`);
348
- {
349
- const l = e.selector(n, e.postProcess);
350
- return console.groupEnd(), l ? r ? (await f(s), await L(t, e, n, s, ++o, a, r)) : (console.log("Element found = ", l), l) : r ? (console.log("Element removed."), M) : (await f(s), await L(t, e, n, s, ++o, a, r));
351
- }
352
- }, R = async (t, e, n = 1e3, s = 10, o = !1) => {
353
- const a = e == null ? void 0 : e.getElementName();
354
- console.group("Looking for Element: " + a);
355
- let r = null;
356
- if (e.parent)
357
- try {
358
- console.groupCollapsed("Look for Parent ", e.parent.getElementName()), r = await R(t, e.parent, n, s, o), console.groupEnd();
359
- } catch (l) {
360
- if (console.groupEnd(), o && l.message.includes("not found"))
361
- return console.log("Parent not found, so element was removed"), console.groupEnd(), M;
362
- throw console.groupEnd(), l;
363
- }
364
- try {
365
- console.log("Using parent element: ", r);
366
- const l = await L(t, e, r, n, 0, s, o);
367
- return console.groupEnd(), l;
368
- } catch (l) {
369
- if (o && l.message.includes("not found"))
370
- return console.log("Parent not found, so element was removed"), console.groupEnd(), M;
371
- throw console.groupEnd(), l;
372
- }
373
- };
374
- var Q = /* @__PURE__ */ ((t) => (t.WAITING = "waiting", t.RUNNING = "running", t.STOPPED = "stopped", t.PAUSED = "paused", t.SUCCESS = "success", t.ERROR = "error", t.SKIPPED = "skipped", t))(Q || {});
375
- class E {
376
- constructor() {
377
- i(this, "status");
378
- i(this, "error");
379
- i(this, "id");
380
- i(this, "context");
381
- this.status = "waiting", this.error = "", this.id = G(), this.context = {
382
- beforeHTML: "",
383
- beforeInputValues: {},
384
- afterInputValues: {},
385
- afterHTML: "",
386
- url: "",
387
- startTimestamp: "",
388
- endTimestamp: ""
389
- };
390
- }
391
- getJSON() {
392
- return {
393
- id: this.id,
394
- description: this.getDescription(),
395
- context: this.context,
396
- status: this.status,
397
- error: this.error
398
- };
399
- }
400
- reset() {
401
- this.status = "waiting", this.error = "", this.resetAction();
402
- }
403
- getInputValuesFromPage() {
404
- const e = {};
405
- return c.document.querySelectorAll("input").forEach((s, o) => {
406
- const a = `value-id-${o}`;
407
- s.setAttribute("input-id", a), e[a] = s.value;
408
- }), e;
409
- }
410
- async execute() {
411
- try {
412
- this.status = "running", this.context.beforeInputValues = this.getInputValuesFromPage(), this.context.beforeHTML = c.document.body.innerHTML, await E.notifyActionUpdated(this), console.log("Action: ", this.getDescription()), await this.executeAction(), this.status = "success", this.error = "", c.isStepByStepMode && c.pause();
413
- } catch (e) {
414
- if (this.status = "error", this.error = e.message, e.message == "Test stopped manually")
415
- throw Error("Error in Action " + this.getDescription() + ". Message: " + e.message);
416
- this.status = "paused", c.pause();
417
- } finally {
418
- this.context.afterInputValues = this.getInputValuesFromPage(), this.context.afterHTML = c.document.body.innerHTML, await E.notifyActionUpdated(this);
419
- }
420
- }
421
- static async notifyActionUpdated(e) {
422
- m.dispatch(T.ACTION_UPDATE, {
423
- action: e.getJSON()
424
- });
425
- }
426
- }
427
- class Z extends E {
428
- constructor(n, s) {
429
- super();
430
- i(this, "name");
431
- i(this, "stepsFn");
432
- i(this, "steps");
433
- i(this, "params");
434
- i(this, "index");
435
- this.name = n, this.stepsFn = s, this.steps = [], this.index = 0;
436
- }
437
- getDescription() {
438
- return this.name;
439
- }
440
- compileSteps() {
441
- super.reset(), this.stepsFn(this.params);
442
- }
443
- stepsToJSON() {
444
- return this.steps.reduce((n, s) => (n.push(s.getJSON()), n), []);
445
- }
446
- getJSON() {
447
- return {
448
- ...super.getJSON(),
449
- type: "Action",
450
- params: this.params,
451
- steps: this.stepsToJSON()
452
- };
453
- }
454
- resetAction() {
455
- this.steps.length = 0, this.index = 0;
456
- }
457
- async handlePause() {
458
- return new Promise((n, s) => {
459
- c.saveCurrentAction(async (o) => {
460
- if (o.status === "skipped") {
461
- n();
462
- return;
463
- }
464
- try {
465
- await this.continue(), n();
466
- } catch (a) {
467
- s(a);
468
- }
469
- }, this);
470
- });
471
- }
472
- async continue() {
473
- for (; this.index < this.steps.length; ) {
474
- if (c.isStopped)
475
- throw new Error("Test stopped manually");
476
- const n = this.steps[this.index];
477
- try {
478
- if (await f(c.speed), await n.execute(), c.isPaused) {
479
- if (await this.handlePause(), n.status === "skipped") {
480
- this.index++;
481
- continue;
482
- }
483
- } else
484
- this.index++;
485
- } catch (s) {
486
- throw m.dispatch(T.ACTION_ERROR, {
487
- action: this.getJSON(),
488
- step: n,
489
- error: s.message,
490
- index: this.index
491
- }), s;
492
- }
493
- }
494
- }
495
- async executeAction() {
496
- this.index = 0, await this.continue();
497
- }
498
- setParams(n) {
499
- this.params = n;
500
- }
501
- addStep(n) {
502
- this.steps.push(n);
503
- }
504
- }
505
- class d extends E {
506
- constructor(n) {
507
- super();
508
- i(this, "uiElement");
509
- i(this, "element");
510
- i(this, "tries");
511
- this.uiElement = n, this.element = null, this.tries = 0;
512
- }
513
- getElementName() {
514
- var n;
515
- return (n = this.uiElement) == null ? void 0 : n.getElementName();
516
- }
517
- updateTries(n) {
518
- this.tries = n;
519
- }
520
- resetTries() {
521
- this.tries = 0;
522
- }
523
- getJSON() {
524
- return {
525
- id: this.id,
526
- element: this.getElementName(),
527
- description: this.getDescription(),
528
- status: this.status,
529
- error: this.error,
530
- context: this.context,
531
- tries: this.tries
532
- };
533
- }
534
- /**
535
- *
536
- * @param uiElement
537
- * @param delay of each try. Defaults to 1 second
538
- */
539
- static waitForElement(n, s, o = 1e3, a = 10, r = !1) {
540
- const l = s.getElementName();
541
- return new Promise(async (w, C) => {
542
- var v;
543
- const g = async (S, D = 1e3, N = 0, b = !1) => {
544
- if (console.groupCollapsed(`tries ${N}/${a}`), n.updateTries(N), await E.notifyActionUpdated(n), N === a)
545
- throw console.groupEnd(), b ? new Error(`UI Element ${l || "UNKNOWN"} still present after 10 tries`) : new Error(`UI Element ${l || "UNKNOWN"} not found after 10 tries`);
546
- {
547
- const K = s.selector(S, s.postProcess);
548
- return console.groupEnd(), K ? b ? (await f(D), await g(S, D, ++N, b)) : (console.log("Element found = ", K), K) : b ? (console.log("Element removed."), null) : (await f(D), await g(S, D, ++N, b));
549
- }
550
- };
551
- console.group("[Action On Element] Looking for Element: " + l);
552
- let k = null, V = !0;
553
- if (s.parent) {
554
- console.groupCollapsed("Look for Parent ", s.parent.getElementName());
555
- try {
556
- k = await d.waitForElement(n, s.parent, o, a, r);
557
- } catch {
558
- V = !1;
559
- } finally {
560
- console.groupEnd();
561
- }
562
- }
563
- if (V) {
564
- console.log("using parent element: ", k);
565
- try {
566
- const S = await g(k, o, 0, r);
567
- console.groupEnd(), w(S);
568
- } catch (S) {
569
- console.groupEnd(), C(new Error(S.message));
570
- }
571
- } else
572
- console.groupEnd(), C(new Error(`Parent ${(v = s.parent) == null ? void 0 : v.getElementName()} of UI Element ${s.name || "UNKNOWN"} not found`));
573
- });
574
- }
575
- async executeAction() {
576
- var n;
577
- try {
578
- this.element = await R(this, this.uiElement), (n = this.element) == null || n.setAttribute("test-id", this.getElementName()), await c.uiUtils.checkElement(this.element, this.getElementName()), this.executeActionOnElement(), await c.uiUtils.hideCheckElementContainer();
579
- } catch (s) {
580
- throw Error(s.message);
581
- }
582
- }
583
- resetAction() {
584
- this.element = null, this.resetTries();
585
- }
586
- }
587
- class we extends d {
588
- constructor(e) {
589
- super(e);
590
- }
591
- executeActionOnElement() {
592
- var e;
593
- return (e = this.element) == null ? void 0 : e.click();
594
- }
595
- getDescription() {
596
- return "Click in " + this.getElementName();
597
- }
598
- getJSON() {
599
- return {
600
- ...super.getJSON(),
601
- type: "Click"
602
- };
603
- }
604
- }
605
- class fe extends d {
606
- constructor(n, s) {
607
- super(n);
608
- i(this, "text");
609
- this.text = s;
610
- }
611
- executeActionOnElement() {
612
- var s;
613
- if (!(((s = this.element) == null ? void 0 : s.innerText) === this.text))
614
- throw new Error(`Text in element ${this.getElementName()} is not '${this.text}'`);
615
- }
616
- getDescription() {
617
- return `Assert that text in ${this.getElementName()} is '${this.text}'`;
618
- }
619
- getJSON() {
620
- return {
621
- ...super.getJSON(),
622
- type: "AssertTextIsAction",
623
- value: this.text
624
- };
625
- }
626
- }
627
- class Ae extends d {
628
- constructor(n, s) {
629
- super(n);
630
- i(this, "text");
631
- this.text = s;
632
- }
633
- executeActionOnElement() {
634
- var s;
635
- if (!((s = this.element) == null ? void 0 : s.innerText.includes(this.text)))
636
- throw new Error(`Text in element ${this.getElementName()} doesn't contain '${this.text}'`);
637
- }
638
- getDescription() {
639
- return `Assert that ${this.getElementName()} contains '${this.text}'`;
640
- }
641
- getJSON() {
642
- return {
643
- ...super.getJSON(),
644
- type: "AssertContainsText",
645
- value: this.text
646
- };
647
- }
648
- }
649
- class xe extends d {
650
- constructor(n, s) {
651
- super(n);
652
- i(this, "value");
653
- this.value = s;
654
- }
655
- executeActionOnElement() {
656
- if (!(this.element.value === this.value))
657
- throw new Error(`Value in element ${this.getElementName()} is not '${this.value}'`);
658
- }
659
- getDescription() {
660
- return `Assert that value in ${this.getElementName()} is '${this.value}'`;
661
- }
662
- getJSON() {
663
- return {
664
- ...super.getJSON(),
665
- type: "AssertValueIsAction",
666
- value: this.value
667
- };
668
- }
669
- }
670
- class Ce extends d {
671
- constructor(e) {
672
- super(e);
673
- }
674
- executeActionOnElement() {
675
- if (!!!this.element)
676
- throw new Error(`Element ${this.getElementName()} doesn't exist`);
677
- }
678
- getDescription() {
679
- return `Assert that ${this.getElementName()} exists`;
680
- }
681
- getJSON() {
682
- return {
683
- ...super.getJSON(),
684
- type: "AssertExistsAction"
685
- };
686
- }
687
- }
688
- class Se extends d {
689
- constructor(e) {
690
- super(e);
691
- }
692
- async executeAction() {
693
- var e;
694
- try {
695
- this.element = await R(this, this.uiElement, 1e3, 5, !0), (e = this.element) == null || e.setAttribute("test-id", this.getElementName()), await c.uiUtils.checkElement(this.element, this.getElementName()), this.executeActionOnElement(), await c.uiUtils.hideCheckElementContainer();
696
- } catch (n) {
697
- throw Error(n.message);
698
- }
699
- }
700
- executeActionOnElement() {
701
- if (!!this.element)
702
- throw new Error(`Element ${this.getElementName()} was not expected to exist`);
703
- }
704
- getDescription() {
705
- return `Assert that ${this.getElementName()} doesn't exist`;
706
- }
707
- getJSON() {
708
- return {
709
- ...super.getJSON(),
710
- type: "AssertNotExistsAction"
711
- };
712
- }
713
- }
714
- class ke extends d {
715
- constructor(n, s) {
716
- super(n);
717
- i(this, "value");
718
- this.value = s;
719
- }
720
- executeActionOnElement() {
721
- var s, o, a, r;
722
- let n = this.element;
723
- if (((s = this.element) == null ? void 0 : s.tagName) !== "INPUT" && ((o = this.element) == null ? void 0 : o.tagName) !== "SELECT" && ((a = this.element) == null ? void 0 : a.tagName) !== "TEXTAREA" && (n = (r = this.element) == null ? void 0 : r.querySelectorAll("input")[0], !n))
724
- throw new Error("Input element not found. Not able to type value in element " + this.getElementName());
725
- n.value = this.value, n.dispatchEvent(new Event("change"));
726
- }
727
- getDescription() {
728
- return `Select value '${this.value}' in ${this.getElementName()}`;
729
- }
730
- getJSON() {
731
- return {
732
- ...super.getJSON(),
733
- type: "Select",
734
- value: this.value
735
- };
736
- }
737
- }
738
- class Y extends d {
739
- constructor(n, s) {
740
- super(n);
741
- i(this, "value");
742
- this.value = s;
743
- }
744
- executeActionOnElement() {
745
- var s, o, a, r;
746
- let n = this.element;
747
- if (((s = this.element) == null ? void 0 : s.tagName) !== "INPUT" && ((o = this.element) == null ? void 0 : o.tagName) !== "SELECT" && ((a = this.element) == null ? void 0 : a.tagName) !== "TEXTAREA" && (n = (r = this.element) == null ? void 0 : r.querySelectorAll("input")[0], !n))
748
- throw new Error("Input element not found. Not able to type value in element " + this.getElementName());
749
- n.value = this.value, n.dispatchEvent(new Event("change")), n.dispatchEvent(new Event("keyup", { bubbles: !0 })), n.dispatchEvent(new Event("input", { bubbles: !0 }));
750
- }
751
- getDescription() {
752
- return `Type value '${this.value}' in ${this.getElementName()}`;
753
- }
754
- getJSON() {
755
- return {
756
- ...super.getJSON(),
757
- type: "Type",
758
- value: this.value
759
- };
760
- }
356
+ var j = {
357
+ start: ae,
358
+ get running() {
359
+ return A;
360
+ }
361
+ }, M = [];
362
+ for (let e = 0; e < 256; ++e) M.push((e + 256).toString(16).slice(1));
363
+ function oe(e, t = 0) {
364
+ return (M[e[t + 0]] + M[e[t + 1]] + M[e[t + 2]] + M[e[t + 3]] + "-" + M[e[t + 4]] + M[e[t + 5]] + "-" + M[e[t + 6]] + M[e[t + 7]] + "-" + M[e[t + 8]] + M[e[t + 9]] + "-" + M[e[t + 10]] + M[e[t + 11]] + M[e[t + 12]] + M[e[t + 13]] + M[e[t + 14]] + M[e[t + 15]]).toLowerCase();
761
365
  }
762
- class Te extends d {
763
- constructor(n, s) {
764
- super(n);
765
- i(this, "value");
766
- this.value = s;
767
- }
768
- executeActionOnElement() {
769
- var s, o, a, r;
770
- let n = this.element;
771
- if (((s = this.element) == null ? void 0 : s.tagName) !== "INPUT" && ((o = this.element) == null ? void 0 : o.tagName) !== "SELECT" && ((a = this.element) == null ? void 0 : a.tagName) !== "TEXTAREA" && (n = (r = this.element) == null ? void 0 : r.querySelectorAll("input")[0], !n))
772
- throw new Error("Input element not found. Not able to type value in element " + this.getElementName());
773
- n.value = this.value, n.dispatchEvent(new Event("change")), n.dispatchEvent(new Event("keyup", { bubbles: !0 })), n.dispatchEvent(new Event("input", { bubbles: !0 }));
774
- }
775
- getDescription() {
776
- return `Type a password in ${this.getElementName()}`;
777
- }
778
- getJSON() {
779
- return {
780
- ...super.getJSON(),
781
- type: "TypePassword",
782
- value: this.value
783
- };
784
- }
366
+ //#endregion
367
+ //#region node_modules/.pnpm/uuid@14.0.0/node_modules/uuid/dist/rng.js
368
+ var se = new Uint8Array(16);
369
+ function ce() {
370
+ return crypto.getRandomValues(se);
785
371
  }
786
- class ve extends d {
787
- constructor(e) {
788
- super(e);
789
- }
790
- executeActionOnElement() {
791
- var e;
792
- (e = this.element) == null || e.dispatchEvent(
793
- new KeyboardEvent("keydown", {
794
- altKey: !1,
795
- code: "Escape",
796
- ctrlKey: !1,
797
- isComposing: !1,
798
- key: "Escape",
799
- location: 0,
800
- metaKey: !1,
801
- repeat: !1,
802
- shiftKey: !1,
803
- which: 27,
804
- charCode: 0,
805
- keyCode: 27
806
- })
807
- );
808
- }
809
- getDescription() {
810
- return `Press Esc key in ${this.getElementName()}`;
811
- }
812
- getJSON() {
813
- return {
814
- ...super.getJSON(),
815
- type: "PressEscKey"
816
- };
817
- }
372
+ //#endregion
373
+ //#region node_modules/.pnpm/uuid@14.0.0/node_modules/uuid/dist/v4.js
374
+ function N(e, t, n) {
375
+ return !t && !e && crypto.randomUUID ? crypto.randomUUID() : le(e, t, n);
818
376
  }
819
- class Ne extends d {
820
- constructor(e) {
821
- super(e);
822
- }
823
- executeActionOnElement() {
824
- var e;
825
- (e = this.element) == null || e.dispatchEvent(
826
- new KeyboardEvent("keyup", {
827
- altKey: !1,
828
- code: "Down",
829
- ctrlKey: !1,
830
- isComposing: !1,
831
- key: "Down",
832
- location: 0,
833
- metaKey: !1,
834
- repeat: !1,
835
- shiftKey: !1,
836
- which: 40,
837
- charCode: 0,
838
- keyCode: 40
839
- })
840
- );
841
- }
842
- getDescription() {
843
- return `Press Down key in ${this.getElementName()}`;
844
- }
845
- getJSON() {
846
- return {
847
- ...super.getJSON(),
848
- type: "PressDownKey"
849
- };
850
- }
377
+ function le(e, t, n) {
378
+ e ||= {};
379
+ let r = e.random ?? e.rng?.() ?? ce();
380
+ if (r.length < 16) throw Error("Random bytes length must be >= 16");
381
+ if (r[6] = r[6] & 15 | 64, r[8] = r[8] & 63 | 128, t) {
382
+ if (n ||= 0, n < 0 || n + 16 > t.length) throw RangeError(`UUID byte range ${n}:${n + 15} is out of buffer bounds`);
383
+ for (let e = 0; e < 16; ++e) t[n + e] = r[e];
384
+ return t;
385
+ }
386
+ return oe(r);
851
387
  }
852
- class be extends d {
853
- constructor(e) {
854
- super(e);
855
- }
856
- executeActionOnElement() {
857
- var e;
858
- (e = this.element) == null || e.dispatchEvent(
859
- new KeyboardEvent("keydown", {
860
- altKey: !1,
861
- code: "Tab",
862
- ctrlKey: !1,
863
- isComposing: !1,
864
- key: "Tab",
865
- location: 0,
866
- metaKey: !1,
867
- repeat: !1,
868
- shiftKey: !1,
869
- which: 9,
870
- charCode: 0,
871
- keyCode: 9
872
- })
873
- );
874
- }
875
- getDescription() {
876
- return `Press Tab key in ${this.getElementName()}`;
877
- }
878
- getJSON() {
879
- return {
880
- ...super.getJSON(),
881
- type: "PressTabKey"
882
- };
883
- }
884
- }
885
- class Oe extends d {
886
- constructor(e) {
887
- super(e);
888
- }
889
- executeActionOnElement() {
890
- var e;
891
- (e = this.element) == null || e.dispatchEvent(
892
- new KeyboardEvent("keydown", {
893
- altKey: !1,
894
- code: "Enter",
895
- ctrlKey: !1,
896
- isComposing: !1,
897
- key: "Enter",
898
- location: 0,
899
- metaKey: !1,
900
- repeat: !1,
901
- shiftKey: !1,
902
- which: 13,
903
- charCode: 0,
904
- keyCode: 13
905
- })
906
- );
907
- }
908
- getDescription() {
909
- return `Press Enter key in ${this.getElementName()}`;
910
- }
911
- getJSON() {
912
- return {
913
- ...super.getJSON(),
914
- type: "PressEnterKey"
915
- };
916
- }
917
- }
918
- var De = /* @__PURE__ */ ((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))(De || {});
919
- const B = {
920
- Escape: 27,
921
- Enter: 13,
922
- Tab: 9,
923
- ArrowDown: 40,
924
- ArrowUp: 38,
925
- ArrowLeft: 37,
926
- ArrowRight: 39,
927
- Backspace: 8,
928
- Delete: 46,
929
- Shift: 16,
930
- Control: 17,
931
- Alt: 18,
932
- Meta: 91
933
- };
934
- class Ie extends d {
935
- constructor(n, s) {
936
- super(n);
937
- i(this, "key");
938
- this.key = s;
939
- }
940
- executeActionOnElement() {
941
- var n;
942
- (n = this.element) == null || n.dispatchEvent(
943
- new KeyboardEvent("keydown", {
944
- key: this.key,
945
- code: this.key,
946
- keyCode: B[this.key],
947
- charCode: 0,
948
- which: B[this.key],
949
- altKey: !1,
950
- ctrlKey: !1,
951
- metaKey: !1,
952
- shiftKey: !1,
953
- isComposing: !1,
954
- location: 0,
955
- repeat: !1
956
- })
957
- );
958
- }
959
- getDescription() {
960
- return `Press ${this.key} key in ${this.getElementName()}`;
961
- }
962
- getJSON() {
963
- return {
964
- ...super.getJSON(),
965
- type: "PressKey",
966
- key: this.key
967
- };
968
- }
969
- }
970
- class Le extends d {
971
- constructor(n, s) {
972
- super(n);
973
- i(this, "file");
974
- this.file = s;
975
- }
976
- executeActionOnElement() {
977
- const n = this.element, s = new DataTransfer();
978
- s.items.add(this.file);
979
- const o = s.files;
980
- n.files = o, n.dispatchEvent(new Event("change"));
981
- function a(l) {
982
- var w;
983
- return l != null && l.parentElement ? ((w = l.parentElement) == null ? void 0 : w.tagName.toLowerCase()) === "form" ? l.parentElement : a(l.parentElement) : null;
984
- }
985
- const r = a(n);
986
- r && r.dispatchEvent(new Event("change"));
987
- }
988
- getDescription() {
989
- return `Upload file in ${this.getElementName()}`;
990
- }
991
- getJSON() {
992
- return {
993
- ...super.getJSON(),
994
- type: "UploadFile"
995
- };
996
- }
997
- }
998
- class Pe extends d {
999
- constructor(n, s) {
1000
- super(n);
1001
- i(this, "memorySlotName");
1002
- this.memorySlotName = s;
1003
- }
1004
- executeActionOnElement() {
1005
- var s, o, a, r;
1006
- let n = this.element;
1007
- if (((s = this.element) == null ? void 0 : s.tagName) !== "INPUT" && ((o = this.element) == null ? void 0 : o.tagName) !== "SELECT" && ((a = this.element) == null ? void 0 : a.tagName) !== "TEXTAREA" && (n = (r = this.element) == null ? void 0 : r.querySelectorAll("input")[0], !n))
1008
- throw new Error("Input element not found. Not able to save value from element " + this.getElementName());
1009
- m.dispatch(T.SAVE_VALUE, {
1010
- memorySlotName: this.memorySlotName,
1011
- value: n.value
1012
- });
1013
- }
1014
- getDescription() {
1015
- return `Save value of ${this.getElementName()} in ${this.memorySlotName}`;
1016
- }
1017
- getJSON() {
1018
- return {
1019
- ...super.getJSON(),
1020
- type: "SaveValue",
1021
- memorySlotName: this.memorySlotName
1022
- };
1023
- }
1024
- }
1025
- class $e extends E {
1026
- constructor(n) {
1027
- super();
1028
- i(this, "miliseconds");
1029
- this.miliseconds = n;
1030
- }
1031
- getDescription() {
1032
- return "Wait " + this.miliseconds + " miliseconds";
1033
- }
1034
- getJSON() {
1035
- return {
1036
- ...super.getJSON(),
1037
- type: "Wait"
1038
- };
1039
- }
1040
- async executeAction() {
1041
- await f(this.miliseconds);
1042
- }
1043
- resetAction() {
1044
- }
1045
- }
1046
- class Ue extends E {
1047
- constructor(n) {
1048
- super();
1049
- i(this, "uiElement");
1050
- i(this, "tries");
1051
- this.uiElement = n, this.tries = 0;
1052
- }
1053
- updateTries(n) {
1054
- this.tries = n;
1055
- }
1056
- resetAction() {
1057
- this.tries = 0;
1058
- }
1059
- getElementName() {
1060
- var n;
1061
- return (n = this.uiElement) == null ? void 0 : n.getElementName();
1062
- }
1063
- async executeAction() {
1064
- await R(this, this.uiElement, 1e3, 10, !0);
1065
- }
1066
- getDescription() {
1067
- return "Wait until " + this.getElementName() + " is removed";
1068
- }
1069
- getJSON() {
1070
- return {
1071
- ...super.getJSON(),
1072
- type: "WaitUntilElementRemoved"
1073
- };
1074
- }
1075
- }
1076
- class Re extends E {
1077
- constructor() {
1078
- super();
1079
- }
1080
- getDescription() {
1081
- return "Paused";
1082
- }
1083
- getJSON() {
1084
- return {
1085
- ...super.getJSON(),
1086
- type: "Pause"
1087
- };
1088
- }
1089
- async executeAction() {
1090
- await c.pause();
1091
- }
1092
- resetAction() {
1093
- }
1094
- }
1095
- class Je extends E {
1096
- constructor(n) {
1097
- super();
1098
- i(this, "description");
1099
- this.description = n;
1100
- }
1101
- getDescription() {
1102
- return "Manual Step: " + this.description;
1103
- }
1104
- getJSON() {
1105
- return {
1106
- ...super.getJSON(),
1107
- type: "ManualStep"
1108
- };
1109
- }
1110
- async executeAction() {
1111
- return await c.uiUtils.showAlert("Waiting manual step..."), new Promise((n, s) => {
1112
- m.on(T.USER_ACCEPT, async () => (await c.uiUtils.hideAlert(), n(!0))), m.on(T.USER_REJECT, async () => (await c.uiUtils.hideAlert(), s()));
1113
- });
1114
- }
1115
- resetAction() {
1116
- }
1117
- }
1118
- class Ve extends E {
1119
- constructor() {
1120
- super();
1121
- }
1122
- getDescription() {
1123
- return "Reload page";
1124
- }
1125
- getJSON() {
1126
- return {
1127
- ...super.getJSON(),
1128
- type: "ReloadPage"
1129
- };
1130
- }
1131
- async executeAction() {
1132
- await location.reload();
1133
- }
1134
- resetAction() {
1135
- }
1136
- }
1137
- class Ke extends E {
1138
- constructor(n, s, o, a = "condition") {
1139
- super();
1140
- i(this, "condition");
1141
- i(this, "ifAction");
1142
- i(this, "elseAction");
1143
- i(this, "conditionDescription");
1144
- this.condition = n, this.ifAction = s, this.elseAction = o, this.conditionDescription = a;
1145
- }
1146
- getDescription() {
1147
- const n = this.elseAction ? `, else ${this.elseAction.getDescription()}` : "";
1148
- return `If ${this.conditionDescription}, then ${this.ifAction.getDescription()}${n}`;
1149
- }
1150
- getJSON() {
1151
- var n;
1152
- return {
1153
- ...super.getJSON(),
1154
- type: "If",
1155
- conditionDescription: this.conditionDescription,
1156
- ifAction: this.ifAction.getJSON(),
1157
- elseAction: (n = this.elseAction) == null ? void 0 : n.getJSON()
1158
- };
1159
- }
1160
- async executeAction() {
1161
- try {
1162
- await this.condition(), await this.ifAction.execute();
1163
- } catch {
1164
- this.elseAction && await this.elseAction.execute();
1165
- }
1166
- }
1167
- resetAction() {
1168
- var n;
1169
- this.ifAction.reset(), (n = this.elseAction) == null || n.reset();
1170
- }
1171
- compileSteps() {
1172
- var n;
1173
- this.ifAction.compileSteps(), (n = this.elseAction) == null || n.compileSteps();
1174
- }
1175
- }
1176
- const U = (t) => t.toLocaleDateString("en-US", { year: "numeric", month: "2-digit", day: "2-digit" }), J = (t) => {
1177
- const e = /* @__PURE__ */ new Date();
1178
- return U(new Date(e.setDate(e.getDate() + t)));
1179
- }, _ = (t) => {
1180
- const e = /* @__PURE__ */ new Date();
1181
- return U(new Date(e.setMonth(e.getMonth() + t)));
1182
- }, Fe = J(1), Me = J(-1), We = J(7), qe = J(-7), Be = _(1), He = _(-1), ht = {
1183
- formatDate: U,
1184
- today: U(/* @__PURE__ */ new Date()),
1185
- tomorrow: Fe,
1186
- nextWeek: We,
1187
- nextMonth: Be,
1188
- yesterday: Me,
1189
- lastWeek: qe,
1190
- lastMonth: He
1191
- };
1192
- class je {
1193
- constructor() {
1194
- i(this, "enabled", !1);
1195
- }
1196
- setEnabled(e) {
1197
- this.enabled = e;
1198
- }
1199
- log(...e) {
1200
- this.enabled && console.log("[tomation]", ...e);
1201
- }
1202
- groupCollapsed(...e) {
1203
- this.enabled && console.groupCollapsed("[tomation]", ...e);
1204
- }
1205
- groupEnd() {
1206
- this.enabled && console.groupEnd();
1207
- }
1208
- error(...e) {
1209
- this.enabled && console.error("[tomation]", ...e);
1210
- }
1211
- }
1212
- const u = new je(), Xe = (t) => {
1213
- u.setEnabled(t);
1214
- }, y = class y {
1215
- static compileAction(e) {
1216
- const n = y.currentAction;
1217
- y.currentAction = e, e.compileSteps(), y.currentAction = n;
1218
- }
1219
- static compileConditionalAction(e) {
1220
- const n = y.currentAction;
1221
- y.currentAction = e, e.compileSteps(), y.currentAction = n;
1222
- }
1223
- static addAction(e) {
1224
- u.log("Add action: ", e.getDescription()), y.currentAction.addStep(e);
1225
- }
1226
- static init(e) {
1227
- y.currentAction = e, y.isCompiling = !0, u.groupCollapsed("Compile: " + e.getDescription()), e.compileSteps(), y.isCompiling = !1, u.log("Compilation finished"), u.groupEnd();
1228
- }
388
+ //#endregion
389
+ //#region src/dom/actions.ts
390
+ var P = null, F = async (e, t, n, r = 1e3, i = 0, a = 10, o = !1) => {
391
+ if (console.log("Automation Status: ", O.status), O.isPaused) return new Promise((s, c) => {
392
+ O.saveCurrentAction(async (e) => {
393
+ if (e.status == L.SKIPPED) return s(null);
394
+ try {
395
+ s(await F(e, t, n, r, i, a, o));
396
+ } catch (e) {
397
+ c(e);
398
+ }
399
+ }, e);
400
+ });
401
+ if (O.isStopped) throw Error("Test stopped manually");
402
+ if (console.groupCollapsed(`tries ${i}/${a}`), e && (e.updateTries(i), await R.notifyActionUpdated(e)), i === a) throw console.groupEnd(), Error(o ? `UI Element ${t.getElementName() || "UNKNOWN"} still present after 10 tries` : `UI Element ${t.getElementName() || "UNKNOWN"} not found after 10 tries`);
403
+ {
404
+ let s = t.selector(n, t.postProcess);
405
+ return console.groupEnd(), s ? o ? (await S(r), await F(e, t, n, r, ++i, a, o)) : (console.log("Element found = ", s), s) : o ? (console.log("Element removed."), P) : (await S(r), await F(e, t, n, r, ++i, a, o));
406
+ }
407
+ }, I = async (e, t, n = 1e3, r = 10, i = !1) => {
408
+ let a = t?.getElementName();
409
+ console.group("Looking for Element: " + a);
410
+ let o = null;
411
+ if (t.parent) try {
412
+ console.groupCollapsed("Look for Parent ", t.parent.getElementName()), o = await I(e, t.parent, n, r, i), console.groupEnd();
413
+ } catch (e) {
414
+ if (console.groupEnd(), i && e.message.includes("not found")) return console.log("Parent not found, so element was removed"), console.groupEnd(), P;
415
+ throw console.groupEnd(), e;
416
+ }
417
+ try {
418
+ console.log("Using parent element: ", o);
419
+ let a = await F(e, t, o, n, 0, r, i);
420
+ return console.groupEnd(), a;
421
+ } catch (e) {
422
+ if (i && e.message.includes("not found")) return console.log("Parent not found, so element was removed"), console.groupEnd(), P;
423
+ throw console.groupEnd(), e;
424
+ }
425
+ }, L = /* @__PURE__ */ function(e) {
426
+ return e.WAITING = "waiting", e.RUNNING = "running", e.STOPPED = "stopped", e.PAUSED = "paused", e.SUCCESS = "success", e.ERROR = "error", e.SKIPPED = "skipped", e;
427
+ }(L || {}), R = class e {
428
+ status;
429
+ error;
430
+ id;
431
+ context;
432
+ constructor() {
433
+ this.status = L.WAITING, this.error = "", this.id = N(), this.context = {
434
+ beforeHTML: "",
435
+ beforeInputValues: {},
436
+ afterInputValues: {},
437
+ afterHTML: "",
438
+ url: "",
439
+ startTimestamp: "",
440
+ endTimestamp: ""
441
+ };
442
+ }
443
+ getJSON() {
444
+ return {
445
+ id: this.id,
446
+ description: this.getDescription(),
447
+ context: this.context,
448
+ status: this.status,
449
+ error: this.error
450
+ };
451
+ }
452
+ reset() {
453
+ this.status = L.WAITING, this.error = "", this.resetAction();
454
+ }
455
+ getInputValuesFromPage() {
456
+ let e = {};
457
+ return O.document.querySelectorAll("input").forEach((t, n) => {
458
+ let r = `value-id-${n}`;
459
+ t.setAttribute("input-id", r), e[r] = t.value;
460
+ }), e;
461
+ }
462
+ async execute() {
463
+ try {
464
+ this.status = L.RUNNING, this.context.beforeInputValues = this.getInputValuesFromPage(), this.context.beforeHTML = O.document.body.innerHTML, await e.notifyActionUpdated(this), console.log("Action: ", this.getDescription()), await this.executeAction(), this.status = L.SUCCESS, this.error = "", O.isStepByStepMode && O.pause();
465
+ } catch (e) {
466
+ if (this.status = L.ERROR, this.error = e.message, e.message == "Test stopped manually") throw Error("Error in Action " + this.getDescription() + ". Message: " + e.message);
467
+ this.status = L.PAUSED, O.pause();
468
+ } finally {
469
+ this.context.afterInputValues = this.getInputValuesFromPage(), this.context.afterHTML = O.document.body.innerHTML, await e.notifyActionUpdated(this);
470
+ }
471
+ }
472
+ static async notifyActionUpdated(e) {
473
+ y.dispatch(v.ACTION_UPDATE, { action: e.getJSON() });
474
+ }
475
+ }, z = class extends R {
476
+ name;
477
+ stepsFn;
478
+ steps;
479
+ params;
480
+ index;
481
+ constructor(e, t) {
482
+ super(), this.name = e, this.stepsFn = t, this.steps = [], this.index = 0;
483
+ }
484
+ getDescription() {
485
+ return this.name;
486
+ }
487
+ compileSteps() {
488
+ super.reset(), this.stepsFn(this.params);
489
+ }
490
+ stepsToJSON() {
491
+ return this.steps.reduce((e, t) => (e.push(t.getJSON()), e), []);
492
+ }
493
+ getJSON() {
494
+ return {
495
+ ...super.getJSON(),
496
+ type: "Action",
497
+ params: this.params,
498
+ steps: this.stepsToJSON()
499
+ };
500
+ }
501
+ resetAction() {
502
+ this.steps.length = 0, this.index = 0;
503
+ }
504
+ async continue() {
505
+ if (O.isPaused) return new Promise((e, t) => {
506
+ O.saveCurrentAction(async (n) => {
507
+ if (n.status == L.SKIPPED) return e();
508
+ try {
509
+ await n.continue(), e();
510
+ } catch (e) {
511
+ t(e);
512
+ }
513
+ }, this);
514
+ });
515
+ if (O.isStopped) throw Error("Test stopped manually");
516
+ if (this.index < this.steps.length) {
517
+ let e = this.steps[this.index];
518
+ try {
519
+ if (await S(O.speed), await e.execute(), !O.isPaused) this.index++, await this.continue();
520
+ else return new Promise((t, n) => {
521
+ O.saveCurrentAction(async (r) => {
522
+ if (r.status == L.SKIPPED) return this.index++, await R.notifyActionUpdated(e), await this.continue(), t();
523
+ try {
524
+ await r.continue(), t();
525
+ } catch (e) {
526
+ n(e);
527
+ }
528
+ }, e);
529
+ });
530
+ } catch (e) {
531
+ throw e;
532
+ }
533
+ }
534
+ }
535
+ async executeAction() {
536
+ this.index = 0, await this.continue();
537
+ }
538
+ setParams(e) {
539
+ this.params = e;
540
+ }
541
+ addStep(e) {
542
+ this.steps.push(e);
543
+ }
544
+ }, B = class e extends R {
545
+ uiElement;
546
+ element;
547
+ tries;
548
+ constructor(e) {
549
+ super(), this.uiElement = e, this.element = null, this.tries = 0;
550
+ }
551
+ getElementName() {
552
+ return this.uiElement?.getElementName();
553
+ }
554
+ updateTries(e) {
555
+ this.tries = e;
556
+ }
557
+ resetTries() {
558
+ this.tries = 0;
559
+ }
560
+ getJSON() {
561
+ return {
562
+ id: this.id,
563
+ element: this.getElementName(),
564
+ description: this.getDescription(),
565
+ status: this.status,
566
+ error: this.error,
567
+ context: this.context,
568
+ tries: this.tries
569
+ };
570
+ }
571
+ static waitForElement(t, n, r = 1e3, i = 10, a = !1) {
572
+ let o = n.getElementName();
573
+ return new Promise(async (s, c) => {
574
+ let l = async (e, r = 1e3, a = 0, s = !1) => {
575
+ if (console.groupCollapsed(`tries ${a}/${i}`), t.updateTries(a), await R.notifyActionUpdated(t), a === i) throw console.groupEnd(), Error(s ? `UI Element ${o || "UNKNOWN"} still present after 10 tries` : `UI Element ${o || "UNKNOWN"} not found after 10 tries`);
576
+ {
577
+ let t = n.selector(e, n.postProcess);
578
+ return console.groupEnd(), t ? s ? (await S(r), await l(e, r, ++a, s)) : (console.log("Element found = ", t), t) : s ? (console.log("Element removed."), null) : (await S(r), await l(e, r, ++a, s));
579
+ }
580
+ };
581
+ console.group("[Action On Element] Looking for Element: " + o);
582
+ let u = null, d = !0;
583
+ if (n.parent) {
584
+ console.groupCollapsed("Look for Parent ", n.parent.getElementName());
585
+ try {
586
+ u = await e.waitForElement(t, n.parent, r, i, a);
587
+ } catch {
588
+ d = !1;
589
+ } finally {
590
+ console.groupEnd();
591
+ }
592
+ }
593
+ if (d) {
594
+ console.log("using parent element: ", u);
595
+ try {
596
+ let e = await l(u, r, 0, a);
597
+ console.groupEnd(), s(e);
598
+ } catch (e) {
599
+ console.groupEnd(), c(Error(e.message));
600
+ }
601
+ } else console.groupEnd(), c(/* @__PURE__ */ Error(`Parent ${n.parent?.getElementName()} of UI Element ${n.name || "UNKNOWN"} not found`));
602
+ });
603
+ }
604
+ async executeAction() {
605
+ try {
606
+ this.element = await I(this, this.uiElement), this.element?.setAttribute("test-id", this.getElementName()), await O.uiUtils.checkElement(this.element, this.getElementName()), this.executeActionOnElement(), await O.uiUtils.hideCheckElementContainer();
607
+ } catch (e) {
608
+ throw Error(e.message);
609
+ }
610
+ }
611
+ resetAction() {
612
+ this.element = null, this.resetTries();
613
+ }
614
+ }, ue = class extends B {
615
+ constructor(e) {
616
+ super(e);
617
+ }
618
+ executeActionOnElement() {
619
+ return this.element?.click();
620
+ }
621
+ getDescription() {
622
+ return "Click in " + this.getElementName();
623
+ }
624
+ getJSON() {
625
+ return {
626
+ ...super.getJSON(),
627
+ type: "Click"
628
+ };
629
+ }
630
+ }, de = class extends B {
631
+ text;
632
+ constructor(e, t) {
633
+ super(e), this.text = t;
634
+ }
635
+ executeActionOnElement() {
636
+ if (this.element?.innerText !== this.text) throw Error(`Text in element ${this.getElementName()} is not '${this.text}'`);
637
+ }
638
+ getDescription() {
639
+ return `Assert that text in ${this.getElementName()} is '${this.text}'`;
640
+ }
641
+ getJSON() {
642
+ return {
643
+ ...super.getJSON(),
644
+ type: "AssertTextIsAction",
645
+ value: this.text
646
+ };
647
+ }
648
+ }, fe = class extends B {
649
+ text;
650
+ constructor(e, t) {
651
+ super(e), this.text = t;
652
+ }
653
+ executeActionOnElement() {
654
+ if (!this.element?.innerText.includes(this.text)) throw Error(`Text in element ${this.getElementName()} doesn't contain '${this.text}'`);
655
+ }
656
+ getDescription() {
657
+ return `Assert that ${this.getElementName()} contains '${this.text}'`;
658
+ }
659
+ getJSON() {
660
+ return {
661
+ ...super.getJSON(),
662
+ type: "AssertContainsText",
663
+ value: this.text
664
+ };
665
+ }
666
+ }, pe = class extends B {
667
+ value;
668
+ constructor(e, t) {
669
+ super(e), this.value = t;
670
+ }
671
+ executeActionOnElement() {
672
+ if (this.element.value !== this.value) throw Error(`Value in element ${this.getElementName()} is not '${this.value}'`);
673
+ }
674
+ getDescription() {
675
+ return `Assert that value in ${this.getElementName()} is '${this.value}'`;
676
+ }
677
+ getJSON() {
678
+ return {
679
+ ...super.getJSON(),
680
+ type: "AssertValueIsAction",
681
+ value: this.value
682
+ };
683
+ }
684
+ }, me = class extends B {
685
+ constructor(e) {
686
+ super(e);
687
+ }
688
+ executeActionOnElement() {
689
+ if (!this.element) throw Error(`Element ${this.getElementName()} doesn't exist`);
690
+ }
691
+ getDescription() {
692
+ return `Assert that ${this.getElementName()} exists`;
693
+ }
694
+ getJSON() {
695
+ return {
696
+ ...super.getJSON(),
697
+ type: "AssertExistsAction"
698
+ };
699
+ }
700
+ }, he = class extends B {
701
+ constructor(e) {
702
+ super(e);
703
+ }
704
+ async executeAction() {
705
+ try {
706
+ this.element = await I(this, this.uiElement, 1e3, 5, !0), this.element?.setAttribute("test-id", this.getElementName()), await O.uiUtils.checkElement(this.element, this.getElementName()), this.executeActionOnElement(), await O.uiUtils.hideCheckElementContainer();
707
+ } catch (e) {
708
+ throw Error(e.message);
709
+ }
710
+ }
711
+ executeActionOnElement() {
712
+ if (this.element) throw Error(`Element ${this.getElementName()} was not expected to exist`);
713
+ }
714
+ getDescription() {
715
+ return `Assert that ${this.getElementName()} doesn't exist`;
716
+ }
717
+ getJSON() {
718
+ return {
719
+ ...super.getJSON(),
720
+ type: "AssertNotExistsAction"
721
+ };
722
+ }
723
+ }, ge = class extends B {
724
+ value;
725
+ constructor(e, t) {
726
+ super(e), this.value = t;
727
+ }
728
+ executeActionOnElement() {
729
+ let e = this.element;
730
+ if (this.element?.tagName !== "INPUT" && this.element?.tagName !== "SELECT" && this.element?.tagName !== "TEXTAREA" && (e = this.element?.querySelectorAll("input")[0], !e)) throw Error("Input element not found. Not able to type value in element " + this.getElementName());
731
+ e.value = this.value, e.dispatchEvent(new Event("change"));
732
+ }
733
+ getDescription() {
734
+ return `Select value '${this.value}' in ${this.getElementName()}`;
735
+ }
736
+ getJSON() {
737
+ return {
738
+ ...super.getJSON(),
739
+ type: "Select",
740
+ value: this.value
741
+ };
742
+ }
743
+ }, V = class extends B {
744
+ value;
745
+ constructor(e, t) {
746
+ super(e), this.value = t;
747
+ }
748
+ executeActionOnElement() {
749
+ let e = this.element;
750
+ if (this.element?.tagName !== "INPUT" && this.element?.tagName !== "SELECT" && this.element?.tagName !== "TEXTAREA" && (e = this.element?.querySelectorAll("input")[0], !e)) throw Error("Input element not found. Not able to type value in element " + this.getElementName());
751
+ e.value = this.value, e.dispatchEvent(new Event("change")), e.dispatchEvent(new Event("keyup", { bubbles: !0 })), e.dispatchEvent(new Event("input", { bubbles: !0 }));
752
+ }
753
+ getDescription() {
754
+ return `Type value '${this.value}' in ${this.getElementName()}`;
755
+ }
756
+ getJSON() {
757
+ return {
758
+ ...super.getJSON(),
759
+ type: "Type",
760
+ value: this.value
761
+ };
762
+ }
763
+ }, _e = class extends B {
764
+ value;
765
+ constructor(e, t) {
766
+ super(e), this.value = t;
767
+ }
768
+ executeActionOnElement() {
769
+ let e = this.element;
770
+ if (this.element?.tagName !== "INPUT" && this.element?.tagName !== "SELECT" && this.element?.tagName !== "TEXTAREA" && (e = this.element?.querySelectorAll("input")[0], !e)) throw Error("Input element not found. Not able to type value in element " + this.getElementName());
771
+ e.value = this.value, e.dispatchEvent(new Event("change")), e.dispatchEvent(new Event("keyup", { bubbles: !0 })), e.dispatchEvent(new Event("input", { bubbles: !0 }));
772
+ }
773
+ getDescription() {
774
+ return `Type a password in ${this.getElementName()}`;
775
+ }
776
+ getJSON() {
777
+ return {
778
+ ...super.getJSON(),
779
+ type: "TypePassword",
780
+ value: this.value
781
+ };
782
+ }
783
+ }, ve = class extends B {
784
+ constructor(e) {
785
+ super(e);
786
+ }
787
+ executeActionOnElement() {
788
+ this.element?.dispatchEvent(new KeyboardEvent("keydown", {
789
+ altKey: !1,
790
+ code: "Escape",
791
+ ctrlKey: !1,
792
+ isComposing: !1,
793
+ key: "Escape",
794
+ location: 0,
795
+ metaKey: !1,
796
+ repeat: !1,
797
+ shiftKey: !1,
798
+ which: 27,
799
+ charCode: 0,
800
+ keyCode: 27
801
+ }));
802
+ }
803
+ getDescription() {
804
+ return `Press Esc key in ${this.getElementName()}`;
805
+ }
806
+ getJSON() {
807
+ return {
808
+ ...super.getJSON(),
809
+ type: "PressEscKey"
810
+ };
811
+ }
812
+ }, ye = class extends B {
813
+ constructor(e) {
814
+ super(e);
815
+ }
816
+ executeActionOnElement() {
817
+ this.element?.dispatchEvent(new KeyboardEvent("keyup", {
818
+ altKey: !1,
819
+ code: "Down",
820
+ ctrlKey: !1,
821
+ isComposing: !1,
822
+ key: "Down",
823
+ location: 0,
824
+ metaKey: !1,
825
+ repeat: !1,
826
+ shiftKey: !1,
827
+ which: 40,
828
+ charCode: 0,
829
+ keyCode: 40
830
+ }));
831
+ }
832
+ getDescription() {
833
+ return `Press Down key in ${this.getElementName()}`;
834
+ }
835
+ getJSON() {
836
+ return {
837
+ ...super.getJSON(),
838
+ type: "PressDownKey"
839
+ };
840
+ }
841
+ }, be = class extends B {
842
+ constructor(e) {
843
+ super(e);
844
+ }
845
+ executeActionOnElement() {
846
+ this.element?.dispatchEvent(new KeyboardEvent("keydown", {
847
+ altKey: !1,
848
+ code: "Tab",
849
+ ctrlKey: !1,
850
+ isComposing: !1,
851
+ key: "Tab",
852
+ location: 0,
853
+ metaKey: !1,
854
+ repeat: !1,
855
+ shiftKey: !1,
856
+ which: 9,
857
+ charCode: 0,
858
+ keyCode: 9
859
+ }));
860
+ }
861
+ getDescription() {
862
+ return `Press Tab key in ${this.getElementName()}`;
863
+ }
864
+ getJSON() {
865
+ return {
866
+ ...super.getJSON(),
867
+ type: "PressTabKey"
868
+ };
869
+ }
870
+ }, xe = class extends B {
871
+ constructor(e) {
872
+ super(e);
873
+ }
874
+ executeActionOnElement() {
875
+ this.element?.dispatchEvent(new KeyboardEvent("keydown", {
876
+ altKey: !1,
877
+ code: "Enter",
878
+ ctrlKey: !1,
879
+ isComposing: !1,
880
+ key: "Enter",
881
+ location: 0,
882
+ metaKey: !1,
883
+ repeat: !1,
884
+ shiftKey: !1,
885
+ which: 13,
886
+ charCode: 0,
887
+ keyCode: 13
888
+ }));
889
+ }
890
+ getDescription() {
891
+ return `Press Enter key in ${this.getElementName()}`;
892
+ }
893
+ getJSON() {
894
+ return {
895
+ ...super.getJSON(),
896
+ type: "PressEnterKey"
897
+ };
898
+ }
899
+ }, H = /* @__PURE__ */ function(e) {
900
+ return e.ESCAPE = "Escape", e.ENTER = "Enter", e.TAB = "Tab", e.ARROW_DOWN = "ArrowDown", e.ARROW_UP = "ArrowUp", e.ARROW_LEFT = "ArrowLeft", e.ARROW_RIGHT = "ArrowRight", e.BACKSPACE = "Backspace", e.DELETE = "Delete", e.SHIFT = "Shift", e.CONTROL = "Control", e.ALT = "Alt", e.META = "Meta", e;
901
+ }(H || {}), U = {
902
+ [H.ESCAPE]: 27,
903
+ [H.ENTER]: 13,
904
+ [H.TAB]: 9,
905
+ [H.ARROW_DOWN]: 40,
906
+ [H.ARROW_UP]: 38,
907
+ [H.ARROW_LEFT]: 37,
908
+ [H.ARROW_RIGHT]: 39,
909
+ [H.BACKSPACE]: 8,
910
+ [H.DELETE]: 46,
911
+ [H.SHIFT]: 16,
912
+ [H.CONTROL]: 17,
913
+ [H.ALT]: 18,
914
+ [H.META]: 91
915
+ }, Se = class extends B {
916
+ key;
917
+ constructor(e, t) {
918
+ super(e), this.key = t;
919
+ }
920
+ executeActionOnElement() {
921
+ this.element?.dispatchEvent(new KeyboardEvent("keydown", {
922
+ key: this.key,
923
+ code: this.key,
924
+ keyCode: U[this.key],
925
+ charCode: 0,
926
+ which: U[this.key],
927
+ altKey: !1,
928
+ ctrlKey: !1,
929
+ metaKey: !1,
930
+ shiftKey: !1,
931
+ isComposing: !1,
932
+ location: 0,
933
+ repeat: !1
934
+ }));
935
+ }
936
+ getDescription() {
937
+ return `Press ${this.key} key in ${this.getElementName()}`;
938
+ }
939
+ getJSON() {
940
+ return {
941
+ ...super.getJSON(),
942
+ type: "PressKey",
943
+ key: this.key
944
+ };
945
+ }
946
+ }, Ce = class extends B {
947
+ file;
948
+ constructor(e, t) {
949
+ super(e), this.file = t;
950
+ }
951
+ executeActionOnElement() {
952
+ let e = this.element, t = new DataTransfer();
953
+ t.items.add(this.file), e.files = t.files, e.dispatchEvent(new Event("change"));
954
+ function n(e) {
955
+ return e?.parentElement ? e.parentElement?.tagName.toLowerCase() === "form" ? e.parentElement : n(e.parentElement) : null;
956
+ }
957
+ let r = n(e);
958
+ r && r.dispatchEvent(new Event("change"));
959
+ }
960
+ getDescription() {
961
+ return `Upload file in ${this.getElementName()}`;
962
+ }
963
+ getJSON() {
964
+ return {
965
+ ...super.getJSON(),
966
+ type: "UploadFile"
967
+ };
968
+ }
969
+ }, we = class extends B {
970
+ memorySlotName;
971
+ constructor(e, t) {
972
+ super(e), this.memorySlotName = t;
973
+ }
974
+ executeActionOnElement() {
975
+ let e = this.element;
976
+ if (this.element?.tagName !== "INPUT" && this.element?.tagName !== "SELECT" && this.element?.tagName !== "TEXTAREA" && (e = this.element?.querySelectorAll("input")[0], !e)) throw Error("Input element not found. Not able to save value from element " + this.getElementName());
977
+ y.dispatch(v.SAVE_VALUE, {
978
+ memorySlotName: this.memorySlotName,
979
+ value: e.value
980
+ });
981
+ }
982
+ getDescription() {
983
+ return `Save value of ${this.getElementName()} in ${this.memorySlotName}`;
984
+ }
985
+ getJSON() {
986
+ return {
987
+ ...super.getJSON(),
988
+ type: "SaveValue",
989
+ memorySlotName: this.memorySlotName
990
+ };
991
+ }
992
+ }, Te = class extends R {
993
+ miliseconds;
994
+ constructor(e) {
995
+ super(), this.miliseconds = e;
996
+ }
997
+ getDescription() {
998
+ return "Wait " + this.miliseconds + " miliseconds";
999
+ }
1000
+ getJSON() {
1001
+ return {
1002
+ ...super.getJSON(),
1003
+ type: "Wait"
1004
+ };
1005
+ }
1006
+ async executeAction() {
1007
+ await S(this.miliseconds);
1008
+ }
1009
+ resetAction() {}
1010
+ }, Ee = class extends R {
1011
+ uiElement;
1012
+ tries;
1013
+ constructor(e) {
1014
+ super(), this.uiElement = e, this.tries = 0;
1015
+ }
1016
+ updateTries(e) {
1017
+ this.tries = e;
1018
+ }
1019
+ resetAction() {
1020
+ this.tries = 0;
1021
+ }
1022
+ getElementName() {
1023
+ return this.uiElement?.getElementName();
1024
+ }
1025
+ async executeAction() {
1026
+ await I(this, this.uiElement, 1e3, 10, !0);
1027
+ }
1028
+ getDescription() {
1029
+ return "Wait until " + this.getElementName() + " is removed";
1030
+ }
1031
+ getJSON() {
1032
+ return {
1033
+ ...super.getJSON(),
1034
+ type: "WaitUntilElementRemoved"
1035
+ };
1036
+ }
1037
+ }, De = class extends R {
1038
+ constructor() {
1039
+ super();
1040
+ }
1041
+ getDescription() {
1042
+ return "Paused";
1043
+ }
1044
+ getJSON() {
1045
+ return {
1046
+ ...super.getJSON(),
1047
+ type: "Pause"
1048
+ };
1049
+ }
1050
+ async executeAction() {
1051
+ await O.pause();
1052
+ }
1053
+ resetAction() {}
1054
+ }, Oe = class extends R {
1055
+ description;
1056
+ constructor(e) {
1057
+ super(), this.description = e;
1058
+ }
1059
+ getDescription() {
1060
+ return "Manual Step: " + this.description;
1061
+ }
1062
+ getJSON() {
1063
+ return {
1064
+ ...super.getJSON(),
1065
+ type: "ManualStep"
1066
+ };
1067
+ }
1068
+ async executeAction() {
1069
+ return await O.uiUtils.showAlert("Waiting manual step..."), new Promise((e, t) => {
1070
+ y.on(v.USER_ACCEPT, async () => (await O.uiUtils.hideAlert(), e(!0))), y.on(v.USER_REJECT, async () => (await O.uiUtils.hideAlert(), t()));
1071
+ });
1072
+ }
1073
+ resetAction() {}
1074
+ }, ke = class extends R {
1075
+ constructor() {
1076
+ super();
1077
+ }
1078
+ getDescription() {
1079
+ return "Reload page";
1080
+ }
1081
+ getJSON() {
1082
+ return {
1083
+ ...super.getJSON(),
1084
+ type: "ReloadPage"
1085
+ };
1086
+ }
1087
+ async executeAction() {
1088
+ await location.reload();
1089
+ }
1090
+ resetAction() {}
1091
+ }, W, G, K = {
1092
+ init: (e) => {
1093
+ W = e, G = !0, x.groupCollapsed("Compile: " + e.getDescription()), e.compileSteps(), G = !1, x.log("Compilation finished"), x.groupEnd();
1094
+ },
1095
+ addAction: (e) => {
1096
+ x.log("Add action: ", e.getDescription()), W.addStep(e);
1097
+ },
1098
+ compileAction: (e) => {
1099
+ let t = W;
1100
+ W = e, e.compileSteps(), W = t;
1101
+ },
1102
+ getCurrentAction: () => W,
1103
+ getIsCompiling: () => G
1104
+ }, q = {}, Ae = (e) => {
1105
+ if (q[e]) q[e]();
1106
+ else throw console.log("Available Tests:", Object.keys(q)), Error(`Test with id ${e} not found.`);
1107
+ }, je = (e, t) => {
1108
+ console.log(`Registering Test: ${e}...`);
1109
+ let n = new z(e, t);
1110
+ K.init(n), console.log(`Compiled Test: ${e}`), y.dispatch(v.REGISTER_TEST, {
1111
+ id: e,
1112
+ action: n.getJSON()
1113
+ }), console.log(`Registered Test: ${e} in TestsMap`), q[e] = () => {
1114
+ j.start(n);
1115
+ };
1229
1116
  };
1230
- i(y, "currentAction"), i(y, "isCompiling");
1231
- let h = y;
1232
- var T = /* @__PURE__ */ ((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.TEST_PAUSE = "tomation-test-pause", t.TEST_PLAY = "tomation-test-play", t.USER_ACCEPT = "tomation-user-accept", t.USER_REJECT = "tomation-user-reject", t.SESSION_INIT = "tomation-session-init", t.ACTION_ERROR = "tomation-action-error", t))(T || {});
1233
- class ze {
1234
- constructor() {
1235
- i(this, "events");
1236
- this.events = /* @__PURE__ */ new Map();
1237
- }
1238
- on(e, n) {
1239
- var s;
1240
- this.events.has(e) || this.events.set(e, []), (s = this.events.get(e)) == null || s.push(n);
1241
- }
1242
- off(e, n) {
1243
- var s;
1244
- this.events.has(e) && this.events.set(e, ((s = this.events.get(e)) == null ? void 0 : s.filter((o) => o !== n)) || []);
1245
- }
1246
- dispatch(e, n) {
1247
- var s;
1248
- this.events.has(e) && ((s = this.events.get(e)) == null || s.forEach((o) => {
1249
- console.log(`Dispatch Event ${e}:`, n), o(n);
1250
- }));
1251
- }
1252
- }
1253
- const m = new ze();
1254
- var ee = /* @__PURE__ */ ((t) => (t[t.SLOW = 2e3] = "SLOW", t[t.NORMAL = 1e3] = "NORMAL", t[t.FAST = 200] = "FAST", t))(ee || {});
1255
- class te {
1256
- static async start(e) {
1257
- if (c.status !== "Stopped")
1258
- throw u.error("Not able to run test while other test is running."), new Error("Not able to run test while other test is running.");
1259
- c.status = "Playing", c.runMode = "Normal", u.groupCollapsed("Start Action: ", e.getDescription()), m.dispatch("tomation-test-started", {
1260
- action: e == null ? void 0 : e.getJSON()
1261
- });
1262
- try {
1263
- await (e == null ? void 0 : e.execute()), m.dispatch("tomation-test-passed", { id: e.name }), c.status = "Stopped";
1264
- } catch (n) {
1265
- throw m.dispatch("tomation-test-failed", { id: e.name }), c.uiUtils.hideCheckElementContainer(), u.error(`🤖 Error running task ${e.getDescription()}. Reason: ${n.message}`), c.status = "Paused", n;
1266
- } finally {
1267
- u.groupEnd(), m.dispatch("tomation-test-end", {
1268
- action: e == null ? void 0 : e.getJSON()
1269
- });
1270
- }
1271
- }
1272
- }
1273
- const P = {}, dt = (t, e) => {
1274
- console.log(`Registering Test: ${t}...`);
1275
- const n = new Z(t, e);
1276
- m.dispatch("tomation-register-test", { id: t }), console.log(`Registered Test: ${t} in TestsMap`), P[t] = () => {
1277
- u.log(`Compilation of Test ${t} starts...`), h.init(n), u.log(`Compilation of Test ${t} Finished.`), u.log(`Start running Test ${t}...`), te.start(n);
1278
- };
1279
- }, Ge = (t) => {
1280
- if (P[t])
1281
- P[t]();
1282
- else
1283
- throw console.log("Available Tests:", Object.keys(P)), new Error(`Test with id ${t} not found.`);
1284
- }, pt = (t, e) => async (n) => {
1285
- const s = new Z(t, e);
1286
- if (s.setParams(n), c.status == "Stopped" && !h.isCompiling)
1287
- try {
1288
- u.log(`Compilation of Task ${t} starts...`), h.init(s), u.log(`Compilation of Task ${t} Finished.`), u.log(`Start running Task ${t}...`), await te.start(s), u.log(`End of Task ${t}: SUCCESS`);
1289
- } catch (o) {
1290
- u.error("Error running task " + t + ". " + o.message);
1291
- }
1292
- else
1293
- u.log(`Adding action ${t} to compilation stack`), h.addAction(s), h.compileAction(s);
1294
- }, mt = (t) => {
1295
- const e = new we(t);
1296
- h.addAction(e);
1297
- }, gt = (t) => ({
1298
- textIs: (e) => {
1299
- h.addAction(new fe(t, e));
1300
- },
1301
- containsText: (e) => {
1302
- h.addAction(new Ae(t, e));
1303
- },
1304
- valueIs: (e) => {
1305
- h.addAction(new xe(t, e));
1306
- },
1307
- exists: () => {
1308
- h.addAction(new Ce(t));
1309
- },
1310
- notExists: () => {
1311
- h.addAction(new Se(t));
1312
- }
1313
- }), yt = (t) => ({
1314
- in: (e) => {
1315
- const n = new ke(e, t);
1316
- h.addAction(n);
1317
- }
1318
- }), Et = (t) => ({
1319
- in: (e) => {
1320
- const n = new Y(e, t);
1321
- h.addAction(n);
1322
- }
1323
- }), wt = () => ({
1324
- in: (t) => {
1325
- const e = new Y(t, "");
1326
- h.addAction(e);
1327
- }
1328
- }), ft = () => ({
1329
- in: (t) => {
1330
- h.addAction(new ve(t));
1331
- }
1332
- }), At = () => ({
1333
- in: (t) => {
1334
- h.addAction(new Ne(t));
1335
- }
1336
- }), xt = () => ({
1337
- in: (t) => {
1338
- h.addAction(new be(t));
1339
- }
1340
- }), Ct = () => ({
1341
- in: (t) => {
1342
- h.addAction(new Oe(t));
1343
- }
1344
- }), St = (t) => ({
1345
- in: (e) => {
1346
- h.addAction(new Ie(e, t));
1347
- }
1348
- }), kt = (t) => ({
1349
- in: (e) => {
1350
- const n = new Te(e, t);
1351
- h.addAction(n);
1352
- }
1353
- }), Tt = (t) => ({
1354
- in: (e) => {
1355
- const n = new Le(e, t);
1356
- h.addAction(n);
1357
- }
1358
- }), vt = (t) => ({
1359
- in: (e) => {
1360
- const n = new Pe(t, e);
1361
- h.addAction(n);
1362
- }
1363
- }), Qe = (t) => {
1364
- h.addAction(new $e(t));
1365
- };
1366
- Qe.untilElement = (t) => ({
1367
- isRemoved: () => {
1368
- h.addAction(new Ue(t));
1369
- }
1370
- });
1371
- const Nt = () => {
1372
- h.addAction(new Re());
1373
- }, bt = (t) => {
1374
- h.addAction(new Je(t));
1375
- }, Ot = () => {
1376
- h.addAction(new Ve());
1377
- }, Dt = (t, e) => ({
1378
- then: (n) => ({
1379
- else: (s) => {
1380
- const o = new Ke(e, n, s, t);
1381
- h.addAction(o);
1382
- }
1383
- })
1384
- });
1385
- class Ze {
1386
- constructor(e) {
1387
- i(this, "_document");
1388
- i(this, "debug");
1389
- i(this, "_uiUtils");
1390
- i(this, "speed");
1391
- i(this, "status");
1392
- i(this, "runMode");
1393
- i(this, "currentActionCallback");
1394
- i(this, "currentAction");
1395
- this._document = e.document, this.debug = !0, this._uiUtils = new Ee(e), this.speed = 1e3, this.status = "Stopped", this.runMode = "Normal";
1396
- }
1397
- get document() {
1398
- return this._document;
1399
- }
1400
- get uiUtils() {
1401
- return this._uiUtils;
1402
- }
1403
- get isStepByStepMode() {
1404
- return this.runMode == "Step By Step";
1405
- }
1406
- get isStopped() {
1407
- return this.status == "Stopped";
1408
- }
1409
- get isPlaying() {
1410
- return this.status == "Playing";
1411
- }
1412
- get isPaused() {
1413
- return this.status == "Paused";
1414
- }
1415
- pause() {
1416
- u.log("Pause Test"), this.status = "Paused", m.dispatch(
1417
- "tomation-test-pause"
1418
- /* TEST_PAUSE */
1419
- );
1420
- }
1421
- continue() {
1422
- u.log("Continue Test"), this.status = "Playing", this.runMode = "Normal", m.dispatch(
1423
- "tomation-test-play"
1424
- /* TEST_PLAY */
1425
- ), this.currentActionCallback && this.currentAction && (u.log("Continue: Executing current action callback"), this.currentActionCallback(this.currentAction), this.currentActionCallback = void 0);
1426
- }
1427
- next() {
1428
- u.log("Continue Test to Next Step..."), this.status = "Paused", this.runMode = "Step By Step", this.currentActionCallback && this.currentAction && (u.log("Next: Executing current action callback"), this.currentActionCallback(this.currentAction), this.currentActionCallback = void 0);
1429
- }
1430
- stop() {
1431
- u.log("Stop Test"), this.status = "Stopped", this.currentActionCallback && this.currentAction && (u.log("Stop: Executing current action callback"), this.currentActionCallback(this.currentAction), this.currentActionCallback = void 0), m.dispatch(
1432
- "tomation-test-stop"
1433
- /* TEST_STOP */
1434
- );
1435
- }
1436
- retryAction() {
1437
- u.log("Retry current step"), this.status = "Playing", m.dispatch(
1438
- "tomation-test-play"
1439
- /* TEST_PLAY */
1440
- ), this.currentActionCallback && this.currentAction && (this.currentAction.resetTries && (u.log("Retry: Resetting tries for current action"), this.currentAction.resetTries()), u.log("Retry: Executing current action callback"), this.currentActionCallback(this.currentAction), this.currentActionCallback = void 0);
1441
- }
1442
- skipAction() {
1443
- u.log("Skip current step"), this.status = "Playing", this.currentActionCallback && this.currentAction && (this.currentAction.status = Q.SKIPPED, u.log("Skip: Marked current action as SKIPPED"), E.notifyActionUpdated(this.currentAction), u.log("Skip: Executing current action callback"), this.currentActionCallback(this.currentAction), this.currentActionCallback = void 0);
1444
- }
1445
- saveCurrentAction(e, n) {
1446
- u.log("Save current action"), this.currentActionCallback = e, this.currentAction = n;
1447
- }
1448
- setDebug(e) {
1449
- Xe(e);
1450
- }
1451
- }
1452
- let c;
1453
- const H = (t, e) => (c = new Ze(t), ie(c.document), e == null || e.forEach((n) => n()), c);
1454
- function It(t) {
1455
- const {
1456
- matches: e,
1457
- tests: n = [],
1458
- speed: s = "NORMAL",
1459
- debug: o = !1
1460
- } = t;
1461
- if (!(typeof e == "string" ? document.location.href.includes(e) : !!document.location.href.match(e))) {
1462
- console.log(`[tomation] URL "${document.location.href}" does not match "${e}"`);
1463
- return;
1464
- }
1465
- try {
1466
- console.log("[tomation] Setting up messaging bridge with extension..."), Object.values(T).forEach((r) => {
1467
- console.log(`[tomation] Setting up listener for event "${r}"`), m.on(r, (l) => {
1468
- console.log(`[tomation] Dispatching event "${r}" to extension`, l), window.postMessage({
1469
- message: "injectedScript-to-contentScript",
1470
- sender: "tomation",
1471
- payload: {
1472
- cmd: r,
1473
- params: l
1474
- }
1475
- });
1476
- });
1477
- }), window.addEventListener("message", (r) => {
1478
- try {
1479
- console.log("[tomation] Received message from extension:", r.data);
1480
- const { message: l, sender: w, payload: C } = r.data || {}, { cmd: g, params: k } = C || {};
1481
- if (w !== "web-extension")
1482
- return;
1483
- if (l === "contentScript-to-injectedScript") {
1484
- const v = {
1485
- "run-test-request": () => Ge(k == null ? void 0 : k.testId),
1486
- "reload-tests-request": () => H(window, n || []),
1487
- "pause-test-request": () => c.pause(),
1488
- "stop-test-request": () => c.stop(),
1489
- "continue-test-request": () => c.continue(),
1490
- "next-step-request": () => c.next(),
1491
- "retry-action-request": () => c.retryAction(),
1492
- "skip-action-request": () => c.skipAction(),
1493
- "user-accept-request": () => m.dispatch(
1494
- "tomation-user-accept"
1495
- /* USER_ACCEPT */
1496
- ),
1497
- "user-reject-request": () => m.dispatch(
1498
- "tomation-user-reject"
1499
- /* USER_REJECT */
1500
- )
1501
- }[g];
1502
- v ? (console.log(`[tomation] Executing command "${g}" from extension`), v()) : console.warn(`[tomation] Unknown command "${g}" from extension`);
1503
- return;
1504
- }
1505
- } catch (l) {
1506
- console.error("[tomation] Error handling message from extension:", l);
1507
- }
1508
- }), window.postMessage({
1509
- message: "injectedScript-to-contentScript",
1510
- sender: "tomation",
1511
- payload: {
1512
- cmd: "tomation-session-init",
1513
- params: {
1514
- sessionId: G()
1515
- }
1516
- }
1517
- }), H(window, n), c.setDebug(o), c.speed = ee[s], console.log("[tomation] Ready ✓");
1518
- } catch (r) {
1519
- console.error("[tomation] Initialization failed:", r);
1520
- }
1117
+ //#endregion
1118
+ //#region src/tomation.ts
1119
+ function J(e) {
1120
+ let { matches: t, tests: n = [], speed: r = "NORMAL", debug: i = !1 } = e, a = N();
1121
+ if (console.log(`[tomation] Initializing on URL: ${document.location.href} with session ID: ${a}`), window.postMessage({
1122
+ message: "injectedScript-to-contentScript",
1123
+ sender: "tomation",
1124
+ payload: {
1125
+ cmd: v.SESSION_INIT,
1126
+ params: { sessionId: a }
1127
+ }
1128
+ }), !(typeof t == "string" ? document.location.href.includes(t) : document.location.href.match(t))) {
1129
+ console.log(`[tomation] URL "${document.location.href}" does not match "${t}"`), window.postMessage({
1130
+ message: "injectedScript-to-contentScript",
1131
+ sender: "tomation",
1132
+ payload: {
1133
+ cmd: v.URL_MISMATCH,
1134
+ params: {
1135
+ sessionId: a,
1136
+ matches: t,
1137
+ url: document.location.href
1138
+ }
1139
+ }
1140
+ });
1141
+ return;
1142
+ }
1143
+ try {
1144
+ console.log("[tomation] Setting up messaging bridge with extension..."), Object.values(v).forEach((e) => {
1145
+ console.log(`[tomation] Setting up listener for event "${e}"`), y.on(e, (t) => {
1146
+ let n = {
1147
+ cmd: e,
1148
+ params: {
1149
+ ...t,
1150
+ sessionId: a
1151
+ }
1152
+ };
1153
+ console.log(`[tomation] Dispatching event "${e}" to extension: `, n), window.postMessage({
1154
+ message: "injectedScript-to-contentScript",
1155
+ sender: "tomation",
1156
+ payload: n
1157
+ });
1158
+ });
1159
+ }), window.addEventListener("message", (e) => {
1160
+ try {
1161
+ console.log("[tomation] Received message from extension:", e.data);
1162
+ let { message: t, sender: r, payload: i } = e.data || {}, { cmd: a, params: o } = i || {};
1163
+ if (r !== "web-extension") return;
1164
+ if (t === "contentScript-to-injectedScript") {
1165
+ let e = {
1166
+ "run-test-request": () => Ae(o?.testId),
1167
+ "reload-tests-request": () => k(window, n || []),
1168
+ "pause-test-request": () => O.pause(),
1169
+ "stop-test-request": () => O.stop(),
1170
+ "continue-test-request": () => O.continue(),
1171
+ "next-step-request": () => O.next(),
1172
+ "retry-action-request": () => O.retryAction(),
1173
+ "skip-action-request": () => O.skipAction(),
1174
+ "user-accept-request": () => y.dispatch(v.USER_ACCEPT),
1175
+ "user-reject-request": () => y.dispatch(v.USER_REJECT)
1176
+ }[a];
1177
+ e ? (console.log(`[tomation] Executing command "${a}" from extension`), e()) : console.warn(`[tomation] Unknown command "${a}" from extension`);
1178
+ return;
1179
+ }
1180
+ } catch (e) {
1181
+ console.error("[tomation] Error handling message from extension:", e);
1182
+ }
1183
+ }), k(window, n), O.setDebug(i), O.speed = T[r], window.postMessage({
1184
+ message: "injectedScript-to-contentScript",
1185
+ sender: "tomation",
1186
+ payload: {
1187
+ cmd: v.SESSION_CONNECTED,
1188
+ params: {
1189
+ speed: O.speed,
1190
+ sessionId: a
1191
+ }
1192
+ }
1193
+ }), console.log("[tomation] Ready ✓");
1194
+ } catch (e) {
1195
+ console.error("[tomation] Initialization failed:", e);
1196
+ }
1521
1197
  }
1522
- export {
1523
- Q as ACTION_STATUS,
1524
- gt as Assert,
1525
- m as AutomationEvents,
1526
- c as AutomationInstance,
1527
- wt as ClearValue,
1528
- mt as Click,
1529
- ht as DateUtils,
1530
- T as EVENT_NAMES,
1531
- Dt as If,
1532
- De as KEY_MAP,
1533
- bt as ManualTask,
1534
- Nt as Pause,
1535
- At as PressDownKey,
1536
- Ct as PressEnterKey,
1537
- ft as PressEscKey,
1538
- St as PressKey,
1539
- xt as PressTabKey,
1540
- Ot as ReloadPage,
1541
- Ge as RunTest,
1542
- vt as SaveValue,
1543
- yt as Select,
1544
- j as SelectorBuilder,
1545
- H as Setup,
1546
- pt as Task,
1547
- dt as Test,
1548
- ee as TestSpeed,
1549
- Et as Type,
1550
- kt as TypePassword,
1551
- oe as UIElement,
1552
- Tt as UploadFile,
1553
- Qe as Wait,
1554
- lt as and,
1555
- tt as classIncludes,
1556
- et as classIs,
1557
- It as default,
1558
- at as elementIndexIs,
1559
- ct as firstChildTextIs,
1560
- st as innerTextContains,
1561
- nt as innerTextIs,
1562
- ut as is,
1563
- rt as isFirstElement,
1564
- it as placeholderIs,
1565
- Xe as setAutomationLogs,
1566
- _e as setFilterLogs,
1567
- ot as titleIs,
1568
- It as tomation,
1569
- f as wait
1198
+ //#endregion
1199
+ //#region src/dsl/task.ts
1200
+ var Me = (e, t) => async (n) => {
1201
+ let r = new z(e, t);
1202
+ if (r.setParams(n), !j.running && !K.getIsCompiling()) try {
1203
+ x.log(`Compilation of Task ${e} starts...`), K.init(r), x.log(`Compilation of Task ${e} Finished.`), x.log(`Start running Task ${e}...`), await j.start(r), x.log(`End of Task ${e}: SUCCESS`);
1204
+ } catch (t) {
1205
+ x.error("Error running task " + e + ". " + t.message);
1206
+ }
1207
+ else x.log(`Adding action ${e} to compilation stack`), K.addAction(r), K.compileAction(r);
1208
+ }, Ne = (e) => {
1209
+ let t = new ue(e);
1210
+ K.addAction(t);
1211
+ }, Pe = (e) => ({
1212
+ textIs: (t) => {
1213
+ K.addAction(new de(e, t));
1214
+ },
1215
+ containsText: (t) => {
1216
+ K.addAction(new fe(e, t));
1217
+ },
1218
+ valueIs: (t) => {
1219
+ K.addAction(new pe(e, t));
1220
+ },
1221
+ exists: () => {
1222
+ K.addAction(new me(e));
1223
+ },
1224
+ notExists: () => {
1225
+ K.addAction(new he(e));
1226
+ }
1227
+ }), Fe = (e) => ({ in: (t) => {
1228
+ let n = new ge(t, e);
1229
+ K.addAction(n);
1230
+ } }), Ie = (e) => ({ in: (t) => {
1231
+ let n = new V(t, e);
1232
+ K.addAction(n);
1233
+ } }), Le = () => ({ in: (e) => {
1234
+ let t = new V(e, "");
1235
+ K.addAction(t);
1236
+ } }), Re = () => ({ in: (e) => {
1237
+ K.addAction(new ve(e));
1238
+ } }), ze = () => ({ in: (e) => {
1239
+ K.addAction(new ye(e));
1240
+ } }), Be = () => ({ in: (e) => {
1241
+ K.addAction(new be(e));
1242
+ } }), Ve = () => ({ in: (e) => {
1243
+ K.addAction(new xe(e));
1244
+ } }), He = (e) => ({ in: (t) => {
1245
+ K.addAction(new Se(t, e));
1246
+ } }), Ue = (e) => ({ in: (t) => {
1247
+ let n = new _e(t, e);
1248
+ K.addAction(n);
1249
+ } }), We = (e) => ({ in: (t) => {
1250
+ let n = new Ce(t, e);
1251
+ K.addAction(n);
1252
+ } }), Ge = (e) => ({ in: (t) => {
1253
+ let n = new we(e, t);
1254
+ K.addAction(n);
1255
+ } }), Y = (e) => {
1256
+ K.addAction(new Te(e));
1570
1257
  };
1258
+ Y.untilElement = (e) => ({ isRemoved: () => {
1259
+ K.addAction(new Ee(e));
1260
+ } });
1261
+ var Ke = () => {
1262
+ K.addAction(new De());
1263
+ }, qe = (e) => {
1264
+ K.addAction(new Oe(e));
1265
+ }, X = () => {
1266
+ K.addAction(new ke());
1267
+ }, Z = (e) => e.toLocaleDateString("en-US", {
1268
+ year: "numeric",
1269
+ month: "2-digit",
1270
+ day: "2-digit"
1271
+ }), Q = (e) => {
1272
+ let t = /* @__PURE__ */ new Date();
1273
+ return Z(new Date(t.setDate(t.getDate() + e)));
1274
+ }, $ = (e) => {
1275
+ let t = /* @__PURE__ */ new Date();
1276
+ return Z(new Date(t.setMonth(t.getMonth() + e)));
1277
+ }, Je = Q(1), Ye = Q(-1), Xe = Q(7), Ze = Q(-7), Qe = $(1), $e = $(-1), et = {
1278
+ formatDate: Z,
1279
+ today: Z(/* @__PURE__ */ new Date()),
1280
+ tomorrow: Je,
1281
+ nextWeek: Xe,
1282
+ nextMonth: Qe,
1283
+ yesterday: Ye,
1284
+ lastWeek: Ze,
1285
+ lastMonth: $e
1286
+ }, tt = J;
1287
+ //#endregion
1288
+ export { L as ACTION_STATUS, Pe as Assert, y as AutomationEvents, O as AutomationInstance, Le as ClearValue, Ne as Click, et as DateUtils, v as EVENT_NAMES, H as KEY_MAP, qe as ManualTask, Ke as Pause, ze as PressDownKey, Ve as PressEnterKey, Re as PressEscKey, He as PressKey, Be as PressTabKey, X as ReloadPage, Ge as SaveValue, Fe as Select, k as Setup, Me as Task, je as Test, T as TestSpeed, Ie as Type, Ue as TypePassword, f as UIElement, We as UploadFile, Y as Wait, d as and, r as classIncludes, n as classIs, tt as default, l as elementIndexIs, u as firstChildTextIs, a as innerTextContains, i as innerTextIs, ne as is, c as isFirstElement, s as placeholderIs, o as titleIs, J as tomation, S as wait };