add attachments array
This commit is contained in:
parent
606860d250
commit
13d305b959
|
|
@ -50,6 +50,16 @@ Start time of this particular test step.
|
||||||
|
|
||||||
List of steps inside this step.
|
List of steps inside this step.
|
||||||
|
|
||||||
|
## property: TestStep.attachments
|
||||||
|
* since: v1.10
|
||||||
|
- type: <[Array]<[Object]>>
|
||||||
|
- `name` <[string]> Attachment name.
|
||||||
|
- `contentType` <[string]> Content type of this attachment to properly present in the report, for example `'application/json'` or `'image/png'`.
|
||||||
|
- `path` ?<[string]> Optional path on the filesystem to the attached file.
|
||||||
|
- `body` ?<[Buffer]> Optional attachment body used instead of a file.
|
||||||
|
|
||||||
|
The list of files or buffers attached in the step execution through [`property: TestInfo.attachments`].
|
||||||
|
|
||||||
## property: TestStep.title
|
## property: TestStep.title
|
||||||
* since: v1.10
|
* since: v1.10
|
||||||
- type: <[string]>
|
- type: <[string]>
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ export type AttachmentPayload = {
|
||||||
path?: string;
|
path?: string;
|
||||||
body?: string;
|
body?: string;
|
||||||
contentType: string;
|
contentType: string;
|
||||||
|
stepId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TestEndPayload = {
|
export type TestEndPayload = {
|
||||||
|
|
|
||||||
|
|
@ -512,6 +512,7 @@ class TeleTestStep implements reporterTypes.TestStep {
|
||||||
parent: reporterTypes.TestStep | undefined;
|
parent: reporterTypes.TestStep | undefined;
|
||||||
duration: number = -1;
|
duration: number = -1;
|
||||||
steps: reporterTypes.TestStep[] = [];
|
steps: reporterTypes.TestStep[] = [];
|
||||||
|
attachments = [];
|
||||||
|
|
||||||
private _startTime: number = 0;
|
private _startTime: number = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -319,6 +319,7 @@ class JobDispatcher {
|
||||||
startTime: new Date(params.wallTime),
|
startTime: new Date(params.wallTime),
|
||||||
duration: -1,
|
duration: -1,
|
||||||
steps: [],
|
steps: [],
|
||||||
|
attachments: [],
|
||||||
location: params.location,
|
location: params.location,
|
||||||
};
|
};
|
||||||
steps.set(params.stepId, step);
|
steps.set(params.stepId, step);
|
||||||
|
|
@ -358,6 +359,7 @@ class JobDispatcher {
|
||||||
body: params.body !== undefined ? Buffer.from(params.body, 'base64') : undefined
|
body: params.body !== undefined ? Buffer.from(params.body, 'base64') : undefined
|
||||||
};
|
};
|
||||||
data.result.attachments.push(attachment);
|
data.result.attachments.push(attachment);
|
||||||
|
data.steps.get(params.stepId ?? '')?.attachments.push(attachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _failTestWithErrors(test: TestCase, errors: TestError[]) {
|
private _failTestWithErrors(test: TestCase, errors: TestError[]) {
|
||||||
|
|
|
||||||
|
|
@ -237,20 +237,21 @@ export class TestInfoImpl implements TestInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_parentStep(isStage?: boolean) {
|
||||||
|
if (isStage) {
|
||||||
|
// Predefined stages form a fixed hierarchy - use the current one as parent.
|
||||||
|
return this._findLastStageStep(this._steps);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
zones.zoneData<TestStepInternal>('stepZone')
|
||||||
|
?? this._findLastStageStep(this._steps) // If no parent step on stack, assume the current stage as parent.
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
_addStep(data: Omit<TestStepInternal, 'complete' | 'stepId' | 'steps'>): TestStepInternal {
|
_addStep(data: Omit<TestStepInternal, 'complete' | 'stepId' | 'steps'>): TestStepInternal {
|
||||||
const stepId = `${data.category}@${++this._lastStepId}`;
|
const stepId = `${data.category}@${++this._lastStepId}`;
|
||||||
|
|
||||||
let parentStep: TestStepInternal | undefined;
|
const parentStep = this._parentStep(data.isStage);
|
||||||
if (data.isStage) {
|
|
||||||
// Predefined stages form a fixed hierarchy - use the current one as parent.
|
|
||||||
parentStep = this._findLastStageStep(this._steps);
|
|
||||||
} else {
|
|
||||||
parentStep = zones.zoneData<TestStepInternal>('stepZone');
|
|
||||||
if (!parentStep) {
|
|
||||||
// If no parent step on stack, assume the current stage as parent.
|
|
||||||
parentStep = this._findLastStageStep(this._steps);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const filteredStack = filteredStackTrace(captureRawStack());
|
const filteredStack = filteredStackTrace(captureRawStack());
|
||||||
data.boxedStack = parentStep?.boxedStack;
|
data.boxedStack = parentStep?.boxedStack;
|
||||||
|
|
@ -414,7 +415,8 @@ export class TestInfoImpl implements TestInfo {
|
||||||
name: attachment.name,
|
name: attachment.name,
|
||||||
contentType: attachment.contentType,
|
contentType: attachment.contentType,
|
||||||
path: attachment.path,
|
path: attachment.path,
|
||||||
body: attachment.body?.toString('base64')
|
body: attachment.body?.toString('base64'),
|
||||||
|
stepId: this._parentStep()?.stepId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
27
packages/playwright/types/testReporter.d.ts
vendored
27
packages/playwright/types/testReporter.d.ts
vendored
|
|
@ -684,6 +684,33 @@ export interface TestStep {
|
||||||
*/
|
*/
|
||||||
titlePath(): Array<string>;
|
titlePath(): Array<string>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The list of files or buffers attached in the step execution through
|
||||||
|
* [testInfo.attachments](https://playwright.dev/docs/api/class-testinfo#test-info-attachments).
|
||||||
|
*/
|
||||||
|
attachments: Array<{
|
||||||
|
/**
|
||||||
|
* Attachment name.
|
||||||
|
*/
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content type of this attachment to properly present in the report, for example `'application/json'` or
|
||||||
|
* `'image/png'`.
|
||||||
|
*/
|
||||||
|
contentType: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional path on the filesystem to the attached file.
|
||||||
|
*/
|
||||||
|
path?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional attachment body used instead of a file.
|
||||||
|
*/
|
||||||
|
body?: Buffer;
|
||||||
|
}>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Step category to differentiate steps with different origin and verbosity. Built-in categories are:
|
* Step category to differentiate steps with different origin and verbosity. Built-in categories are:
|
||||||
* - `hook` for fixtures and hooks initialization and teardown
|
* - `hook` for fixtures and hooks initialization and teardown
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue