To create a test using @playwright/test, follow these steps:
First, install Playwright and its dependencies:
npm install -D playwright
Create a new file named my-test.spec.ts
in your project directory.
In my-test.spec.ts
, import the test
object from @playwright/test
and write your test using the test
function. Here's a simple example that navigates to https://ray.run/ and checks if the title contains "Ray":
import { test, expect } from '@playwright/test';
test('Check Ray title', async ({ page }) => {
await page.goto('https://ray.run/');
const title = await page.title();
expect(title).toContain('Ray');
});
Create a playwright.config.ts
file in your project directory with the following content:
import { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
use: {
headless: true,
viewport: { width: 1280, height: 720 },
ignoreHTTPSErrors: true,
},
};
export default config;
Execute your test using the playwright test
command:
npx playwright test
That's it! You've successfully created and executed a test using @playwright/test.
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].