I want to test an application for language translations. How to do this in playwright? Playwright has this config "locale" and "timezoneId" . But when I set them and access a site, it is still showing the content in english. Questions:
This thread is trying to answer question "How can I set my browser language in Playwright to test an application's language translations?"
You can check how the locale in your UserAgent is set by visiting https://gtranslate.io/detect-browser-language
With Playwright is it possible to assert against the above page, whether your locale config for the browser context is being recognized
//detectBrowserLanguage.spec.ts
import { expect, test } from "@playwright/test";
const expectedLocale = "de-DE";
test.use({ locale: expectedLocale });
test("checkMyBrowserLocale", async ({ page }) => {
await page.goto("https://gtranslate.io/detect-browser-language");
const tableAcceptLanguageHeader = page
.getByRole("table")
.filter({ hasText: "Preference Score" });
const tableNavigatorLanguages = page
.getByRole("table")
.filter({ hasNotText: "Preference Score" });
const localeAcceptLanguageHeader = await tableAcceptLanguageHeader
.getByRole("row")
.filter({ hasNot: page.locator("th") })
.locator("td")
.first()
.innerText();
const localeNavigatorLanguages = await tableNavigatorLanguages
.getByRole("row")
.filter({ hasNot: page.locator("th") })
.locator("td")
.first()
.innerText();
expect(localeAcceptLanguageHeader).toBe(expectedLocale);
expect(localeNavigatorLanguages).toBe(expectedLocale);
});
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].