Playwright Offers API to write custom test reports. A custom reporter is a class that implements specific methods to handle events during the test run. Playwright Reporter API can be implemented and the native reporter methods of API can overridden based on needs. Below is an example:
PlaywrightCustomReporter.js
class MyCustomReporter { onBegin(config, suite) { console.log(`Starting the test run with ${suite.allTests().length} tests`); } onSuiteBegin(suite) { console.log(`Starting suite: ${suite.title}`); } onSuiteEnd(suite) { console.log(`Finished suite: ${suite.title}`); } onTestBegin(test) { console.log(`Starting test: ${test.title}`); } onTestEnd(test, result) { console.log(`Finished test: ${test.title} with status ${result.status}`); if (result.error) { console.error(`Error: ${result.error.message}`); } } onTestFailure(test, result) { console.error(`Test failed: ${test.title}`); console.error(`Error: ${result.error.message}`); } onTestSuccess(test, result) { console.log(`Test passed: ${test.title}`); } onTestTimeout(test) { console.warn(`Test timed out: ${test.title}`); } // Called when a test's retry count is exhausted onTestRetry(test) { console.warn(`Test retried: ${test.title}`); } onEnd(result) { console.log(`Test run finished with status ${result.status}`); console.log(`Total tests: ${result.totalTests}`); console.log(`Passed: ${result.passedTests}`); console.log(`Failed: ${result.failedTests}`); } onStdOut(data) { process.stdout.write(data); } onStdErr(data) { process.stderr.write(data); } onStepBegin(test, step) { console.log('Step Begin:'); console.log('Test:', test); console.log('Step:', step); } onStepEnd(test, step, result) { console.log('Step End:'); console.log('Test:', test); console.log('Step:', step); console.log('Result:', result); } } export default MyCustomReporter;
This code defines a custom reporter class MyCustomReporter
that implements various methods to track and log the progress of a test run. It's designed to be used with a testing framework, likely Playwright, where it provides detailed logs at different stages of the test execution process.
Here’s a brief explanation of each method:
onBegin(config, suite)
: Logs the start of the test run, including the number of tests in the suite.onSuiteBegin(suite)
: Logs the start of a test suite.onSuiteEnd(suite)
: Logs the end of a test suite.onTestBegin(test)
: Logs the start of an individual test.onTestEnd(test, result)
: Logs the end of an individual test, including its status and any errors if they occurred.onTestFailure(test, result)
: Logs detailed information about a failed test.onTestSuccess(test, result)
: Logs a message when a test passes.onTestTimeout(test)
: Logs when a test times out.onTestRetry(test)
: Logs when a test is retried.onEnd(result)
: Logs the summary of the test run, including the status and counts of total, passed, and failed tests.onStdOut(data)
: Writes stdout output to the console.onStdErr(data)
: Writes stderr output to the console.onStepBegin(test, step)
: Logs the start of a test step, along with the test and step details.
{ "test": { "title": "basic test", "_only": false, "_requireFile": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\example.spec.js", "results": [ { "retry": 0, "parallelIndex": 0, "workerIndex": 0, "duration": 2662, "startTime": "2024-08-21T14:36:32.149Z", "stdout": [], "stderr": [], "attachments": [], "status": "passed", "steps": [ { "title": "Before Hooks", "category": "hook", "startTime": "2024-08-21T14:36:32.156Z", "duration": 1519, "steps": [ { "title": "fixture: browser", "category": "fixture", "startTime": "2024-08-21T14:36:32.170Z", "duration": 304, "steps": [ { "title": "browserType.launch", "category": "pw:api", "startTime": "2024-08-21T14:36:32.176Z", "duration": 298, "steps": [] } ] }, { "title": "fixture: context", "category": "fixture", "startTime": "2024-08-21T14:36:32.476Z", "duration": 20, "steps": [ { "title": "browser.newContext", "category": "pw:api", "startTime": "2024-08-21T14:36:32.480Z", "duration": 12, "steps": [] } ] }, { "title": "fixture: page", "category": "fixture", "startTime": "2024-08-21T14:36:32.497Z", "duration": 1178, "steps": [ { "title": "browserContext.newPage", "category": "pw:api", "startTime": "2024-08-21T14:36:32.501Z", "duration": 1174, "steps": [] } ] } ] }, { "title": "page.goto(https://sandbox.mabl.com/)", "category": "pw:api", "startTime": "2024-08-21T14:36:33.680Z", "duration": 1231, "steps": [], "location": { "file": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\example.spec.js", "line": 5, "column": 15 } }, { "title": "locator.getByRole('button', { name: 'new window' }).click", "category": "pw:api", "startTime": "2024-08-21T14:36:34.925Z", "duration": 186, "steps": [], "location": { "file": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\example.spec.js", "line": 6, "column": 57 } }, { "title": "After Hooks", "category": "hook", "startTime": "2024-08-21T14:36:35.112Z", "duration": 24, "steps": [ { "title": "fixture: page", "category": "fixture", "startTime": "2024-08-21T14:36:35.114Z", "duration": 1, "steps": [] }, { "title": "fixture: context", "category": "fixture", "startTime": "2024-08-21T14:36:35.116Z", "duration": 1, "steps": [] } ] } ], "errors": [] } ], "location": { "file": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\example.spec.js", "line": 4, "column": 1 }, "parent": { "title": "example.spec.js", "_only": false, "_requireFile": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\example.spec.js", "location": { "file": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\example.spec.js", "line": 0, "column": 0 }, "parent": { "title": "", "_only": false, "_requireFile": "", "parent": { "title": "", "_only": false, "_requireFile": "", "_use": [], "_entries": [ null ], "_hooks": [], "_staticAnnotations": [], "_tags": [], "_modifiers": [], "_parallelMode": "none", "_type": "root" }, "_use": [], "_entries": [ null ], "_hooks": [], "_staticAnnotations": [], "_tags": [], "_modifiers": [], "_parallelMode": "none", "_fullProject": { "project": { "grep": {}, "grepInvert": null, "outputDir": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\test-results", "repeatEach": 1, "retries": 0, "metadata": {}, "name": "", "testDir": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index", "snapshotDir": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index", "testIgnore": [], "testMatch": "**/*.@(spec|test).?(c|m)[jt]s?(x)", "timeout": 30000, "use": {}, "dependencies": [], "__projectId": "" }, "fullConfig": { "config": { "configFile": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\playwright.config.js", "rootDir": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index", "forbidOnly": false, "fullyParallel": false, "globalSetup": null, "globalTeardown": null, "globalTimeout": 0, "grepInvert": null, "maxFailures": 0, "metadata": { "actualWorkers": 1 }, "preserveOutput": "always", "reporter": [ [ "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\PlaywrightReporter.js", null ] ], "reportSlowTests": { "max": 5, "threshold": 15000 }, "quiet": false, "projects": [ null ], "shard": null, "updateSnapshots": "missing", "version": "1.46.1", "workers": 4, "webServer": null }, "configDir": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index", "configCLIOverrides": {}, "webServers": [], "plugins": [], "projects": [ null ], "cliArgs": [], "cliListOnly": false, "cliPassWithNoTests": false, "cliFailOnFlakyTests": false, "defineConfigWasUsed": true }, "expect": {}, "respectGitIgnore": true, "snapshotPathTemplate": "{snapshotDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-projectName}{-snapshotSuffix}{ext}", "ignoreSnapshots": false, "id": "", "deps": [] }, "_type": "project" }, "_use": [], "_entries": [ null ], "_hooks": [], "_staticAnnotations": [], "_tags": [], "_modifiers": [], "_parallelMode": "none", "_fileId": "dd9b2edffe9b7501040c", "_type": "file" }, "type": "test", "expectedStatus": "passed", "timeout": 30000, "annotations": [], "retries": 0, "repeatEachIndex": 0, "_testType": { "fixtures": [ { "fixtures": { "defaultBrowserType": [ "chromium", { "scope": "worker", "option": true } ], "browserName": [ null, { "scope": "worker", "option": true } ], "playwright": [ null, { "scope": "worker", "box": true } ], "headless": [ null, { "scope": "worker", "option": true } ], "channel": [ null, { "scope": "worker", "option": true } ], "launchOptions": [ {}, { "scope": "worker", "option": true } ], "connectOptions": [ null, { "scope": "worker", "option": true } ], "screenshot": [ "off", { "scope": "worker", "option": true } ], "video": [ "off", { "scope": "worker", "option": true } ], "trace": [ "off", { "scope": "worker", "option": true } ], "_browserOptions": [ null, { "scope": "worker", "auto": true, "box": true } ], "browser": [ null, { "scope": "worker", "timeout": 0 } ], "acceptDownloads": [ null, { "option": true } ], "bypassCSP": [ null, { "option": true } ], "colorScheme": [ null, { "option": true } ], "deviceScaleFactor": [ null, { "option": true } ], "extraHTTPHeaders": [ null, { "option": true } ], "geolocation": [ null, { "option": true } ], "hasTouch": [ null, { "option": true } ], "httpCredentials": [ null, { "option": true } ], "ignoreHTTPSErrors": [ null, { "option": true } ], "isMobile": [ null, { "option": true } ], "javaScriptEnabled": [ null, { "option": true } ], "locale": [ null, { "option": true } ], "offline": [ null, { "option": true } ], "permissions": [ null, { "option": true } ], "proxy": [ null, { "option": true } ], "storageState": [ null, { "option": true } ], "clientCertificates": [ null, { "option": true } ], "timezoneId": [ null, { "option": true } ], "userAgent": [ null, { "option": true } ], "viewport": [ null, { "option": true } ], "actionTimeout": [ 0, { "option": true } ], "testIdAttribute": [ "data-testid", { "option": true } ], "navigationTimeout": [ 0, { "option": true } ], "baseURL": [ null, { "option": true } ], "serviceWorkers": [ null, { "option": true } ], "contextOptions": [ {}, { "option": true } ], "_combinedContextOptions": [ null, { "box": true } ], "_setupContextOptions": [ null, { "auto": "all-hooks-included", "title": "context configuration", "box": true } ], "_setupArtifacts": [ null, { "auto": "all-hooks-included", "title": "trace recording", "box": true } ], "_contextFactory": [ null, { "scope": "test", "title": "context", "box": true } ], "_optionContextReuseMode": [ "none", { "scope": "worker", "option": true } ], "_optionConnectOptions": [ null, { "scope": "worker", "option": true } ], "_reuseContext": [ null, { "scope": "worker", "title": "context", "box": true } ] }, "location": { "file": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\node_modules\\playwright\\lib\\index.js", "line": 884, "column": 39 } } ] }, "id": "dd9b2edffe9b7501040c-afd96d08a88ecfcf2eec", "_poolDigest": "37500f500367e2c2037c76158069d8d577577210", "_workerHash": "-37500f500367e2c2037c76158069d8d577577210-0", "_projectId": "", "_staticAnnotations": [], "_tags": [] }, "step": { "retry": 0, "parallelIndex": 0, "workerIndex": 0, "duration": 5545, "startTime": "2024-08-21T14:38:11.661Z", "stdout": [], "stderr": [], "attachments": [], "status": "passed", "steps": [ { "title": "Before Hooks", "category": "hook", "startTime": "2024-08-21T14:38:11.668Z", "duration": 1587, "steps": [ { "title": "fixture: browser", "category": "fixture", "startTime": "2024-08-21T14:38:11.685Z", "duration": 331, "steps": [ { "title": "browserType.launch", "category": "pw:api", "startTime": "2024-08-21T14:38:11.694Z", "duration": 322, "steps": [] } ] }, { "title": "fixture: context", "category": "fixture", "startTime": "2024-08-21T14:38:12.018Z", "duration": 32, "steps": [ { "title": "browser.newContext", "category": "pw:api", "startTime": "2024-08-21T14:38:12.023Z", "duration": 23, "steps": [] } ] }, { "title": "fixture: page", "category": "fixture", "startTime": "2024-08-21T14:38:12.051Z", "duration": 1204, "steps": [ { "title": "browserContext.newPage", "category": "pw:api", "startTime": "2024-08-21T14:38:12.056Z", "duration": 1198, "steps": [] } ] } ] }, { "title": "page.goto(https://sandbox.mabl.com/)", "category": "pw:api", "startTime": "2024-08-21T14:38:13.260Z", "duration": 4140, "steps": [], "location": { "file": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\example.spec.js", "line": 5, "column": 15 } }, { "title": "locator.getByRole('button', { name: 'new window' }).click", "category": "pw:api", "startTime": "2024-08-21T14:38:17.409Z", "duration": 123, "steps": [], "location": { "file": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\example.spec.js", "line": 6, "column": 57 } }, { "title": "After Hooks", "category": "hook", "startTime": "2024-08-21T14:38:17.534Z", "duration": 22, "steps": [ { "title": "fixture: page", "category": "fixture", "startTime": "2024-08-21T14:38:17.535Z", "duration": 1, "steps": [] }, { "title": "fixture: context", "category": "fixture", "startTime": "2024-08-21T14:38:17.537Z", "duration": 0, "steps": [] } ] } ], "errors": [] } }
onStepEnd(test, step, result)
: Logs the end of a test step, including the result of the step.
{ "test":{ "title": "basic test", "_only": false, "_requireFile": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\example.spec.js", "results": [ { "retry": 0, "parallelIndex": 0, "workerIndex": 0, "duration": 3094, "startTime": "2024-08-21T14:33:03.207Z", "stdout": [], "stderr": [], "attachments": [], "status": "passed", "steps": [ { "title": "Before Hooks", "category": "hook", "startTime": "2024-08-21T14:33:03.218Z", "duration": 2537, "steps": [ { "title": "fixture: browser", "category": "fixture", "startTime": "2024-08-21T14:33:03.237Z", "duration": 933, "steps": [ { "title": "browserType.launch", "category": "pw:api", "startTime": "2024-08-21T14:33:03.245Z", "duration": 925, "steps": [] } ] }, { "title": "fixture: context", "category": "fixture", "startTime": "2024-08-21T14:33:04.172Z", "duration": 21, "steps": [ { "title": "browser.newContext", "category": "pw:api", "startTime": "2024-08-21T14:33:04.176Z", "duration": 13, "steps": [] } ] }, { "title": "fixture: page", "category": "fixture", "startTime": "2024-08-21T14:33:04.194Z", "duration": 1561, "steps": [ { "title": "browserContext.newPage", "category": "pw:api", "startTime": "2024-08-21T14:33:04.198Z", "duration": 1557, "steps": [] } ] } ] }, { "title": "page.goto(https://sandbox.mabl.com/)", "category": "pw:api", "startTime": "2024-08-21T14:33:05.761Z", "duration": 1291, "steps": [], "location": { "file": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\example.spec.js", "line": 5, "column": 15 } }, { "title": "locator.getByRole('button', { name: 'new window' }).click", "category": "pw:api", "startTime": "2024-08-21T14:33:07.065Z", "duration": 161, "steps": [], "location": { "file": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\example.spec.js", "line": 6, "column": 57 } }, { "title": "After Hooks", "category": "hook", "startTime": "2024-08-21T14:33:07.228Z", "duration": 30, "steps": [ { "title": "fixture: page", "category": "fixture", "startTime": "2024-08-21T14:33:07.230Z", "duration": 0, "steps": [] }, { "title": "fixture: context", "category": "fixture", "startTime": "2024-08-21T14:33:07.231Z", "duration": 0, "steps": [] } ] } ], "errors": [] } ], "location": { "file": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\example.spec.js", "line": 4, "column": 1 }, "parent": { "title": "example.spec.js", "_only": false, "_requireFile": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\example.spec.js", "location": { "file": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\example.spec.js", "line": 0, "column": 0 }, "parent": { "title": "", "_only": false, "_requireFile": "", "parent": { "title": "", "_only": false, "_requireFile": "", "_use": [], "_entries": [ null ], "_hooks": [], "_staticAnnotations": [], "_tags": [], "_modifiers": [], "_parallelMode": "none", "_type": "root" }, "_use": [], "_entries": [ null ], "_hooks": [], "_staticAnnotations": [], "_tags": [], "_modifiers": [], "_parallelMode": "none", "_fullProject": { "project": { "grep": {}, "grepInvert": null, "outputDir": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\test-results", "repeatEach": 1, "retries": 0, "metadata": {}, "name": "", "testDir": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index", "snapshotDir": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index", "testIgnore": [], "testMatch": "**/*.@(spec|test).?(c|m)[jt]s?(x)", "timeout": 30000, "use": {}, "dependencies": [], "__projectId": "" }, "fullConfig": { "config": { "configFile": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\playwright.config.js", "rootDir": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index", "forbidOnly": false, "fullyParallel": false, "globalSetup": null, "globalTeardown": null, "globalTimeout": 0, "grepInvert": null, "maxFailures": 0, "metadata": { "actualWorkers": 1 }, "preserveOutput": "always", "reporter": [ [ "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\PlaywrightReporter.js", null ] ], "reportSlowTests": { "max": 5, "threshold": 15000 }, "quiet": false, "projects": [ null ], "shard": null, "updateSnapshots": "missing", "version": "1.46.1", "workers": 4, "webServer": null }, "configDir": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index", "configCLIOverrides": {}, "webServers": [], "plugins": [], "projects": [ null ], "cliArgs": [], "cliListOnly": false, "cliPassWithNoTests": false, "cliFailOnFlakyTests": false, "defineConfigWasUsed": true }, "expect": {}, "respectGitIgnore": true, "snapshotPathTemplate": "{snapshotDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-projectName}{-snapshotSuffix}{ext}", "ignoreSnapshots": false, "id": "", "deps": [] }, "_type": "project" }, "_use": [], "_entries": [ null ], "_hooks": [], "_staticAnnotations": [], "_tags": [], "_modifiers": [], "_parallelMode": "none", "_fileId": "dd9b2edffe9b7501040c", "_type": "file" }, "type": "test", "expectedStatus": "passed", "timeout": 30000, "annotations": [], "retries": 0, "repeatEachIndex": 0, "_testType": { "fixtures": [ { "fixtures": { "defaultBrowserType": [ "chromium", { "scope": "worker", "option": true } ], "browserName": [ null, { "scope": "worker", "option": true } ], "playwright": [ null, { "scope": "worker", "box": true } ], "headless": [ null, { "scope": "worker", "option": true } ], "channel": [ null, { "scope": "worker", "option": true } ], "launchOptions": [ {}, { "scope": "worker", "option": true } ], "connectOptions": [ null, { "scope": "worker", "option": true } ], "screenshot": [ "off", { "scope": "worker", "option": true } ], "video": [ "off", { "scope": "worker", "option": true } ], "trace": [ "off", { "scope": "worker", "option": true } ], "_browserOptions": [ null, { "scope": "worker", "auto": true, "box": true } ], "browser": [ null, { "scope": "worker", "timeout": 0 } ], "acceptDownloads": [ null, { "option": true } ], "bypassCSP": [ null, { "option": true } ], "colorScheme": [ null, { "option": true } ], "deviceScaleFactor": [ null, { "option": true } ], "extraHTTPHeaders": [ null, { "option": true } ], "geolocation": [ null, { "option": true } ], "hasTouch": [ null, { "option": true } ], "httpCredentials": [ null, { "option": true } ], "ignoreHTTPSErrors": [ null, { "option": true } ], "isMobile": [ null, { "option": true } ], "javaScriptEnabled": [ null, { "option": true } ], "locale": [ null, { "option": true } ], "offline": [ null, { "option": true } ], "permissions": [ null, { "option": true } ], "proxy": [ null, { "option": true } ], "storageState": [ null, { "option": true } ], "clientCertificates": [ null, { "option": true } ], "timezoneId": [ null, { "option": true } ], "userAgent": [ null, { "option": true } ], "viewport": [ null, { "option": true } ], "actionTimeout": [ 0, { "option": true } ], "testIdAttribute": [ "data-testid", { "option": true } ], "navigationTimeout": [ 0, { "option": true } ], "baseURL": [ null, { "option": true } ], "serviceWorkers": [ null, { "option": true } ], "contextOptions": [ {}, { "option": true } ], "_combinedContextOptions": [ null, { "box": true } ], "_setupContextOptions": [ null, { "auto": "all-hooks-included", "title": "context configuration", "box": true } ], "_setupArtifacts": [ null, { "auto": "all-hooks-included", "title": "trace recording", "box": true } ], "_contextFactory": [ null, { "scope": "test", "title": "context", "box": true } ], "_optionContextReuseMode": [ "none", { "scope": "worker", "option": true } ], "_optionConnectOptions": [ null, { "scope": "worker", "option": true } ], "_reuseContext": [ null, { "scope": "worker", "title": "context", "box": true } ] }, "location": { "file": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\node_modules\\playwright\\lib\\index.js", "line": 884, "column": 39 } } ] }, "id": "dd9b2edffe9b7501040c-afd96d08a88ecfcf2eec", "_poolDigest": "37500f500367e2c2037c76158069d8d577577210", "_workerHash": "-37500f500367e2c2037c76158069d8d577577210-0", "_projectId": "", "_staticAnnotations": [], "_tags": [] }, "step": { "retry": 0, "parallelIndex": 0, "workerIndex": 0, "duration": 2705, "startTime": "2024-08-21T14:31:07.284Z", "stdout": [], "stderr": [], "attachments": [], "status": "passed", "steps": [ { "title": "Before Hooks", "category": "hook", "startTime": "2024-08-21T14:31:07.292Z", "duration": 1483, "steps": [ { "title": "fixture: browser", "category": "fixture", "startTime": "2024-08-21T14:31:07.310Z", "duration": 327, "steps": [ { "title": "browserType.launch", "category": "pw:api", "startTime": "2024-08-21T14:31:07.319Z", "duration": 317, "steps": [] } ] }, { "title": "fixture: context", "category": "fixture", "startTime": "2024-08-21T14:31:07.639Z", "duration": 18, "steps": [ { "title": "browser.newContext", "category": "pw:api", "startTime": "2024-08-21T14:31:07.643Z", "duration": 11, "steps": [] } ] }, { "title": "fixture: page", "category": "fixture", "startTime": "2024-08-21T14:31:07.659Z", "duration": 1116, "steps": [ { "title": "browserContext.newPage", "category": "pw:api", "startTime": "2024-08-21T14:31:07.663Z", "duration": 1112, "steps": [] } ] } ] }, { "title": "page.goto(https://sandbox.mabl.com/)", "category": "pw:api", "startTime": "2024-08-21T14:31:08.781Z", "duration": 1333, "steps": [], "location": { "file": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\example.spec.js", "line": 5, "column": 15 } }, { "title": "locator.getByRole('button', { name: 'new window' }).click", "category": "pw:api", "startTime": "2024-08-21T14:31:10.127Z", "duration": 177, "steps": [], "location": { "file": "C:\\Users\\VinayChristopher\\OneDrive - Royal Cyber Inc\\Documents\\D drive\\Official\\TEAF\\playwrght\\index\\example.spec.js", "line": 6, "column": 57 } }, { "title": "After Hooks", "category": "hook", "startTime": "2024-08-21T14:31:10.306Z", "duration": 33, "steps": [ { "title": "fixture: page", "category": "fixture", "startTime": "2024-08-21T14:31:10.309Z", "duration": 0, "steps": [] }, { "title": "fixture: context", "category": "fixture", "startTime": "2024-08-21T14:31:10.311Z", "duration": 0, "steps": [] } ] } ], "errors": [] }, "result": { "title": "browserType.launch", "parent": { "title": "fixture: browser", "parent": { "title": "Before Hooks", "category": "hook", "startTime": "2024-08-21T14:34:58.224Z", "duration": 1530, "steps": [ null, { "title": "fixture: context", "category": "fixture", "startTime": "2024-08-21T14:34:58.555Z", "duration": 22, "steps": [ { "title": "browser.newContext", "category": "pw:api", "startTime": "2024-08-21T14:34:58.560Z", "duration": 13, "steps": [] } ] }, { "title": "fixture: page", "category": "fixture", "startTime": "2024-08-21T14:34:58.579Z", "duration": 1175, "steps": [ { "title": "browserContext.newPage", "category": "pw:api", "startTime": "2024-08-21T14:34:58.584Z", "duration": 1170, "steps": [] } ] } ] }, "category": "fixture", "startTime": "2024-08-21T14:34:58.241Z", "duration": 312, "steps": [ null ] }, "category": "pw:api", "startTime": "2024-08-21T14:34:58.247Z", "duration": 305, "steps": [] } }
There are primarily two ways to use the Custom Reporter API.
Define in playwright.config.js/ts
import { defineConfig } from '@playwright/test'; export default defineConfig({ globalTeardown: './global-teardown', });
Passing the parameter while executing the test command
import {exec} from "child_process"; exec("npx playwright test --reporter="./myreporter/PlaywrightCustomReporter.js"")