//gives count of downloads in download folder.
this.getCountOfDownloads = function (fileName,elementToClick) {
//provides a way to look for filenames matching a certain pattern (in the worst case, you can wait for the *.* - basically, any file to appear)
var glob = require("glob");
var filesArray = glob.sync("./src/test/javascript/e2e/downloads/"+"*.xlsx");
console.log("sizee",filesArray.length);
browser.driver.wait(function () {
elementToClick.click();//to download
if (typeof filesArray !== 'undefined' && filesArray.length > 0) {
// this check is necessary because `glob.sync` can return
// an empty list, which will be considered as a valid output
// making the wait to end.
return filesArray;
}
}, 4444).then(function (filesArray) {
console.log("sizee",filesArray[0]);
// now we have the filename and can do whatever we want
});
browser.sleep(5555); console.log("sizee",filesArray.length);
};
elemtclick
下载文件。
当我点击同步按钮
时,我可以在intelj
中看到
起初它是空的。然后我运行它,它在两个控制台输出显示大小为0。然后在下一次运行中,它变为1,因为之前下载的文件。
filesarray> 0
未成为现实。
我将browsersleep
放在elementclick
之后,但仍未等待文件或与之同步。
我想做的是
但它看不到文件:(, 我想我必须刷新会议,但也许还有一种方式
答案 0 :(得分:0)
我认为你遇到了异步问题。 console.log()不等待browser.sleep。它立即发生。 我想你需要再次调用glob.sync,但我不知道那段代码。
//gives count of downloads in download folder.
this.getCountOfDownloads = function (fileName,elementToClick) {
//provides a way to look for filenames matching a certain pattern (in the worst case, you can wait for the *.* - basically, any file to appear)
var glob = require("glob");
var filesArray = glob.sync("./src/test/javascript/e2e/downloads/"+"*.xlsx");
console.log("sizee",filesArray.length);
browser.driver.wait(function () {
elementToClick.click();//to download
browser.sleep(5555);
filesArray = glob.sync("./src/test/javascript/e2e/downloads/"+"*.xlsx");
console.log("sizee",filesArray.length);
if (typeof filesArray !== 'undefined' && filesArray.length > 0) {
// this check is necessary because `glob.sync` can return
// an empty list, which will be considered as a valid output
// making the wait to end.
return filesArray.length;
}
}, 4444).then(function (filesArray) {
console.log("sizee",filesArray[0]);
// now we have the filename and can do whatever we want
});
};