我的硒代码部署在Unix机器中的Jenkinns中。当我的调度程序触发工作套件时,作业将在Windows中的硒节点上运行。gere,我有一个测试用例,其中文件在一个节点之一中下载,我需要验证该下载的文件。
如何从Unix机器中的Windows中识别下载的文件(两者都是不同的环境)。
如果您想在chrome上验证此问题,则遵循代码是一种解决方案。
注意:它写在打字稿上,因此您必须对其进行调整。
function checkChromeForDownloadedFile(fileName: string, state: string = 'COMPLETE') {
// open new tab
await browser.executeScript('return window.open()');
// switch to downloads tab window
let tabs: string[] = await browser.getAllWindowHandles();
await browser.switchTo().window(tabs[1]);
// open downloads page
await browser.get('chrome://downloads');
// 1 sec delay.
await browser.sleep(1000);
let downloadedItems;
try {
await browser.wait(() => {
// fetch downloaded items
return browser.executeScript('return downloads.Manager.get().items_').then((result) => {
downloadedItems = result;
if (!downloadedItems) {
return false;
}
// search for downloaded file with state complete and filename
return downloadedItems.some(i => i.file_name === fileName && i.state === state.toUpperCase());
}).catch( () => {
return false;
});
}, 10000, `File ${fileName} with download sate ${state} was not found within 10 seconds`);
} catch (error) {
console.log('there was an error while trying to fetch downloaded files');
throw error;
}
// close the tab
await browser.close();
// switch back to original window
await browser.switchTo().window(tabs[0]);
}