To run tests with @playwright/test, you have two options: the command line interface (CLI) or the UI mode.
In the terminal, use the following commands:
npx playwright test
npx playwright test landing-page.spec.ts
npx playwright test tests/todo-page/ tests/landing-page/
npx playwright test landing login
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.
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.
If you still have questions, please ask a question and I will try to answer it.
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].