🚀 Feature Request
Add endTime property to TestResult which would be the end time of this particular test run.
(and probably add it to TestStep as well)
Example
No response
Motivation
Currently testResult.startTime + testResult.duration is smaller than the actual end time. So computing the end time from these two properties is not accurate.
In our use case, we need a more accurate timestamp because we match server logs to a specific test based on time.
Test showing this behaviour
test('should approximate end time from with startTime + duration', async ({ runInlineTest }) => {
const result = await runInlineTest({
'reporter.ts': `
class Reporter {
onTestEnd(test, result) {
console.log('%%start=' + result.startTime.getTime());
console.log('%%duration=' + result.duration);
}
onStdOut(data) {
// forward test stdout so %%actualEndTest lines reach outputLines
process.stdout.write(data.toString());
}
}
module.exports = Reporter;
`,
'playwright.config.ts': `module.exports = { reporter: './reporter' };`,
'a.spec.ts': `
import { test } from '@playwright/test';
test('timing', async () => {
await new Promise(f => setTimeout(f, 250));
console.log('%%actualEndTest=' + Date.now());
});
`,
}, { reporter: '', workers: 1 });
const start = Number(result.outputLines.find(l => l.startsWith('start='))!.split('=')[1]);
const duration = Number(result.outputLines.find(l => l.startsWith('duration='))!.split('=')[1]);
const actualEndTest = Number(result.outputLines.find(l => l.startsWith('actualEndTest='))!.split('=')[1]);
const reportedTestEnd = start + duration;
const delta = actualEndTest - reportedTestEnd;
const dateToTime = (ms: number) => new Date(ms).toISOString().slice(11, 23); // HH:MM:SS.mmm
console.log([
`start\t\t${dateToTime(start)}`,
`reportedEnd\t${dateToTime(reportedTestEnd)}`,
`actualEnd\t${dateToTime(actualEndTest)}`,
`durationMs\t${duration} ms`,
`deltaMs\t\t${delta} ms`,
].join('\n'));
});
Relative: #38604
🚀 Feature Request
Add
endTimeproperty toTestResultwhich would be the end time of this particular test run.(and probably add it to
TestStepas well)Example
No response
Motivation
Currently
testResult.startTime+testResult.durationis smaller than the actual end time. So computing the end time from these two properties is not accurate.In our use case, we need a more accurate timestamp because we match server logs to a specific test based on time.
Test showing this behaviour
Relative: #38604