I have an application, where i am using supabase as auth provider. Now i want to setup E2E testing using playwright. I got a setup test, which will run before each test:
//auth.setup.ts
import { test as setup } from '@playwright/test';
import { waitForOneOf } from './helpers/playwrightHelpers';
const authFile = 'playwright/.auth/user.json';
setup('authenticate', async ({ page }) => {
// Perform authentication steps. Replace these actions with your own.
await page.goto('/');
// cookie banner
let [ index ] = await waitForOneOf([
page.getByTestId('cookie-settings-save')
]);
let isExisting = index === 0;
if (isExisting) {
await page.getByTestId('cookie-settings-save').click()
}
await page.getByTestId('nav-profile').click();
await page.getByTestId('nav-login-btn').click();
// Use Supabase's API to sign in
// await login dialog
[ index ] = await waitForOneOf([
page.getByTestId('signin-form')
]);
isExisting = index === 0;
if (isExisting) {
await page.getByLabel('Email').fill('[email protected]')
await page.getByLabel('Passwort').fill('123123')
await page.getByRole('button', { name: 'Login' }).click()
await page.getByTestId('signin-form').isHidden()
}
await page.context().storageState({ path: authFile });
});
//test.spec.ts
import { test } from '@playwright/test';
test.use({ storageState: 'playwright/.auth/user.json' });
test('edit profile', async ({ page }) => {
await page.goto('/ch/profil')
})
Logging in works. But it seems as if the supabase session is not persisted (cookies not set). So on the last line (test.spec.ts), where i am navigating to a page only visible to authenticated user, i get an error.
I tried setting up a supabase client inside the setup test. But wierdly, the setup test will then not run anymore before each test. I googled a lot, but i havent got wiser.