To set up Playwright for desktop app testing with Node.js and TypeScript, follow these steps:
Install dependencies: Install Playwright and its test runner, @playwright/test, using npm or yarn:
npm install playwright @playwright/test
Create a tsconfig.json file:
Inside the tests directory, create a tsconfig.json
file and configure it accordingly:
{
"compilerOptions": {
"target": "ESNext",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"outDir": "tests-out"
},
"include": ["tests"]
}
Update package.json:
Add two scripts to your package.json
file: pretest
and test
. The pretest
script runs TypeScript on the tests, while test
runs the generated tests in the tests-out
directory:
"scripts": {
"pretest": "tsc",
"test": "playwright test tests-out"
}
Write a test:
Create a test file, e.g., mytest.spec.ts
, and write a simple test using Playwright:
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');
});
Run the test: Execute your test using the following command:
npm test
Now you have successfully set up Playwright for desktop app testing with Node.js and TypeScript. Remember, Playwright runs browsers in headless mode by default. To see the browser UI, pass the headless: false
flag when launching the browser. You can also use the slowMo
option to slow down execution if needed.
For more tips and best practices, check out Tips for Writing Efficient Playwright Test Scripts and Mastering Playwright Test Automation: Your Comprehensive Cheat Sheet.
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].