From ecceac37a46338f649a2260afe6567fcdea2d46f Mon Sep 17 00:00:00 2001 From: Olga Bulat Date: Thu, 20 Apr 2023 12:05:04 +0300 Subject: [PATCH] Fix openFirstResult --- frontend/test/playwright/utils/navigation.ts | 16 +++++++--------- .../pages/pages-single-result.spec.ts | 3 --- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/frontend/test/playwright/utils/navigation.ts b/frontend/test/playwright/utils/navigation.ts index 038882d8a8..d26b58391b 100644 --- a/frontend/test/playwright/utils/navigation.ts +++ b/frontend/test/playwright/utils/navigation.ts @@ -375,16 +375,14 @@ export const searchFromHeader = async (page: Page, term: string) => { * Scroll down and up to load all lazy-loaded content. */ export const openFirstResult = async (page: Page, mediaType: MediaType) => { - await Promise.all([ - page.waitForNavigation(), - page - .locator(`a[href*="/${mediaType}/"]`) - .first() - .click({ - position: { x: 32, y: 32 }, - }), - ]) + const firstResult = page.locator(`a[href*="/${mediaType}/"]`).first() + const firstResultHref = await firstResult.getAttribute("href") + if (!firstResultHref) { + throw new Error(`Could not find a link to a ${mediaType} in the page`) + } + await firstResult.click({ position: { x: 32, y: 32 } }) await scrollDownAndUp(page) + await page.waitForURL(firstResultHref) } /** diff --git a/frontend/test/playwright/visual-regression/pages/pages-single-result.spec.ts b/frontend/test/playwright/visual-regression/pages/pages-single-result.spec.ts index a6a7e9de2e..525b36a809 100644 --- a/frontend/test/playwright/visual-regression/pages/pages-single-result.spec.ts +++ b/frontend/test/playwright/visual-regression/pages/pages-single-result.spec.ts @@ -1,6 +1,5 @@ import { test } from "@playwright/test" -import { removeHiddenOverflow } from "~~/test/playwright/utils/page" import breakpoints from "~~/test/playwright/utils/breakpoints" import { goToSearchTerm, @@ -30,8 +29,6 @@ for (const mediaType of supportedMediaTypes) { test(`from search results`, async ({ page }) => { // This will include the "Back to results" link. await openFirstResult(page, mediaType) - await removeHiddenOverflow(page) - await page.waitForEvent("load") await expectSnapshot( `${mediaType}-${dir}-from-search-results`,