Assertions are crucial in QA regression testing as they help verify that the application code works for end users. They focus on the rendered output, which is what users interact with, rather than implementation details.
In @playwright/test, you can use the expect
function for assertions. Choose a matcher that reflects your expectation, like toEqual
, toContain
, or toBeTruthy
. Playwright also offers web-specific async matchers that wait until the expected condition is met.
Here's an example using TypeScript:
import { test, expect } from '@playwright/test';
test('Check page title', async ({ page }) => {
await page.goto('https://ray.run/');
const title = await page.title();
expect(title).toEqual('Ray.run - Playwright Test Automation');
});
For debugging, install the VS Code extension and set breakpoints in your tests. Run tests in debug mode by right-clicking the line number next to the test. To debug a specific test, use the --debug
flag with npx playwright test
:
npx playwright test example.spec.ts:9 --debug
For CI failures, use the Playwright trace viewer to get a full trace of your tests as a local Progressive Web App (PWA). This makes it easy to share and identify issues quickly, saving time spent troubleshooting problems during development cycles.
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].