playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature]: Timestamps in HTML report and CI reporters

Open pgarbocz opened this issue 1 year ago • 0 comments

🚀 Feature Request

It would be nice to have timestamps of start and completion of a test inside the HTML report and also in the CI reporters, like list reporter, to know when the tested application failed and what time I should look at in the application logs.

For CI reporters maybe it makes more sense to print timestamps only in the details of the failed tests to not break the slim format.

Example

No response

Motivation

When we run the tests for the application on a test server, they generates a lot of logs of our application. When some test fail, we need to check the logs to see if there are any exceptions/errors. If we had the timestamps when it started and when it completed the test (either succeeded or failed), we could easily find the proper piece of logs.

From what I saw, in JUnit xml there is a timestamp and duration time, thanks to that Azure Devops can present Date started and Date completed for each test case.

pgarbocz avatar Jun 28 '24 07:06 pgarbocz

Maybe you could use a fixture:

import { test as base } from '@playwright/test';

export const test = base.extend<{ testHook: void }>({
    testHook: [
        async ({ }, use): Promise<void> => {
            // Any code here will be run as a before each hook
            // See more: https://playwright.dev/docs/test-fixtures#execution-order
            console.log(`Playwright worker: ${test.info().workerIndex}\n`);

            console.log(`Test started at ${new Date().toString()}\n`);

            await use();

            // Any code here will be run as a after each hook
            console.log(`Test finished at ${new Date().toString()}\n`);
        },

        // Automatic fixtures are set up for each test/worker, even when the test does not list them directly
        // See more: https://playwright.dev/docs/test-fixtures#automatic-fixtures
        { auto: true },
    ],
});

brunojbarros avatar Jul 01 '24 10:07 brunojbarros

@brunojbarros Yes, that's a workaround, but then the reporter spams these logs for each tests when run in command.

pgarbocz avatar Jul 15 '24 11:07 pgarbocz