To configure TypeScript for your @playwright/test project, follow these steps:
Create a tsconfig.json
file inside the tests
directory with the following content:
{
"compilerOptions": {
"target": "ESNext",
"module": "CommonJS",
"moduleResolution": "node",
"sourceMap": true,
"outDir": "tests-out"
},
"include": ["tests/**/*.ts"]
}
These options help TypeScript compile your code correctly before running it with Playwright.
Add pretest
and test
scripts to your package.json
:
"scripts": {
"pretest": "tsc -p tests",
"test": "playwright test -c tests-out"
}
The pretest
script compiles TypeScript files in the tests
directory, while test
runs the compiled tests from the tests-out
directory.
Execute your tests with the command:
npm run test
This command builds and runs your TypeScript tests using Playwright.
Remember, Playwright supports TypeScript out of the box, so you can write your tests in TypeScript and Playwright will handle the rest. If you encounter issues, you can manually compile your TypeScript code with Playwright Test.
If you use path mapping in your tsconfig.json
, ensure the baseUrl
is set correctly. After setting up path mapping, you can import using mapped paths.
Playwright offers various reporters, such as the junit reporter, or you can create custom reporters by implementing a class with reporter methods from the Reporter API.
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].