Back to All Questions
Question 36 of 100
Assertions
Intermediate
What is the difference between Hard and Soft Assertions in Playwright?
The Answer
Hard assertions (default) stop the test immediately on failure. Soft assertions (`expect.soft()`) allow the test to continue running and collect ALL failures, reporting them together at the end.
Deep Dive Explanation
Use soft assertions when validating multiple independent fields on a page (like a profile form) where you want to see all broken fields at once. Use hard assertions for critical pre-conditions β if the page title is wrong, there's no point checking the form fields.
example.spec.ts
test('hard vs soft assertions', async ({ page }) => {
await page.goto('/profile');
// HARD assertion - test stops here if it fails
await expect(page).toHaveTitle('User Profile');
// SOFT assertions - test continues even if these fail
await expect.soft(page.getByLabel('Name')).toHaveValue('John Doe');
await expect.soft(page.getByLabel('Email')).toHaveValue('john@example.com');
await expect.soft(page.getByLabel('Phone')).toHaveValue('+1-555-0100');
// Test continues here regardless of soft assertion results
await page.getByRole('button', { name: 'Save' }).click();
// All soft assertion failures are reported at test end
});