在用Ruby编写的Capybara/Rspec套件中,我们使用特殊的驱动程序来测试触摸交互和移动屏幕尺寸。
此代码适用于Chromedriver 2.28
我们在规范/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)姐妹选择器视图移动姐妹选择器应该在页面上 故障/错误:访问"/产品/拳击手三角裤">
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)
可在此处找到可接受的设备名称的完整列表。有关移动设备仿真的更多信息,请访问 ChromeDriver 网站 https://chromedriver.chromium.org/mobile-emulation。
通过更改修复
mobile_emulation = { "deviceName" => "Apple iPhone 6" }
自
mobile_emulation = { "deviceName" => "iPhone 6" }