Rayrun
← Back to videos

Playwright Tutorial - (NODEJS) Get Test Information during test execution

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:

  1. 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);
  2. 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`});
  3. 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();
  4. 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.

Related Videos

#16 - ARIA and how Playwright is making use of it to identify UI controls?
#16 - ARIA and how Playwright is making use of it to identify UI controls?
Create feature, steps & config | Playwright & Cucumber - Typescript | Part 1
Create feature, steps & config | Playwright & Cucumber - Typescript | Part 1
Playwright Working with Multiple tabs (NODEJS)
Playwright Working with Multiple tabs (NODEJS)
Code-first Playwright intro tutorial on macOS (install to first script)
Code-first Playwright intro tutorial on macOS (install to first script)
TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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 luc@ray.run.