我正在创建一个测试,它会转到特定页面并单击以及下载excel文件的按钮。
该文件托管在远离的位置,在下载开始之前通常需要1.5分钟从主机服务器收集它,完全下载它只需要2-3秒。
从我点击提交按钮和下载开始的时间之间开始,间隔为1.5分钟(如前所述)。
我尝试使用.wait(120000) - 2分钟是安全的。
测试给出错误(参见下图)。
这是我的测试代码。
test('R03', async t => {
await t
.click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText('Year_1'))
.click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText('Location_1'))
.click(Selector('span').withText('SUBMIT'))
.wait(120000); // in ms
});
调试测试显示以下错误:
× R03
1) Failed to complete a request to
"http://example.com/Reports/ViewerPartial/DXXRDV.axd?actionKey=exportTo&arg=%7B%22documentId%22%3A%227c93875b0e0247e391d50759c00ef3a7%22%2C%22exportOptions%22%3A%22%7B%5C%22Html%5C%22%3A%7B%5C%22%40EmbedImagesInHTML%5C%22%3A%5C%22true%5C%22%7D%7D%22%2C%22format%22%3A%22xlsx%22%7D"
within the timeout period. The problem may be related to local
machine's network or firewall settings, server outage, or network
problems that make the server inaccessible.
我隐藏了域名,因公司原因将其更改为example.com。 如果我删除.wait(120000),则测试完成并显示成功。任何建议将不胜感激。试图掌握它(testcafe)
作为解决方法,您可以使用for循环等待文件到达下载文件夹:
import { join } from 'path';
import { existsSync } from 'fs';
import {t} from 'testcafe';
test("My Test", async (t) => {
await t
.click(Selector('[data-bind^="css:{ \\\'dx-state- disabled\\\'].find('div').withText('Year_1'))
.click(Selector('[data-bind^="css:{ \\\'dx-state-disabled\\\'].find('div').withText('Location_1'))
.click(Selector('span').withText('SUBMIT'));
await waitUntilFileIsDownloaded();
});
async function waitUntilFileIsDownloaded(){
const downloadsFolder= `${process.env.HOME}/Downloads`;
const expectedFile = join(downloadsFolder, 'data.csv');
console.log(`waiting for file '${expectedFile}' ...`);
for (let index = 0; index < 120; index++) {
if (existsSync(expectedFile)) {
console.log(`file downloaded after ${index} seconds`);
return;
}
await t.wait(1000);
console.log(`waiting for '${index}' seconds`);
}
console.log('File has not been downloaded in due time');
}