First, install Playwright. Run npm init playwright@latest
in your terminal. This will prompt you to make some choices about your setup. Don't worry, Playwright has sensible defaults for most of these.
npm init playwright@latest
Playwright supports all modern rendering engines, including WebKit. However, it doesn't work with the branded version of Safari. So, you'll be testing against the recent WebKit build.
Next, you'll want to configure your project for testing with Playwright and React. Check out the "Experimental: components" section of the Playwright documentation for this.
Now, let's create a test file for your React app. Here's a simple test script you can use as a starting point:
import { test } from '@playwright/test';
import { expect } from 'chai';
test('basic test', async ({ page }) => {
await page.goto('https://ray.run/');
const title = await page.title();
expect(title).to.equal('Ray');
});
You can also use beforeMount
and afterMount
hooks to set up things like an app router or fake server. This gives you more flexibility when testing.
In short, here's your game plan:
For more insights on Playwright, check out these blog posts on detecting and handling flaky tests and writing efficient test scripts.
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].