使用量角器在Firefox上下载文件 [英] Download file on Firefox with protractor

查看:122
本文介绍了使用量角器在Firefox上下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在带有量角器的Firefox上下载一个zip文件。
点击下载链接,弹出打开/保存文件的Windows对话框。那我该怎么办?我需要传递给驱动程序的args是什么?
使用chrome我可以用
下载:{
'prompt_for_download':false
},

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 Profile 设置适当的偏好

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上下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆