Download and open file using Chrome Capybara Selenium

你离开我真会死。 提交于 2019-12-12 00:44:09

问题


I'm writing tests that downloads a PDF and opens it in browser so that I can confirm some content within. I'm struggling to find a solution to configure Chromedriver to download and open instead of saving to the downloads folder (default).

Is there a way I can do this?

Thanks


回答1:


Currently (2015-07-12) this is an open issue in chromedriver. See: https://code.google.com/p/chromedriver/issues/detail?id=1081 for details.

You may be able to work-around it by configuring the chrome profile. Based on the information in the bug you might try something like:

Capybara.register_driver :chrome_pdf do |app|
  caps = Selenium::WebDriver::Remote::Capabilities.chrome(
    "chromeOptions" => {
      "excludeSwitches" => [ "test-type", "ignore-certificate-errors" ],
    }
  )
  Capybara::Selenium::Driver.new(app, :browser => :chrome, :desired_capabilities => caps)
end

And set:

Capybara.javascript_driver = :chrome_pdf

or just switch to this driver when needed:

Capybara.current_driver = :chrome_pdf


来源:https://stackoverflow.com/questions/31182716/download-and-open-file-using-chrome-capybara-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!