Search code examples
automated-testsplaywrightplaywright-typescript

Using test.use({ locale: 'fr-CA' }) and two test ids are being partially translated


I am wondering if I anyone has run into this problem before with test ids getting translated or partially translated.

I have a test that I am implementing using Playwright. Before the test, I am setting the locale to use French Canadian. I have only 2 test ids that are being partially translated to French so my test is failing unless I update the locator to getbyTestId for the english and a partial French translation.

Setting Locale


test.describe('Check French', () => {
   test.use( { locale: 'fr-CA'});
   test('Run the test in French'.........

Locators

this.requestFirstCode = page.getByTestId(
      /CardEmail|CardCourriel/,
    );

this.requestSecondCode = page.getByTestId(
      /CardPhone|CardTéléphone/,
    );

I was expecting the test to run with the english test ids.


Solution

  • The idea of testId - it's independent of the locale.

    If your app has a different implementation, you'd ask the FrontEnd team to change it - data-testid attributes should be unaffected by UI changes.