Ruby 铬合金的自定义配置文件
环境:Mac OS X 10.8.3、Ruby 2.0.0p0、selenium webdriver 2.32.1、ChromeDriver 26.0.1383.0 我想更改默认浏览器语言。我正在测试站点是否正确检测到浏览器语言并以该语言显示页面 我可以将Firefox语言设置为德语:Ruby 铬合金的自定义配置文件,ruby,google-chrome,selenium,selenium-webdriver,selenium-chromedriver,Ruby,Google Chrome,Selenium,Selenium Webdriver,Selenium Chromedriver,环境:Mac OS X 10.8.3、Ruby 2.0.0p0、selenium webdriver 2.32.1、ChromeDriver 26.0.1383.0 我想更改默认浏览器语言。我正在测试站点是否正确检测到浏览器语言并以该语言显示页面 我可以将Firefox语言设置为德语: require "selenium-webdriver" profile = Selenium::WebDriver::Firefox::Profile.new profile["intl.accept_la
require "selenium-webdriver"
profile = Selenium::WebDriver::Firefox::Profile.new
profile["intl.accept_languages"] = "de"
caps = Selenium::WebDriver::Remote::Capabilities.firefox(firefox_profile: profile)
caps.platform = "Linux"
caps.version = 20
driver = Selenium::WebDriver.for(
:remote,
url: "http://USERNAME:ACCESS-KEY@ondemand.saucelabs.com:80/wd/hub",
desired_capabilities: caps)
driver.navigate.to "http://sandbox.translatewiki.net/"
我想用Chrome(和其他浏览器,如果可能的话)做同样的事情
我尝试了几种方法试图用Chrome打开德语页面,但每次页面都是用英语显示,而不是德语
require "selenium-webdriver"
profile = Selenium::WebDriver::Chrome::Profile.new
profile["intl.accept_languages"] = "de"
caps = Selenium::WebDriver::Remote::Capabilities.chrome(firefox_profile: profile)
caps.platform = "Linux"
caps.version = ""
driver = Selenium::WebDriver.for(
:remote,
url: "http://USERNAME:ACCESS-KEY@ondemand.saucelabs.com:80/wd/hub",
desired_capabilities: caps)
driver.navigate.to "http://sandbox.translatewiki.net/"
如果我将firefox\u profile:profile
更改为profile:profile
或chrome\u profile:profile
,页面每次都会以英语(而不是德语)打开
据我在中看到的,仅支持:firefox\u配置文件
我可以在一台计算机上完成这项工作,但在使用沙司实验室时却不行。我在本地机器上看到了德语翻译,使用的是:
profile = Selenium::WebDriver::Chrome::Profile.new
profile["intl.accept_languages"] = "de"
@driver = Selenium::WebDriver.for :chrome, :profile => profile
@target = 'http://sandbox.translatewiki.net/'
osx:10.7.5
ruby 1.9.3p0(2011-10-30修订版33570)[x86_64-darwin11.4.2]哇,SauceLabs+Chrome+Selenium+ruby的文档非常不一致,有时甚至相互矛盾。不幸的是,我没有一个SauceLabs帐户来测试,所以我所能做的就是给你建议 表示ChromeDriver不支持自定义配置文件是一个已知问题。显示如何为Chrome设置自定义配置文件。算了吧 为此设置配置文件或默认语言不是标准的一部分,因此您可能运气不佳 一种解决方法是将浏览器设置为使用代理,并在代理中添加/替换代理中的Accept Language标头 尽管如此,从Selenium Ruby代码中可以看出,这篇文章可能有什么内容,所以请尝试一下:
profile = Selenium::WebDriver::Chrome::Profile.new
profile["intl.accept_languages"] = "de"
caps = Selenium::WebDriver::Remote::Capabilities.chrome
caps['chromeOptions'] = { 'profile' => profile.as_json['zip'] }
driver = Selenium::WebDriver.for(
:remote,
url: "http://USERNAME:ACCESS-KEY@ondemand.saucelabs.com:80/wd/hub",
desired_capabilities: caps)
driver.navigate.to "http://sandbox.translatewiki.net/"
编辑:似乎--lang-
开关不能实现您想要的功能,因此忽略以下内容。我要把它留给子孙后代
这可能会起作用(忘记配置文件,使用命令行开关):
这应该起作用:
require "selenium-webdriver"
profile = Selenium::WebDriver::Chrome::Profile.new
profile["intl.accept_languages"] = "de"
caps = Selenium::WebDriver::Remote::Capabilities.chrome(
platform: "Linux",
version: "",
'chrome.profile' => profile.as_json['zip']
)
Selenium::WebDriver.for(:remote,
url: "http://...@ondemand.saucelabs.com:80/wd/hub",
desired_capabilities: caps
)
现在你可以用这个方法
def launch_browser options={}
language = options.fetch(:language, "en_US")
url = options.fetch(:url, "www.google.com")
prefs = {
:intl => {
:accept_languages => language
}
}
browser = Watir::Browser.new :chrome, :prefs => prefs
browser.goto url
end
然后你只要打个电话就行了
launch_browser :language => "de"
那么,如果你将:firefox_profile传递给Chrome caps,它是否有效?@p0deje:它不起作用。无论我做什么,Chrome总是用英语而不是德语打开页面。你确定如果你在浏览器中设置了默认语言,你的页面会正确加载吗?扳手->选项->高级->更改字体和语言设置->语言->谷歌Chrome语言(在下拉菜单中选择你的语言),然后接受,问题是它在没有硒的情况下是否有效。如果你在chrome中更改了语言,但它仍然不起作用,你也永远不会让selenium起作用,因为它基本上就是这么做的。Rich,正如我问题的最后一句话所说,我可以在本地机器上做这件事(请注意我博客的链接),但在使用Sauce Labs时不行。Sauce Labs确实有免费帐户…:)我找不到
--lang de
开关在哪里找到的?我找到了开关--lang
+国家代码和。这可能行不通,但有可能。你有没有试着联系SauceLabs?真的,他们应该给你一个答案。我知道Jari是唯一能回答这个问题的人!有史以来花费最多的500英镑。:)这是否已被证实有效?它似乎与我提出的解决方案非常接近,如果一个有效,另一个无效,我会感到惊讶。有人知道如何使用配置文件启用flash插件吗?chrome.profile键对我不起作用,但如此评论所述的设置很好:
launch_browser :language => "de"