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

谁能告诉我如何使用茉莉花框架编写测试用例以下载pdf文件的链接?提前致谢。

慕村9548890
浏览 278回答 3
3回答

杨魅力

我需要根据预期结果检查下载文件的内容(本例中为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毫秒的超时是默认值,因此可以省略,但是我提醒您,以防万一有人要更改它。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java