Project

General

Profile

Actions

Playwright Need To Know

Installation inside VS code

  • Install the Microsoft playwright extension
  • Open an empty folder (otherwise it will write where you are)
  • Ctlr-shift-p "install playwright"
    • Don't select "Install Linux dependencies" (this will invoke `apt-get? that you don't have on openSUSE)

Modify the default language in VS code for Playwright

When playing around with Playwright inside VS code I noticed that recording a test (running playwright codegen) used German for some Labels on the login page.

The recorded file looked like this:

  await page.getByLabel('Benutzername').click();
  await page.getByLabel('Benutzername').fill('root');
  await page.getByLabel('Passwort').click();
  await page.getByLabel('Passwort').fill('linux');
  await page.getByRole('button', { name: 'Anmelden' }).click();

The problem is that running the test does this in English. So we will fail because in the english settings "Benutzername" should translate to "User name".

To avoid this mess you need to define a default language for Playwright inside VS code. Open the settings.json and add:

    "playwright.env": {
        "LANG": "en-EN",
    }

With those settings the test recording will happen in English and you don't need to translate the locators by hand.

Updated by rainerkoenig 11 months ago · 1 revisions