为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕斯709654 2019-10-11 14:31:26
谁能告诉我如何使用茉莉花框架编写测试用例以下载pdf文件的链接?提前致谢。
查看完整描述

3 回答

?
开满天机

TA贡献1786条经验 获得超12个赞

我需要根据预期结果检查下载文件的内容(本例中为CSV导出),并发现以下内容可以正常工作:


var filename = '/tmp/export.csv';

var fs = require('fs');


if (fs.existsSync(filename)) {

    // Make sure the browser doesn't have to rename the download.

    fs.unlinkSync(filename);

}


$('a.download').click();


browser.driver.wait(function() {

    // Wait until the file has been downloaded.

    // We need to wait thus as otherwise protractor has a nasty habit of

    // trying to do any following tests while the file is still being

    // downloaded and hasn't been moved to its final location.

    return fs.existsSync(filename);

}, 30000).then(function() {

    // Do whatever checks you need here.  This is a simple comparison;

    // for a larger file you might want to do calculate the file's MD5

    // hash and see if it matches what you expect.

    expect(fs.readFileSync(filename, { encoding: 'utf8' })).toEqual(

        "A,B,C\r\n"

    );

});

我发现Leo的配置建议有助于将下载文件保存在可访问的位置。


30000毫秒的超时是默认值,因此可以省略,但是我提醒您,以防万一有人要更改它。


查看完整回答
反对 回复 2019-10-11
  • 3 回答
  • 0 关注
  • 412 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信