Let me tell you something that will save your career. A test without assertions is not a test. It is a script. It clicks buttons, fills forms, navigates pages -- and then walks away. It never checks if anything actually worked. This is the most common mistake I see in QA teams.
Think of it this way. You visit a doctor. The doctor walks in, says hello, sits down, writes a prescription, and leaves. Never checks your blood pressure. Never listens to your heartbeat. Never asks where it hurts. That is a test without assertions. The visit happened. But no diagnosis was made. No one knows if you are healthy or dying.
Now imagine a doctor who checks your BP, listens to your chest, runs a blood test, checks your reflexes. That doctor is writing assertions. Each check verifies one thing. BP is 120/80? Pass. Heart rate is 72? Pass. Blood sugar is 300? FAIL -- something is wrong. That is what assertions do for your tests.
Playwright uses the expect() function for all assertions. It comes from @playwright/test -- not from Jest, not from Chai. Playwright built its own assertion library specifically designed for web testing. The magic? Every assertion auto-retries. More on that in the next lesson.
import { test, expect } from '@playwright/test';
test('login should work', async ({ page }) => {
await page.goto('/banking');
await page.getByLabel('Username').fill('testuser');
await page.getByLabel('Password').fill('password123');
await page.getByRole('button', { name: 'Login' }).click();
// WITHOUT assertions -- this test always passes. Useless.
// WITH assertions -- now we actually verify something happened:
await expect(page).toHaveURL(/\/dashboard/);
await expect(page.getByText('Welcome, testuser')).toBeVisible();
await expect(page.getByRole('button', { name: 'Logout' })).toBeVisible();
});Rule of thumb: every test should have at least one assertion. Most tests should have 2-5. If your test has zero assertions, delete it or add some. If it has 20, you are probably testing too many things in one test.
I have seen QA teams run 500 tests nightly -- zero assertions in any of them. All green. All passing. All useless. The app had 12 critical bugs in production. Do not be that team.
Q: Why are assertions important in test automation?
A: Assertions are the actual verification step of a test. Without them, a test is just a script that performs actions but never checks the outcome. It will pass even if the application is completely broken. Assertions compare the actual state of the application against the expected state. If they do not match, the test fails -- which is the whole point. Every test must assert at least one thing, otherwise it provides zero value and creates false confidence.
Key Point: Tests without assertions are scripts, not tests. Every test must verify at least one outcome using expect().