Finally, let's quickly cover authentication within browser tests. Similar to the API Client, the AdonisJS Auth and Session packages also provide plugins for the Browser Client. So, since we're using session authentication,n we'll want to add both the session and auth plugins.
// tests/bootstrap.ts
import { sessionBrowserClient } from "@adonisjs/session/plugins/browser_client";
import { authBrowserClient } from "@adonisjs/auth/plugins/browser_client";
export const plugins: Config["plugins"] = [
assert(),
openapi({
schemas: [new URL("../docs/openapi.json", import.meta.url)],
}),
apiClient(),
browserClient({
runInSuites: ["browser"],
}),
pluginAdonisJS(app),
sessionApiClient(app),
authApiClient(app),
++ sessionBrowserClient(app),
++ authBrowserClient(app),
shieldApiClient(),
disallowPinnedTests({
disallow: !!process.env.CI,
}),
];Perfect! These both add their methods to the browserContext. This provides a way to operate multiple pages with the same context so that our session or auth persists if an action taken on one page opens another page.