@nhonh/qabot 0.6.1 → 1.0.1
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/bin/qabot.js +82 -13
- package/package.json +1 -1
- package/src/cli/commands/test.js +229 -230
- package/src/cli/interactive.js +211 -0
- package/src/core/constants.js +1 -1
- package/src/core/logger.js +147 -45
- package/src/e2e/e2e-prompts.js +45 -44
- package/src/reporter/html-builder.js +250 -91
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import Enquirer from "enquirer";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { logger } from "../core/logger.js";
|
|
4
|
+
import { loadConfig } from "../core/config.js";
|
|
5
|
+
import { analyzeProject } from "../analyzers/project-analyzer.js";
|
|
6
|
+
import { VERSION } from "../core/constants.js";
|
|
7
|
+
|
|
8
|
+
const V = chalk.hex("#A78BFA");
|
|
9
|
+
const V2 = chalk.hex("#7C3AED");
|
|
10
|
+
const DIM = chalk.hex("#6B7280");
|
|
11
|
+
const W = chalk.hex("#F3F4F6");
|
|
12
|
+
const G = chalk.hex("#34D399");
|
|
13
|
+
|
|
14
|
+
export async function runInteractive(projectDir) {
|
|
15
|
+
const enquirer = new Enquirer();
|
|
16
|
+
const { config, isEmpty } = await loadConfig(projectDir);
|
|
17
|
+
|
|
18
|
+
logger.banner();
|
|
19
|
+
|
|
20
|
+
if (isEmpty) {
|
|
21
|
+
logger.warn("No qabot.config.json found in this directory.");
|
|
22
|
+
logger.blank();
|
|
23
|
+
const { shouldInit } = await enquirer.prompt({
|
|
24
|
+
type: "confirm",
|
|
25
|
+
name: "shouldInit",
|
|
26
|
+
message: V("Initialize QABot for this project?"),
|
|
27
|
+
initial: true,
|
|
28
|
+
});
|
|
29
|
+
if (shouldInit) return { action: "init" };
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const profile = await analyzeProject(projectDir);
|
|
34
|
+
const projectName = config.project?.name || profile.name;
|
|
35
|
+
const allFeatures = Object.keys(config.features || {});
|
|
36
|
+
|
|
37
|
+
console.log(DIM(" Project: ") + W(projectName));
|
|
38
|
+
console.log(DIM(" Type: ") + W(profile.type));
|
|
39
|
+
console.log(
|
|
40
|
+
DIM(" Tests: ") + W(`${allFeatures.length} features detected`),
|
|
41
|
+
);
|
|
42
|
+
logger.blank();
|
|
43
|
+
console.log(V2(" " + "\u2500".repeat(48)));
|
|
44
|
+
logger.blank();
|
|
45
|
+
|
|
46
|
+
const { testType } = await enquirer.prompt({
|
|
47
|
+
type: "select",
|
|
48
|
+
name: "testType",
|
|
49
|
+
message: V("\u25C6") + W(" What would you like to do?"),
|
|
50
|
+
pointer: V("\u25B8 "),
|
|
51
|
+
choices: [
|
|
52
|
+
{
|
|
53
|
+
name: "e2e",
|
|
54
|
+
message: `${G("\u25CF")} E2E Browser Test ${DIM("Playwright automation on live app")}`,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "unit",
|
|
58
|
+
message: `${chalk.hex("#60A5FA")("\u25CF")} Unit Test ${DIM("Jest / Vitest in terminal")}`,
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "generate",
|
|
62
|
+
message: `${chalk.hex("#FBBF24")("\u25CF")} AI Generate + Run ${DIM("AI writes tests, then runs them")}`,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "full",
|
|
66
|
+
message: `${chalk.hex("#C084FC")("\u25CF")} Full Suite ${DIM("Unit + E2E combined")}`,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "report",
|
|
70
|
+
message: `${chalk.hex("#22D3EE")("\u25CF")} View Report ${DIM("Open last HTML report")}`,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "auth",
|
|
74
|
+
message: `${DIM("\u25CF")} Configure AI Provider ${DIM("Setup OpenAI/Claude/Proxy")}`,
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
if (testType === "report") return { action: "report" };
|
|
80
|
+
if (testType === "auth") return { action: "auth" };
|
|
81
|
+
|
|
82
|
+
logger.blank();
|
|
83
|
+
|
|
84
|
+
const featureChoices = [
|
|
85
|
+
{
|
|
86
|
+
name: "__all__",
|
|
87
|
+
message: chalk.bold("All features") + DIM(` (${allFeatures.length})`),
|
|
88
|
+
},
|
|
89
|
+
...allFeatures.slice(0, 30).map((f) => {
|
|
90
|
+
const src = config.features[f]?.src || "";
|
|
91
|
+
const priority = config.features[f]?.priority || "";
|
|
92
|
+
const pColor =
|
|
93
|
+
priority === "P0"
|
|
94
|
+
? chalk.hex("#F87171")
|
|
95
|
+
: priority === "P1"
|
|
96
|
+
? chalk.hex("#FBBF24")
|
|
97
|
+
: DIM;
|
|
98
|
+
return {
|
|
99
|
+
name: f,
|
|
100
|
+
message: `${pColor(priority || " ")} ${W(f)} ${DIM(src)}`,
|
|
101
|
+
};
|
|
102
|
+
}),
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
const { feature } = await enquirer.prompt({
|
|
106
|
+
type: "select",
|
|
107
|
+
name: "feature",
|
|
108
|
+
message: V("\u25C6") + W(" Select feature"),
|
|
109
|
+
pointer: V("\u25B8 "),
|
|
110
|
+
choices: featureChoices,
|
|
111
|
+
limit: 18,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const selectedFeature = feature === "__all__" ? null : feature;
|
|
115
|
+
|
|
116
|
+
let targetUrl = null;
|
|
117
|
+
let headed = false;
|
|
118
|
+
|
|
119
|
+
if (testType === "e2e" || testType === "full") {
|
|
120
|
+
logger.blank();
|
|
121
|
+
|
|
122
|
+
const envEntries = Object.entries(config.environments || {});
|
|
123
|
+
const envChoices = envEntries.map(([name, env]) => ({
|
|
124
|
+
name: env.url || name,
|
|
125
|
+
message: `${V("\u25CF")} ${W(name.padEnd(16))} ${DIM(env.url || "")}`,
|
|
126
|
+
}));
|
|
127
|
+
envChoices.push({
|
|
128
|
+
name: "__custom__",
|
|
129
|
+
message: `${chalk.hex("#FBBF24")("\u25CF")} ${W("Custom URL")} ${DIM("Enter URL manually")}`,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const { envUrl } = await enquirer.prompt({
|
|
133
|
+
type: "select",
|
|
134
|
+
name: "envUrl",
|
|
135
|
+
message: V("\u25C6") + W(" Target environment"),
|
|
136
|
+
pointer: V("\u25B8 "),
|
|
137
|
+
choices: envChoices,
|
|
138
|
+
limit: 12,
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
if (envUrl === "__custom__") {
|
|
142
|
+
const { customUrl } = await enquirer.prompt({
|
|
143
|
+
type: "input",
|
|
144
|
+
name: "customUrl",
|
|
145
|
+
message: V("\u25C6") + W(" Enter URL"),
|
|
146
|
+
validate: (v) =>
|
|
147
|
+
v.startsWith("http")
|
|
148
|
+
? true
|
|
149
|
+
: "URL must start with http:// or https://",
|
|
150
|
+
});
|
|
151
|
+
targetUrl = customUrl;
|
|
152
|
+
} else {
|
|
153
|
+
targetUrl = envUrl;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
logger.blank();
|
|
157
|
+
|
|
158
|
+
const { browserMode } = await enquirer.prompt({
|
|
159
|
+
type: "select",
|
|
160
|
+
name: "browserMode",
|
|
161
|
+
message: V("\u25C6") + W(" Browser mode"),
|
|
162
|
+
pointer: V("\u25B8 "),
|
|
163
|
+
choices: [
|
|
164
|
+
{
|
|
165
|
+
name: "headless",
|
|
166
|
+
message: `${DIM("\u25CF")} Headless ${DIM("Fast, runs in background")}`,
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
name: "headed",
|
|
170
|
+
message: `${G("\u25CF")} Headed ${DIM("Watch the browser live")}`,
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
});
|
|
174
|
+
headed = browserMode === "headed";
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
logger.blank();
|
|
178
|
+
console.log(V2(" " + "\u2500".repeat(48)));
|
|
179
|
+
logger.blank();
|
|
180
|
+
|
|
181
|
+
const summary = [];
|
|
182
|
+
summary.push(DIM(" Action: ") + V(testType.toUpperCase()));
|
|
183
|
+
summary.push(DIM(" Feature: ") + W(selectedFeature || "all"));
|
|
184
|
+
if (targetUrl)
|
|
185
|
+
summary.push(DIM(" URL: ") + chalk.hex("#22D3EE")(targetUrl));
|
|
186
|
+
if (testType === "e2e" || testType === "full")
|
|
187
|
+
summary.push(
|
|
188
|
+
DIM(" Browser: ") + W(headed ? "Headed (visible)" : "Headless"),
|
|
189
|
+
);
|
|
190
|
+
summary.forEach((l) => console.log(l));
|
|
191
|
+
logger.blank();
|
|
192
|
+
|
|
193
|
+
const { confirm } = await enquirer.prompt({
|
|
194
|
+
type: "confirm",
|
|
195
|
+
name: "confirm",
|
|
196
|
+
message: V("\u25C6") + G(" Ready to run?"),
|
|
197
|
+
initial: true,
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
if (!confirm) {
|
|
201
|
+
logger.dim("Cancelled.");
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
action: testType,
|
|
207
|
+
feature: selectedFeature,
|
|
208
|
+
url: targetUrl,
|
|
209
|
+
headed,
|
|
210
|
+
};
|
|
211
|
+
}
|
package/src/core/constants.js
CHANGED
package/src/core/logger.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
const V = chalk.hex("#A78BFA");
|
|
4
|
+
const V2 = chalk.hex("#7C3AED");
|
|
5
|
+
const V3 = chalk.hex("#C4B5FD");
|
|
6
|
+
const G = chalk.hex("#34D399");
|
|
7
|
+
const R = chalk.hex("#F87171");
|
|
8
|
+
const Y = chalk.hex("#FBBF24");
|
|
9
|
+
const DIM = chalk.hex("#6B7280");
|
|
10
|
+
const W = chalk.hex("#F3F4F6");
|
|
11
11
|
|
|
12
12
|
function formatMs(ms) {
|
|
13
13
|
if (ms < 1000) return `${ms}ms`;
|
|
@@ -17,55 +17,74 @@ function formatMs(ms) {
|
|
|
17
17
|
|
|
18
18
|
export const logger = {
|
|
19
19
|
info(msg) {
|
|
20
|
-
console.log(
|
|
20
|
+
console.log(V(` \u25CF `) + W(msg));
|
|
21
21
|
},
|
|
22
22
|
success(msg) {
|
|
23
|
-
console.log(
|
|
23
|
+
console.log(G(` \u2714 `) + W(msg));
|
|
24
24
|
},
|
|
25
25
|
warn(msg) {
|
|
26
|
-
console.log(
|
|
26
|
+
console.log(Y(` \u25B2 `) + Y(msg));
|
|
27
27
|
},
|
|
28
28
|
error(msg) {
|
|
29
|
-
console.log(
|
|
29
|
+
console.log(R(` \u2716 `) + R(msg));
|
|
30
30
|
},
|
|
31
31
|
|
|
32
32
|
step(current, total, msg) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
` ${ICONS.step} ${chalk.dim(`[${current}/${total}]`)} ${msg}`,
|
|
36
|
-
),
|
|
37
|
-
);
|
|
33
|
+
const bar = progressBar(current, total, 12);
|
|
34
|
+
console.log(V(` ${bar} `) + W(msg));
|
|
38
35
|
},
|
|
39
36
|
|
|
40
37
|
dim(msg) {
|
|
41
|
-
console.log(
|
|
38
|
+
console.log(DIM(` ${msg}`));
|
|
42
39
|
},
|
|
43
40
|
blank() {
|
|
44
41
|
console.log("");
|
|
45
42
|
},
|
|
46
43
|
|
|
44
|
+
banner() {
|
|
45
|
+
logger.blank();
|
|
46
|
+
console.log(
|
|
47
|
+
V2(" \u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588") +
|
|
48
|
+
W(" QABot"),
|
|
49
|
+
);
|
|
50
|
+
console.log(
|
|
51
|
+
V(" \u2588\u2588 \u2588\u2588 \u2588\u2588 \u2588\u2588") +
|
|
52
|
+
DIM(" AI-Powered QA Automation"),
|
|
53
|
+
);
|
|
54
|
+
console.log(
|
|
55
|
+
V3(
|
|
56
|
+
" \u2588\u2588\u2588\u2588\u2588\u2588 \u2588\u2588\u2588\u2588\u2588\u2588",
|
|
57
|
+
),
|
|
58
|
+
);
|
|
59
|
+
logger.blank();
|
|
60
|
+
},
|
|
61
|
+
|
|
47
62
|
header(title) {
|
|
48
63
|
logger.blank();
|
|
49
|
-
console.log(
|
|
50
|
-
console.log(
|
|
64
|
+
console.log(V2(" \u2502"));
|
|
65
|
+
console.log(V2(" \u251C\u2500 ") + chalk.bold.white(title));
|
|
66
|
+
console.log(V2(" \u2502"));
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
section(title) {
|
|
70
|
+
logger.blank();
|
|
71
|
+
console.log(V(" \u25C6 ") + chalk.bold.white(title));
|
|
72
|
+
console.log(DIM(" " + "\u2500".repeat(48)));
|
|
51
73
|
},
|
|
52
74
|
|
|
53
75
|
box(title, lines) {
|
|
54
|
-
const w =
|
|
55
|
-
const border = chalk.dim("\u2500".repeat(w));
|
|
76
|
+
const w = 52;
|
|
56
77
|
logger.blank();
|
|
57
|
-
console.log(
|
|
78
|
+
console.log(V2(" \u256D" + "\u2500".repeat(w) + "\u256E"));
|
|
58
79
|
console.log(
|
|
59
|
-
|
|
60
|
-
chalk.bold.white(` ${title.padEnd(w - 1)}`) +
|
|
61
|
-
chalk.dim("\u2502"),
|
|
80
|
+
V2(" \u2502 ") + chalk.bold.white(title.padEnd(w - 2)) + V2(" \u2502"),
|
|
62
81
|
);
|
|
63
|
-
console.log(
|
|
82
|
+
console.log(V2(" \u251C" + "\u2500".repeat(w) + "\u2524"));
|
|
64
83
|
for (const line of lines) {
|
|
65
|
-
const
|
|
66
|
-
console.log(
|
|
84
|
+
const content = ` ${line}`.padEnd(w - 1);
|
|
85
|
+
console.log(V2(" \u2502") + content + V2(" \u2502"));
|
|
67
86
|
}
|
|
68
|
-
console.log(
|
|
87
|
+
console.log(V2(" \u2570" + "\u2500".repeat(w) + "\u256F"));
|
|
69
88
|
logger.blank();
|
|
70
89
|
},
|
|
71
90
|
|
|
@@ -75,30 +94,113 @@ export const logger = {
|
|
|
75
94
|
Math.max(h.length, ...rows.map((r) => String(r[i] || "").length)) + 2,
|
|
76
95
|
);
|
|
77
96
|
const headerLine = headers
|
|
78
|
-
.map((h, i) =>
|
|
97
|
+
.map((h, i) => V(h.padEnd(colWidths[i])))
|
|
79
98
|
.join("");
|
|
80
|
-
const separator = colWidths.map((w) => "\u2500".repeat(w)).join("");
|
|
81
|
-
|
|
82
|
-
console.log(
|
|
99
|
+
const separator = colWidths.map((w) => DIM("\u2500".repeat(w))).join("");
|
|
100
|
+
logger.blank();
|
|
101
|
+
console.log(" " + headerLine);
|
|
102
|
+
console.log(" " + separator);
|
|
83
103
|
for (const row of rows) {
|
|
84
104
|
const line = row
|
|
85
|
-
.map((cell, i) =>
|
|
105
|
+
.map((cell, i) => {
|
|
106
|
+
const str = String(cell || "");
|
|
107
|
+
if (str.includes("\u2714")) return G(str.padEnd(colWidths[i]));
|
|
108
|
+
if (str.includes("\u2716")) return R(str.padEnd(colWidths[i]));
|
|
109
|
+
return W(str.padEnd(colWidths[i]));
|
|
110
|
+
})
|
|
86
111
|
.join("");
|
|
87
|
-
console.log(
|
|
112
|
+
console.log(" " + line);
|
|
88
113
|
}
|
|
89
114
|
},
|
|
90
115
|
|
|
91
116
|
testResult(name, status, duration) {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
|
|
117
|
+
const icons = {
|
|
118
|
+
passed: G("\u2714"),
|
|
119
|
+
failed: R("\u2716"),
|
|
120
|
+
skipped: Y("\u25CB"),
|
|
121
|
+
running: V("\u25CF"),
|
|
122
|
+
};
|
|
123
|
+
const icon = icons[status] || DIM("\u25CB");
|
|
124
|
+
const dur = duration ? DIM(` ${formatMs(duration)}`) : "";
|
|
125
|
+
const nameStr =
|
|
126
|
+
status === "failed" ? R(name) : status === "skipped" ? Y(name) : W(name);
|
|
127
|
+
console.log(` ${icon} ${nameStr}${dur}`);
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
liveTest(index, total, name, status, duration) {
|
|
131
|
+
const pct = Math.round((index / total) * 100);
|
|
132
|
+
const bar = progressBar(index, total, 20);
|
|
133
|
+
const icons = {
|
|
134
|
+
passed: G("\u2714"),
|
|
135
|
+
failed: R("\u2716"),
|
|
136
|
+
skipped: Y("\u25CB"),
|
|
137
|
+
running: V("\u29BF"),
|
|
138
|
+
};
|
|
139
|
+
const icon = icons[status] || V("\u29BF");
|
|
140
|
+
const dur = duration ? DIM(` ${formatMs(duration)}`) : "";
|
|
141
|
+
const counter = DIM(`[${index}/${total}]`);
|
|
142
|
+
|
|
143
|
+
process.stdout.write(
|
|
144
|
+
`\r ${V(bar)} ${counter} ${icon} ${W(name)}${dur}${"".padEnd(20)}`,
|
|
145
|
+
);
|
|
146
|
+
if (status !== "running") process.stdout.write("\n");
|
|
147
|
+
},
|
|
148
|
+
|
|
149
|
+
progress(label, current, total) {
|
|
150
|
+
const bar = progressBar(current, total, 24);
|
|
151
|
+
const pct = total > 0 ? Math.round((current / total) * 100) : 0;
|
|
152
|
+
process.stdout.write(
|
|
153
|
+
`\r ${V(bar)} ${V2(`${pct}%`)} ${DIM(label)}${"".padEnd(10)}`,
|
|
154
|
+
);
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
summary(passed, failed, skipped, duration) {
|
|
158
|
+
logger.blank();
|
|
159
|
+
console.log(V2(" \u256D" + "\u2500".repeat(42) + "\u256E"));
|
|
160
|
+
console.log(
|
|
161
|
+
V2(" \u2502") + chalk.bold.white(" Results".padEnd(42)) + V2("\u2502"),
|
|
162
|
+
);
|
|
163
|
+
console.log(V2(" \u251C" + "\u2500".repeat(42) + "\u2524"));
|
|
164
|
+
console.log(
|
|
165
|
+
V2(" \u2502") +
|
|
166
|
+
G(` \u2714 ${String(passed).padStart(3)} passed`.padEnd(42)) +
|
|
167
|
+
V2("\u2502"),
|
|
168
|
+
);
|
|
169
|
+
if (failed > 0)
|
|
170
|
+
console.log(
|
|
171
|
+
V2(" \u2502") +
|
|
172
|
+
R(` \u2716 ${String(failed).padStart(3)} failed`.padEnd(42)) +
|
|
173
|
+
V2("\u2502"),
|
|
174
|
+
);
|
|
175
|
+
if (skipped > 0)
|
|
176
|
+
console.log(
|
|
177
|
+
V2(" \u2502") +
|
|
178
|
+
Y(` \u25CB ${String(skipped).padStart(3)} skipped`.padEnd(42)) +
|
|
179
|
+
V2("\u2502"),
|
|
180
|
+
);
|
|
181
|
+
console.log(
|
|
182
|
+
V2(" \u2502") +
|
|
183
|
+
DIM(` \u23F1 ${formatMs(duration)}`.padEnd(42)) +
|
|
184
|
+
V2("\u2502"),
|
|
185
|
+
);
|
|
186
|
+
const total = passed + failed + skipped;
|
|
187
|
+
const rate = total > 0 ? Math.round((passed / total) * 100) : 0;
|
|
188
|
+
const rateColor = rate >= 80 ? G : rate >= 50 ? Y : R;
|
|
189
|
+
console.log(
|
|
190
|
+
V2(" \u2502") +
|
|
191
|
+
rateColor(` ${rate}% pass rate`.padEnd(42)) +
|
|
192
|
+
V2("\u2502"),
|
|
193
|
+
);
|
|
194
|
+
console.log(V2(" \u2570" + "\u2500".repeat(42) + "\u256F"));
|
|
195
|
+
logger.blank();
|
|
101
196
|
},
|
|
102
197
|
};
|
|
103
198
|
|
|
199
|
+
function progressBar(current, total, width) {
|
|
200
|
+
const pct = total > 0 ? current / total : 0;
|
|
201
|
+
const filled = Math.round(pct * width);
|
|
202
|
+
const empty = width - filled;
|
|
203
|
+
return "\u2588".repeat(filled) + DIM("\u2591".repeat(empty));
|
|
204
|
+
}
|
|
205
|
+
|
|
104
206
|
export { formatMs };
|
package/src/e2e/e2e-prompts.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export function buildE2EPrompt(featureName, context) {
|
|
2
2
|
const sourceSection = context.sourceCode
|
|
3
|
-
? `\n## Source Code
|
|
3
|
+
? `\n## Source Code Analysis\nUse this to understand the page structure, components, routes, buttons, forms, modals, and data flow:\n\`\`\`\n${context.sourceCode.slice(0, 8000)}\n\`\`\`\n`
|
|
4
4
|
: "";
|
|
5
5
|
|
|
6
6
|
const routeSection = context.route
|
|
@@ -8,59 +8,60 @@ export function buildE2EPrompt(featureName, context) {
|
|
|
8
8
|
: "";
|
|
9
9
|
|
|
10
10
|
const useCaseSection = context.useCases?.length
|
|
11
|
-
? `\n## QA Use Cases\n${context.useCases.map((uc) => `### ${uc.scenario}\n${uc.steps.map((s, i) => `${i + 1}. ${s}`).join("\n")}`).join("\n\n")}\n`
|
|
11
|
+
? `\n## QA Use Cases (from QA team)\n${context.useCases.map((uc) => `### ${uc.scenario}\n${uc.steps.map((s, i) => `${i + 1}. ${s}`).join("\n")}`).join("\n\n")}\n`
|
|
12
12
|
: "";
|
|
13
13
|
|
|
14
|
-
return `You are
|
|
14
|
+
return `You are an expert QA automation engineer. Write comprehensive Playwright E2E tests.
|
|
15
15
|
|
|
16
16
|
## Feature: ${featureName}
|
|
17
17
|
## Base URL: ${context.baseUrl || "http://localhost:3000"}
|
|
18
|
-
## Auth
|
|
18
|
+
## Auth: ${context.authProvider || "none"} (use auth helper if needed)
|
|
19
19
|
${routeSection}${sourceSection}${useCaseSection}
|
|
20
|
-
## Task
|
|
21
|
-
Write a Playwright test spec for the "${featureName}" feature. The test should:
|
|
22
|
-
1. Navigate to the correct page
|
|
23
|
-
2. Verify the page loads correctly (key elements visible)
|
|
24
|
-
3. Test main user interactions
|
|
25
|
-
4. Take screenshots at key checkpoints
|
|
26
|
-
5. Verify expected outcomes
|
|
27
20
|
|
|
28
|
-
##
|
|
21
|
+
## REQUIREMENTS — Generate AT LEAST 8 test cases covering:
|
|
22
|
+
|
|
23
|
+
### Must Include (P0 — Critical):
|
|
24
|
+
1. Page Load & Layout — verify page loads, key sections visible, no console errors
|
|
25
|
+
2. Navigation — verify URL is correct, breadcrumbs/tabs work
|
|
26
|
+
3. Primary User Action — the main thing a user does on this page (click button, submit form, etc)
|
|
27
|
+
4. Data Display — verify data renders correctly (lists, cards, tables, amounts)
|
|
28
|
+
|
|
29
|
+
### Should Include (P1 — Important):
|
|
30
|
+
5. Secondary Actions — other clickable elements, links, toggles
|
|
31
|
+
6. Error States — what happens when something goes wrong (empty data, network error)
|
|
32
|
+
7. Loading States — skeleton/spinner shows while data loads
|
|
33
|
+
8. Responsive/Mobile — if applicable, test viewport changes
|
|
34
|
+
|
|
35
|
+
### Nice to Have (P2 — Edge Cases):
|
|
36
|
+
9. Edge Cases — empty states, boundary values, special characters
|
|
37
|
+
10. Authentication Guards — verify redirects when not logged in
|
|
38
|
+
|
|
39
|
+
## PLAYWRIGHT RULES:
|
|
29
40
|
1. Use \`const { test, expect } = require("@playwright/test");\`
|
|
30
|
-
2.
|
|
31
|
-
3. Use
|
|
32
|
-
4. Use
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
2. ALWAYS start with \`test.describe("${featureName}", () => { ... })\`
|
|
42
|
+
3. Use \`test.beforeEach\` for common setup (login + navigate)
|
|
43
|
+
4. Use accessible selectors IN THIS ORDER of preference:
|
|
44
|
+
- \`page.getByRole("button", { name: /text/i })\`
|
|
45
|
+
- \`page.getByText(/text/i)\`
|
|
46
|
+
- \`page.getByTestId("id")\`
|
|
47
|
+
- \`page.locator("css-selector")\` (LAST resort)
|
|
48
|
+
5. After every navigation: \`await page.waitForLoadState("networkidle")\`
|
|
49
|
+
6. Take screenshot at EVERY test: \`await page.screenshot({ path: "e2e/screenshots/${featureName}-{testname}.png", fullPage: true })\`
|
|
50
|
+
7. Use \`expect(locator).toBeVisible()\` not \`toBeTruthy()\`
|
|
51
|
+
8. Use \`{ timeout: 15000 }\` for slow-loading elements
|
|
52
|
+
9. Handle auth:
|
|
37
53
|
\`\`\`
|
|
38
54
|
const { login } = require("../helpers/auth.js");
|
|
39
|
-
test.beforeEach(async ({ page, baseURL }) => {
|
|
55
|
+
test.beforeEach(async ({ page, baseURL }) => {
|
|
56
|
+
await login(page, baseURL);
|
|
57
|
+
await page.goto("${context.route || "/" + featureName}");
|
|
58
|
+
await page.waitForLoadState("networkidle");
|
|
59
|
+
});
|
|
40
60
|
\`\`\`
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
## Structure
|
|
45
|
-
\`\`\`
|
|
46
|
-
test.describe("${featureName}", () => {
|
|
47
|
-
test.beforeEach(async ({ page, baseURL }) => {
|
|
48
|
-
// login if needed
|
|
49
|
-
// navigate to feature page
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test("page loads correctly", async ({ page }) => {
|
|
53
|
-
// verify key elements
|
|
54
|
-
// take screenshot
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test("main interaction works", async ({ page }) => {
|
|
58
|
-
// perform action
|
|
59
|
-
// verify outcome
|
|
60
|
-
// take screenshot
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
\`\`\`
|
|
61
|
+
10. Each test MUST have a clear assertion with \`expect()\`
|
|
62
|
+
11. Add \`test.slow()\` for tests that need extra time
|
|
64
63
|
|
|
65
|
-
|
|
64
|
+
## OUTPUT FORMAT:
|
|
65
|
+
Return ONLY JavaScript code. No markdown fences. No explanation.
|
|
66
|
+
Generate a COMPLETE runnable spec file with 8-12 tests.`;
|
|
66
67
|
}
|