0

I am having some problems setting the language of my chrome-browser to english when running Tests in my CI/CD-Pipeline. I use Selenium and TestNG for testing. Everytime I run my tests locally it works perfectly fine but when the Pipeline executes the tests, it always ends up failing the asserted value. This seems to be because the pipeline changes the browsers language to english instead of german.

I already tried the following code snippets to change the browsers language but none of them worked:

WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.setHeadless(headless); //headless is true
options.setExperimentalOption("prefs", Collections.singletonMap("intl.accept_languages", "de-DE"));

and

options.addArguments("--lang=de-DE")

and

options.addArguments("lang=de-DE")

and

options.addArguments("lang=de")

I tried literally every solution I found online. I think the problem might be the headless mode but I couldn't figure out how to solve it.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
JanR443
  • 11
  • 2

2 Answers2

0

To change the language to German through ChromeDriver while executing Selenium tests you can use the following line of code:

options.addArguments('--lang=de_DE');
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

On Linux, Chrome uses the LANGUAGE environment variable (chrome.i18n).

If you run the WebDriver with docker just add -e LANGUAGE=de_DE -e LANG=de_DE.

If you use selenium-grid deployed to Kubernetes you can set chromeNode.extraEnvironmentVariables to

extraEnvironmentVariables:
  - name: LANG
    value: de_DE
  - name: LANGUAGE
    value: de_DE

In the newest version of docker-selenium they are added a wrapper to set the LANGUAGE env var based on the --lang arugment (see PullRequest)

mpoqq
  • 96
  • 5