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

时间:2023-05-01
本文介绍了量角器 e2e 测试用例下载 pdf 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

谁能告诉我如何为使用 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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:JS/HTML5 WebSocket:无需 HTTP 调用即可连接 下一篇:如何编写一个期望在 Jasmine 中抛出“错误"的

相关文章

最新文章