在我们用Ruby编写的Capybara / Rspec套件中,我们使用特殊的驱动程序来测试触摸交互和移动屏幕尺寸。
此代码适用于Chromedriver 2.28
我们在spec / spec_helper.rb中的设置
Capybara.register_driver :chrome_emulating_iphone_6 do |app|
mobile_emulation = { "deviceName" => "Apple iPhone 6" }
caps = Selenium::WebDriver::Remote::Capabilities.chrome(
'chromeOptions' => {
'mobileEmulation' => mobile_emulation,
'args' => [ ' --disable-web-security' ]
}
)
Capybara::Selenium::Driver.new(app, :browser => :chrome,
:desired_capabilities => caps)
end
以上代码适用于Chromedriver 2.28
检查确切版本:
$ chromedriver -v
ChromeDriver 2.28.455517 (2c6d2707d8ea850c862f04ac066724273981e88f)
升级到Chromedriver 2.30后,上面的代码会中断 升级后的版本似乎打破了规范:
$ chromedriver -v
ChromeDriver 2.30.477690 (c53f4ad87510ee97b5c3425a14c0e79780cdf262)
ruby规范失败了:
1)姐妹选择器视图移动姐妹选择器应该在页面上 失败/错误:访问" / products / boxer-briefs"
Selenium::WebDriver::Error::UnknownError:
unknown error: cannot parse capability: chromeOptions
from unknown error: cannot parse mobileEmulation
from unknown error: 'Apple iPhone 6' must be a valid device
from unknown error: must be a valid device
(Driver info: chromedriver=2.30.477690 (c53f4ad87510ee97b5c3425a14c0e79780cdf262),platform=Mac OS X 10.11.6 x86_64)
答案 0 :(得分:0)
修正了
mobile_emulation = { "deviceName" => "Apple iPhone 6" }
到
mobile_emulation = { "deviceName" => "iPhone 6" }
答案 1 :(得分:0)
可接受设备名称的完整列表位于https://codesearch.chromium.org/chromium/src/third_party/WebKit/Source/devtools/front_end/emulated_devices/module.json。有关移动设备模拟的其他信息,请访问ChromeDriver网站http://chromedriver.chromium.org/mobile-emulation。