element
element copied to clipboard
Allow setting the browser language
Is your feature request related to a problem? Please describe.
Our application behaves differently according to the language of the browser. Currently, we have no way of influencing the language.
Describe the solution you'd like
Ideally, it would be possible to set environment variables when starting an element test in the cloud which are then consumed by the browser. Also effectively setting the browser language in elements would be a solution (either using the TestSettings or the browser interface).
Describe alternatives you've considered
Methods I tried:
- setting parameters for chromium using
--lang=
doesn't work due to restrictions of chromium itself - setting of environment variables is not supported when running in the cloud
Hi @torfmaster
Have you ever tried extraHTTPHeaders: {'Accept-Language': 'en, fr, vi'}
with TestSettings
like this image below?
Hi @torfmaster,
The --lang
launchArg doesn't work due to a bug of Puppeteer. However, as @honglax suggested, you can set the browser language by using extraHTTPHeaders
in the TestSettings. In my case, this is what I used:
export const settings: TestSettings = {
extraHTTPHeaders: { 'Accept-Language': 'bn' }
}
and this is the screenshot that I got when running the test on Flood (cloud), targeting Google. You can see that the language has been set to Bangla (Bangladesh)
Please try it out and let us know if you still have any problems.
Thank you for your response! I already tried that but that only sets the server part. As for javascript which consumes navigator.language
. I already tried also setting the javascript part by overriding the navigator
prototype, however, this only works as long as all of the tests stay on the same page - which isn't the case - otherwise the language gets reset.
Have you tried using launchArgs
to set --lang=de
?
@ivanvanderbyl as @sonnguyenmau mentioned setting the launchArgs
doesn't work as the chromium version provided by puppeteer doesn't accept the --lang
argument anymore (still, it is listed as a supported argument). The only way to set the browser language from outside is using export LANG=en-GB
for example, but that isn't supported by element
inside flood.
Hi @torfmaster, we're thinking of a solution, which is to set the lang
to the process.env
, then make your web page get that value to detect the language. To give you a better support, can you please give us more info about your test scenarios and the target page that you're going to test?
As a heads-up, Element v2.0 will replace Puppeteer with Playwright as the core, and it seems Playwright has better support for setting locale