【发布时间】:2022-01-23 10:37:09
【问题描述】:
请提供在Testcafe中设置下载文件路径的步骤。
【问题讨论】:
-
请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。
标签: testing download automated-tests e2e-testing testcafe
请提供在Testcafe中设置下载文件路径的步骤。
【问题讨论】:
标签: testing download automated-tests e2e-testing testcafe
如果您需要查找和检查下载的文件,可以使用以下方式:
使用 RequestLogger:Check the Downloaded File Name and Content example
从系统环境变量中获取“Downloads”文件夹路径或使用downloads-folder包:
import fs from 'fs';
import downloadsFolder from 'downloads-folder';
fixture('fixture')
.page('http://example.com/');
test('test', async t => {
await t.click('#download');
const filePath = downloadsFolder() + '/my-file.txt';
await t.expect(fs.existsSync(filePath)).ok();
});
此外,TestCafe 内部 API 允许您更改下载路径:https://stackoverflow.com/a/65732040/10684943。请注意,不建议使用此方法。使用它需要您自担风险。
【讨论】: