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 示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:断言文件下载的 Testcafe 示例


基础教程推荐
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01