使用Chrome Capybara Selenium下载并打开文件 [英] Download and open file using Chrome Capybara Selenium

查看:770
本文介绍了使用Chrome Capybara Selenium下载并打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写测试,下载PDF并在浏览器中打开它,以便我可以确认一些内容。我正在努力找到一个解决方案来配置Chromedriver下载和打开,而不是保存到下载文件夹(默认)。

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).

有没有办法吗?

感谢

推荐答案

目前(2015-07-12)是chromedriver中的一个开放问题。
请参阅: https://code.google.com/p / chromedriver / issues / detail?id = 1081 了解详情。

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

您可以通过配置Chrome配置文件来解决此问题。根据错误中的信息,您可以尝试类似:

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

并设置:

Capybara.javascript_driver = :chrome_pdf

需要:

Capybara.current_driver = :chrome_pdf

这篇关于使用Chrome Capybara Selenium下载并打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆