我正在尝试在运行我的规范时模拟不同的设备,现在没有结果.
#spec_helper require 'rspec' require 'capybara' require 'capybara/rspec' require 'selenium/webdriver' Capybara.register_driver :headless_chrome do |app| Capybara::Selenium::Driver.load_selenium browser_options = ::Selenium::WebDriver::Chrome::Options.new browser_options.args << '--headless' mobile_emulation = { "deviceName" => "iPhone 8" } capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( "chromeOptions" => { "mobileEmulation" => mobile_emulation } ) Capybara::Selenium::Driver.new(app,browser: :chrome,options: browser_options,desired_capabilities: capabilities) end
我应该在选项而不是功能中包含mobile_emulation部分吗?
解决方法
chromeOptions不再是一个有效的密钥(它被goog:chromeOptions取代),但由于你已经使用了:: Selenium :: WebDriver :: Chrome :: Options类,你应该只使用add_emulation方法 –
https://www.rubydoc.info/gems/selenium-webdriver/Selenium/WebDriver/Chrome/Options#add_emulation-instance_method.
browser_options = ::Selenium::WebDriver::Chrome::Options.new browser_options.args << '--headless' browser_options.add_emulation(device_name: 'iPhone 8') Capybara::Selenium::Driver.new(app,options: browser_options)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。