Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Replace hard-coded strings in Playwright tests (#4804)

Olga Bulatd8eca37669bb
diff --git a/frontend/src/components/VRadio/VRadio.vue b/frontend/src/components/VRadio/VRadio.vue
index 677ff3566..95481bab0 100644
--- a/frontend/src/components/VRadio/VRadio.vue
+++ b/frontend/src/components/VRadio/VRadio.vue
@@ -69,7 +69,7 @@ export default defineComponent({
/>
<VSvg
name="radiomark"
- class="radiomark absolute start-0 h-5 w-5 text-default opacity-0 transition-opacity"
+ class="radiomark pointer-events-none absolute start-0 h-5 w-5 text-default opacity-0 transition-opacity"
width="20"
height="20"
/>
diff --git a/frontend/test/playwright/e2e/all-results-keyboard.spec.ts b/frontend/test/playwright/e2e/all-results-keyboard.spec.ts
index 7e95cd62d..52945eed7 100644
--- a/frontend/test/playwright/e2e/all-results-keyboard.spec.ts
+++ b/frontend/test/playwright/e2e/all-results-keyboard.spec.ts
@@ -61,7 +61,7 @@ test.describe("all results grid keyboard accessibility test", () => {
}) => {
await walkToType("audio", page)
- await expect(page.locator("[role=alert]")).toBeVisible()
+ await expect(page.getByRole("alert")).toBeVisible()
})
test("should hide the instructions snackbar when interacted with audio", async ({
@@ -69,13 +69,13 @@ test.describe("all results grid keyboard accessibility test", () => {
}) => {
await walkToType("audio", page)
- await expect(page.locator("[role=alert]")).toBeVisible()
+ await expect(page.getByRole("alert")).toBeVisible()
const focusedResult = await locateFocusedResult(page)
const playButton = await audio.getInactive(focusedResult)
await playButton.click()
- await expect(page.locator("[role=alert]")).toBeHidden()
+ await expect(page.getByRole("alert")).toBeHidden()
})
test("should allow toggling audio playback via play/pause click", async ({
@@ -94,7 +94,7 @@ test.describe("all results grid keyboard accessibility test", () => {
expect(path).toMatch(/\/search\/?\?q=birds$/)
const pauseButton = await audio.getActive(focusedResult)
- pauseButton.click()
+ await pauseButton.click()
await expect(playButton).toBeVisible()
})
diff --git a/frontend/test/playwright/e2e/audio-detail.spec.ts b/frontend/test/playwright/e2e/audio-detail.spec.ts
index 97b1f2eb7..31f989a04 100644
--- a/frontend/test/playwright/e2e/audio-detail.spec.ts
+++ b/frontend/test/playwright/e2e/audio-detail.spec.ts
@@ -22,10 +22,10 @@ const goToCustomAudioPage = async (page: Page) => {
}
const errorPageHeading = (page: Page) => {
- return getH1(page, /The content you’re looking for seems to have disappeared/)
+ return getH1(page, t("404.title"))
}
const getMainPlayButton = (page: Page) =>
- page.getByRole("button", { name: "Play" }).first()
+ page.getByRole("button", { name: t("playPause.play") }).first()
test.describe.configure({ mode: "parallel" })
@@ -46,7 +46,7 @@ test("sends GET_MEDIA event on CTA button click", async ({ context, page }) => {
await goToCustomAudioPage(page)
await openAndCloseExternalLink(page, {
- name: new RegExp(t("audioDetails.weblink"), "i"),
+ name: t("audioDetails.weblink"),
})
const getMediaEvent = analyticsEvents.find((event) => event.n === "GET_MEDIA")
diff --git a/frontend/test/playwright/e2e/audio-results.spec.ts b/frontend/test/playwright/e2e/audio-results.spec.ts
index 8e43a3db1..ea83f05c5 100644
--- a/frontend/test/playwright/e2e/audio-results.spec.ts
+++ b/frontend/test/playwright/e2e/audio-results.spec.ts
@@ -22,7 +22,7 @@ test.describe("all results grid keyboard accessibility test", () => {
}) => {
await walkToType("audio", page)
- await expect(page.locator("[role=alert]")).toBeVisible()
+ await expect(page.getByRole("alert")).toBeVisible()
})
test("should hide the instructions snackbar when interacted with audio", async ({
@@ -30,12 +30,12 @@ test.describe("all results grid keyboard accessibility test", () => {
}) => {
await walkToType("audio", page)
- await expect(page.locator("[role=alert]")).toBeVisible()
+ await expect(page.getByRole("alert")).toBeVisible()
const focusedResult = await locateFocusedResult(page)
await focusedResult.press("Space")
- await expect(page.locator("[role=alert]")).toBeHidden()
+ await expect(page.getByRole("alert")).toBeHidden()
})
})
diff --git a/frontend/test/playwright/e2e/filters.spec.ts b/frontend/test/playwright/e2e/filters.spec.ts
index 7535e69f9..757d4ff73 100644
--- a/frontend/test/playwright/e2e/filters.spec.ts
+++ b/frontend/test/playwright/e2e/filters.spec.ts
@@ -17,6 +17,8 @@ import {
expectEventPayloadToMatch,
} from "~~/test/playwright/utils/analytics"
+import { t } from "~~/test/playwright/utils/i18n"
+
import enMessages from "~/locales/en.json"
import {
@@ -34,13 +36,15 @@ const assertCheckboxCount = async (
checked: "checked" | "notChecked" | "total",
count: number
) => {
- const checkedString = {
- checked: ":checked",
- notChecked: ":not(:checked)",
- total: "",
- }[checked]
- const locatorString = `input[type="checkbox"]${checkedString}`
- await expect(page.locator(locatorString)).toHaveCount(count, { timeout: 200 })
+ const options =
+ checked === "checked"
+ ? { checked: true }
+ : checked === "notChecked"
+ ? { checked: false }
+ : {}
+ await expect(page.getByRole("checkbox", options)).toHaveCount(count, {
+ timeout: 200,
+ })
}
// Note that this includes two switches for sensitive content preferences.
@@ -50,6 +54,14 @@ const FILTER_COUNTS = {
[IMAGE]: 73,
}
+const cc0 = t("licenseReadableNames.cc0")
+
+const cc0AndCommercial = [cc0, t("filters.licenseTypes.commercial")]
+
+const commercial = t("filters.licenseTypes.commercial")
+
+const tall = t("filters.aspectRatios.tall")
+
breakpoints.describeMobileAndDesktop(({ breakpoint }) => {
test.beforeEach(async ({ context, page }) => {
await mockProviderApis(context)
@@ -72,10 +84,8 @@ breakpoints.describeMobileAndDesktop(({ breakpoint }) => {
test("initial filters are applied based on the url", async ({ page }) => {
await page.goto("/search?q=cat&license_type=commercial&license=cc0")
await filters.open(page)
- // Creator filter was removed from the UI
- const expectedFilters = ["Zero", "Use commercially"]
- for (const checkbox of expectedFilters) {
+ for (const checkbox of cc0AndCommercial) {
await expect(page.getByRole("checkbox", { name: checkbox })).toBeChecked()
}
})
@@ -85,10 +95,8 @@ breakpoints.describeMobileAndDesktop(({ breakpoint }) => {
}) => {
await page.goto("/search/?q=cat&license_type=commercial&license=cc0")
await filters.open(page)
- // Creator filter was removed from the UI
- const expectedFilters = ["Zero", "Use commercially"]
- for (const checkbox of expectedFilters) {
+ for (const checkbox of cc0AndCommercial) {
await expect(page.getByRole("checkbox", { name: checkbox })).toBeChecked()
}
await changeSearchType(page, IMAGE)
@@ -97,7 +105,7 @@ breakpoints.describeMobileAndDesktop(({ breakpoint }) => {
"/search/image?q=cat&license_type=commercial&license=cc0"
)
await filters.open(page)
- for (const checkbox of expectedFilters) {
+ for (const checkbox of cc0AndCommercial) {
await expect(page.getByRole("checkbox", { name: checkbox })).toBeChecked()
}
})
@@ -108,15 +116,14 @@ breakpoints.describeMobileAndDesktop(({ breakpoint }) => {
await page.goto("/search/image?q=cat&license_type=commercial&license=cc0")
await filters.open(page)
- // Creator filter was removed from the UI
- for (const checkbox of ["Zero", "Use commercially"]) {
+ for (const checkbox of cc0AndCommercial) {
await expect(page.getByRole("checkbox", { name: checkbox })).toBeChecked()
}
await changeSearchType(page, ALL_MEDIA)
await filters.open(page)
- await expect(page.locator('input[type="checkbox"]:checked')).toHaveCount(3)
+ await expect(page.getByRole("checkbox", { checked: true })).toHaveCount(3)
await expect(page).toHaveURL(
"/search?q=cat&license_type=commercial&license=cc0"
@@ -143,7 +150,7 @@ breakpoints.describeMobileAndDesktop(({ breakpoint }) => {
await filters.open(page)
await expect(
- page.getByRole("checkbox", { name: "Use commercially" })
+ page.getByRole("checkbox", { name: commercial })
).not.toBeChecked()
// Use commercially is not enabled yet, so commercial licenses are still available
@@ -158,12 +165,10 @@ breakpoints.describeMobileAndDesktop(({ breakpoint }) => {
}
// Enable the commercial use filter
- await page.locator('label:has-text("Use commercially")').click()
+ await page.getByText(t("filters.licenseTypes.commercial")).click()
await page.waitForURL(/license_type=commercial/)
- await expect(
- page.getByRole("checkbox", { name: "Use commercially" })
- ).toBeChecked()
+ await expect(page.getByRole("checkbox", { name: commercial })).toBeChecked()
// Because we checked "Use commercially", licenses that disallow commercial
// use will be disabled and the rest will still be enabled.
@@ -201,15 +206,16 @@ breakpoints.describeMobileAndDesktop(({ breakpoint }) => {
await page.goto("/search/image?q=cat&aspect_ratio=tall&license=cc0")
await filters.open(page)
- await expect(page.getByRole("checkbox", { name: "Tall" })).toBeChecked()
- await expect(page.getByRole("checkbox", { name: "Zero" })).toBeChecked()
+ for (const name of [tall, cc0]) {
+ await expect(page.getByRole("checkbox", { name })).toBeChecked()
+ }
await changeSearchType(page, AUDIO)
await filters.open(page)
// Only CC0 checkbox is checked, and the filter button label is
// '1 Filter' on `xl` or '1' on `lg` screens
- await expect(page.getByRole("checkbox", { name: "Zero" })).toBeChecked()
+ await expect(page.getByRole("checkbox", { name: cc0 })).toBeChecked()
await filters.close(page)
// eslint-disable-next-line playwright/no-conditional-in-test
@@ -238,17 +244,17 @@ breakpoints.describeMobileAndDesktop(({ breakpoint }) => {
await page.goto("/search/image?q=cat")
await filters.open(page)
- await expect(page.getByRole("checkbox", { name: "Zero" })).not.toBeChecked()
+ await expect(page.getByRole("checkbox", { name: cc0 })).not.toBeChecked()
// Alternative way with a predicate. Note no await.
const responsePromise = page.waitForResponse(
(response) =>
response.url().includes("/images/") && response.status() === 200
)
- await page.getByLabel("Zero").click()
+ await page.getByLabel(cc0).click()
const response = await responsePromise
- await expect(page.getByRole("checkbox", { name: "Zero" })).toBeChecked()
+ await expect(page.getByRole("checkbox", { name: cc0 })).toBeChecked()
// Remove the host url and path because when proxied, the 'http://localhost:49153' is used instead of the
// real API url
expect(response.url()).toContain("?q=cat&license=cc0")
diff --git a/frontend/test/playwright/e2e/global-audio.spec.ts b/frontend/test/playwright/e2e/global-audio.spec.ts
index 24a92bd95..0f7ce9eea 100644
--- a/frontend/test/playwright/e2e/global-audio.spec.ts
+++ b/frontend/test/playwright/e2e/global-audio.spec.ts
@@ -37,10 +37,12 @@ test.describe("global audio", () => {
// and confirm is still playing (or loading to play)
const mainPlayerButton = page.locator(".main-track >> button").first()
- await expect(mainPlayerButton).toHaveAttribute(
- "aria-label",
- /(Loading|Pause|Replay)/
+ const labels = ["loading", "pause", "replay"].map((l) =>
+ t(`playPause.${l}`)
)
+ const labelPattern = new RegExp(`(${labels.join("|")})`, "i")
+
+ await expect(mainPlayerButton).toHaveAttribute("aria-label", labelPattern)
})
test("track can be closed while playing", async ({ page }) => {
diff --git a/frontend/test/playwright/e2e/header-internal.spec.ts b/frontend/test/playwright/e2e/header-internal.spec.ts
index b7613b3d3..57b93a6e3 100644
--- a/frontend/test/playwright/e2e/header-internal.spec.ts
+++ b/frontend/test/playwright/e2e/header-internal.spec.ts
@@ -30,6 +30,8 @@ const closeMenu = async (page: Page, dir: LanguageDirection = "ltr") => {
const isPagesPopoverOpen = async (page: Page) =>
page.locator(".popover-content").isVisible({ timeout: 100 })
+const aboutPageTitle = t("about.title")
+
test.describe.configure({ mode: "parallel" })
test.describe("Header internal", () => {
@@ -43,18 +45,20 @@ test.describe("Header internal", () => {
await clickMenuButton(page)
expect(await isDialogOpen(page)).toBe(true)
await expect(page.locator(currentPageLink)).toBeVisible()
- await expect(page.locator(currentPageLink)).toHaveText("About")
+ await expect(page.locator(currentPageLink)).toHaveText(
+ t("navigation.about")
+ )
await closeMenu(page)
expect(await isDialogOpen(page)).toBe(false)
- await expect(await getMenuButton(page)).toBeVisible()
+ await expect(getMenuButton(page)).toBeVisible()
})
test("the modal locks the scroll on xs breakpoint", async ({ page }) => {
await page.goto("/about")
// Wait for hydration
- await expect(await getMenuButton(page)).toBeEnabled()
+ await expect(getMenuButton(page)).toBeEnabled()
await scrollToBottom(page)
await clickMenuButton(page)
@@ -85,11 +89,13 @@ test.describe("Header internal", () => {
await clickMenuButton(page)
await page.getByRole("link", { name: t("navigation.about") }).click()
await page.waitForURL("/about")
+
+ const pageTitleRegex = new RegExp(aboutPageTitle, "i")
// For some reason during this test the navigation overlay sometimes takes ~5-9 ms
// During that time, the page cannot scroll. We just need to wait for the
// page's title to be visible before going on.
await page
- .locator("h1", { hasText: "About" })
+ .getByRole("heading", { level: 1, name: pageTitleRegex })
.waitFor({ state: "visible" })
await scrollToBottom(page)
const scrollPosition = await page.evaluate(() => window.scrollY)
@@ -125,7 +131,9 @@ test.describe("Header internal", () => {
await clickMenuButton(page)
expect(await isPagesPopoverOpen(page)).toBe(true)
await expect(page.locator(currentPageLinkInPopover)).toBeVisible()
- await expect(page.locator(currentPageLinkInPopover)).toHaveText("About")
+ await expect(page.locator(currentPageLinkInPopover)).toHaveText(
+ t("navigation.about")
+ )
await clickMenuButton(page)
expect(await isPagesPopoverOpen(page)).toBe(false)
diff --git a/frontend/test/playwright/e2e/image-detail.spec.ts b/frontend/test/playwright/e2e/image-detail.spec.ts
index 1862343b3..3bc5114c1 100644
--- a/frontend/test/playwright/e2e/image-detail.spec.ts
+++ b/frontend/test/playwright/e2e/image-detail.spec.ts
@@ -16,7 +16,6 @@ const imageObject = {
id: "e9d97a98-621b-4ec2-bf70-f47a74380452",
provider: "flickr",
}
-
const goToCustomImagePage = async (page: Page) => {
// Test in a custom image detail page, it should apply the same for any image.
await page.goto(`image/${imageObject.id}`)
@@ -26,7 +25,7 @@ const goToCustomImagePage = async (page: Page) => {
const errorPageLocator = (page: Page) =>
page.getByRole("heading", {
level: 1,
- name: /The content you’re looking for seems to have disappeared/,
+ name: new RegExp(t("404.title")),
})
test.describe.configure({ mode: "parallel" })
@@ -77,7 +76,7 @@ test("sends GET_MEDIA event on CTA button click", async ({ context, page }) => {
await goToCustomImagePage(page)
- await page.getByRole("link", { name: /get this image/i }).click()
+ await page.getByRole("link", { name: t("imageDetails.weblink") }).click()
const getMediaEvent = analyticsEvents.find((event) => event.n === "GET_MEDIA")
diff --git a/frontend/test/playwright/e2e/preferences.spec.ts b/frontend/test/playwright/e2e/preferences.spec.ts
index 711e0c064..db154dd3c 100644
--- a/frontend/test/playwright/e2e/preferences.spec.ts
+++ b/frontend/test/playwright/e2e/preferences.spec.ts
@@ -76,7 +76,7 @@ const getSwitchableInput = async (
name: string,
checked: boolean
) => {
- const checkbox = page.locator(`input[type=checkbox]#${name}`).first()
+ const checkbox = page.getByRole("checkbox", { name }).first()
await expect(checkbox).toBeEnabled()
if (checked) {
await expect(checkbox).toBeChecked()
diff --git a/frontend/test/playwright/e2e/recent-searches.spec.ts b/frontend/test/playwright/e2e/recent-searches.spec.ts
index fb1a0a809..94485c760 100644
--- a/frontend/test/playwright/e2e/recent-searches.spec.ts
+++ b/frontend/test/playwright/e2e/recent-searches.spec.ts
@@ -7,7 +7,7 @@ import {
searchFromHeader,
sleep,
} from "~~/test/playwright/utils/navigation"
-import { getH1 } from "~~/test/playwright/utils/components"
+import { getH1, skipToContentLink } from "~~/test/playwright/utils/components"
import { t } from "~~/test/playwright/utils/i18n"
import breakpoints from "~~/test/playwright/utils/breakpoints"
@@ -24,10 +24,7 @@ const clearButton = async (page: Page) =>
page.locator(`[aria-label="${clearRecentLabel}"]`)
const clickClear = async (page: Page) => (await clearButton(page)).click()
-const searchbarName = t("search.searchBarLabel").replace(
- "{openverse}",
- "Openverse"
-)
+const searchbarName = t("search.searchBarLabel")
const recentSearches = (page: Page) =>
page.locator('[data-testid="recent-searches"]')
@@ -46,7 +43,7 @@ const getFocusedElementName = async (page: Page) => {
}
const tabToSearchbar = async (page: Page) => {
- await page.getByRole("link", { name: t("skipToContent") }).focus()
+ await skipToContentLink(page).focus()
let focusedInputName = null
while (focusedInputName !== searchbarName) {
@@ -104,7 +101,7 @@ breakpoints.describeMobileXsAndDesktop(({ breakpoint }) => {
await openRecentSearches(page)
const recentList = await page
.locator(`[aria-label="${recentLabel}"]`)
- .locator('[role="option"]')
+ .getByRole("option")
.allTextContents()
searches.reverse().forEach((term, idx) => {
expect(recentList[idx].trim()).toEqual(term)
diff --git a/frontend/test/playwright/e2e/report-media.spec.ts b/frontend/test/playwright/e2e/report-media.spec.ts
index fc8d217f8..8233a0216 100644
--- a/frontend/test/playwright/e2e/report-media.spec.ts
+++ b/frontend/test/playwright/e2e/report-media.spec.ts
@@ -12,6 +12,8 @@ import {
expectEventPayloadToMatch,
} from "~~/test/playwright/utils/analytics"
+import { t } from "~~/test/playwright/utils/i18n"
+
import { supportedMediaTypes } from "~/constants/media"
import type { ReportReason } from "~/constants/content-report"
@@ -23,8 +25,18 @@ test.describe.configure({ mode: "parallel" })
const reportingEndpoint = "**/report/"
+const reportButtonLabel = t("mediaDetails.contentReport.long")
+
export const openReportModal = (page: Page) =>
- page.click('text="Report this content"')
+ page.getByRole("button", { name: reportButtonLabel }).click()
+
+const checkOption = async (page: Page, option: ReportReason) => {
+ const name = t(`mediaDetails.contentReport.form.${option}.option`)
+ const radio = page.getByRole("radio", { name })
+ if (!(await radio.isChecked())) {
+ await radio.check()
+ }
+}
// Mock a successful reporting response
export const mockReportingEndpoint = (context: BrowserContext) =>
@@ -40,7 +52,12 @@ export const mockReportingEndpoint = (context: BrowserContext) =>
export const submitApiReport = (page: Page) =>
Promise.all([
page.waitForResponse(reportingEndpoint),
- page.locator('button[type="submit"]:has-text("Report")').click(),
+ page
+ .getByRole("button", {
+ name: t("mediaDetails.contentReport.short"),
+ exact: true,
+ })
+ .click(),
]).then((res) => res[0])
/**
@@ -56,10 +73,12 @@ const submitDmcaReport = async (page: Page, context: BrowserContext) => {
body: "<div>Fake form!</div>",
})
})
- await page.click('text="Infringes copyright"')
+ await checkOption(page, "dmca")
const popupPromise = page.waitForEvent("popup")
- await page.click('text="Open form"')
+ await page
+ .getByRole("link", { name: t("mediaDetails.contentReport.form.dmca.open") })
+ .click()
const form = await popupPromise
const formUrl: string = await form.evaluate("location.href")
@@ -69,16 +88,17 @@ const submitDmcaReport = async (page: Page, context: BrowserContext) => {
// todo: Test a sensitive report with the optional description field
const submitSensitiveContentReport = async (page: Page) => {
- await page.click('text="Contains sensitive content"')
+ await checkOption(page, "sensitive")
return (await submitApiReport(page)).status()
}
const submitOtherReport = async (page: Page) => {
- await page.click('text="Other"')
- await page.fill(
- "text=Describe the issue",
- 'This is an example "Other" report submit by Playwright, our automated e2e test tool.'
- )
+ await checkOption(page, "other")
+ await page
+ .getByRole("textbox")
+ .fill(
+ 'This is an example "Other" report submit by Playwright, our automated e2e test tool.'
+ )
return (await submitApiReport(page)).status()
}
@@ -129,7 +149,9 @@ supportedMediaTypes.forEach((mediaType) => {
expect(result).toEqual(reportResults[reportName as ReportReason])
await page
- .getByRole("dialog", { name: /report submitted successfully/ })
+ .getByRole("dialog", {
+ name: t("mediaDetails.contentReport.successTitle"),
+ })
.isVisible()
const reportMediaEvent = analyticsEvents.find(
diff --git a/frontend/test/playwright/e2e/search-navigation.spec.ts b/frontend/test/playwright/e2e/search-navigation.spec.ts
index 76fc9b78b..370d799d2 100644
--- a/frontend/test/playwright/e2e/search-navigation.spec.ts
+++ b/frontend/test/playwright/e2e/search-navigation.spec.ts
@@ -10,10 +10,15 @@ import {
import { mockProviderApis } from "~~/test/playwright/utils/route"
import breakpoints from "~~/test/playwright/utils/breakpoints"
-import { getBackToSearchLink } from "~~/test/playwright/utils/components"
+import {
+ getBackToSearchLink,
+ getHeaderSearchbar,
+} from "~~/test/playwright/utils/components"
import { getContentLink } from "~~/test/playwright/utils/search-results"
+import { t } from "~~/test/playwright/utils/i18n"
+
import { AUDIO, IMAGE } from "~/constants/media"
test.describe.configure({ mode: "parallel" })
@@ -33,7 +38,7 @@ test.describe("search history navigation", () => {
await filters.open(page)
const modifyLocator = page.getByRole("checkbox", {
- name: "Modify or adapt",
+ name: t("filters.licenseTypes.modification"),
})
// Apply a filter
await modifyLocator.click()
@@ -77,12 +82,12 @@ test.describe("search history navigation", () => {
await goToSearchTerm(page, "galah")
await searchFromHeader(page, "cat")
- await expect(page.locator('input[name="q"]')).toHaveValue("cat")
+ await expect(getHeaderSearchbar(page)).toHaveValue("cat")
await page.goBack()
await expect(await getContentLink(page, IMAGE)).toBeVisible()
- await expect(page.locator('input[name="q"]')).toHaveValue("galah")
+ await expect(getHeaderSearchbar(page)).toHaveValue("galah")
})
test("navigates to the image detail page correctly", async ({ page }) => {
diff --git a/frontend/test/playwright/e2e/search-query-client.spec.ts b/frontend/test/playwright/e2e/search-query-client.spec.ts
index 129065e02..bc644c9e0 100644
--- a/frontend/test/playwright/e2e/search-query-client.spec.ts
+++ b/frontend/test/playwright/e2e/search-query-client.spec.ts
@@ -10,6 +10,8 @@ import { mockProviderApis } from "~~/test/playwright/utils/route"
import breakpoints from "~~/test/playwright/utils/breakpoints"
+import { getHeaderSearchbar } from "~~/test/playwright/utils/components"
+
import { AUDIO, IMAGE } from "~/constants/media"
/**
@@ -37,9 +39,7 @@ test.describe("search query on CSR", () => {
test("q query parameter is set as the search term", async ({ page }) => {
await goToSearchTerm(page, "cat", { mode: "CSR" })
- await expect(page.locator('header input[type="search"]')).toHaveValue(
- "cat"
- )
+ await expect(getHeaderSearchbar(page)).toHaveValue("cat")
await expect(page).toHaveURL("search?q=cat")
})
@@ -48,9 +48,7 @@ test.describe("search query on CSR", () => {
}) => {
await goToSearchTerm(page, "cat", { searchType: AUDIO, mode: "CSR" })
- await expect(page.locator('header input[type="search"]')).toHaveValue(
- "cat"
- )
+ await expect(getHeaderSearchbar(page)).toHaveValue("cat")
await expect(page).toHaveURL("search/audio?q=cat")
})
diff --git a/frontend/test/playwright/e2e/search-query-server.spec.ts b/frontend/test/playwright/e2e/search-query-server.spec.ts
index 8f751e16a..6aeb08a60 100644
--- a/frontend/test/playwright/e2e/search-query-server.spec.ts
+++ b/frontend/test/playwright/e2e/search-query-server.spec.ts
@@ -11,6 +11,9 @@ import { mockProviderApis } from "~~/test/playwright/utils/route"
import breakpoints from "~~/test/playwright/utils/breakpoints"
+import { getHeaderSearchbar } from "~~/test/playwright/utils/components"
+import { t } from "~~/test/playwright/utils/i18n"
+
import { ALL_MEDIA, AUDIO, IMAGE } from "~/constants/media"
/**
@@ -39,10 +42,8 @@ test.describe("search query on SSR", () => {
query: "license=cc0&license_type=commercial",
})
- const searchInput = page.locator('input[type="search"]')
+ const searchInput = getHeaderSearchbar(page)
await expect(searchInput).toHaveValue("cat")
- // Todo: focus the input?
- // await expect(searchInput).toBeFocused()
})
test("url path /search/ is used to select `all` search tab", async ({
@@ -72,8 +73,11 @@ test.describe("search query on SSR", () => {
})
await filters.open(page)
- // Creator filter was removed from the UI
- for (const checkbox of ["Zero", "Use commercially"]) {
+
+ for (const checkbox of [
+ t("licenseReadableNames.cc0"),
+ t("filters.licenseTypes.commercial"),
+ ]) {
await expect(
page.getByRole("checkbox", { name: checkbox })
).toBeChecked()
diff --git a/frontend/test/playwright/e2e/sensitive-results.spec.ts b/frontend/test/playwright/e2e/sensitive-results.spec.ts
index f66f101c2..4ac1fd04d 100644
--- a/frontend/test/playwright/e2e/sensitive-results.spec.ts
+++ b/frontend/test/playwright/e2e/sensitive-results.spec.ts
@@ -24,10 +24,12 @@ const getSensitiveToggle = (page: Page) => {
const getFirstSensitiveResult = (page: Page) => {
return page
.getByRole("link", {
- name: /This image may contain sensitive content/i,
+ name: t("sensitiveContent.title.image"),
})
.first()
}
+const hideLabel = t("sensitiveContent.singleResult.hide")
+const showLabel = t("sensitiveContent.singleResult.show")
test.describe("sensitive_results", () => {
test.afterEach(async ({ context }) => {
@@ -67,7 +69,7 @@ test.describe("sensitive_results", () => {
await goToSearchTerm(page, "cat")
await getFirstSensitiveResult(page).click()
- await page.getByRole("button", { name: /show content/i }).click()
+ await page.getByRole("button", { name: showLabel }).click()
const unblurSensitiveResultEvent = analyticsEvents.find(
(event) => event.n === "UNBLUR_SENSITIVE_RESULT"
@@ -86,8 +88,8 @@ test.describe("sensitive_results", () => {
await goToSearchTerm(page, "cat")
await getFirstSensitiveResult(page).click()
- await page.getByRole("button", { name: /show content/i }).click()
- await page.getByRole("button", { name: /hide content/i }).click()
+ await page.getByRole("button", { name: showLabel }).click()
+ await page.getByRole("button", { name: hideLabel }).click()
const reblurSensitiveResultEvent = analyticsEvents.find(
(event) => event.n === "REBLUR_SENSITIVE_RESULT"
diff --git a/frontend/test/playwright/e2e/skip-to-content.spec.ts b/frontend/test/playwright/e2e/skip-to-content.spec.ts
index 93e919ea8..7441a8528 100644
--- a/frontend/test/playwright/e2e/skip-to-content.spec.ts
+++ b/frontend/test/playwright/e2e/skip-to-content.spec.ts
@@ -4,6 +4,8 @@ import breakpoints from "~~/test/playwright/utils/breakpoints"
import { preparePageForTests } from "~~/test/playwright/utils/navigation"
+import { skipToContentLink } from "~~/test/playwright/utils/components"
+
import { keycodes } from "~/constants/key-codes"
import { skipToContentTargetId } from "~/constants/window"
@@ -36,9 +38,7 @@ for (const pageUrl of pages) {
// Tab to the skip to content button
await page.keyboard.press(keycodes.Tab)
- await expect(
- page.getByRole("link", { name: "Skip to content" })
- ).toBeFocused()
+ await expect(skipToContentLink(page)).toBeFocused()
// We cannot check if the screen reader cursor has moved to the content
// because Playwright does not support this, and when you click on
diff --git a/frontend/test/playwright/e2e/sources.spec.ts b/frontend/test/playwright/e2e/sources.spec.ts
index bbe1d1c7c..04fb09e06 100644
--- a/frontend/test/playwright/e2e/sources.spec.ts
+++ b/frontend/test/playwright/e2e/sources.spec.ts
@@ -2,6 +2,7 @@ import { expect, test } from "@playwright/test"
import { getH1 } from "~~/test/playwright/utils/components"
import { preparePageForTests } from "~~/test/playwright/utils/navigation"
+import { t } from "~~/test/playwright/utils/i18n"
test.describe.configure({ mode: "parallel" })
@@ -22,7 +23,9 @@ test("sources table can be sorted multiple times", async ({ page }) => {
await preparePageForTests(page, "xl")
await page.goto("/sources")
- const totalItems = page.getByRole("cell", { name: /total items/i }).first()
+ const totalItems = page
+ .getByRole("cell", { name: t("sources.providers.item") })
+ .first()
await totalItems.click()
await totalItems.click()
await totalItems.click()
diff --git a/frontend/test/playwright/utils/components.ts b/frontend/test/playwright/utils/components.ts
index 7b93c19c3..a084cc510 100644
--- a/frontend/test/playwright/utils/components.ts
+++ b/frontend/test/playwright/utils/components.ts
@@ -15,9 +15,8 @@ export const getLoadMoreButton = (page: Page, dir: LanguageDirection = "ltr") =>
export const getH1 = (page: Page, text: string | RegExp) =>
page.getByRole("heading", { level: 1, name: text })
-export const getMenuButton = (page: Page, dir: LanguageDirection = "ltr") => {
- return page.getByRole("button", { name: t("header.aria.menu", dir) })
-}
+export const getMenuButton = (page: Page, dir: LanguageDirection = "ltr") =>
+ page.getByRole("button", { name: t("header.aria.menu", dir) })
export const getBackToSearchLink = (
page: Page,
@@ -27,9 +26,13 @@ export const getBackToSearchLink = (
return page.getByRole("link", { name: t("singleResult.back", dir, locale) })
}
-// Get the header home link. Hard-codes the text because `t` does not support interpolation.
-export const getHomeLink = (page: Page) =>
- page.getByRole("banner").getByRole("link", { name: "Openverse Home" })
+export const skipToContentLink = (page: Page, dir: LanguageDirection = "ltr") =>
+ page.getByRole("link", { name: t("skipToContent", dir) })
+
+export const getHomeLink = (page: Page, dir: LanguageDirection = "ltr") =>
+ page
+ .getByRole("banner")
+ .getByRole("link", { name: t("header.homeLink", dir) })
export const getHomepageSearchButton = (
page: Page,
@@ -38,3 +41,8 @@ export const getHomepageSearchButton = (
export const getLanguageSelect = (page: Page, dir: LanguageDirection = "ltr") =>
page.getByRole("combobox", { name: t("language.language", dir) })
+
+export const getHeaderSearchbar = (
+ page: Page,
+ dir: LanguageDirection = "ltr"
+) => page.getByRole("combobox", { name: t("search.searchBarLabel", dir) })
diff --git a/frontend/test/playwright/utils/i18n.ts b/frontend/test/playwright/utils/i18n.ts
index 6db867aa1..b9716a17f 100644
--- a/frontend/test/playwright/utils/i18n.ts
+++ b/frontend/test/playwright/utils/i18n.ts
@@ -45,7 +45,8 @@ export const t = (
} else if (dir === "rtl") {
value = getNestedProperty(messages.rtl, path)
}
- return value === "" ? getNestedProperty(messages.ltr, path) : value
+ const result = value === "" ? getNestedProperty(messages.ltr, path) : value
+ return result.replace("{openverse}", "Openverse")
}
export const languageDirections = ["ltr", "rtl"] as const
export type LanguageDirection = (typeof languageDirections)[number]
diff --git a/frontend/test/playwright/visual-regression/pages/errors.spec.ts b/frontend/test/playwright/visual-regression/pages/errors.spec.ts
index a9e563c67..1f9c5c0f0 100644
--- a/frontend/test/playwright/visual-regression/pages/errors.spec.ts
+++ b/frontend/test/playwright/visual-regression/pages/errors.spec.ts
@@ -132,11 +132,11 @@ for (const searchType of supportedSearchTypes) {
await page.mouse.move(0, 82)
- // The CC logos in the attribution are loaded from the CC website, and can be flaky.
await expectSnapshot(
`search-result-timeout-${dir}`,
page.locator("#main-page"),
{},
+ // Timeout pages attribution has icons that don't always load from CC site
{ maxDiffPixelRatio: 0.01 }
)
})