@midscene/web 0.2.2 → 0.2.3-beta-20240815082813.0

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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/dist/es/index.js +395 -82
  3. package/dist/es/playwright-report.js +313 -2288
  4. package/dist/lib/index.js +374 -81
  5. package/dist/lib/playwright-report.js +312 -2280
  6. package/dist/script/htmlElement.js +9 -6
  7. package/dist/types/index.d.ts +14 -9
  8. package/package.json +3 -4
  9. package/dist/visualizer-report/index.html +0 -1
  10. package/dist/visualizer-report/modern.config.json +0 -196
  11. package/dist/visualizer-report/route.json +0 -36
  12. package/dist/visualizer-report/static/css/index.ce838015.css +0 -1
  13. package/dist/visualizer-report/static/css/index.ce838015.css.map +0 -1
  14. package/dist/visualizer-report/static/js/43.c54711bc.js +0 -6
  15. package/dist/visualizer-report/static/js/43.c54711bc.js.LICENSE.txt +0 -107
  16. package/dist/visualizer-report/static/js/43.c54711bc.js.map +0 -1
  17. package/dist/visualizer-report/static/js/async/16.8b96d0ce.js +0 -151
  18. package/dist/visualizer-report/static/js/async/16.8b96d0ce.js.map +0 -1
  19. package/dist/visualizer-report/static/js/async/212.b25a2c30.js +0 -157
  20. package/dist/visualizer-report/static/js/async/212.b25a2c30.js.map +0 -1
  21. package/dist/visualizer-report/static/js/async/353.78fcb703.js +0 -147
  22. package/dist/visualizer-report/static/js/async/353.78fcb703.js.map +0 -1
  23. package/dist/visualizer-report/static/js/async/399.84fa60a7.js +0 -248
  24. package/dist/visualizer-report/static/js/async/399.84fa60a7.js.map +0 -1
  25. package/dist/visualizer-report/static/js/async/453.782b249a.js +0 -41
  26. package/dist/visualizer-report/static/js/async/453.782b249a.js.map +0 -1
  27. package/dist/visualizer-report/static/js/async/544.ee973964.js +0 -1
  28. package/dist/visualizer-report/static/js/async/544.ee973964.js.map +0 -1
  29. package/dist/visualizer-report/static/js/async/983.ef821e39.js +0 -1
  30. package/dist/visualizer-report/static/js/index.013f8b6a.js +0 -1
  31. package/dist/visualizer-report/static/js/index.013f8b6a.js.map +0 -1
  32. package/dist/visualizer-report/static/js/lib-antd.583c9200.js +0 -141
  33. package/dist/visualizer-report/static/js/lib-antd.583c9200.js.map +0 -1
  34. package/dist/visualizer-report/static/js/lib-polyfill.3da3e38e.js +0 -1
  35. package/dist/visualizer-report/static/js/lib-polyfill.3da3e38e.js.map +0 -1
  36. package/dist/visualizer-report/static/js/lib-react.c011fc71.js +0 -2
  37. package/dist/visualizer-report/static/js/lib-react.c011fc71.js.LICENSE.txt +0 -39
  38. package/dist/visualizer-report/static/js/lib-react.c011fc71.js.map +0 -1
  39. package/dist/visualizer-report/static/js/lib-router.226970ff.js +0 -2
  40. package/dist/visualizer-report/static/js/lib-router.226970ff.js.LICENSE.txt +0 -32
  41. package/dist/visualizer-report/static/js/lib-router.226970ff.js.map +0 -1
package/dist/lib/index.js CHANGED
@@ -22,6 +22,9 @@ var __spreadValues = (a, b) => {
22
22
  return a;
23
23
  };
24
24
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __commonJS = (cb, mod) => function __require() {
26
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
27
+ };
25
28
  var __export = (target, all) => {
26
29
  for (var name in all)
27
30
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -44,6 +47,301 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
44
47
  ));
45
48
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
49
 
50
+ // ../../node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/dayjs.min.js
51
+ var require_dayjs_min = __commonJS({
52
+ "../../node_modules/.pnpm/dayjs@1.11.11/node_modules/dayjs/dayjs.min.js"(exports, module2) {
53
+ "use strict";
54
+ !function(t, e) {
55
+ "object" == typeof exports && "undefined" != typeof module2 ? module2.exports = e() : "function" == typeof define && define.amd ? define(e) : (t = "undefined" != typeof globalThis ? globalThis : t || self).dayjs = e();
56
+ }(exports, function() {
57
+ "use strict";
58
+ var t = 1e3, e = 6e4, n = 36e5, r = "millisecond", i = "second", s = "minute", u = "hour", a = "day", o = "week", c = "month", f = "quarter", h = "year", d = "date", l = "Invalid Date", $ = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, y = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, M = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function(t2) {
59
+ var e2 = ["th", "st", "nd", "rd"], n2 = t2 % 100;
60
+ return "[" + t2 + (e2[(n2 - 20) % 10] || e2[n2] || e2[0]) + "]";
61
+ } }, m = function(t2, e2, n2) {
62
+ var r2 = String(t2);
63
+ return !r2 || r2.length >= e2 ? t2 : "" + Array(e2 + 1 - r2.length).join(n2) + t2;
64
+ }, v = { s: m, z: function(t2) {
65
+ var e2 = -t2.utcOffset(), n2 = Math.abs(e2), r2 = Math.floor(n2 / 60), i2 = n2 % 60;
66
+ return (e2 <= 0 ? "+" : "-") + m(r2, 2, "0") + ":" + m(i2, 2, "0");
67
+ }, m: function t2(e2, n2) {
68
+ if (e2.date() < n2.date())
69
+ return -t2(n2, e2);
70
+ var r2 = 12 * (n2.year() - e2.year()) + (n2.month() - e2.month()), i2 = e2.clone().add(r2, c), s2 = n2 - i2 < 0, u2 = e2.clone().add(r2 + (s2 ? -1 : 1), c);
71
+ return +(-(r2 + (n2 - i2) / (s2 ? i2 - u2 : u2 - i2)) || 0);
72
+ }, a: function(t2) {
73
+ return t2 < 0 ? Math.ceil(t2) || 0 : Math.floor(t2);
74
+ }, p: function(t2) {
75
+ return { M: c, y: h, w: o, d: a, D: d, h: u, m: s, s: i, ms: r, Q: f }[t2] || String(t2 || "").toLowerCase().replace(/s$/, "");
76
+ }, u: function(t2) {
77
+ return void 0 === t2;
78
+ } }, g = "en", D = {};
79
+ D[g] = M;
80
+ var p = "$isDayjsObject", S = function(t2) {
81
+ return t2 instanceof _ || !(!t2 || !t2[p]);
82
+ }, w = function t2(e2, n2, r2) {
83
+ var i2;
84
+ if (!e2)
85
+ return g;
86
+ if ("string" == typeof e2) {
87
+ var s2 = e2.toLowerCase();
88
+ D[s2] && (i2 = s2), n2 && (D[s2] = n2, i2 = s2);
89
+ var u2 = e2.split("-");
90
+ if (!i2 && u2.length > 1)
91
+ return t2(u2[0]);
92
+ } else {
93
+ var a2 = e2.name;
94
+ D[a2] = e2, i2 = a2;
95
+ }
96
+ return !r2 && i2 && (g = i2), i2 || !r2 && g;
97
+ }, O = function(t2, e2) {
98
+ if (S(t2))
99
+ return t2.clone();
100
+ var n2 = "object" == typeof e2 ? e2 : {};
101
+ return n2.date = t2, n2.args = arguments, new _(n2);
102
+ }, b = v;
103
+ b.l = w, b.i = S, b.w = function(t2, e2) {
104
+ return O(t2, { locale: e2.$L, utc: e2.$u, x: e2.$x, $offset: e2.$offset });
105
+ };
106
+ var _ = function() {
107
+ function M2(t2) {
108
+ this.$L = w(t2.locale, null, true), this.parse(t2), this.$x = this.$x || t2.x || {}, this[p] = true;
109
+ }
110
+ var m2 = M2.prototype;
111
+ return m2.parse = function(t2) {
112
+ this.$d = function(t3) {
113
+ var e2 = t3.date, n2 = t3.utc;
114
+ if (null === e2)
115
+ return /* @__PURE__ */ new Date(NaN);
116
+ if (b.u(e2))
117
+ return /* @__PURE__ */ new Date();
118
+ if (e2 instanceof Date)
119
+ return new Date(e2);
120
+ if ("string" == typeof e2 && !/Z$/i.test(e2)) {
121
+ var r2 = e2.match($);
122
+ if (r2) {
123
+ var i2 = r2[2] - 1 || 0, s2 = (r2[7] || "0").substring(0, 3);
124
+ return n2 ? new Date(Date.UTC(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2)) : new Date(r2[1], i2, r2[3] || 1, r2[4] || 0, r2[5] || 0, r2[6] || 0, s2);
125
+ }
126
+ }
127
+ return new Date(e2);
128
+ }(t2), this.init();
129
+ }, m2.init = function() {
130
+ var t2 = this.$d;
131
+ this.$y = t2.getFullYear(), this.$M = t2.getMonth(), this.$D = t2.getDate(), this.$W = t2.getDay(), this.$H = t2.getHours(), this.$m = t2.getMinutes(), this.$s = t2.getSeconds(), this.$ms = t2.getMilliseconds();
132
+ }, m2.$utils = function() {
133
+ return b;
134
+ }, m2.isValid = function() {
135
+ return !(this.$d.toString() === l);
136
+ }, m2.isSame = function(t2, e2) {
137
+ var n2 = O(t2);
138
+ return this.startOf(e2) <= n2 && n2 <= this.endOf(e2);
139
+ }, m2.isAfter = function(t2, e2) {
140
+ return O(t2) < this.startOf(e2);
141
+ }, m2.isBefore = function(t2, e2) {
142
+ return this.endOf(e2) < O(t2);
143
+ }, m2.$g = function(t2, e2, n2) {
144
+ return b.u(t2) ? this[e2] : this.set(n2, t2);
145
+ }, m2.unix = function() {
146
+ return Math.floor(this.valueOf() / 1e3);
147
+ }, m2.valueOf = function() {
148
+ return this.$d.getTime();
149
+ }, m2.startOf = function(t2, e2) {
150
+ var n2 = this, r2 = !!b.u(e2) || e2, f2 = b.p(t2), l2 = function(t3, e3) {
151
+ var i2 = b.w(n2.$u ? Date.UTC(n2.$y, e3, t3) : new Date(n2.$y, e3, t3), n2);
152
+ return r2 ? i2 : i2.endOf(a);
153
+ }, $2 = function(t3, e3) {
154
+ return b.w(n2.toDate()[t3].apply(n2.toDate("s"), (r2 ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(e3)), n2);
155
+ }, y2 = this.$W, M3 = this.$M, m3 = this.$D, v2 = "set" + (this.$u ? "UTC" : "");
156
+ switch (f2) {
157
+ case h:
158
+ return r2 ? l2(1, 0) : l2(31, 11);
159
+ case c:
160
+ return r2 ? l2(1, M3) : l2(0, M3 + 1);
161
+ case o:
162
+ var g2 = this.$locale().weekStart || 0, D2 = (y2 < g2 ? y2 + 7 : y2) - g2;
163
+ return l2(r2 ? m3 - D2 : m3 + (6 - D2), M3);
164
+ case a:
165
+ case d:
166
+ return $2(v2 + "Hours", 0);
167
+ case u:
168
+ return $2(v2 + "Minutes", 1);
169
+ case s:
170
+ return $2(v2 + "Seconds", 2);
171
+ case i:
172
+ return $2(v2 + "Milliseconds", 3);
173
+ default:
174
+ return this.clone();
175
+ }
176
+ }, m2.endOf = function(t2) {
177
+ return this.startOf(t2, false);
178
+ }, m2.$set = function(t2, e2) {
179
+ var n2, o2 = b.p(t2), f2 = "set" + (this.$u ? "UTC" : ""), l2 = (n2 = {}, n2[a] = f2 + "Date", n2[d] = f2 + "Date", n2[c] = f2 + "Month", n2[h] = f2 + "FullYear", n2[u] = f2 + "Hours", n2[s] = f2 + "Minutes", n2[i] = f2 + "Seconds", n2[r] = f2 + "Milliseconds", n2)[o2], $2 = o2 === a ? this.$D + (e2 - this.$W) : e2;
180
+ if (o2 === c || o2 === h) {
181
+ var y2 = this.clone().set(d, 1);
182
+ y2.$d[l2]($2), y2.init(), this.$d = y2.set(d, Math.min(this.$D, y2.daysInMonth())).$d;
183
+ } else
184
+ l2 && this.$d[l2]($2);
185
+ return this.init(), this;
186
+ }, m2.set = function(t2, e2) {
187
+ return this.clone().$set(t2, e2);
188
+ }, m2.get = function(t2) {
189
+ return this[b.p(t2)]();
190
+ }, m2.add = function(r2, f2) {
191
+ var d2, l2 = this;
192
+ r2 = Number(r2);
193
+ var $2 = b.p(f2), y2 = function(t2) {
194
+ var e2 = O(l2);
195
+ return b.w(e2.date(e2.date() + Math.round(t2 * r2)), l2);
196
+ };
197
+ if ($2 === c)
198
+ return this.set(c, this.$M + r2);
199
+ if ($2 === h)
200
+ return this.set(h, this.$y + r2);
201
+ if ($2 === a)
202
+ return y2(1);
203
+ if ($2 === o)
204
+ return y2(7);
205
+ var M3 = (d2 = {}, d2[s] = e, d2[u] = n, d2[i] = t, d2)[$2] || 1, m3 = this.$d.getTime() + r2 * M3;
206
+ return b.w(m3, this);
207
+ }, m2.subtract = function(t2, e2) {
208
+ return this.add(-1 * t2, e2);
209
+ }, m2.format = function(t2) {
210
+ var e2 = this, n2 = this.$locale();
211
+ if (!this.isValid())
212
+ return n2.invalidDate || l;
213
+ var r2 = t2 || "YYYY-MM-DDTHH:mm:ssZ", i2 = b.z(this), s2 = this.$H, u2 = this.$m, a2 = this.$M, o2 = n2.weekdays, c2 = n2.months, f2 = n2.meridiem, h2 = function(t3, n3, i3, s3) {
214
+ return t3 && (t3[n3] || t3(e2, r2)) || i3[n3].slice(0, s3);
215
+ }, d2 = function(t3) {
216
+ return b.s(s2 % 12 || 12, t3, "0");
217
+ }, $2 = f2 || function(t3, e3, n3) {
218
+ var r3 = t3 < 12 ? "AM" : "PM";
219
+ return n3 ? r3.toLowerCase() : r3;
220
+ };
221
+ return r2.replace(y, function(t3, r3) {
222
+ return r3 || function(t4) {
223
+ switch (t4) {
224
+ case "YY":
225
+ return String(e2.$y).slice(-2);
226
+ case "YYYY":
227
+ return b.s(e2.$y, 4, "0");
228
+ case "M":
229
+ return a2 + 1;
230
+ case "MM":
231
+ return b.s(a2 + 1, 2, "0");
232
+ case "MMM":
233
+ return h2(n2.monthsShort, a2, c2, 3);
234
+ case "MMMM":
235
+ return h2(c2, a2);
236
+ case "D":
237
+ return e2.$D;
238
+ case "DD":
239
+ return b.s(e2.$D, 2, "0");
240
+ case "d":
241
+ return String(e2.$W);
242
+ case "dd":
243
+ return h2(n2.weekdaysMin, e2.$W, o2, 2);
244
+ case "ddd":
245
+ return h2(n2.weekdaysShort, e2.$W, o2, 3);
246
+ case "dddd":
247
+ return o2[e2.$W];
248
+ case "H":
249
+ return String(s2);
250
+ case "HH":
251
+ return b.s(s2, 2, "0");
252
+ case "h":
253
+ return d2(1);
254
+ case "hh":
255
+ return d2(2);
256
+ case "a":
257
+ return $2(s2, u2, true);
258
+ case "A":
259
+ return $2(s2, u2, false);
260
+ case "m":
261
+ return String(u2);
262
+ case "mm":
263
+ return b.s(u2, 2, "0");
264
+ case "s":
265
+ return String(e2.$s);
266
+ case "ss":
267
+ return b.s(e2.$s, 2, "0");
268
+ case "SSS":
269
+ return b.s(e2.$ms, 3, "0");
270
+ case "Z":
271
+ return i2;
272
+ }
273
+ return null;
274
+ }(t3) || i2.replace(":", "");
275
+ });
276
+ }, m2.utcOffset = function() {
277
+ return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
278
+ }, m2.diff = function(r2, d2, l2) {
279
+ var $2, y2 = this, M3 = b.p(d2), m3 = O(r2), v2 = (m3.utcOffset() - this.utcOffset()) * e, g2 = this - m3, D2 = function() {
280
+ return b.m(y2, m3);
281
+ };
282
+ switch (M3) {
283
+ case h:
284
+ $2 = D2() / 12;
285
+ break;
286
+ case c:
287
+ $2 = D2();
288
+ break;
289
+ case f:
290
+ $2 = D2() / 3;
291
+ break;
292
+ case o:
293
+ $2 = (g2 - v2) / 6048e5;
294
+ break;
295
+ case a:
296
+ $2 = (g2 - v2) / 864e5;
297
+ break;
298
+ case u:
299
+ $2 = g2 / n;
300
+ break;
301
+ case s:
302
+ $2 = g2 / e;
303
+ break;
304
+ case i:
305
+ $2 = g2 / t;
306
+ break;
307
+ default:
308
+ $2 = g2;
309
+ }
310
+ return l2 ? $2 : b.a($2);
311
+ }, m2.daysInMonth = function() {
312
+ return this.endOf(c).$D;
313
+ }, m2.$locale = function() {
314
+ return D[this.$L];
315
+ }, m2.locale = function(t2, e2) {
316
+ if (!t2)
317
+ return this.$L;
318
+ var n2 = this.clone(), r2 = w(t2, e2, true);
319
+ return r2 && (n2.$L = r2), n2;
320
+ }, m2.clone = function() {
321
+ return b.w(this.$d, this);
322
+ }, m2.toDate = function() {
323
+ return new Date(this.valueOf());
324
+ }, m2.toJSON = function() {
325
+ return this.isValid() ? this.toISOString() : null;
326
+ }, m2.toISOString = function() {
327
+ return this.$d.toISOString();
328
+ }, m2.toString = function() {
329
+ return this.$d.toUTCString();
330
+ }, M2;
331
+ }(), k = _.prototype;
332
+ return O.prototype = k, [["$ms", r], ["$s", i], ["$m", s], ["$H", u], ["$W", a], ["$M", c], ["$y", h], ["$D", d]].forEach(function(t2) {
333
+ k[t2[1]] = function(e2) {
334
+ return this.$g(e2, t2[0], t2[1]);
335
+ };
336
+ }), O.extend = function(t2, e2) {
337
+ return t2.$i || (t2(e2, _, O), t2.$i = true), O;
338
+ }, O.locale = w, O.isDayjs = S, O.unix = function(t2) {
339
+ return O(1e3 * t2);
340
+ }, O.en = D[g], O.Ls = D, O.p = {}, O;
341
+ });
342
+ }
343
+ });
344
+
47
345
  // src/index.ts
48
346
  var src_exports = {};
49
347
  __export(src_exports, {
@@ -125,6 +423,7 @@ var import_node_fs = __toESM(require("fs"));
125
423
  var import_node_path = __toESM(require("path"));
126
424
  var import_image = require("@midscene/core/image");
127
425
  var import_utils = require("@midscene/core/utils");
426
+ var import_dayjs = __toESM(require_dayjs_min());
128
427
 
129
428
  // src/web-element.ts
130
429
  var WebElementInfo = class {
@@ -213,6 +512,13 @@ function findNearestPackageJson(dir) {
213
512
  }
214
513
  return findNearestPackageJson(parentDir);
215
514
  }
515
+ function reportFileName(tag = "web") {
516
+ const dateTimeInFileName = (0, import_dayjs.default)().format("YYYY-MM-DD_HH-mm-ss-SSS");
517
+ return `${tag}-${dateTimeInFileName}`;
518
+ }
519
+ function printReportMsg(filepath) {
520
+ console.log("Midscene - report file updated:", filepath);
521
+ }
216
522
 
217
523
  // src/common/tasks.ts
218
524
  var PageTaskExecutor = class {
@@ -574,31 +880,49 @@ var PageTaskExecutor = class {
574
880
  var PageAgent = class {
575
881
  constructor(page, opts) {
576
882
  this.page = page;
577
- this.dumps = [
883
+ this.opts = Object.assign(
578
884
  {
579
- groupName: (opts == null ? void 0 : opts.taskFile) || "unnamed",
580
- executions: []
581
- }
582
- ];
583
- this.testId = (opts == null ? void 0 : opts.testId) || String(process.pid);
885
+ generateReport: true,
886
+ groupName: "Midscene Report",
887
+ groupDescription: ""
888
+ },
889
+ opts || {}
890
+ );
891
+ this.dump = {
892
+ groupName: this.opts.groupName,
893
+ groupDescription: this.opts.groupDescription,
894
+ executions: []
895
+ };
584
896
  this.taskExecutor = new PageTaskExecutor(this.page, {
585
897
  cache: (opts == null ? void 0 : opts.cache) || { aiTasks: [] }
586
898
  });
899
+ this.reportFileName = reportFileName((opts == null ? void 0 : opts.testId) || "web");
587
900
  }
588
- appendDump(execution) {
589
- const currentDump = this.dumps[0];
901
+ appendExecutionDump(execution) {
902
+ const currentDump = this.dump;
590
903
  currentDump.executions.push(execution);
591
904
  }
905
+ dumpDataString() {
906
+ this.dump.groupName = this.opts.groupName;
907
+ this.dump.groupDescription = this.opts.groupDescription;
908
+ return (0, import_utils4.stringifyDumpData)(this.dump);
909
+ }
592
910
  writeOutActionDumps() {
593
- this.dumpFile = (0, import_utils4.writeDumpFile)({
594
- fileName: `run-${this.testId}`,
911
+ const generateReport = this.opts.generateReport;
912
+ this.reportFile = (0, import_utils4.writeLogFile)({
913
+ fileName: this.reportFileName,
595
914
  fileExt: import_utils4.groupedActionDumpFileExt,
596
- fileContent: (0, import_utils4.stringifyDumpData)(this.dumps)
915
+ fileContent: this.dumpDataString(),
916
+ type: "dump",
917
+ generateReport
597
918
  });
919
+ if (generateReport) {
920
+ printReportMsg(this.reportFile);
921
+ }
598
922
  }
599
923
  async aiAction(taskPrompt) {
600
924
  const { executor } = await this.taskExecutor.action(taskPrompt);
601
- this.appendDump(executor.dump());
925
+ this.appendExecutionDump(executor.dump());
602
926
  this.writeOutActionDumps();
603
927
  if (executor.isInErrorState()) {
604
928
  const errorTask = executor.latestErrorTask();
@@ -608,7 +932,7 @@ ${errorTask == null ? void 0 : errorTask.errorStack}`);
608
932
  }
609
933
  async aiQuery(demand) {
610
934
  const { output, executor } = await this.taskExecutor.query(demand);
611
- this.appendDump(executor.dump());
935
+ this.appendExecutionDump(executor.dump());
612
936
  this.writeOutActionDumps();
613
937
  if (executor.isInErrorState()) {
614
938
  const errorTask = executor.latestErrorTask();
@@ -619,7 +943,7 @@ ${errorTask == null ? void 0 : errorTask.errorStack}`);
619
943
  }
620
944
  async aiAssert(assertion, msg) {
621
945
  const { output, executor } = await this.taskExecutor.assert(assertion);
622
- this.appendDump(executor.dump());
946
+ this.appendExecutionDump(executor.dump());
623
947
  this.writeOutActionDumps();
624
948
  if (!(output == null ? void 0 : output.pass)) {
625
949
  const errMsg = msg || `Assertion failed: ${assertion}`;
@@ -647,13 +971,13 @@ ${reasonMsg}`);
647
971
  // src/playwright/cache.ts
648
972
  var import_node_fs2 = __toESM(require("fs"));
649
973
  var import_node_path2 = __toESM(require("path"));
650
- var import_utils6 = require("@midscene/core/utils");
974
+ var import_utils7 = require("@midscene/core/utils");
651
975
  function writeTestCache(taskFile, taskTitle, taskCacheJson) {
652
976
  const packageJson = getPkgInfo();
653
- (0, import_utils6.writeDumpFile)({
977
+ (0, import_utils7.writeLogFile)({
654
978
  fileName: `${taskFile}(${taskTitle})`,
655
979
  fileExt: "json",
656
- fileContent: (0, import_utils6.stringifyDumpData)(
980
+ fileContent: (0, import_utils7.stringifyDumpData)(
657
981
  __spreadValues({
658
982
  pkgName: packageJson.name,
659
983
  pkgVersion: packageJson.version,
@@ -667,7 +991,7 @@ function writeTestCache(taskFile, taskTitle, taskCacheJson) {
667
991
  }
668
992
  function readTestCache(taskFile, taskTitle) {
669
993
  const cacheFile = (0, import_node_path2.join)(
670
- (0, import_utils6.getDumpDirPath)("cache"),
994
+ (0, import_utils7.getLogDirByType)("cache"),
671
995
  `${taskFile}(${taskTitle}).json`
672
996
  );
673
997
  const pkgInfo = getPkgInfo();
@@ -721,32 +1045,47 @@ var groupAndCaseForTest = (testInfo) => {
721
1045
  return { taskFile, taskTitle };
722
1046
  };
723
1047
  var midsceneAgentKeyId = "_midsceneAgentId";
1048
+ var midsceneDumpAnnotationId = "MIDSCENE_DUMP_ANNOTATION";
724
1049
  var PlaywrightAiFixture = () => {
725
1050
  const pageAgentMap = {};
726
- const agentForPage = (page, opts) => {
1051
+ const agentForPage = (page, testInfo) => {
727
1052
  let idForPage = page[midsceneAgentKeyId];
728
1053
  if (!idForPage) {
729
1054
  idForPage = (0, import_node_crypto.randomUUID)();
730
1055
  page[midsceneAgentKeyId] = idForPage;
731
- const testCase = readTestCache(opts.taskFile, opts.taskTitle) || {
1056
+ const { testId } = testInfo;
1057
+ const { taskFile, taskTitle } = groupAndCaseForTest(testInfo);
1058
+ const testCase = readTestCache(taskFile, taskTitle) || {
732
1059
  aiTasks: []
733
1060
  };
734
1061
  pageAgentMap[idForPage] = new PageAgent(page, {
735
- testId: `${opts.testId}-${idForPage}`,
736
- taskFile: opts.taskFile,
737
- cache: testCase
1062
+ testId: `playwright-${testId}-${idForPage}`,
1063
+ groupName: taskTitle,
1064
+ groupDescription: taskFile,
1065
+ cache: testCase,
1066
+ generateReport: false
1067
+ // we will generate it in the reporter
738
1068
  });
739
1069
  }
740
1070
  return pageAgentMap[idForPage];
741
1071
  };
1072
+ const updateDumpAnnotation = (test, dump) => {
1073
+ const currentAnnotation = test.annotations.find((item) => {
1074
+ return item.type === midsceneDumpAnnotationId;
1075
+ });
1076
+ if (currentAnnotation) {
1077
+ currentAnnotation.description = dump;
1078
+ } else {
1079
+ test.annotations.push({
1080
+ type: midsceneDumpAnnotationId,
1081
+ description: dump
1082
+ });
1083
+ }
1084
+ };
742
1085
  return {
743
1086
  ai: async ({ page }, use, testInfo) => {
744
1087
  const { taskFile, taskTitle } = groupAndCaseForTest(testInfo);
745
- const agent = agentForPage(page, {
746
- testId: testInfo.testId,
747
- taskFile,
748
- taskTitle
749
- });
1088
+ const agent = agentForPage(page, testInfo);
750
1089
  await use(
751
1090
  async (taskPrompt, opts) => {
752
1091
  await page.waitForLoadState("networkidle");
@@ -757,79 +1096,33 @@ var PlaywrightAiFixture = () => {
757
1096
  );
758
1097
  const taskCacheJson = agent.taskExecutor.taskCache.generateTaskCache();
759
1098
  writeTestCache(taskFile, taskTitle, taskCacheJson);
760
- if (agent.dumpFile) {
761
- testInfo.annotations.push({
762
- type: "MIDSCENE_AI_ACTION",
763
- description: JSON.stringify({
764
- testId: testInfo.testId,
765
- dumpPath: agent.dumpFile
766
- })
767
- });
768
- }
1099
+ updateDumpAnnotation(testInfo, agent.dumpDataString());
769
1100
  },
770
1101
  aiAction: async ({ page }, use, testInfo) => {
771
1102
  const { taskFile, taskTitle } = groupAndCaseForTest(testInfo);
772
- const agent = agentForPage(page, {
773
- testId: testInfo.testId,
774
- taskFile,
775
- taskTitle
776
- });
1103
+ const agent = agentForPage(page, testInfo);
777
1104
  await use(async (taskPrompt) => {
778
1105
  await page.waitForLoadState("networkidle");
779
1106
  await agent.aiAction(taskPrompt);
780
1107
  });
781
- if (agent.dumpFile) {
782
- testInfo.annotations.push({
783
- type: "MIDSCENE_AI_ACTION",
784
- description: JSON.stringify({
785
- testId: testInfo.testId,
786
- dumpPath: agent.dumpFile
787
- })
788
- });
789
- }
1108
+ updateDumpAnnotation(testInfo, agent.dumpDataString());
790
1109
  },
791
1110
  aiQuery: async ({ page }, use, testInfo) => {
792
- const { taskFile, taskTitle } = groupAndCaseForTest(testInfo);
793
- const agent = agentForPage(page, {
794
- testId: testInfo.testId,
795
- taskFile,
796
- taskTitle
797
- });
1111
+ const agent = agentForPage(page, testInfo);
798
1112
  await use(async (demand) => {
799
1113
  await page.waitForLoadState("networkidle");
800
1114
  const result = await agent.aiQuery(demand);
801
1115
  return result;
802
1116
  });
803
- if (agent.dumpFile) {
804
- testInfo.annotations.push({
805
- type: "MIDSCENE_AI_ACTION",
806
- description: JSON.stringify({
807
- testId: testInfo.testId,
808
- dumpPath: agent.dumpFile
809
- })
810
- });
811
- }
1117
+ updateDumpAnnotation(testInfo, agent.dumpDataString());
812
1118
  },
813
1119
  aiAssert: async ({ page }, use, testInfo) => {
814
- const { taskFile, taskTitle } = groupAndCaseForTest(testInfo);
815
- const agent = agentForPage(page, {
816
- testId: testInfo.testId,
817
- taskFile,
818
- taskTitle
819
- });
1120
+ const agent = agentForPage(page, testInfo);
820
1121
  await use(async (assertion, errorMsg) => {
821
1122
  await page.waitForLoadState("networkidle");
822
1123
  await agent.aiAssert(assertion, errorMsg);
823
1124
  });
824
- if (agent.dumpFile) {
825
- testInfo.annotations.push({
826
- type: "MIDSCENE_AI_ACTION",
827
- description: JSON.stringify({
828
- testId: testInfo.testId,
829
- dumpPath: agent.dumpFile
830
- })
831
- });
832
- }
1125
+ updateDumpAnnotation(testInfo, agent.dumpDataString());
833
1126
  }
834
1127
  };
835
1128
  };