Run Tests with Command Line | Bondar Academy
Course: Playwright UI Testing with TypeScript
Module: Getting Started with Playwright
Instructor: Artem Bondar
Lesson Summary
Playwright Framework Overview This lesson provides an overview of the Playwright Framework and demonstrates how to run tests using the command line interface. Running Playwright Tests To execute all Playwright tests, use the command: npx playwright test This command runs all tests across all spec files configured in the project. For example, running this command executed six tests using five workers in just over four seconds. Understanding Workers Workers: Each worker acts as a single test executor. The number of workers is determined by the machine's CPU cores, divided by two. For instance, a MacBook with an M1 Pro chip (10 cores) can utilize five workers. Configuration: The number of workers can be set in the configuration file, with options for CI pipelines and local execution. Running Tests in Headed Mode To run tests with visible browsers, add the --headed flag: npx playwright test --headed Running Specific Tests To run tests for a specific project or spec file, use: npx playwright test --project=Chromium npx playwright test --spec=example.spec.ts Additionally, you can run a test by its name using: npx playwright test -g "has title" Viewing Test Reports To view the report of the last execution, use: npx playwright show-report To skip a test, use the .only or .skip annotations in the spec file. TypeScript Configuration If TypeScript compiler errors occur, create a tsconfig.json file with the following settings: { "compilerOptions": { "types": ["node"] } } This lesson covers the essential commands and configurations needed to effectively use Playwright in a testing environment.