goog:chromeOptions使用RSpec,Capybara和Selenium完全忽略

时间:2019-02-20 17:00:02

标签: selenium rspec capybara

还有其他人有这个问题吗?似乎goog:chromeOptions某处未正确传递给chromedriver-这导致Chrome仅使用默认选项打开。

我正在使用以下Capybara / Selenium配置:

Capybara.register_driver :chrome do |app|
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    'goog:chromeOptions': {
      args: %w[ start-maximized ]
    }
  )

  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    desired_capabilities: capabilities,
    driver_opts: {
      log_path: "./tmp/chrome#{Time.now.to_i}.log",
      verbose: true
    }
  )
end

Capybara.javascript_driver = :chrome

但是,当我打开Capybara会话日志时,根本没有设置goog:chromeOptions。这就是为什么我的Chrome窗口没有最大化的原因吗?

会话日志:

[1550680994.143][INFO]: COMMAND InitSession {
   "capabilities": {
      "firstMatch": [ {
         "browserName": "chrome",
         "goog:chromeOptions": {
           //nothing is here???  should have args!
         }
      } ]
   },
   "desiredCapabilities": {
      "browserName": "chrome",
      "cssSelectorsEnabled": true,
      "goog:chromeOptions": {
        //nothing is here???  should have args!
      },
      "javascriptEnabled": true,
      "nativeEvents": false,
      "platform": "ANY",
      "rotatable": false,
      "takesScreenshot": false,
      "version": ""
   }
}

操作系统:

Ubuntu 18.04

我的环境:

ruby 2.6.1
capybara (2.18.0)
selenium-webdriver (3.13.0)
ChromeDriver 2.37.544315

每次我运行Selenium测试时,窗口不会最大化。但这不是另一个“屏幕没有最大化”的帖子(已经有很多)。这似乎是我的选项未正确解析的问题?我没有错。我将尽我所能遵循所有自述文件和指南。它只是不起作用:(

1 个答案:

答案 0 :(得分:0)

通过升级Capybara和Selenium Webdriver修复了该问题!

capybara (3.13.2)
selenium-webdriver (3.141.0)

现在,调试日志具有我期望看到的内容:

[1550686685.534][INFO]: COMMAND InitSession {
   "capabilities": {
      "firstMatch": [ {
         "browserName": "chrome",
         "goog:chromeOptions": {
            "args": [ "start-maximized" ]
         }
      } ]
   },
   "desiredCapabilities": {
      "browserName": "chrome",
      "cssSelectorsEnabled": true,
      "goog:chromeOptions": {
         "args": [ "start-maximized" ]
      },
      "javascriptEnabled": true,
      "nativeEvents": false,
      "platform": "ANY",
      "rotatable": false,
      "takesScreenshot": false,
      "version": ""
   }
}