我正在运行规格时尝试仿真不同的设备,但目前没有结果。
#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
部分而不是功能吗?
答案 0 :(得分:1)
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, browser: :chrome, options: browser_options)