Playwright 1.51 is here, bringing a host of new features to make debugging, reporting, and test automation even more powerful. Whether you're tackling test failures, improving test visibility, or streamlining authentication workflows, this release has something for you. Letβs dive into whatβs new!
π AI-Friendly Copy Prompt for Debugging
When a test fails, Playwright now provides a Copy Prompt feature that generates a structured debugging prompt. You can paste this directly into an AI tool to get assistance in understanding and fixing the issue. This makes troubleshooting faster and more efficient. The copy prompt button appears in the error tab of both the HTML reporter and UI mode.
If you want your prompt to be smart and include the diff, add this to your config:
export default defineConfig({β
captureGitInfo: { diff: true }β
});
πͺͺ Git Info in HTML Reports
Understanding test failures in context just got easier! Playwright 1.51 allows you to include Git commit details in your HTML reports, providing more traceability for when and why a test was executed. This is especially helpful for teams working in CI/CD environments where changes happen frequently.
Capture and Store Git Information in HTML Reports
If you donβt use GitHub, GitLab, or Jenkins, you need to specify this line:
export default defineConfig({β
captureGitInfo: { commit: true }β
});
π₯ Firebase Authentication Support
Testing applications that use Firebase authentication is now smoother with native support. This enhancement simplifies authentication flows in tests, making it easier to validate user access and interactions without complex setup.
Save and Restore IndexedDB Contents in Storage State β Firebase Authentication
To persist authentication state, including IndexedDB, you can use the following setup:
import { test as setup, expect } from '@playwright/test';β
import path from 'path';β
const authFile = path.join(__dirname, '../playwright/.auth/user.json');β
setup('authenticate', async ({ page }) => {β
await page.goto('/');β
// ... perform authentication steps ...β
// make sure to save IndexedDBβ
await page.context().storageState({ path: authFile, indexedDB: true });β
});
ποΈ Match Only Visible Locators
A major improvement in locator precision! Playwright now lets you filter locators to match only visible elements using filter: { visible: true }
. This ensures tests interact only with elements users can see, reducing flakiness and improving reliability.
Example: Filtering Locators to Only Match Visible Elements
Consider the following HTML:
<button id="submit1" type="button" style="display: none">Submit</button>
<button id="submit2" type="button">Submit</button>
Using getByText('Submit')
would cause a strict mode violation because multiple buttons match. To filter only visible locators, use:
import { test, expect } from '@playwright/test';β
test('should only show visible submit button', async ({ page }) => {β
await page.goto('/');β
await expect(page.getByText('Submit').filter({β
visible: trueβ
})).toBeVisible();β
});
πͺ Test Step Improvements: Timeouts, Skipping, and Attachments
Managing test steps is now even more flexible. Playwright 1.51 introduces:
- Timeouts for test steps, allowing granular control over execution time.
- Skipping steps conditionally, making workflows more adaptable.
- Attachments for test steps, improving reporting and debugging visibility.
Add Timeout to a Test Step
Specify a maximum runtime for an individual test step:
import { test, expect } from '@playwright/test';β
test('some test', async ({ page }) => {β
await test.step('a step', async () => {β
// This step can time out separately from the testβ
}, { timeout: 1000 });β
});
Conditionally Skip a Running Step
Abort the currently running step and mark it as skipped with an optional description:
import { test, expect } from '@playwright/test';β
test('basic test', async ({ page, isMobile }) => {β
await test.step('check some behavior', async step => {β
step.skip(isMobile, 'not relevant on mobile layouts');β
// ... rest of the step codeβ
});β
});
Attach Files or Values to a Test Step
Attach a value or a file from disk to the current test step:
import { test, expect } from '@playwright/test';β
await test.step('Verify movie rating tooltip content', async (step) => {β
await firstMovieRating.hover();β
const tooltip = page.getByRole('tooltip');β
const tooltipText = await tooltip.textContent() ?? '';β
await expect(tooltip).toContainText(/average rating on/);β
// Attach the tooltip text content to the test reportβ
await step.attach('tooltip text content', { body: tooltipText, contentType: 'text/markdown' });β
});
These enhancements make complex test scenarios more maintainable and easier to debug.
π· ARIA Snapshot Updates
ARIA snapshots, which help in accessibility testing, now store snapshots in separate YAML files. This improves organization and makes it easier to track updates when snapshots change.
Example: Storing ARIA Snapshots in Separate Files
await expect(page.getByRole('main')).toMatchAriaSnapshot({ name: 'main.aria.yml' });
Updating Snapshots & Source Code
-
--update-snapshots
updates all snapshots or only changed ones. -
--update-source-method
defines how source code is updated (overwrite
,3-way
, orpatch
).
Example:
npx playwright test --update-snapshots=changed --update-source-method=3way
π Upgrade to Playwright 1.51
With Playwright 1.51, debugging becomes smarter, reports get more context, and test automation becomes even more reliable. Ready to explore these new features? Upgrade now and take your Playwright tests to the next level! π
npm install @playwright/test@latest
Check out the latest release video for more details and a live demo:
Whatβs your favorite feature in this release? Let us know in the comments! π
Top comments (0)