Library
There are two Playwright packages: 'playwright' (the library) and '@playwright/test' (the test runner). Unless you're writing a script or a tool that isn't a test suite, always use @playwright/test. It gives you web-first assertions, fixtures, retries, reporters, and automatic cleanup. The library requires you to manage all that yourself.
Library vs @playwright/test — when to use each
Use the library (playwright package) when you're writing a Node.js script that automates a browser — web scraping, generating PDFs, automating repetitive tasks. You manage the browser lifecycle manually: launch, create context, create page, do stuff, close everything.
Use @playwright/test for everything else — e2e tests, component testing, integration tests. It provides isolated page/context per test, automatic cleanup, web-first assertions that auto-retry, fixtures, parallel execution, HTML reports.
Library — everything is manual
With the library, I explicitly launch a browser, create a context (with any device emulation settings), create a page, do my work, then close context and browser. If I forget to close, the browser process leaks. No fixtures, no auto-retry assertions — just raw async code.
@playwright/test — the right way for tests
With the test runner, page and context are injected as fixtures — created fresh for each test, automatically closed after. toHaveTitle() is a web-first assertion: it auto-retries until the condition is met or timeout expires. No manual cleanup needed.
Key differences side by side
The biggest practical differences: assertions and cleanup. With the library, page.title() returns a Promise — you check it with assert() which doesn't retry. With the test runner, expect(page).toHaveTitle() retries automatically. With the library, you must await context.close() and await browser.close() every time. With the test runner, the framework handles it.
Other things the test runner adds that the library doesn't have: projects (multi-browser config), retries, reporters (HTML, blob, JUnit), parallel workers, trace recording, fixtures for auth state sharing.