@empiricalrun/test-gen 0.53.12 → 0.53.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @empiricalrun/test-gen
2
2
 
3
+ ## 0.53.13
4
+
5
+ ### Patch Changes
6
+
7
+ - b847558: feat: cua codegen works for clicks in iframes
8
+ - bb402a4: feat: accept framelocators in test-gen tool calls
9
+ - aa38bee: feat: add valid playwright project names to system prompt
10
+
3
11
  ## 0.53.12
4
12
 
5
13
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"agent-loop.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/agent-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAEL,UAAU,EAMX,MAAM,wBAAwB,CAAC;AAYhC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAyChE,wBAAsB,aAAa,CAAC,EAClC,SAAS,EACT,aAAa,EACb,QAAQ,EACR,KAAK,GACN,EAAE;IACD,SAAS,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IAC3B,aAAa,EAAE,mBAAmB,CAAC;IACnC,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,iBA2CA"}
1
+ {"version":3,"file":"agent-loop.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/agent-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAEL,UAAU,EAMX,MAAM,wBAAwB,CAAC;AAYhC,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAyChE,wBAAsB,aAAa,CAAC,EAClC,SAAS,EACT,aAAa,EACb,QAAQ,EACR,KAAK,GACN,EAAE;IACD,SAAS,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;IAC3B,aAAa,EAAE,mBAAmB,CAAC;IACnC,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,iBA4CA"}
@@ -49,6 +49,7 @@ const log = (...args) => {
49
49
  };
50
50
  async function chatAgentLoop({ chatModel, selectedModel, reporter, trace, }) {
51
51
  const systemPrompt = await (0, prompt_1.buildSystemPrompt)();
52
+ trace?.update({ input: { systemPrompt } });
52
53
  const { tools, toolExecutors } = getTools(selectedModel);
53
54
  while (!chatModel.askUserForInput) {
54
55
  const toolCalls = chatModel.getPendingToolCalls();
@@ -1 +1 @@
1
- {"version":3,"file":"repo.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/repo.ts"],"names":[],"mappings":"AAmCA,wBAAsB,cAAc,oBAwBnC"}
1
+ {"version":3,"file":"repo.d.ts","sourceRoot":"","sources":["../../../src/agent/chat/repo.ts"],"names":[],"mappings":"AAqCA,wBAAsB,cAAc,oBAqCnC"}
@@ -7,6 +7,7 @@ exports.getRepoContext = void 0;
7
7
  const fs_extra_1 = __importDefault(require("fs-extra"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const repo_tree_1 = require("../../utils/repo-tree");
10
+ const utils_1 = require("../browsing/utils");
10
11
  async function getAllMarkdownFiles() {
11
12
  const dir = path_1.default.join(process.cwd(), ".empiricalrun");
12
13
  if (!fs_extra_1.default.existsSync(dir)) {
@@ -48,6 +49,17 @@ While specifying paths to files, use relative paths from the current working dir
48
49
  - Correct path: "tests/lesson.spec.ts"
49
50
  - Incorrect path: "/repo/tests/lesson.spec.ts" or "${path_1.default.basename(process.cwd())}/tests/lesson.spec.ts"
50
51
  `;
52
+ const playwrightConfig = await (0, utils_1.readPlaywrightConfig)(process.cwd());
53
+ const validProjectNames = await (0, utils_1.getValidProjectNames)(playwrightConfig);
54
+ if (validProjectNames.length > 0) {
55
+ REPO_CONTEXT_PROMPT += `
56
+ ## Playwright configuration
57
+
58
+ This repo is configured with these Playwright projects (in the playwright.config.ts file):
59
+ ${validProjectNames.map((name) => `- ${name}`).join("\n")}
60
+
61
+ `;
62
+ }
51
63
  const knowledge = await knowledgeContext();
52
64
  if (knowledge.length > 0) {
53
65
  REPO_CONTEXT_PROMPT += `
@@ -1 +1 @@
1
- {"version":3,"file":"computer.d.ts","sourceRoot":"","sources":["../../../src/agent/cua/computer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,KAAK,cAAc,GACf,wBAAwB,CAAC,KAAK,GAC9B,wBAAwB,CAAC,WAAW,GACpC,wBAAwB,CAAC,IAAI,GAC7B,wBAAwB,CAAC,QAAQ,GACjC,wBAAwB,CAAC,IAAI,GAC7B,wBAAwB,CAAC,UAAU,GACnC,wBAAwB,CAAC,MAAM,GAC/B,wBAAwB,CAAC,IAAI,GAC7B,wBAAwB,CAAC,IAAI,CAAC;AAElC,wBAAsB,aAAa,CAAC,IAAI,EAAE,IAAI,mBAG7C;AAgCD,wBAAsB,cAAc,CAClC,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,MAAM,GACV,OAAO,CAAC;IACT,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC,CAMD;AAED,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC;IACT,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC,CAqID"}
1
+ {"version":3,"file":"computer.d.ts","sourceRoot":"","sources":["../../../src/agent/cua/computer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAIvC,KAAK,cAAc,GACf,wBAAwB,CAAC,KAAK,GAC9B,wBAAwB,CAAC,WAAW,GACpC,wBAAwB,CAAC,IAAI,GAC7B,wBAAwB,CAAC,QAAQ,GACjC,wBAAwB,CAAC,IAAI,GAC7B,wBAAwB,CAAC,UAAU,GACnC,wBAAwB,CAAC,MAAM,GAC/B,wBAAwB,CAAC,IAAI,GAC7B,wBAAwB,CAAC,IAAI,CAAC;AAElC,wBAAsB,aAAa,CAAC,IAAI,EAAE,IAAI,mBAG7C;AAgCD,wBAAsB,cAAc,CAClC,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,MAAM,GACV,OAAO,CAAC;IACT,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC,CAMD;AA4DD,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC;IACT,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC,CAiID"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handleModelAction = exports.handlePageGoto = exports.getScreenshot = void 0;
4
+ const utils_1 = require("../browsing/utils");
4
5
  async function getScreenshot(page) {
5
6
  const screenshotBytes = await page.screenshot();
6
7
  return Buffer.from(screenshotBytes).toString("base64");
@@ -43,6 +44,53 @@ async function handlePageGoto(page, url) {
43
44
  };
44
45
  }
45
46
  exports.handlePageGoto = handlePageGoto;
47
+ async function getLocatorForClick(page, { x, y }) {
48
+ const locator = await page.evaluate(([x, y]) => {
49
+ const element = document.elementFromPoint(x, y);
50
+ const bbox = element?.getBoundingClientRect();
51
+ return {
52
+ locator: window.playwright.generateLocator(element),
53
+ isIframe: element?.tagName === "IFRAME",
54
+ x0: bbox?.x,
55
+ y0: bbox?.y,
56
+ src: element?.getAttribute("src"),
57
+ id: element?.getAttribute("id"),
58
+ };
59
+ }, [x, y]);
60
+ if (!locator.isIframe) {
61
+ return locator.locator;
62
+ }
63
+ await (0, utils_1.injectPwLocatorGenerator)(page);
64
+ const relativeX = x - locator.x0;
65
+ const relativeY = y - locator.y0;
66
+ // TODO: Reuse locator.locator for the frameLocator.
67
+ let frameEl = locator.src
68
+ ? page.locator(`[src="${locator.src}"]`)
69
+ : page.locator(`#${locator.id}`);
70
+ const frameLocator = locator.src
71
+ ? `locator('[src="${locator.src}"]')`
72
+ : `locator('#${locator.id}')`;
73
+ const elementLocatorInsideFrame = await frameEl
74
+ .contentFrame()
75
+ .locator(":root")
76
+ .evaluate((rootElement, coords) => {
77
+ const xPos = coords[0];
78
+ const yPos = coords[1];
79
+ if (xPos === undefined || yPos === undefined) {
80
+ throw new Error("Coordinates are undefined in evaluate call");
81
+ }
82
+ const element = document.elementFromPoint(xPos, yPos);
83
+ return window.playwright.generateLocator(element);
84
+ }, [relativeX, relativeY]);
85
+ return `${frameLocator}.contentFrame().${elementLocatorInsideFrame}`;
86
+ }
87
+ async function getLocatorForFill(page) {
88
+ const locator = await page.evaluate(() => {
89
+ const element = document.activeElement;
90
+ return window.playwright.generateLocator(element);
91
+ });
92
+ return locator;
93
+ }
46
94
  async function handleModelAction(page, action) {
47
95
  const actionType = action.type;
48
96
  let actionCode = "";
@@ -61,19 +109,18 @@ async function handleModelAction(page, action) {
61
109
  pwButton = "middle";
62
110
  }
63
111
  if (pwButton) {
64
- const locator = await page.evaluate(([x, y]) => {
65
- const element = document.elementFromPoint(x, y);
66
- return window.playwright.generateLocator(element);
67
- }, [x, y]);
112
+ const locator = await getLocatorForClick(page, { x, y });
68
113
  actionCode = `await page.${locator}.click();\n`;
69
114
  await page.mouse.click(x, y, { button: pwButton });
70
115
  }
71
116
  if (button === "back" || button === "forward") {
72
117
  // Do page navigations, since there is no way to click on the back/forward buttons
73
118
  if (button === "back") {
119
+ actionCode = `await page.goBack();\n`;
74
120
  await page.goBack();
75
121
  }
76
122
  else if (button === "forward") {
123
+ actionCode = `await page.goForward();\n`;
77
124
  await page.goForward();
78
125
  }
79
126
  }
@@ -83,6 +130,8 @@ async function handleModelAction(page, action) {
83
130
  const { x, y } = action;
84
131
  console.log(`Action: doubleclick at (${x}, ${y})`);
85
132
  actionSummary = `Double click at (${x}, ${y})`;
133
+ const locator = await getLocatorForClick(page, { x, y });
134
+ actionCode = `await page.${locator}.dblclick();\n`;
86
135
  await page.mouse.dblclick(x, y, { button: "left" });
87
136
  break;
88
137
  }
@@ -96,6 +145,7 @@ async function handleModelAction(page, action) {
96
145
  case "drag": {
97
146
  const { path } = action;
98
147
  console.log(`Action: drag along path ${path}`);
148
+ // TODO: actionCode is not implemented
99
149
  actionSummary = `Drag along path ${path}`;
100
150
  if (!path || path.length === 0) {
101
151
  break;
@@ -138,10 +188,7 @@ async function handleModelAction(page, action) {
138
188
  console.log(`Action: type text '${text}'`);
139
189
  actionSummary = `Type text '${text}'`;
140
190
  await page.keyboard.type(text);
141
- const locator = await page.evaluate(() => {
142
- const element = document.activeElement;
143
- return window.playwright.generateLocator(element);
144
- });
191
+ const locator = await getLocatorForFill(page);
145
192
  actionCode = `await page.${locator}.fill("${text}");\n`;
146
193
  break;
147
194
  }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cua.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cua.spec.d.ts","sourceRoot":"","sources":["../../../../src/agent/master/browser-tests/cua.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const run_1 = require("../run");
4
+ const fixtures_1 = require("./fixtures");
5
+ (0, fixtures_1.test)("computer use agent generates code for iframes", async ({ page, server, }) => {
6
+ await page.goto(`${server.baseURL}/iframe-elements.html`);
7
+ const result = await (0, run_1.createTestUsingComputerUseAgent)({
8
+ page,
9
+ task: `Click on both of the "Enter your name" input fields`,
10
+ });
11
+ (0, fixtures_1.expect)(result.code).toMatch(/page\.getByPlaceholder\(['"]Enter your name['"]?\)\.click/);
12
+ (0, fixtures_1.expect)(result.code).toMatch(/locator\(['"]#nested-frame['"]?\)\.contentFrame\(\)\.getByPlaceholder\(['"]Enter your name['"]?\)/);
13
+ });
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Page } from "playwright";
1
+ import { FrameLocator, Page } from "playwright";
2
2
  import { ScopeVars } from "./types";
3
- export declare function createTest(task: string, page: Page, scope?: ScopeVars): Promise<void>;
3
+ export declare function createTest(task: string, pageRef: Page | FrameLocator, scope?: ScopeVars): Promise<void>;
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAQlC,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAoBpC,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,SAAS,iBAsD3E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAQhD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAoBpC,wBAAsB,UAAU,CAC9B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,IAAI,GAAG,YAAY,EAC5B,KAAK,CAAC,EAAE,SAAS,iBAwDlB"}
package/dist/index.js CHANGED
@@ -21,11 +21,12 @@ function setupProcessListeners(cleanup) {
21
21
  events.forEach((event) => process.removeListener(event, cleanup));
22
22
  };
23
23
  }
24
- async function createTest(task, page, scope) {
24
+ async function createTest(task, pageRef, scope) {
25
25
  const removeListeners = setupProcessListeners(flushEvents);
26
26
  try {
27
27
  const testConfigArg = process.env.TEST_GEN_TOKEN;
28
28
  const testGenConfig = (0, scenarios_1.loadTestConfigs)(testConfigArg);
29
+ const useComputerUseAgent = testGenConfig.options?.useComputerUseAgent;
29
30
  if (testGenConfig.options && testGenConfig.options.metadata) {
30
31
  (0, reporter_1.setReporterConfig)({
31
32
  projectRepoName: testGenConfig.options?.metadata.projectRepoName,
@@ -39,8 +40,9 @@ async function createTest(task, page, scope) {
39
40
  projectRepoName: testGenConfig.options?.metadata.projectRepoName,
40
41
  });
41
42
  }
43
+ // pageRef can be a FrameLocator, in which case we need to get the Page where the iframe is located
44
+ let page = "owner" in pageRef ? pageRef.owner().page() : pageRef;
42
45
  const fileServiceClient = new client_1.default();
43
- const useComputerUseAgent = testGenConfig.options?.useComputerUseAgent;
44
46
  let agentResult;
45
47
  if (useComputerUseAgent) {
46
48
  agentResult = await (0, cua_1.createTestUsingComputerUseAgent)({
@@ -1 +1 @@
1
- {"version":3,"file":"test-gen-browser.d.ts","sourceRoot":"","sources":["../../src/tools/test-gen-browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AA8EnD,eAAO,MAAM,4BAA4B,EAAE,IA0E1C,CAAC"}
1
+ {"version":3,"file":"test-gen-browser.d.ts","sourceRoot":"","sources":["../../src/tools/test-gen-browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAyFnD,eAAO,MAAM,4BAA4B,EAAE,IA0E1C,CAAC"}
@@ -66,6 +66,17 @@ await extPage
66
66
  // Instead, add the TODO before or after the multi-line statement
67
67
  \`\`\`
68
68
 
69
+ The TODO comment must be inside a test block, not outside of it. For example, this is invalid:
70
+
71
+ \`\`\`
72
+ // --- BEGIN INVALID EXAMPLE ---
73
+ test("Example test code", async ({ page }) => {
74
+ await page.goto("https://example.com");
75
+ });
76
+ // TODO(agent on page): Click on the login button
77
+ // --- END INVALID EXAMPLE ---
78
+ \`\`\`
79
+
69
80
  After execution, the browser agent will return a summary of actions that it took, and the generated Playwright code for them.
70
81
  You can then use the text editor tool to replace the TODO comment with the generated Playwright code.
71
82
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empiricalrun/test-gen",
3
- "version": "0.53.12",
3
+ "version": "0.53.13",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"