【问题标题】:Selenium Test for file downloadSelenium 测试文件下载
【发布时间】:2015-07-21 20:31:47
【问题描述】:

我想知道现在是否可以使用 Selenium 实现“下载测试”。检测文件下载是否已开始就足够了。 重要的是要说这些文件不是静态的,因此无法通过特定的 URL 访问它们。它们是根据用户提供的输入动态创建并填充数据的。 我也不能使用 FirefoxProfile,因为我的自动化网络测试使用 chrome 驱动程序和 phantomjs。它们还需要在 Hudson 下运行(这里当然只使用了 phantomjs)。 应用程序在 JBoss Server 下运行,所以我使用的是 Arquillian 库。

谢谢

【问题讨论】:

  • 这在 PhantomJS 中是不可能的。您应该研究如何使用 xvfb 运行 chrome。

标签: java selenium phantomjs jboss6.x jboss-arquillian


【解决方案1】:

是的,仅适用于 Firefox 因此必须配置特殊功能

firefox_profile = FirefoxProfile()
firefox_profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/csv, image/png, application/octet-stream, text/plain") # File mine types
firefox_profile.set_preference("browser.download.manager.showWhenStarting", False)

firefox_profile.set_preference("browser.download.dir", "/tmp")
firefox_profile.set_preference("browser.download.folderList", 2)

但是对于任何其他浏览器,我通常会做一个简单的技巧,我会得到一个文件链接,而不是使用 f.e.请求库并检查文件头

import requests
r = requests.head("https://www.google.com.ua//images/srpr/logo11w.png")
assert r.status_code == 200
assert r.headers['content-type'] == 'image/png'

【讨论】:

  • 查看另一个我的解决方案,我希望这会有所帮助
猜你喜欢
  • 1970-01-01
  • 2019-09-24
  • 1970-01-01
  • 2021-05-13
  • 2010-12-09
  • 1970-01-01
  • 2014-01-05
  • 2015-08-23
  • 1970-01-01
相关资源
最近更新 更多