量角器 e2e 测试用例下载 pdf 文件

Protractor e2e test case for downloading pdf file(量角器 e2e 测试用例下载 pdf 文件)
本文介绍了量角器 e2e 测试用例下载 pdf 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

谁能告诉我如何为使用 jasmine 框架下载 pdf 文件的链接编写测试用例?提前致谢.

Can anyone tell me how to write test case for a link to download pdf file using jasmine framework ? Thanks in advance.

推荐答案

目前可以设置下载路径位置

I can currently set download path location

capabilities: {
    'browserName': 'chrome',
    'platform': 'ANY',
    'version': 'ANY',
    'chromeOptions': {
        // Get rid of --ignore-certificate yellow warning
        args: ['--no-sandbox', '--test-type=browser'],
        // Set download path and avoid prompting for download even though
        // this is already the default on Chrome but for completeness
        prefs: {
            'download': {
                'prompt_for_download': false,
                'default_directory': '/e2e/downloads/',
            }
        }
    }
}

对于远程测试,您需要更复杂的基础架构,例如设置 Samba 共享或网络共享目录目标.

For remote testing you would need a more complex infrastructure like setting up a Samba share or network shared directory destination.


var FirefoxProfile = require('firefox-profile');
var q = require('q');

[...]
getMultiCapabilities: getFirefoxProfile,
framework: 'jasmine2',

[...]
function getFirefoxProfile() {
    "use strict";
    var deferred = q.defer();
    var firefoxProfile = new FirefoxProfile();
    firefoxProfile.setPreference("browser.download.folderList", 2);
    firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);
    firefoxProfile.setPreference("browser.download.dir", '/tmp');
    firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");

    firefoxProfile.encoded(function(encodedProfile) {
        var multiCapabilities = [{
            browserName: 'firefox',
            firefox_profile : encodedProfile
        }];
        deferred.resolve(multiCapabilities);
    });
    return deferred.promise;
}

最后,也许很明显,要触发下载,您可以点击下载链接,例如

Finally and maybe obvious, to trigger the download you click on the download link as you know, e.g.

$('a.some-download-link').click();

这篇关于量角器 e2e 测试用例下载 pdf 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

jasmine.createSpyObj with properties(jasmine.createSpyObj 与属性)
What#39;s a good way to reuse test code using Jasmine?(使用 Jasmine 重用测试代码的好方法是什么?)
Does Jasmine#39;s toThrow matcher require the argument to be wrapped in an anonymous function?(Jasmine 的 toThrow 匹配器是否需要将参数包装在匿名函数中?)
Jasmine - Spying on a method call within a constructor(Jasmine - 在构造函数中监视方法调用)
Getting requirejs to work with Jasmine(让 requirejs 与 Jasmine 一起工作)
How can I spy on a getter property using jasmine?(如何使用 jasmine 监视 getter 属性?)