TestInfo contains information about currently running test. It is available to any test function, test.beforeEach() and test.afterEach() hooks and test-scoped fixtures. TestInfo provides utilities to control test execution: attach files, update test timeout, determine which test is currently running and whether it was retried, etc.
In this video, Jared from Commit Quality demonstrates some useful examples of how to use the test info parameter in Playwright. Test info contains information about your currently executing test and provides utilities to control test execution. Here are a few examples of how test info can be used:
Output the title of the test: You can access the test title using testInfo.title
. This could be used for logging or naming a screenshot based on the test title.
console.log(testInfo.title);
Use test info title to name a screenshot: You can toggle a screenshot to be named based on the test info title by using the screenshot method in Playwright and passing the test info title as the path option.
await page.screenshot({path: `screenshots/${testInfo.title}.png`});
Failing a test: You can use test info to mark a test as failed, even if it passed. This could be useful if you want to manually control which tests should fail.
testInfo.fail();
Setting a test timeout: Test info can be used to set a custom timeout for a particular test based on the default timeout set in the configuration file.
testInfo.setTimeout(testInfo.timeout + 2000);
There are many more possibilities when using test info in Playwright. Check out the Playwright documentation for a more in-depth look at the different ways test info can be used.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].