問題描述
我需要使用量角器在 Firefox 上下載一個 zip 文件.單擊下載鏈接時,會彈出要求打開/保存文件的 Windows 對話框.那么我該如何處理.我需要將哪些參數傳遞給驅動程序?使用 chrome 我可以做到這一點下載: {'prompt_for_download':假},
I need to download a zip file on Firefox with protractor. On clicking on download link, Windows dialog asking to Open/Save the file pops up. So How can I handle that. What args do I need to pass to driver? With chrome I can do that with download: { 'prompt_for_download': false },
但是我應該用 Firefox 做什么.
but what should i do with firefox.
推薦答案
問題是 - 您無法通過量角器/硒操作另存為..."對話框.您應該首先避免打開它,讓 firefox 自動下載指定 mime 類型的文件 - 在您的情況下為 application/zip
.
The problem is - you cannot manipulate that "Save As..." dialog via protractor/selenium. You should avoid it being opened in the first place and let firefox automatically download the files of a specified mime-type(s) - in your case application/zip
.
換句話說,您需要使用自定義 Firefox 來啟動 Firefox配置文件設置適當的偏好:
In other words, you need to fire up Firefox with a custom Firefox Profile setting the 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
目錄.
Here we are basically saying: Firefox, please download zip files automatically, without asking into the /path/to/save/downloads
directory.
這篇關于使用量角器在 Firefox 上下載文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!