Browser navigation tests
What you need to know
A browser navigation test exercises a deployed-like application through a real browser. Test direct visits and client-side Link transitions separately because they can exercise different server and client paths.
By the end, you can: assert direct and client transitions; capture console errors.
A route transition test
import {test,expect} from '@playwright/test';test('catalog navigation',async({page})=>{ const errors:string[]=[];page.on('pageerror',e=>errors.push(e.message)); await page.goto('/'); await page.getByRole('link',{name:'Catalog'}).click(); await expect(page).toHaveURL(/\/catalog$/); await expect(page.getByRole('heading',{name:'Catalog'})).toBeVisible(); await page.reload(); await expect(page.getByRole('heading',{name:'Catalog'})).toBeVisible(); expect(errors).toEqual([]);});Expected behavior: Expected pass in the staged fixture with a configured baseURL; collects exceptions through the final assertion.
How it works
Use Playwright with a reviewed production server bound to loopback. Start with a new browser context per test, attach a pageerror listener before navigation, and assert an observable page heading and URL. A direct load checks initial routing and content; a Link click also exercises client routing and may use prefetched data. Back, forward and reload can expose different state. Use role-based locators and auto-retrying assertions, not a fixed sleep to guess when rendering completes. Capture browser console errors separately from page exceptions. The final expect(errors).toEqual([]) checks the array at that point; it does not wait for future exceptions. Define the journey endpoint and assert the relevant observable completion before checking errors. Do not dump secrets in traces. If a soft transition must be verified, instrument an intentional observable state (for example a shared layout counter) and confirm preservation, rather than assuming a click proves no reload. Test missing routes and error recovery in a bounded fixture.
An explicit navigation matrix
Direct /catalog -> CatalogHome -> Link Catalog -> CatalogBack -> River BooksForward -> CatalogReload -> CatalogDirect /missing -> not-found responseExpected behavior: Check the status separately for direct requests. Visible text alone does not establish a correct 404.
Common mistake
Avoid waitForTimeout as a general synchronization strategy, and do not infer client navigation or hydration from a screenshot alone.
Practice and verification
Extend the browser fixture with back/forward checks and a layout-state preservation assertion. Record actual browser version, test command and any redacted exception evidence.
Scope: Proposed Next.js 16.x / React 19, Cache Components disabled unless noted. Framework, browser and component examples are staged; local standalone tests are reported separately. Exact dependency patches and platform contracts pending.
Further reading: Playwright · Locators