Unverified Commit a73eee23 authored by Yousef Dawood's avatar Yousef Dawood Committed by GitHub

docs: add instant navigation testing to Playwright guide (#100003)

### What?

Adds a "Testing instant navigations" section to the Playwright guide. It
covers the `instant()` helper from `@next/playwright`: how to install
it,
an example test, and how to enable the testing API when running tests
against a production build.

### Why?

The `instant()` helper is documented in the Instant navigation guide and
the `instant` API reference, but the Playwright guide never mentions it.
People who come to this page to learn how to test Next.js apps with
Playwright won't find out that a helper exists for catching regressions
in
instant navigations.

### How?

- Adds a new section at the end of the Playwright guide, wrapped in
  `<AppOnly>` because the feature requires Cache Components.
- Includes the install command, an example test using `instant()` with
  `page.waitForURL()`, a note about passing `baseURL`, and the
  `exposeTestingApiInProductionBuild` config for production builds.
- Content is based on the existing official docs:
  - https://nextjs.org/docs/app/guides/instant-navigation
-
https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config/instant
-
https://nextjs.org/docs/app/api-reference/config/next-config-js/exposeTestingApiInProductionBuild
parent ae63c57a
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
title: How to set up Playwright with Next.js title: How to set up Playwright with Next.js
nav_title: Playwright nav_title: Playwright
description: Learn how to set up Playwright with Next.js for End-to-End (E2E) Testing. description: Learn how to set up Playwright with Next.js for End-to-End (E2E) Testing.
related:
description: Learn more about testing instant navigations.
links:
- app/guides/instant-navigation
--- ---
Playwright is a testing framework that lets you automate Chromium, Firefox, and WebKit with a single API. You can use it to write **End-to-End (E2E)** testing. This guide will show you how to set up Playwright with Next.js and write your first tests. Playwright is a testing framework that lets you automate Chromium, Firefox, and WebKit with a single API. You can use it to write **End-to-End (E2E)** testing. This guide will show you how to set up Playwright with Next.js and write your first tests.
...@@ -131,6 +135,14 @@ test('should navigate to the about page', async ({ page }) => { ...@@ -131,6 +135,14 @@ test('should navigate to the about page', async ({ page }) => {
> **Good to know**: You can use `page.goto("/")` instead of `page.goto("http://localhost:3000/")`, if you add [`"baseURL": "http://localhost:3000"`](https://playwright.dev/docs/api/class-testoptions#test-options-base-url) to the `playwright.config.ts` [configuration file](https://playwright.dev/docs/test-configuration). > **Good to know**: You can use `page.goto("/")` instead of `page.goto("http://localhost:3000/")`, if you add [`"baseURL": "http://localhost:3000"`](https://playwright.dev/docs/api/class-testoptions#test-options-base-url) to the `playwright.config.ts` [configuration file](https://playwright.dev/docs/test-configuration).
<AppOnly>
### Testing instant navigations
If you're using Cache Components, the `instant()` helper from `@next/playwright` lets you assert what is visible immediately after a navigation, before any dynamic content streams in. See the [Instant navigation guide](/docs/app/guides/instant-navigation) and the [`instant` API reference](/docs/app/api-reference/file-conventions/route-segment-config/instant) for setup and examples.
</AppOnly>
### Running your Playwright tests ### Running your Playwright tests
Playwright will simulate a user navigating your application using three browsers: Chromium, Firefox and WebKit, this requires your Next.js server to be running. We recommend running your tests against your production code to more closely resemble how your application will behave. Playwright will simulate a user navigating your application using three browsers: Chromium, Firefox and WebKit, this requires your Next.js server to be running. We recommend running your tests against your production code to more closely resemble how your application will behave.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment