Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: build error context in pw fixture (#39670)

Pavel Feldman98872a4d69b9
diff --git a/packages/html-reporter/src/DEPS.list b/packages/html-reporter/src/DEPS.list
index c7e0c4943d..7d6766edb9 100644
--- a/packages/html-reporter/src/DEPS.list
+++ b/packages/html-reporter/src/DEPS.list
@@ -1,6 +1,7 @@
[*]
@playwright/experimental-ct-react
@web/**
+@isomorphic/**
[chip.spec.tsx]
***
diff --git a/packages/html-reporter/src/testResultView.tsx b/packages/html-reporter/src/testResultView.tsx
index 0a689be253..cb8e631397 100644
--- a/packages/html-reporter/src/testResultView.tsx
+++ b/packages/html-reporter/src/testResultView.tsx
@@ -28,9 +28,9 @@ import { CodeSnippet, PromptButton, TestScreenshotErrorView } from './testErrorV
import * as icons from './icons';
import './testResultView.css';
import { useAsyncMemo } from '@web/uiUtils';
-import { copyPrompt } from '@web/shared/prompts';
import type { LoadedReport } from './loadedReport';
import { TestCaseListView } from './testFileView';
+import { stripAnsiEscapes } from '@isomorphic/stringUtils';
interface ImageDiffWithAnchors extends ImageDiff {
anchors: string[];
@@ -94,25 +94,28 @@ export const TestResultView: React.FC<{
const prompt = useAsyncMemo(async () => {
if (report.json().options?.noCopyPrompt)
return undefined;
+ if (!errorContext)
+ return undefined;
+
+ let text = errorContext.path ? await fetch(errorContext.path).then(r => r.text()) : errorContext.body;
+ if (!text)
+ return undefined;
const stdoutAttachment = result.attachments.find(a => a.name === 'stdout');
const stderrAttachment = result.attachments.find(a => a.name === 'stderr');
const stdout = stdoutAttachment?.body && stdoutAttachment.contentType === 'text/plain' ? stdoutAttachment.body : undefined;
const stderr = stderrAttachment?.body && stderrAttachment.contentType === 'text/plain' ? stderrAttachment.body : undefined;
+ if (stdout)
+ text += '\n\n# Stdout\n\n```\n' + stripAnsiEscapes(stdout) + '\n```';
+ if (stderr)
+ text += '\n\n# Stderr\n\n```\n' + stripAnsiEscapes(stderr) + '\n```';
+
+ const metadata = report.json().metadata;
+ if (metadata?.gitDiff)
+ text += '\n\n# Local changes\n\n```diff\n' + metadata.gitDiff + '\n```';
- return await copyPrompt({
- testInfo: [
- `- Name: ${test.path.join(' >> ')} >> ${test.title}`,
- `- Location: ${test.location.file}:${test.location.line}:${test.location.column}`
- ].join('\n'),
- metadata: report.json().metadata,
- errorContext: errorContext?.path ? await fetch(errorContext.path!).then(r => r.text()) : errorContext?.body,
- errors: result.errors,
- buildCodeFrame: async error => error.codeframe,
- stdout,
- stderr,
- });
- }, [test, errorContext, report, result], undefined);
+ return text;
+ }, [errorContext, report, result], undefined);
return <div className='test-result'>
{!!errors.length && <AutoChip header='Errors'>
diff --git a/packages/html-reporter/vite.config.ts b/packages/html-reporter/vite.config.ts
index f0032feb27..c37eb2cd87 100644
--- a/packages/html-reporter/vite.config.ts
+++ b/packages/html-reporter/vite.config.ts
@@ -28,6 +28,7 @@ export default defineConfig({
resolve: {
alias: {
'@web': path.resolve(__dirname, '../web/src'),
+ '@isomorphic': path.resolve(__dirname, '../playwright-core/src/utils/isomorphic'),
},
},
build: {
diff --git a/packages/playwright/src/DEPS.list b/packages/playwright/src/DEPS.list
index 63df33ec4f..1db4544ec5 100644
--- a/packages/playwright/src/DEPS.list
+++ b/packages/playwright/src/DEPS.list
@@ -9,6 +9,7 @@ common/
[index.ts]
@testIsomorphic/**
./prompt.ts
+./errorContext.ts
./worker/testTracing.ts
./mcp/sdk/
./mcp/test/
@@ -18,4 +19,3 @@ common/
**
[errorContext.ts]
-./transform/babelBundle.ts
diff --git a/packages/playwright/src/errorContext.ts b/packages/playwright/src/errorContext.ts
new file mode 100644
index 0000000000..a7655f4ce0
--- /dev/null
+++ b/packages/playwright/src/errorContext.ts
@@ -0,0 +1,121 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import fs from 'fs';
+import path from 'path';
+
+import { parseErrorStack, stripAnsiEscapes } from 'playwright-core/lib/utils';
+
+import type { TestInfoError } from '../types/test';
+
+const fixTestInstructions = `# Instructions
+
+- Following Playwright test failed.
+- Explain why, be concise, respect Playwright best practices.
+- Provide a snippet of code with the fix, if possible.
+`;
+
+export function buildErrorContext(options: {
+ titlePath: string[];
+ location: { file: string; line: number; column: number };
+ errors: TestInfoError[];
+ pageSnapshot?: string;
+}): string | undefined {
+ const { titlePath, location, errors, pageSnapshot } = options;
+
+ const meaningfulErrors = errors.filter(e => !!e.message);
+
+ if (!meaningfulErrors.length && !pageSnapshot)
+ return undefined;
+
+ const lines = [
+ fixTestInstructions,
+ '# Test info',
+ '',
+ `- Name: ${titlePath.join(' >> ')}`,
+ `- Location: ${location.file}:${location.line}:${location.column}`,
+ ];
+
+ if (meaningfulErrors.length) {
+ lines.push('', '# Error details');
+
+ for (const error of meaningfulErrors) {
+ lines.push(
+ '',
+ '```',
+ stripAnsiEscapes(error.message || ''),
+ '```',
+ );
+ }
+ }
+
+ if (pageSnapshot) {
+ lines.push(
+ '',
+ '# Page snapshot',
+ '',
+ '```yaml',
+ pageSnapshot,
+ '```',
+ );
+ }
+
+ const lastError = meaningfulErrors[meaningfulErrors.length - 1];
+ const codeFrame = lastError ? buildCodeFrame(lastError, location) : undefined;
+ if (codeFrame) {
+ lines.push(
+ '',
+ '# Test source',
+ '',
+ '```ts',
+ codeFrame,
+ '```',
+ );
+ }
+
+ return lines.join('\n');
+}
+
+function buildCodeFrame(error: TestInfoError, testLocation: { file: string; line: number; column: number }): string | undefined {
+ const stack = error.stack;
+ if (!stack)
+ return undefined;
+
+ const parsed = parseErrorStack(stack, path.sep);
+ const errorLocation = parsed.location;
+ if (!errorLocation)
+ return undefined;
+
+ let source: string;
+ try {
+ source = fs.readFileSync(errorLocation.file, 'utf8');
+ } catch {
+ return undefined;
+ }
+
+ const sourceLines = source.split('\n');
+ const linesAbove = 100;
+ const linesBelow = 100;
+ const start = Math.max(0, errorLocation.line - linesAbove - 1);
+ const end = Math.min(sourceLines.length, errorLocation.line + linesBelow);
+ const scope = sourceLines.slice(start, end);
+ const lineNumberWidth = String(end).length;
+ const message = stripAnsiEscapes(error.message || '').split('\n')[0] || undefined;
+ const frame = scope.map((line, index) => `${(start + index + 1) === errorLocation.line ? '> ' : ' '}${(start + index + 1).toString().padEnd(lineNumberWidth, ' ')} | ${line}`);
+ if (message)
+ frame.splice(errorLocation.line - start, 0, `${' '.repeat(lineNumberWidth + 2)} | ${' '.repeat(Math.max(0, errorLocation.column - 2))} ^ ${message}`);
+ return frame.join('\n');
+}
diff --git a/packages/playwright/src/index.ts b/packages/playwright/src/index.ts
index 772f803866..38346b9774 100644
--- a/packages/playwright/src/index.ts
+++ b/packages/playwright/src/index.ts
@@ -19,7 +19,7 @@ import path from 'path';
import * as playwrightLibrary from 'playwright-core';
import { setBoxedStackPrefixes, createGuid, currentZone, debugMode, jsonStringifyForceASCII, asLocatorDescription, renderTitleForCall, getActionGroup } from 'playwright-core/lib/utils';
-
+import { buildErrorContext } from './errorContext';
import { currentTestInfo } from './common/globals';
import { rootTestType } from './common/testType';
import { createCustomMessageHandler, runDaemonForBrowser } from './mcp/test/browserBackend';
@@ -733,22 +733,22 @@ class ArtifactsRecorder {
if (context)
await this._takePageSnapshot(context);
- if (this._pageSnapshot && this._testInfo.errors.length > 0 && !this._testInfo.attachments.some(a => a.name === 'error-context')) {
- const lines = [
- '# Page snapshot',
- '',
- '```yaml',
- this._pageSnapshot,
- '```',
- ];
- const filePath = this._testInfo.outputPath('error-context.md');
- await fs.promises.writeFile(filePath, lines.join('\n'), 'utf8');
-
- this._testInfo._attach({
- name: 'error-context',
- contentType: 'text/markdown',
- path: filePath,
- }, undefined);
+ if (this._testInfo.errors.length > 0) {
+ const errorContextContent = buildErrorContext({
+ titlePath: this._testInfo.titlePath,
+ location: { file: this._testInfo.file, line: this._testInfo.line, column: this._testInfo.column },
+ errors: this._testInfo.errors,
+ pageSnapshot: this._pageSnapshot,
+ });
+ if (errorContextContent) {
+ const filePath = this._testInfo.outputPath('error-context.md');
+ await fs.promises.writeFile(filePath, errorContextContent, 'utf8');
+ this._testInfo._attach({
+ name: 'error-context',
+ contentType: 'text/markdown',
+ path: filePath,
+ }, undefined);
+ }
}
}
diff --git a/packages/trace-viewer/src/ui/errorsTab.tsx b/packages/trace-viewer/src/ui/errorsTab.tsx
index a93bcd1f82..36d65c4b7c 100644
--- a/packages/trace-viewer/src/ui/errorsTab.tsx
+++ b/packages/trace-viewer/src/ui/errorsTab.tsx
@@ -23,10 +23,7 @@ import type { Language } from '@isomorphic/locatorGenerators';
import { CopyToClipboardTextButton } from './copyToClipboard';
import { useAsyncMemo } from '@web/uiUtils';
import { attachmentURL } from './attachmentsTab';
-import { copyPrompt, stripAnsiEscapes } from '@web/shared/prompts';
import { MetadataWithCommitInfo } from '@testIsomorphic/types';
-import { calculateSha1 } from './sourceTab';
-import type { StackFrame } from '@protocol/channels';
import { useTraceModel } from './traceModelContext';
const CopyPromptButton: React.FC<{ prompt: string }> = ({ prompt }) => {
@@ -92,48 +89,18 @@ export const ErrorsTab: React.FunctionComponent<{
testRunMetadata: MetadataWithCommitInfo | undefined,
}> = ({ errorsModel, sdkLanguage, revealInSource, wallTime, testRunMetadata }) => {
const model = useTraceModel();
- const errorContext = useAsyncMemo(async () => {
+
+ const prompt = useAsyncMemo(async () => {
const attachment = model?.attachments.find(a => a.name === 'error-context');
if (!attachment)
- return;
- return await fetch(attachmentURL(model, attachment)).then(r => r.text());
- }, [model], undefined);
-
- const buildCodeFrame = React.useCallback(async (error: ErrorDescription) => {
- const location = error.stack?.[0];
- if (!location)
- return;
-
- let response = model ? await fetch(model.createRelativeUrl(`sha1/src@${await calculateSha1(location.file)}.txt`)) : undefined;
- if (!response || response.status === 404)
- response = await fetch(`file?path=${encodeURIComponent(location.file)}`);
- if (response.status >= 400)
- return;
-
- const source = await response.text();
-
- return codeFrame({
- source,
- message: stripAnsiEscapes(error.message).split('\n')[0] || undefined,
- location,
- linesAbove: 100,
- linesBelow: 100,
- });
- }, [model]);
-
- const prompt = useAsyncMemo(
- () => copyPrompt(
- {
- testInfo: model?.title ?? '',
- metadata: testRunMetadata,
- errorContext,
- errors: model?.errorDescriptors ?? [],
- buildCodeFrame
- }
- ),
- [errorContext, testRunMetadata, model, buildCodeFrame],
- undefined
- );
+ return undefined;
+ let text = await fetch(attachmentURL(model, attachment)).then(r => r.text());
+ if (!text)
+ return undefined;
+ if (testRunMetadata?.gitDiff)
+ text += '\n\n# Local changes\n\n```diff\n' + testRunMetadata.gitDiff + '\n```';
+ return text;
+ }, [model, testRunMetadata], undefined);
if (!errorsModel.errors.size)
return <PlaceholderPanel text='No errors' />;
@@ -148,15 +115,3 @@ export const ErrorsTab: React.FunctionComponent<{
})}
</div>;
};
-
-function codeFrame({ source, message, location, linesAbove, linesBelow }: { source: string, message?: string, location: StackFrame, linesAbove: number, linesBelow: number }): string {
- const lines = source.split('\n').slice();
- const start = Math.max(0, location.line - linesAbove - 1);
- const end = Math.min(lines.length, location.line + linesBelow);
- const scope = lines.slice(start, end);
- const lineNumberWidth = String(end).length;
- const frame = scope.map((line, index) => `${(start + index + 1) === location.line ? '> ' : ' '}${(start + index + 1).toString().padEnd(lineNumberWidth, ' ')} | ${line}`);
- if (message)
- frame.splice(location.line - start, 0, `${' '.repeat(lineNumberWidth + 2)} | ${' '.repeat(location.column - 2)} ^ ${message}`);
- return frame.join('\n');
-}
diff --git a/packages/web/src/shared/prompts.ts b/packages/web/src/shared/prompts.ts
deleted file mode 100644
index f6807af40d..0000000000
--- a/packages/web/src/shared/prompts.ts
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import type { MetadataWithCommitInfo } from '@testIsomorphic/types';
-
-const fixTestInstructions = `
-# Instructions
-
-- Following Playwright test failed.
-- Explain why, be concise, respect Playwright best practices.
-- Provide a snippet of code with the fix, if possible.
-`.trimStart();
-
-export async function copyPrompt<ErrorInfo extends { message: string }>({
- testInfo,
- metadata,
- errorContext,
-
- errors,
- buildCodeFrame,
- stdout,
- stderr,
-}: {
- testInfo: string;
- metadata: MetadataWithCommitInfo | undefined;
- errorContext: string | undefined;
-
- errors: ErrorInfo[];
- buildCodeFrame(error: ErrorInfo): Promise<string | undefined>;
- stdout?: string;
- stderr?: string;
-}): Promise<string | undefined> {
- const meaningfulSingleLineErrors = new Set(errors.filter(e => e.message && !e.message.includes('\n')).map(e => e.message!));
- for (const error of errors) {
- for (const singleLineError of meaningfulSingleLineErrors.keys()) {
- if (error.message?.includes(singleLineError))
- meaningfulSingleLineErrors.delete(singleLineError);
- }
- }
-
- const meaningfulErrors = errors.filter(error => {
- if (!error.message)
- return false;
-
- // Skip errors that are just a single line - they are likely to already be the error message.
- if (!error.message.includes('\n') && !meaningfulSingleLineErrors.has(error.message))
- return false;
-
- return true;
- });
-
- if (!meaningfulErrors.length)
- return undefined;
-
- const lines = [
- fixTestInstructions,
- `# Test info`,
- '',
- testInfo,
- ];
-
- if (stdout)
- lines.push('', '# Stdout', '', '```', stripAnsiEscapes(stdout), '```');
-
- if (stderr)
- lines.push('', '# Stderr', '', '```', stripAnsiEscapes(stderr), '```');
-
- lines.push('', '# Error details');
-
- for (const error of meaningfulErrors) {
- lines.push(
- '',
- '```',
- stripAnsiEscapes(error.message || ''),
- '```',
- );
- }
-
- if (errorContext)
- lines.push(errorContext);
-
- const codeFrame = await buildCodeFrame(meaningfulErrors[meaningfulErrors.length - 1]);
- if (codeFrame) {
- lines.push(
- '',
- '# Test source',
- '',
- '```ts',
- codeFrame,
- '```',
- );
- }
-
- if (metadata?.gitDiff) {
- lines.push(
- '',
- '# Local changes',
- '',
- '```diff',
- metadata.gitDiff,
- '```',
- );
- }
-
- return lines.join('\n');
-}
-
-const ansiRegex = new RegExp('([\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~])))', 'g');
-export function stripAnsiEscapes(str: string): string {
- return str.replace(ansiRegex, '');
-}
diff --git a/tests/playwright-test/playwright.artifacts.spec.ts b/tests/playwright-test/playwright.artifacts.spec.ts
index cbdff1d396..c9dbecf180 100644
--- a/tests/playwright-test/playwright.artifacts.spec.ts
+++ b/tests/playwright-test/playwright.artifacts.spec.ts
@@ -138,18 +138,22 @@ test('should work with screenshot: on', async ({ runInlineTest }, testInfo) => {
expect(listFiles(testInfo.outputPath('test-results'))).toEqual([
'.last-run.json',
'artifacts-failing',
+ ' error-context.md',
' test-failed-1.png',
'artifacts-own-context-failing',
+ ' error-context.md',
' test-failed-1.png',
'artifacts-own-context-passing',
' test-finished-1.png',
'artifacts-passing',
' test-finished-1.png',
'artifacts-persistent-failing',
+ ' error-context.md',
' test-failed-1.png',
'artifacts-persistent-passing',
' test-finished-1.png',
'artifacts-shared-shared-failing',
+ ' error-context.md',
' test-failed-1.png',
'artifacts-shared-shared-passing',
' test-finished-1.png',
@@ -157,6 +161,7 @@ test('should work with screenshot: on', async ({ runInlineTest }, testInfo) => {
' test-finished-1.png',
' test-finished-2.png',
'artifacts-two-contexts-failing',
+ ' error-context.md',
' test-failed-1.png',
' test-failed-2.png',
]);
@@ -176,14 +181,19 @@ test('should work with screenshot: only-on-failure', async ({ runInlineTest }, t
expect(listFiles(testInfo.outputPath('test-results'))).toEqual([
'.last-run.json',
'artifacts-failing',
+ ' error-context.md',
' test-failed-1.png',
'artifacts-own-context-failing',
+ ' error-context.md',
' test-failed-1.png',
'artifacts-persistent-failing',
+ ' error-context.md',
' test-failed-1.png',
'artifacts-shared-shared-failing',
+ ' error-context.md',
' test-failed-1.png',
'artifacts-two-contexts-failing',
+ ' error-context.md',
' test-failed-1.png',
' test-failed-2.png',
]);
@@ -212,7 +222,10 @@ test('should work with screenshot: on-first-failure', async ({ runInlineTest },
expect(listFiles(testInfo.outputPath('test-results'))).toEqual([
'.last-run.json',
'a-fails',
+ ' error-context.md',
' test-failed-1.png',
+ 'a-fails-retry1',
+ ' error-context.md',
]);
});
@@ -237,6 +250,7 @@ test('should work with screenshot: only-on-failure & fullPage', async ({ runInli
expect(listFiles(testInfo.outputPath('test-results'))).toEqual([
'.last-run.json',
'artifacts-should-fail-and-take-fullPage-screenshots',
+ ' error-context.md',
' test-failed-1.png',
]);
const screenshotFailure = fs.readFileSync(
@@ -271,6 +285,7 @@ test('should capture a single screenshot on failure when afterAll fails', async
expect(listFiles(testInfo.outputPath('test-results'))).toEqual([
'.last-run.json',
'a-passes',
+ ' error-context.md',
' test-failed-1.png',
]);
});
@@ -290,24 +305,29 @@ test('should work with trace: on', async ({ runInlineTest }, testInfo) => {
expect(listFiles(testInfo.outputPath('test-results'))).toEqual([
'.last-run.json',
'artifacts-failing',
+ ' error-context.md',
' trace.zip',
'artifacts-own-context-failing',
+ ' error-context.md',
' trace.zip',
'artifacts-own-context-passing',
' trace.zip',
'artifacts-passing',
' trace.zip',
'artifacts-persistent-failing',
+ ' error-context.md',
' trace.zip',
'artifacts-persistent-passing',
' trace.zip',
'artifacts-shared-shared-failing',
+ ' error-context.md',
' trace.zip',
'artifacts-shared-shared-passing',
' trace.zip',
'artifacts-two-contexts',
' trace.zip',
'artifacts-two-contexts-failing',
+ ' error-context.md',
' trace.zip',
]);
});
@@ -326,14 +346,19 @@ test('should work with trace: retain-on-failure', async ({ runInlineTest }, test
expect(listFiles(testInfo.outputPath('test-results'))).toEqual([
'.last-run.json',
'artifacts-failing',
+ ' error-context.md',
' trace.zip',
'artifacts-own-context-failing',
+ ' error-context.md',
' trace.zip',
'artifacts-persistent-failing',
+ ' error-context.md',
' trace.zip',
'artifacts-shared-shared-failing',
+ ' error-context.md',
' trace.zip',
'artifacts-two-contexts-failing',
+ ' error-context.md',
' trace.zip',
]);
});
@@ -351,15 +376,30 @@ test('should work with trace: on-first-retry', async ({ runInlineTest }, testInf
expect(result.failed).toBe(5);
expect(listFiles(testInfo.outputPath('test-results'))).toEqual([
'.last-run.json',
+ 'artifacts-failing',
+ ' error-context.md',
'artifacts-failing-retry1',
+ ' error-context.md',
' trace.zip',
+ 'artifacts-own-context-failing',
+ ' error-context.md',
'artifacts-own-context-failing-retry1',
+ ' error-context.md',
' trace.zip',
+ 'artifacts-persistent-failing',
+ ' error-context.md',
'artifacts-persistent-failing-retry1',
+ ' error-context.md',
' trace.zip',
+ 'artifacts-shared-shared-failing',
+ ' error-context.md',
'artifacts-shared-shared-failing-retry1',
+ ' error-context.md',
' trace.zip',
+ 'artifacts-two-contexts-failing',
+ ' error-context.md',
'artifacts-two-contexts-failing-retry1',
+ ' error-context.md',
' trace.zip',
]);
});
@@ -377,25 +417,45 @@ test('should work with trace: on-all-retries', async ({ runInlineTest }, testInf
expect(result.failed).toBe(5);
expect(listFiles(testInfo.outputPath('test-results'))).toEqual([
'.last-run.json',
+ 'artifacts-failing',
+ ' error-context.md',
'artifacts-failing-retry1',
+ ' error-context.md',
' trace.zip',
'artifacts-failing-retry2',
+ ' error-context.md',
' trace.zip',
+ 'artifacts-own-context-failing',
+ ' error-context.md',
'artifacts-own-context-failing-retry1',
+ ' error-context.md',
' trace.zip',
'artifacts-own-context-failing-retry2',
+ ' error-context.md',
' trace.zip',
+ 'artifacts-persistent-failing',
+ ' error-context.md',
'artifacts-persistent-failing-retry1',
+ ' error-context.md',
' trace.zip',
'artifacts-persistent-failing-retry2',
+ ' error-context.md',
' trace.zip',
+ 'artifacts-shared-shared-failing',
+ ' error-context.md',
'artifacts-shared-shared-failing-retry1',
+ ' error-context.md',
' trace.zip',
'artifacts-shared-shared-failing-retry2',
+ ' error-context.md',
' trace.zip',
+ 'artifacts-two-contexts-failing',
+ ' error-context.md',
'artifacts-two-contexts-failing-retry1',
+ ' error-context.md',
' trace.zip',
'artifacts-two-contexts-failing-retry2',
+ ' error-context.md',
' trace.zip',
]);
});
@@ -414,15 +474,40 @@ test('should work with trace: retain-on-first-failure', async ({ runInlineTest }
expect(listFiles(testInfo.outputPath('test-results'))).toEqual([
'.last-run.json',
'artifacts-failing',
+ ' error-context.md',
' trace.zip',
+ 'artifacts-failing-retry1',
+ ' error-context.md',
+ 'artifacts-failing-retry2',
+ ' error-context.md',
'artifacts-own-context-failing',
+ ' error-context.md',
' trace.zip',
+ 'artifacts-own-context-failing-retry1',
+ ' error-context.md',
+ 'artifacts-own-context-failing-retry2',
+ ' error-context.md',
'artifacts-persistent-failing',
+ ' error-context.md',
' trace.zip',
+ 'artifacts-persistent-failing-retry1',
+ ' error-context.md',
+ 'artifacts-persistent-failing-retry2',
+ ' error-context.md',
'artifacts-shared-shared-failing',
+ ' error-context.md',
' trace.zip',
+ 'artifacts-shared-shared-failing-retry1',
+ ' error-context.md',
+ 'artifacts-shared-shared-failing-retry2',
+ ' error-context.md',
'artifacts-two-contexts-failing',
+ ' error-context.md',
' trace.zip',
+ 'artifacts-two-contexts-failing-retry1',
+ ' error-context.md',
+ 'artifacts-two-contexts-failing-retry2',
+ ' error-context.md',
]);
});
@@ -440,34 +525,49 @@ test('should work with trace: retain-on-failure-and-retries', async ({ runInline
expect(listFiles(testInfo.outputPath('test-results'))).toEqual([
'.last-run.json',
'artifacts-failing',
+ ' error-context.md',
' trace.zip',
'artifacts-failing-retry1',
+ ' error-context.md',
' trace.zip',
'artifacts-failing-retry2',
+ ' error-context.md',
' trace.zip',
'artifacts-own-context-failing',
+ ' error-context.md',
' trace.zip',
'artifacts-own-context-failing-retry1',
+ ' error-context.md',
' trace.zip',
'artifacts-own-context-failing-retry2',
+ ' error-context.md',
' trace.zip',
'artifacts-persistent-failing',
+ ' error-context.md',
' trace.zip',
'artifacts-persistent-failing-retry1',
+ ' error-context.md',
' trace.zip',
'artifacts-persistent-failing-retry2',
+ ' error-context.md',
' trace.zip',
'artifacts-shared-shared-failing',
+ ' error-context.md',
' trace.zip',
'artifacts-shared-shared-failing-retry1',
+ ' error-context.md',
' trace.zip',
'artifacts-shared-shared-failing-retry2',
+ ' error-context.md',
' trace.zip',
'artifacts-two-contexts-failing',
+ ' error-context.md',
' trace.zip',
'artifacts-two-contexts-failing-retry1',
+ ' error-context.md',
' trace.zip',
'artifacts-two-contexts-failing-retry2',
+ ' error-context.md',
' trace.zip',
]);
});
diff --git a/tests/playwright-test/playwright.connect.spec.ts b/tests/playwright-test/playwright.connect.spec.ts
index 94664a3ae6..71aa32b0cc 100644
--- a/tests/playwright-test/playwright.connect.spec.ts
+++ b/tests/playwright-test/playwright.connect.spec.ts
@@ -167,7 +167,11 @@ test('should print debug log when failed to connect', async ({ runInlineTest })
expect(result.exitCode).toBe(1);
expect(result.failed).toBe(1);
expect(result.output).toContain('b-debug-log-string');
- expect(result.results[0].attachments).toEqual([]);
+ expect(result.results[0].attachments).toEqual([{
+ name: 'error-context',
+ contentType: 'text/markdown',
+ path: expect.stringContaining('error-context.md'),
+ }]);
});
test('should record trace', async ({ runInlineTest }) => {
@@ -224,6 +228,7 @@ test('should record trace', async ({ runInlineTest }) => {
' Fixture "page"',
' Fixture "context"',
' Close context',
+ 'Attach "error-context"',
'Worker Cleanup',
' Fixture "browser"',
]);
diff --git a/tests/playwright-test/playwright.trace.spec.ts b/tests/playwright-test/playwright.trace.spec.ts
index e771195992..78ebd785be 100644
--- a/tests/playwright-test/playwright.trace.spec.ts
+++ b/tests/playwright-test/playwright.trace.spec.ts
@@ -129,6 +129,7 @@ test('should record api trace', async ({ runInlineTest, server }, testInfo) => {
' Fixture "context"',
' Close context',
' Fixture "request"',
+ 'Attach "error-context"',
'Worker Cleanup',
' Fixture "browser"',
]);
@@ -657,6 +658,7 @@ test('should show non-expect error in trace', async ({ runInlineTest }, testInfo
' Fixture "page"',
' Fixture "context"',
' Close context',
+ 'Attach "error-context"',
'Worker Cleanup',
' Fixture "browser"',
]);
@@ -985,6 +987,7 @@ test('should record nested steps, even after timeout', async ({ runInlineTest },
' step in barPage teardown',
' Close context',
'Attach "error-context"',
+ 'Attach "error-context"',
'Worker Cleanup',
' Fixture "browser"',
]);
@@ -1072,6 +1075,7 @@ test('should attribute worker fixture teardown to the right test', async ({ runI
expect(trace2.model.renderActionTree()).toEqual([
'Before Hooks',
'After Hooks',
+ 'Attach "error-context"',
'Worker Cleanup',
' Fixture "foo"',
' step in foo teardown',
@@ -1221,6 +1225,7 @@ test('should not corrupt actions when no library trace is present', async ({ run
'After Hooks',
' Fixture "foo"',
' Expect "toBe"',
+ 'Attach "error-context"',
'Worker Cleanup',
]);
});
@@ -1251,6 +1256,7 @@ test('should record trace for manually created context in a failed test', async
'Set content',
'Expect "toBe"',
'After Hooks',
+ 'Attach "error-context"',
'Worker Cleanup',
' Fixture "browser"',
]);
@@ -1338,6 +1344,7 @@ test('should record trace after fixture teardown timeout', {
'Evaluate',
'After Hooks',
' Fixture "fixture"',
+ 'Attach "error-context"',
'Worker Cleanup',
' Fixture "browser"',
]);
diff --git a/tests/playwright-test/reporter-line.spec.ts b/tests/playwright-test/reporter-line.spec.ts
index f999b39918..1a686bf42e 100644
--- a/tests/playwright-test/reporter-line.spec.ts
+++ b/tests/playwright-test/reporter-line.spec.ts
@@ -308,6 +308,8 @@ Running 1 test using 1 worker
9 |
at ${test.info().outputPath('a.test.ts')}:7:17
+ Error Context: test-results/a-foo/error-context.md
+
1 interrupted
a.test.ts:3:13 › foo ───────────────────────────────────────────────────────────────────────────
diff --git a/tests/playwright-test/reporter-list.spec.ts b/tests/playwright-test/reporter-list.spec.ts
index c48893d9e7..514563bcc6 100644
--- a/tests/playwright-test/reporter-list.spec.ts
+++ b/tests/playwright-test/reporter-list.spec.ts
@@ -488,6 +488,8 @@ Running 1 test using 1 worker
9 |
at ${test.info().outputPath('a.test.ts')}:7:17
+ Error Context: test-results/a-foo/error-context.md
+
1 interrupted
a.test.ts:3:13 › foo ───────────────────────────────────────────────────────────────────────────
`);