如何在 Cucumber / Capybara 中设置浏览器语言?
我希望根据浏览器语言显示不同的语言,当然我想进行测试以确保它正常工作。我使用的是 Cucumber 和 Capybara,Gem 版本分别为 1.0.6 和 1.1.1。
我在网上找到了一些建议,但到目前为止没有一个有效。我(单独)尝试了以下方法,但没有成功。
page.driver.language = language
header "Accept-Language", language
page.driver.header 'Accept-Language', language
其中语言设置为“en”或“fr”。
有人可以帮忙吗?谢谢,格雷姆。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
知道了!
我的线路是正确的,问题出在其他地方。
这工作正常,问题是我的场景如下。
它应该是
“我是匿名用户”步骤只是先注销。似乎必须在执行使用浏览器的任何其他步骤之前设置浏览器语言。
Got it!
I had the right line, the problem was elsewhere.
This works fine, the problem was that my Scenario was as follows.
And it should have been
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.
使用 poltergeist:
更多详细信息:https://github.com/teampoltergeist/poltergeist#manipulate-request-headers
With poltergeist:
More details: https://github.com/teampoltergeist/poltergeist#manipulating-request-headers
你用什么水豚驱动?这适用于机械化:
What Capybara driver are you using? This works for Mechanize: