Files
Tim NeutkensandGitHub e860cec656 test: migrate webdriver callers to next.browser (#93941)
### What?

Migrate remaining direct `next-webdriver` test callers that have a
`NextInstance` to `next.browser()`, and expose the shared `Playwright`
browser type from `e2e-utils`.

### Why?

`NextInstance.browser` should be the supported browser-opening interface
for test fixtures, with `next-webdriver` kept as the private
implementation detail.

### How?

Updated affected development, e2e, and production tests to call
`next.browser()` directly, passing `baseUrl` where tests intentionally
target a manually spawned or proxied server. Shared helpers now receive
browser callbacks from the test context, and browser types import
`Playwright` from `e2e-utils` instead of deriving from `next.browser` or
importing from private paths.

<!-- NEXT_JS_LLM_PR -->
2026-05-22 14:01:58 +02:00

68 lines
2.3 KiB
TypeScript

import { FileRef, nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
import { join } from 'path'
describe('link-with-api-rewrite', () => {
const { next } = nextTestSetup({
files: {
pages: new FileRef(join(__dirname, 'app/pages')),
'next.config.js': new FileRef(join(__dirname, 'app/next.config.js')),
},
dependencies: {},
})
it('should perform hard navigation for rewritten urls', async () => {
const browser = await next.browser('/')
try {
// Click the link on the page, we expect that there will be a hard
// navigation later (we do this be checking that the window global is
// unset).
await browser.eval('window.beforeNav = "hi"')
await browser.elementById('rewrite').click()
await retry(async () => {
expect(await browser.eval('window.beforeNav')).not.toEqual('hi')
})
// Check to see that we were in fact navigated to the correct page.
const pathname = await browser.eval('window.location.pathname')
expect(pathname).toBe('/some/route/for')
// Check to see that the resulting data is coming from the right endpoint.
const text = await browser.eval(
'window.document.documentElement.innerText'
)
expect(text).toBe('{"from":"/some/route/for"}')
} finally {
await browser.close()
}
})
it('should perform hard navigation for direct urls', async () => {
const browser = await next.browser('/')
try {
// Click the link on the page, we expect that there will be a hard
// navigation later (we do this be checking that the window global is
// unset).
await browser.eval('window.beforeNav = "hi"')
await browser.elementById('direct').click()
await retry(async () => {
expect(await browser.eval('window.beforeNav')).not.toEqual('hi')
})
// Check to see that we were in fact navigated to the correct page.
const pathname = await browser.eval('window.location.pathname')
expect(pathname).toBe('/api/json')
// Check to see that the resulting data is coming from the right endpoint.
const text = await browser.eval(
'window.document.documentElement.innerText'
)
expect(text).toBe('{"from":""}')
} finally {
await browser.close()
}
})
})