2015-07-21 78 views
0

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

谢谢

+2

这对于PhantomJS来说是不可能的。你应该看看你如何用xvfb运行chrome。 –

回答

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) 

但对于其他浏览器,我通常做一个简单的一招我获取文件的链接而不是使用fe请求库和检查文件头文件

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' 
+0

正如我所说,我不能使用FirefoxProfile ... –

+0

看到另一个我的解决方案,我希望这将有助于 – dmr