5
我需要使用量角器在Firefox上下載zip文件。 點擊下載鏈接,彈出Windows對話框詢問打開/保存文件。所以我該如何處理。我需要傳遞給驅動程序的參數是什麼? 隨着鉻我可以做到這一點 下載:{ 'prompt_for_download':假 },使用量角器在Firefox上下載文件
但我應該做與Firefox。
我需要使用量角器在Firefox上下載zip文件。 點擊下載鏈接,彈出Windows對話框詢問打開/保存文件。所以我該如何處理。我需要傳遞給驅動程序的參數是什麼? 隨着鉻我可以做到這一點 下載:{ 'prompt_for_download':假 },使用量角器在Firefox上下載文件
但我應該做與Firefox。
問題是 - 您無法通過量角器/硒操作「另存爲...」對話框。你應該避免它首先打開,讓Firefox自動下載指定MIME類型的文件 - 在你的案例application/zip
。
換句話說,你需要火了火狐定製Firefox Profile設置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"]
)
]);
},
// ...
}
在這裏,我們基本上是說:火狐,請自動下載zip文件,不問到/path/to/save/downloads
目錄。
非常感謝您的工作。 –
@alecxe我們如何驗證文件被下載的天氣? – Nick
@尼克肯定,等待它被下載,這裏是工作示例:http://stackoverflow.com/questions/41082777/protractor-test-download-file-without-knowing-filename。 – alecxe