What does the 'test' function do in Playwright?


In @playwright/test, test is a function that lets you declare tests and write assertions. It takes one or two arguments: an object with fixtures and optional TestInfo.

Here's how you can use it:

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

test('my test', async ({ page }) => {
  await page.goto('https://ray.run/');
  // Your test code here

The first argument is an object containing fixtures like page, browser, and context. You can use these fixtures to interact with web pages and perform operations on web elements.

The second argument, TestInfo, gives you details about the current test. It has properties like title, retry, and status.

Playwright also offers hooks like afterEach and afterAll. You can use afterEach to do cleanup tasks or log information after each test. afterAll runs once per worker after all tests are done. It's useful for tasks like closing database connections or cleaning up temporary files.

Additionally, Playwright provides functions like fixme(). This function marks a test as "fixme", indicating it needs more work to pass. You can use it with no arguments to mark all tests, boolean conditionals to mark only those where condition evaluates true, or callback functions to mark only those where callback returns true.

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

Related Questions

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.