🧑‍💻(e2e) display more information when auth fails

When the auth fails, it was quite obscure to
understand what was going on.
We now take a screenshot of the page and display
the console logs.
This commit is contained in:
Anthony LC
2025-03-11 12:12:03 +01:00
committed by Anthony LC
parent 8056fd7d66
commit 05a6818439
2 changed files with 27 additions and 13 deletions

View File

@@ -4,3 +4,4 @@ report/
blob-report/ blob-report/
playwright/.auth/ playwright/.auth/
playwright/.cache/ playwright/.cache/
screenshots/

View File

@@ -12,23 +12,36 @@ const saveStorageState = async (
const context = await browser.newContext(useConfig); const context = await browser.newContext(useConfig);
const page = await context.newPage(); const page = await context.newPage();
await page.goto('/', { waitUntil: 'networkidle' }); try {
await page.content(); await page.goto('/', { waitUntil: 'networkidle' });
await expect(page.getByText('Docs').first()).toBeVisible(); await page.content();
await expect(page.getByText('Docs').first()).toBeVisible();
await keyCloakSignIn(page, browserName); await keyCloakSignIn(page, browserName);
await expect( await expect(
page.locator('header').first().getByRole('button', { page.locator('header').first().getByRole('button', {
name: 'Logout', name: 'Logout',
}), }),
).toBeVisible(); ).toBeVisible();
await page.context().storageState({ await page.context().storageState({
path: storageState as string, path: storageState as string,
}); });
} catch (error) {
console.log(error);
await browser.close(); await page.screenshot({
path: `./screenshots/${browserName}-${Date.now()}.png`,
});
// Get console logs
const consoleLogs = await page.evaluate(() =>
console.log(window.console.log),
);
console.log(consoleLogs);
} finally {
await browser.close();
}
}; };
async function globalSetup(config: FullConfig) { async function globalSetup(config: FullConfig) {