@@ -58,7 +57,8 @@ const PromptButton: React.FC<{
const [copied, setCopied] = React.useState(false);
return ;
};
diff --git a/packages/web/src/components/prompts.ts b/packages/web/src/components/prompts.ts
index d446dfa17d..8f57ac2dd5 100644
--- a/packages/web/src/components/prompts.ts
+++ b/packages/web/src/components/prompts.ts
@@ -19,45 +19,35 @@ function stripAnsiEscapes(str: string): string {
return str.replace(ansiRegex, '');
}
-function enumerate(items: string[]) {
- if (items.length === 0)
- return '';
- if (items.length === 1)
- return items[0];
- return items.slice(0, -1).join(', ') + ' and ' + items[items.length - 1];
-}
-
export function fixTestPrompt(error: string, diff?: string, pageSnapshot?: string) {
- const includedData = ['the error', diff && 'a code diff', pageSnapshot && 'a snapshot of the page'].filter((v): v is string => Boolean(v));
const promptParts = [
- `My Playwright test failed, what's going wrong? I've included ${enumerate(includedData)} below.`,
- `Please give me a suggestion how to fix it, and then explain what went wrong. Be very concise and apply Playwright best practices.`,
- `Don't include many headings in your output. Make sure what you're saying is correct, and take into account whether there might be a bug in the app.`,
- 'Here is the error:',
- '\n',
+ `My Playwright test failed.`,
+ `Explain why, be concise, respect Playwright best practices.`,
+ '',
+ 'Error:',
+ '',
'```js',
stripAnsiEscapes(error),
'```',
- '\n',
];
if (pageSnapshot) {
promptParts.push(
- 'This is how the page looked at the end of the test:\n',
+ '',
+ 'Page snapshot:',
'```yaml',
pageSnapshot,
'```',
- '\n'
);
}
if (diff) {
promptParts.push(
- 'And this is the code diff:\n',
+ '',
+ 'Local changes:',
'```diff',
diff,
'```',
- '\n'
);
}
diff --git a/tests/playwright-test/reporter-html.spec.ts b/tests/playwright-test/reporter-html.spec.ts
index 1f6f8c4180..9783194073 100644
--- a/tests/playwright-test/reporter-html.spec.ts
+++ b/tests/playwright-test/reporter-html.spec.ts
@@ -2804,7 +2804,7 @@ for (const useIntermediateMergeReport of [true, false] as const) {
await page.getByRole('link', { name: 'sample' }).click();
await page.getByRole('button', { name: 'Copy as Prompt' }).click();
const prompt = await page.evaluate(() => navigator.clipboard.readText());
- expect(prompt, 'first line').toContain(`My Playwright test failed, what's going wrong? I've included the error, a code diff and a snapshot of the page below.`);
+ expect(prompt, 'first line').toContain(`Playwright test failed.`);
expect(prompt, 'contains error').toContain('expect(received).toBe(expected)');
expect(prompt, 'contains snapshot').toContain('- button "Click me"');
expect(prompt, 'contains diff').toContain(`+ expect(2).toBe(3);`);