I\'m generating files automatically, and I have another script which will check if a given file is already generated, so how could I implement such a function:
f
function verifyFileDownload(extension) {
browser.sleep(150000); //waiting for file to download
const fs = require('fs');
let os = require('os');
var flag = true;
console.log(os.userInfo());
fs.readdir('/Users/' + require("os").userInfo().username + '/Downloads/', (error, file) => {
if (error) {
throw error;
}
console.log('File name' + file);
for (var i = 0; i < file.length; i++) {
const fileParts = file[i].split('.');
const ext = fileParts[fileParts.length - 1];
if (ext === extension) {
flag = false;
}
}
if (!flag) {
return;
}
throw error;
});
};