@empiricalrun/test-gen 0.38.5 → 0.38.6

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.
@@ -15,7 +15,7 @@ test("should annotate all links on empirical landing page", async ({
15
15
  });
16
16
 
17
17
  const annotations = await page.evaluate(() => {
18
- const { annotations } = window.annotateClickableElements();
18
+ const { annotations } = annotateClickableElements();
19
19
 
20
20
  return Object.entries(annotations).map(([hint, config]) => ({
21
21
  innerText: config.node.innerText,
@@ -80,7 +80,7 @@ test("should annotate all important items on quizizz page", async ({
80
80
  });
81
81
 
82
82
  const annotations = await page.evaluate(() => {
83
- const { annotations } = window.annotateClickableElements();
83
+ const { annotations } = annotateClickableElements();
84
84
 
85
85
  return Object.entries(annotations).map(([hint, config]) => ({
86
86
  hint,
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/actions/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,EAAE,GAAG,CAAC;QAChB,MAAM,EAAE,GAAG,CAAC;KACb;CACF;AAED,wBAAsB,oCAAoC,CACxD,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,IAAI,EACV,iBAAiB,CAAC,EAAE,MAAM,gBAoF3B;AAED,wBAAgB,cAAc,WAG7B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/actions/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,EAAE,GAAG,CAAC;QAChB,MAAM,EAAE,GAAG,CAAC;KACb;CACF;AAED,wBAAsB,oCAAoC,CACxD,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,IAAI,EACV,iBAAiB,CAAC,EAAE,MAAM,gBAkH3B;AAED,wBAAgB,cAAc,WAG7B"}
@@ -16,6 +16,31 @@ async function getPlaywrightLocatorUsingCssSelector(cssSelector, xpath, page, el
16
16
  selectedElem =
17
17
  // @ts-ignore
18
18
  window?.annotationInstance?.annotations?.[elementAnnotation]?.node;
19
+ const elementDepth =
20
+ //@ts-ignore
21
+ window?.annotationInstance?.annotations?.[elementAnnotation].depth;
22
+ const frameLocatorStr = elementDepth
23
+ // @ts-ignore
24
+ .map((e, index) => {
25
+ const locator = index === 0
26
+ ? //To handle the parent iframe
27
+ window.playwright.generateLocator(e)
28
+ : elementDepth[index - 1].contentWindow.playwright.generateLocator(e);
29
+ return locator.replace(/^locator\(/, "frameLocator(");
30
+ })
31
+ .join(".");
32
+ let elementLocator;
33
+ //If the element is inside an iframe, we need to append the locator for the iframe
34
+ if (elementDepth.length > 0) {
35
+ elementLocator =
36
+ elementDepth[elementDepth.length - 1].contentWindow.playwright.generateLocator(selectedElem);
37
+ }
38
+ else {
39
+ elementLocator = window.playwright.generateLocator(selectedElem);
40
+ }
41
+ return frameLocatorStr
42
+ ? `${frameLocatorStr}.${elementLocator}`
43
+ : elementLocator;
19
44
  }
20
45
  else if (locator.xpath) {
21
46
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAK3D,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAiBvD,OAAO,EAAe,aAAa,EAAE,MAAM,aAAa,CAAC;AAMzD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAKhD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,UAI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CAAC;AAMzD,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAKhD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,UAIvD;AA6FD;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE,aAAa,EACxB,KAAK,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,MAAM,CAAC,CA0DjB;AAyBD,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,iBAuGxD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,QA+BjD;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAM1E;AAWD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,YAAY,EAAE,MAAM,EACpB,gBAAgB,EAAE,oBAAoB,EACtC,gBAAgB,GAAE,MAAM,EAAU,GACjC,OAAO,CAAC,MAAM,CAAC,CA+CjB;AAED,wBAAsB,sBAAsB,CAAC,EAC3C,YAAiB,EACjB,IAAS,EACT,eAAoB,EACpB,gBAAqB,EACrB,UAAyC,GAC1C,EAAE;IACD,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,8EASA;AAED,qBAAa,eAAe;IACd,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,MAAM;IACrC,OAAO,CAAC,aAAa,CAAqB;YAE5B,mBAAmB;YAUnB,gBAAgB;IAsBjB,OAAO;IAuBb,SAAS;CAKjB"}
@@ -179,15 +179,83 @@ async function injectPwLocatorGenerator(page) {
179
179
  fs_extra_1.default.readFile(annotateElementPath, "utf-8"),
180
180
  ]);
181
181
  page.on("load", async () => {
182
- // add script for subsequent page load events
183
182
  try {
184
183
  await Promise.all(scripts.map((s) => page.addScriptTag({ content: s })));
184
+ await page.evaluate(async () => {
185
+ //@ts-ignore
186
+ const injectScriptInIframe = (iframeDoc) => {
187
+ try {
188
+ [
189
+ "https://assets-test.empirical.run/pw-selector.js",
190
+ "https://code.jquery.com/jquery-3.7.1.min.js",
191
+ ].forEach((url) => {
192
+ const scr = iframeDoc.createElement("script");
193
+ scr.src = url;
194
+ console.log("Injecting script in iframe", scr);
195
+ iframeDoc.head.appendChild(scr);
196
+ });
197
+ }
198
+ catch (e) {
199
+ console.warn("Error injecting script in iframe:", e);
200
+ }
201
+ };
202
+ const iframes = document.getElementsByTagName("iframe");
203
+ for (const iframe of iframes) {
204
+ iframe.getBoundingClientRect();
205
+ const rect = iframe.getBoundingClientRect();
206
+ const isVisible = rect.width > 0 && rect.height > 0;
207
+ if (isVisible) {
208
+ //@ts-ignore
209
+ const iframeContent = iframe.contentDocument || iframe.contentWindow?.document;
210
+ if (iframeContent) {
211
+ injectScriptInIframe(iframeContent);
212
+ }
213
+ }
214
+ }
215
+ });
185
216
  }
186
217
  catch (e) {
187
- // skip errors which can occur while the page is getting stable
218
+ console.warn("Error during script injection on page load:", e);
188
219
  }
189
220
  });
190
- await Promise.all(scripts.map((s) => page.addScriptTag({ content: s })));
221
+ try {
222
+ await Promise.all(scripts.map((s) => page.addScriptTag({ content: s })));
223
+ await page.evaluate(async () => {
224
+ //@ts-ignore
225
+ const injectScriptInIframe = (iframeDoc) => {
226
+ try {
227
+ [
228
+ "https://assets-test.empirical.run/pw-selector.js",
229
+ "https://code.jquery.com/jquery-3.7.1.min.js",
230
+ ].forEach((url) => {
231
+ const scr = iframeDoc.createElement("script");
232
+ scr.src = url;
233
+ console.log("Injecting script in iframe", scr);
234
+ iframeDoc.head.appendChild(scr);
235
+ });
236
+ }
237
+ catch (e) {
238
+ console.warn("Error injecting script in iframe:", e);
239
+ }
240
+ };
241
+ const iframes = document.getElementsByTagName("iframe");
242
+ for (const iframe of iframes) {
243
+ iframe.getBoundingClientRect();
244
+ const rect = iframe.getBoundingClientRect();
245
+ const isVisible = rect.width > 0 && rect.height > 0;
246
+ if (isVisible) {
247
+ //@ts-ignore
248
+ const iframeContent = iframe.contentDocument || iframe.contentWindow?.document;
249
+ if (iframeContent) {
250
+ injectScriptInIframe(iframeContent);
251
+ }
252
+ }
253
+ }
254
+ });
255
+ }
256
+ catch (e) {
257
+ console.warn("Error injecting script in iframe:", e);
258
+ }
191
259
  }
192
260
  exports.injectPwLocatorGenerator = injectPwLocatorGenerator;
193
261
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/agent/master/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,GAAG,EACH,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAclD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EACL,oBAAoB,EAErB,MAAM,aAAa,CAAC;AAoBrB,wBAAsB,aAAa,CAAC,EAClC,IAAI,EACJ,eAAe,EACf,aAAa,EACb,OAAO,EACP,KAAK,EACL,GAAG,EACH,OAAO,EACP,cAAc,EACd,uBAAuB,EACvB,OAAO,EACP,aAAa,EACb,QAAgB,EAChB,WAAW,GACZ,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,GAAG,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,OAAO,CAAC,EAAE,oBAAoB,CAAC;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,OAAO,EAAE,iBAAi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EAAE,MAAM,CAAC;IACjC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB,2FA2FA;AAGD,wBAAsB,0BAA0B,CAAC,EAC/C,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,SAAS,GACV,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,oBAAoB,CAAC;IAC9B,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;;;GAsTA"}
@@ -202,17 +202,17 @@ async function createTestUsingMasterAgent({ task, page, testCase, options, scope
202
202
  const pageScreenshot = buffer.toString("base64");
203
203
  let output;
204
204
  let generatedCodeSteps = [];
205
- let annotations;
206
205
  let annotatedPageScreenshot;
206
+ let annotationKeys = [];
207
207
  if (useHints) {
208
208
  await page.waitForTimeout(2000);
209
- const annotationResult = await page.evaluate(() => {
209
+ annotationKeys = await page.evaluate(() => {
210
210
  // @ts-ignore
211
- window.annotationInstance = window.annotateClickableElements();
211
+ // eslint-disable-next-line no-undef
212
+ window.annotationInstance = annotateClickableElements();
212
213
  // @ts-ignore
213
- return window.annotationInstance;
214
+ return Object.keys(window.annotationInstance.annotations);
214
215
  });
215
- annotations = annotationResult?.annotations || {};
216
216
  await page.waitForTimeout(2000);
217
217
  const annonationBuffer = await page.screenshot({
218
218
  //This is done to improve element annotation accuracy, anyways it doesn't annotate elements which are out of viewport
@@ -236,7 +236,6 @@ async function createTestUsingMasterAgent({ task, page, testCase, options, scope
236
236
  if (await (0, session_1.shouldStopSession)()) {
237
237
  break;
238
238
  }
239
- const annotationKeys = annotations ? Object.keys(annotations) : [];
240
239
  const toolCall = await getNextAction({
241
240
  task,
242
241
  executedActions: masterAgentActions,
@@ -275,12 +274,12 @@ async function createTestUsingMasterAgent({ task, page, testCase, options, scope
275
274
  name: "trigger-hints-flow",
276
275
  input: {
277
276
  outputFromGetNextAction: output,
278
- generatedAnnotations: annotations,
277
+ generatedAnnotations: annotationKeys,
279
278
  },
280
279
  });
281
280
  const result = await (0, with_hints_1.triggerHintsFlow)({
282
281
  outputFromGetNextAction: output,
283
- generatedAnnotations: annotations,
282
+ generatedAnnotations: annotationKeys,
284
283
  page: testGenPage,
285
284
  llm,
286
285
  trace: triggerHintsFlowSpan,
@@ -1 +1 @@
1
- {"version":3,"file":"with-hints.d.ts","sourceRoot":"","sources":["../../../src/agent/master/with-hints.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAI5B,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,eAAO,MAAM,0BAA0B;iBAMxB,OAAO,8BAA8B;;oBAElC,MAAM;6BACG,MAAM;MAC7B,MAAM,GAAG,OAAO,yBAAyB,EAiC5C,CAAC;AAEF,eAAO,MAAM,gBAAgB;6BAOF;QACvB,MAAM,EAAE,MAAM,CAAC;QACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B;0BACqB,OAAO,MAAM,EAAE,GAAG,CAAC;UACnC,WAAW;SACZ,GAAG;;MAEN,QAAQ;IACV,sBAAsB,EAAE,OAAO,CAAC;IAChC,wBAAwB,EAAE,OAAO,qBAAqB,GAAG,SAAS,CAAC;CACpE,CAqGA,CAAC"}
1
+ {"version":3,"file":"with-hints.d.ts","sourceRoot":"","sources":["../../../src/agent/master/with-hints.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,MAAM,MAAM,QAAQ,CAAC;AAI5B,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,eAAO,MAAM,0BAA0B;iBAMxB,OAAO,8BAA8B;;oBAElC,MAAM;6BACG,MAAM;MAC7B,MAAM,GAAG,OAAO,yBAAyB,EAiC5C,CAAC;AAEF,eAAO,MAAM,gBAAgB;6BAOF;QACvB,MAAM,EAAE,MAAM,CAAC;QACf,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B;0BACqB,OAAO,MAAM,EAAE,GAAG,CAAC;UACnC,WAAW;SACZ,GAAG;;MAEN,QAAQ;IACV,sBAAsB,EAAE,OAAO,CAAC;IAChC,wBAAwB,EAAE,OAAO,qBAAqB,GAAG,SAAS,CAAC;CACpE,CAuGA,CAAC"}
@@ -37,12 +37,12 @@ const triggerHintsFlow = async ({ outputFromGetNextAction, generatedAnnotations,
37
37
  try {
38
38
  const hasElementAnnotation = outputFromGetNextAction?.elementAnnotation?.length &&
39
39
  outputFromGetNextAction?.elementAnnotation?.trim()?.length &&
40
- outputFromGetNextAction?.elementAnnotation in
41
- (generatedAnnotations || {});
40
+ generatedAnnotations?.includes(outputFromGetNextAction?.elementAnnotation);
42
41
  trace?.event({
43
42
  name: "has-element-annotation",
44
43
  output: {
45
44
  hasElementAnnotation,
45
+ generatedAnnotations,
46
46
  },
47
47
  });
48
48
  if (!hasElementAnnotation) {