@empiricalrun/test-gen 0.10.1 → 0.10.3
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 +13 -0
- package/dist/actions/assertTextVisibility.d.ts.map +1 -1
- package/dist/actions/assertTextVisibility.js +4 -14
- package/dist/actions/goto.d.ts.map +1 -1
- package/dist/actions/goto.js +2 -0
- package/dist/agent/browsing/index.d.ts.map +1 -1
- package/dist/agent/browsing/index.js +2 -5
- package/dist/agent/browsing/utils.d.ts +2 -0
- package/dist/agent/browsing/utils.d.ts.map +1 -1
- package/dist/agent/browsing/utils.js +9 -1
- package/dist/bin/index.js +4 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @empiricalrun/test-gen
|
|
2
2
|
|
|
3
|
+
## 0.10.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 08f12e9: fix: browsing agent output works with ci reporter
|
|
8
|
+
|
|
9
|
+
## 0.10.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 4c9f5a6: fix: inject pw locator script on page.goto
|
|
14
|
+
- 5763c7e: fix: remove hasText filter from assert action
|
|
15
|
+
|
|
3
16
|
## 0.10.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assertTextVisibility.d.ts","sourceRoot":"","sources":["../../src/actions/assertTextVisibility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD,eAAO,MAAM,6CAA6C,2BAChC,CAAC;AAE3B,eAAO,MAAM,mCAAmC,EAAE,
|
|
1
|
+
{"version":3,"file":"assertTextVisibility.d.ts","sourceRoot":"","sources":["../../src/actions/assertTextVisibility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAGrD,eAAO,MAAM,6CAA6C,2BAChC,CAAC;AAE3B,eAAO,MAAM,mCAAmC,EAAE,yBAmDjD,CAAC"}
|
|
@@ -7,14 +7,8 @@ const assertTextVisibilityActionGenerator = (page) => {
|
|
|
7
7
|
return {
|
|
8
8
|
execute: async (args) => {
|
|
9
9
|
const css = args.css_selector;
|
|
10
|
-
const locator = await (0, utils_1.getPlaywrightLocatorUsingCssSelector)(args.css_selector, page
|
|
11
|
-
|
|
12
|
-
});
|
|
13
|
-
await page
|
|
14
|
-
.locator(css)
|
|
15
|
-
.filter({ hasText: args.text })
|
|
16
|
-
.first()
|
|
17
|
-
.isVisible({ timeout: 3000 });
|
|
10
|
+
const locator = await (0, utils_1.getPlaywrightLocatorUsingCssSelector)(args.css_selector, page);
|
|
11
|
+
await page.locator(css).first().isVisible({ timeout: 3000 });
|
|
18
12
|
return {
|
|
19
13
|
locator,
|
|
20
14
|
};
|
|
@@ -22,7 +16,7 @@ const assertTextVisibilityActionGenerator = (page) => {
|
|
|
22
16
|
// TODO: args transformer to be kept at a single place
|
|
23
17
|
template: (args, options) => {
|
|
24
18
|
const css = args.css_selector;
|
|
25
|
-
const assertStr = `await expect(page.locator("${css}")
|
|
19
|
+
const assertStr = `await expect(page.locator("${css}")).toBeVisible();`;
|
|
26
20
|
if (options?.locator) {
|
|
27
21
|
return `
|
|
28
22
|
// ${assertStr}
|
|
@@ -40,10 +34,6 @@ const assertTextVisibilityActionGenerator = (page) => {
|
|
|
40
34
|
parameters: {
|
|
41
35
|
type: "object",
|
|
42
36
|
properties: {
|
|
43
|
-
text: {
|
|
44
|
-
type: "string",
|
|
45
|
-
description: "text to be asserted",
|
|
46
|
-
},
|
|
47
37
|
css_selector: {
|
|
48
38
|
type: "string",
|
|
49
39
|
description: "CSS selector to identify the element uniquely and click it. When creating CSS selectors, ensure they are unique and specific enough to select only one element, even if there are multiple elements of the same type (like multiple h1 elements)",
|
|
@@ -53,7 +43,7 @@ const assertTextVisibilityActionGenerator = (page) => {
|
|
|
53
43
|
description: "reason for calling this function",
|
|
54
44
|
},
|
|
55
45
|
},
|
|
56
|
-
required: ["css_selector", "
|
|
46
|
+
required: ["css_selector", "reason"],
|
|
57
47
|
},
|
|
58
48
|
},
|
|
59
49
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"goto.d.ts","sourceRoot":"","sources":["../../src/actions/goto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"goto.d.ts","sourceRoot":"","sources":["../../src/actions/goto.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAErD,eAAO,MAAM,2BAA2B,cAAc,CAAC;AAEvD,eAAO,MAAM,mBAAmB,EAAE,yBAqCjC,CAAC"}
|
package/dist/actions/goto.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.gotoActionGenerator = exports.PLAYWRIGHT_GOTO_ACTION_NAME = void 0;
|
|
4
|
+
const utils_1 = require("../agent/browsing/utils");
|
|
4
5
|
exports.PLAYWRIGHT_GOTO_ACTION_NAME = "page_goto";
|
|
5
6
|
const gotoActionGenerator = (page) => {
|
|
6
7
|
return {
|
|
@@ -8,6 +9,7 @@ const gotoActionGenerator = (page) => {
|
|
|
8
9
|
const url = args.url;
|
|
9
10
|
await page.goto(url);
|
|
10
11
|
await page.waitForTimeout(3000);
|
|
12
|
+
await (0, utils_1.injectPwLocatorGenerator)(page);
|
|
11
13
|
},
|
|
12
14
|
// TODO: args transformer to be kept at a single place
|
|
13
15
|
template: (args) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAYlC,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,IAAI,EACV,OAAO,GAAE;IACP,YAAY,CAAC,EAAE;QACb,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;KAC9B,CAAC;CACE,mBAwDP"}
|
|
@@ -10,6 +10,7 @@ const provider_1 = require("../../bin/ai/prompts/provider");
|
|
|
10
10
|
const trace_1 = __importDefault(require("../../bin/ai/trace"));
|
|
11
11
|
const logger_1 = require("../../bin/logger");
|
|
12
12
|
const html_1 = require("../../utils/html");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
13
14
|
const logger = new logger_1.CustomLogger();
|
|
14
15
|
async function browsingAgent(task, page, options = {}) {
|
|
15
16
|
const trace = new trace_1.default({ name: "browsing-agent" });
|
|
@@ -17,11 +18,7 @@ async function browsingAgent(task, page, options = {}) {
|
|
|
17
18
|
const tools = actions.getActionSchemas();
|
|
18
19
|
let isTaskDone = false;
|
|
19
20
|
const previousActions = [];
|
|
20
|
-
|
|
21
|
-
const script = await resp.text();
|
|
22
|
-
await page.addScriptTag({
|
|
23
|
-
content: script,
|
|
24
|
-
});
|
|
21
|
+
await (0, utils_1.injectPwLocatorGenerator)(page);
|
|
25
22
|
let lastActionErrors = [];
|
|
26
23
|
// await page.waitForTimeout(3_00_000)
|
|
27
24
|
while (!isTaskDone) {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Page } from "playwright";
|
|
1
2
|
import { TestGenConfig } from "../../types";
|
|
2
3
|
export declare function prepareFileForBrowsingAgent(genConfig: TestGenConfig): Promise<void>;
|
|
4
|
+
export declare function injectPwLocatorGenerator(page: Page): Promise<void>;
|
|
3
5
|
export declare function canRunBrowsingAgent(filePath: string): void;
|
|
4
6
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/agent/browsing/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAIlC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,wBAAsB,2BAA2B,CAAC,SAAS,EAAE,aAAa,iBAiBzE;AAWD,wBAAsB,wBAAwB,CAAC,IAAI,EAAE,IAAI,iBAMxD;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,QA4BnD"}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.canRunBrowsingAgent = exports.prepareFileForBrowsingAgent = void 0;
|
|
6
|
+
exports.canRunBrowsingAgent = exports.injectPwLocatorGenerator = exports.prepareFileForBrowsingAgent = void 0;
|
|
7
7
|
const child_process_1 = require("child_process");
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
9
|
const logger_1 = require("../../bin/logger");
|
|
@@ -29,6 +29,14 @@ ${steps}\`, page, test);
|
|
|
29
29
|
});
|
|
30
30
|
`;
|
|
31
31
|
}
|
|
32
|
+
async function injectPwLocatorGenerator(page) {
|
|
33
|
+
const resp = await fetch("https://assets-test.empirical.run/pw-selector.js");
|
|
34
|
+
const script = await resp.text();
|
|
35
|
+
await page.addScriptTag({
|
|
36
|
+
content: script,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.injectPwLocatorGenerator = injectPwLocatorGenerator;
|
|
32
40
|
function canRunBrowsingAgent(filePath) {
|
|
33
41
|
if (!fs_extra_1.default.existsSync(filePath)) {
|
|
34
42
|
throw new Error(`File for browsing agent to run not found: ${filePath}`);
|
package/dist/bin/index.js
CHANGED
|
@@ -17,6 +17,7 @@ dotenv_1.default.config({
|
|
|
17
17
|
});
|
|
18
18
|
const logger = new logger_1.CustomLogger();
|
|
19
19
|
async function runAgent(sourceFile, isUpdate, testGenConfigs) {
|
|
20
|
+
const generatedTestScenarios = [];
|
|
20
21
|
const compatibleWithBrowsing = !sourceFile.endsWith(".yaml") &&
|
|
21
22
|
!sourceFile.startsWith("https://docs.google.com/spreadsheets") &&
|
|
22
23
|
!isUpdate;
|
|
@@ -29,14 +30,14 @@ async function runAgent(sourceFile, isUpdate, testGenConfigs) {
|
|
|
29
30
|
else {
|
|
30
31
|
fileForBrowsingAgent = testGenConfig.specPath;
|
|
31
32
|
await (0, utils_1.prepareFileForBrowsingAgent)(testGenConfig);
|
|
33
|
+
generatedTestScenarios.push(...testGenConfig.scenarios);
|
|
32
34
|
}
|
|
33
35
|
if (fileForBrowsingAgent) {
|
|
34
36
|
logger.success("Generating tests using browsing agent");
|
|
35
37
|
await (0, run_1.generateTestsUsingBrowsingAgent)(fileForBrowsingAgent);
|
|
36
|
-
|
|
38
|
+
return generatedTestScenarios;
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
|
-
const generatedTestScenarios = [];
|
|
40
41
|
for (const testGenConfig of testGenConfigs) {
|
|
41
42
|
const { specPath, scenarios } = testGenConfig;
|
|
42
43
|
if (!fs_extra_1.default.existsSync(specPath)) {
|
|
@@ -82,6 +83,6 @@ async function parseArgs() {
|
|
|
82
83
|
}
|
|
83
84
|
const { sourceFile, testGenConfigs, isUpdate } = await parseArgs();
|
|
84
85
|
const generated = await runAgent(sourceFile, isUpdate, testGenConfigs);
|
|
85
|
-
// TODO: make this work with browsing agent
|
|
86
86
|
await (0, ci_1.reportOnCI)(generated);
|
|
87
|
+
process.exit(0);
|
|
87
88
|
})();
|