Setting the Language in Chrome Headless for E2E Tests

Georg Dangl by Georg Dangl in Web Development Thursday, June 01, 2023

Thursday, June 01, 2023

Posted in Testing

For End-to-End (E2E) testing of web apps, the headless mode of Chrome is a great choice. We're using it in our projects to ensure some true end to end test coverage, often for stories like happy paths for important actions. E2E tests are usually quite cumbersome to write, and tend to be brittle during upgrades, but they give you a lot of confidence when doing automated deployments, and free up valuable developer time from having to do repeated, manual tests and verifications. I've blogged before about them, for example hows to instrument them via Playwright or how you can use Selenium in a Docker container.

One thing that's been missing is the ability to set a language for the headless Chrome instance when testing. Especially if you have multilingual apps that automatically detect the users language, you might experience problems in testing when you're checking for text contents or trying to find Html elements via their labels. There was a long open issue with Chrome, where the language supplied via a command line argument was simply not set in headless mode.

But, this has changed with the new headless option for chrome!

Finally, when you start headless via --headless=new, you can simply set the language with another switch: --lang=en. This makes testing so much easier, and allows to provide a consistent developer experience, no matter the local language settings.

Happy testing!

Share this post

comments powered by Disqus

About me

Hi, my name's George! I love coding and blogging about it. I focus on all things around .Net, Web Development and DevOps.


Need a consultant for BIM, GAEB or Software Development?

Contact me at [email protected], +49 (173) 56 45 689 or visit my professional page!

// Just 💗 Coding

Social Links