断言文件下载的 Testcafe 示例

Testcafe example to assert file download(断言文件下载的 Testcafe 示例)
本文介绍了断言文件下载的 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 示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)
How to get response url in XMLHttpRequest?(如何在 XMLHttpRequest 中获取响应 url?)