使用量角器在 Firefox 上下载文件

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

问题描述

我需要使用量角器在 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 上下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)