tomation 0.0.11 → 0.0.13

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