Detect Chrome Browser Language when running Vaadin Integration Test Class

151 Views Asked by At

I am using Vaadin Testbench to implement test imulations. I have to check whether the Chrome Browsers language is English or German and based on that I have to set values either in English or German to simulate.

How to detect Chrome browser language when running the Integration test class? Based on the language detected I will set the language in the Chrome Driver parameters.

1

There are 1 best solutions below

0
On

Using Vaadin TestBench, you can retrieve the language via a JavaScript call like so

String language = (String) executeScript(
                "let language = window.navigator.userLanguage || window.navigator.language;"
                + "return language");

Note also that rather than retrieving the language, it might be useful to set it explicitly yourself like so

ChromeOptions options = new ChromeOptions();
options.addArguments("--lang=es");
ChromeDriver driver = new ChromeDriver(options);