Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set the browser language in Cucumber / Capybara?

I'd like a different language to be displayed depending on the browser language and naturally I'd like to test to make sure it's working properly. I'm using Cucumber and Capybara, Gem versions 1.0.6 and 1.1.1 respectively.

I've found a few suggestions on the web, but none that work so far. I've tried the following (individually) without success.

page.driver.language = language
header "Accept-Language", language
page.driver.header 'Accept-Language', language

Where language is set to either "en" or "fr".

Can anyone help? Thanks, Graeme.

like image 335
Simmo Avatar asked Oct 19 '25 02:10

Simmo


1 Answers

Got it!

I had the right line, the problem was elsewhere.

page.driver.header 'Accept-Language', language

This works fine, the problem was that my Scenario was as follows.

Scenario:
  Given I am an anonymous user
  And the browser language is fr
  Then I should see "Bonjour"

And it should have been

Scenario:
  Given the browser language is fr
  And I am an anonymous user
  Then I should see "Bonjour"

The 'I am an anonymous user' step was just doing a sign out first. It would seem that the browser language must be set before any other steps are taken which use the browser.

like image 61
Simmo Avatar answered Oct 21 '25 17:10

Simmo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!