我需要使用 Protractor 在 Firefox 上下载一个 zip 文件。 单击下载链接时,会弹出要求打开/保存文件的 Windows 对话框。那么我该如何处理呢。我需要将哪些参数传递给驱动程序? 使用 chrome 我可以做到这一点 下载: { 'prompt_for_download':假 },
但是我应该用 firefox 做什么。
最佳答案
问题是 - 您无法通过 Protractor/selenium 操作“另存为...”对话框。您应该首先避免打开它,让 firefox 自动下载指定 mime 类型的文件 - 在您的情况下为 application/zip
。
换句话说,您需要使用自定义 Firefox Profile 启动 Firefox设置 appropriate preferences :
var q = require("q");
var FirefoxProfile = require("firefox-profile");
var makeFirefoxProfile = function(preferenceMap, specs) {
var deferred = q.defer();
var firefoxProfile = new FirefoxProfile();
for (var key in preferenceMap) {
firefoxProfile.setPreference(key, preferenceMap[key]);
}
firefoxProfile.encoded(function (encodedProfile) {
var capabilities = {
browserName: "firefox",
firefox_profile: encodedProfile,
specs: specs
};
deferred.resolve(capabilities);
});
return deferred.promise;
};
exports.config = {
getMultiCapabilities: function() {
return q.all([
makeFirefoxProfile(
{
"browser.download.folderList": 2,
"browser.download.dir": "/path/to/save/downloads",
"browser.helperApps.neverAsk.saveToDisk": "application/zip"
},
["specs/*.spec.js"]
)
]);
},
// ...
}
这里我们基本上是在说:Firefox,请自动下载 zip 文件,无需进入 /path/to/save/downloads
目录。
关于javascript - 使用 Protractor 在 Firefox 上下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31526120/