Testcafe示例来断言文件下载 [英] Testcafe example to assert file download
本文介绍了Testcafe示例来断言文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想编写一个夹具来模拟导出文件,并确保从浏览器操作中下载了文件. 有什么例子吗?
I want to write a fixture to simulate the export file and make sure a file is downloaded from browser actions. any example?
不适用
推荐答案
没有一种奇特的方式来检查下载是否完成,TestCafe在浏览器中控制下载能力的能力受到一定限制.
There's not a fancy way check if the download has finished, TestCafe is somewhat limited in its ability to control the download ability in the browser.
import fs from 'fs';
const fileName = 'junk.txt';
const downloadLocation = 'C:\\Wherever\\Downloads\\';
const fileDLUrlBase = 'https://example.com/downloads/';
fixture('download test fixture');
test('download test', async t => {
await t.navigateTo(fileDLUrlBase + fileName);
await t.wait(30000);
// Wait 30 seconds
await t.expect(fs.fileExistsSync(downloadLocation + fileName));
});
如果需要,您可以将其转换为一个循环,该循环每5秒检查一次,持续60秒.
You could convert that to a loop that checks, say, every 5 seconds for 60 seconds, if you wanted.
这篇关于Testcafe示例来断言文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文