playwright: Add single login for all tests

Add a single login for all tests in the form of a global setup. This commit also removes the login from all tests and replaces it with navigation to landing page and revamps the popup closing logic from being applied in logging step  into a separate fixture.
This commit is contained in:
Tom Koscielniak 2025-06-19 11:46:39 +02:00 committed by Klara Simickova
parent 78bb1e118b
commit b499dfcf93
14 changed files with 124 additions and 39 deletions

View file

@ -1,3 +1,5 @@
import path from 'path';
import { type Page, expect } from '@playwright/test';
import { closePopupsIfExist, isHosted, togglePreview } from './helpers';
@ -74,3 +76,14 @@ const loginConsole = async (page: Page, user: string, password: string) => {
await togglePreview(page);
await expect(page.getByRole('heading', { name: 'All images' })).toBeVisible();
};
export const storeStorageStateAndToken = async (page: Page) => {
const { cookies } = await page
.context()
.storageState({ path: path.join(__dirname, '../../.auth/user.json') });
process.env.TOKEN = `Bearer ${
cookies.find((cookie) => cookie.name === 'cs_jwt')?.value
}`;
// eslint-disable-next-line playwright/no-wait-for-timeout
await page.waitForTimeout(100);
};

View file

@ -1,6 +1,6 @@
import { expect, FrameLocator, type Page, test } from '@playwright/test';
import { isHosted } from './helpers';
import { closePopupsIfExist, isHosted } from './helpers';
import { ibFrame, navigateToLandingPage } from './navHelpers';
/**
@ -70,6 +70,8 @@ export const fillInImageOutputGuest = async (page: Page | FrameLocator) => {
* @param blueprintName - the name of the blueprint to delete
*/
export const deleteBlueprint = async (page: Page, blueprintName: string) => {
// Since new browser is opened during the BP cleanup, we need to call the popup closer again
await closePopupsIfExist(page);
await test.step(
'Delete the blueprint with name: ' + blueprintName,
async () => {