Rayrun

How do I execute tests using Playwright?

Answer

To run tests with @playwright/test, you have two options: the command line interface (CLI) or the UI mode.

CLI

In the terminal, use the following commands:

  • Run all tests: npx playwright test
  • Run a single test file: npx playwright test landing-page.spec.ts
  • Run multiple test files: npx playwright test tests/todo-page/ tests/landing-page/
  • Run tests with specific keywords: npx playwright test landing login

UI Mode

For a better developer experience, use the UI mode with features like time travel debugging and watch mode. Type npx playwright test --ui in your terminal.

Debugging in VS Code

You can debug your Playwright tests directly in VS Code. Error messages and call logs are displayed within the editor, and you can live debug your code by clicking on locators.

To record new actions at the cursor position, click the "Record at cursor" button in the Testing sidebar. This generates actions in the existing file, allowing you to continue writing your script after running the initial code.

Here's a sample test using TypeScript:

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

test('Check Ray homepage', async ({ page }) => {
  await page.goto('https://ray.run/');
  const title = await page.title();
  expect(title).toBe('Ray - The Future of Work');
});

In summary, you can execute Playwright tests using the CLI or the UI mode. The CLI offers flexibility for running specific files, while the UI mode provides additional features for an enhanced development experience.

Thank you!
Was this helpful?
Still have questions?

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

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 [email protected].