diff --git a/playwright/helpers/navHelpers.ts b/playwright/helpers/navHelpers.ts index 2ef83ce4..e085faec 100644 --- a/playwright/helpers/navHelpers.ts +++ b/playwright/helpers/navHelpers.ts @@ -24,3 +24,15 @@ export const ibFrame = (page: Page): FrameLocator | Page => { .locator('iframe[name="cockpit1\\:localhost\\/cockpit-image-builder"]') .contentFrame(); }; + +/** + * Navigates to the landing page of the Image Builder + * @param page - the page object + */ +export const navigateToLandingPage = async (page: Page) => { + if (isHosted()) { + await page.goto('/insights/image-builder/landing'); + } else { + await page.goto('/cockpit-image-builder'); + } +}; diff --git a/playwright/helpers/wizardHelpers.ts b/playwright/helpers/wizardHelpers.ts index 0dcbe5b3..3d5296c0 100644 --- a/playwright/helpers/wizardHelpers.ts +++ b/playwright/helpers/wizardHelpers.ts @@ -1,7 +1,7 @@ import { expect, FrameLocator, type Page, test } from '@playwright/test'; import { isHosted } from './helpers'; -import { ibFrame } from './navHelpers'; +import { ibFrame, navigateToLandingPage } from './navHelpers'; /** * Clicks the create button, handles the modal, clicks the button again and selecets the BP in the list @@ -65,6 +65,7 @@ export const fillInImageOutputGuest = async (page: Page | FrameLocator) => { /** * Delete the blueprint with the given name * Will locate to the Image Builder page and search for the blueprint first + * If the blueprint is not found, it will fail gracefully * @param page - the page object * @param blueprintName - the name of the blueprint to delete */ @@ -73,10 +74,21 @@ export const deleteBlueprint = async (page: Page, blueprintName: string) => { 'Delete the blueprint with name: ' + blueprintName, async () => { // Locate back to the Image Builder page every time because the test can fail at any stage + await navigateToLandingPage(page); const frame = await ibFrame(page); await frame .getByRole('textbox', { name: 'Search input' }) .fill(blueprintName); + // Check if no blueprints found -> that means no blueprint was created -> fail gracefully and do not raise error + try { + await expect( + frame.getByRole('heading', { name: 'No blueprints found' }) + ).toBeVisible({ timeout: 5_000 }); // Shorter timeout to avoid hanging uncessarily + return; // Fail gracefully, no blueprint to delete + // eslint-disable-next-line @typescript-eslint/no-unused-vars + } catch (error) { + // If the No BP heading was not found, it means the blueprint (possibly) was created -> continue with deletion + } await frame .getByTestId('blueprint-card') .getByText(blueprintName)