flood-io / element

💦Load test your app using real web browsers
https://element.flood.io
Apache License 2.0
350 stars 43 forks source link

Allow setting the browser language #310

Open torfmaster opened 3 years ago

torfmaster commented 3 years ago

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:

honglax commented 3 years ago

Hi @torfmaster

Have you ever tried extraHTTPHeaders: {'Accept-Language': 'en, fr, vi'} with TestSettings like this image below?

element-set-language

sonnguyenmau commented 3 years ago

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)

image

Please try it out and let us know if you still have any problems.

torfmaster commented 3 years ago

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.

ivanvanderbyl commented 3 years ago

Have you tried using launchArgs to set --lang=de ?

torfmaster commented 3 years ago

@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.

sonnguyenmau commented 3 years ago

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