我正在尝试运行从Web应用程序下载文件的测试。然而,我遇到的问题是文件已经存在,我有一个if
语句来处理它并在下载另一个之前将其删除。问题是它永远不会进入if
语句。
我知道我的文件路径是正确的。还有别的我在这里做错了吗?
const fs = require('fs')
fit('Download Visible Records', () => {
const filename = `C:\\Users\\me\\Downloads\\DataExport_2017-04-18-10-04am.csv`
if (fs.existsSync(filename)) {
console.log('Are we getting here??') // NEVER ACTUALLY GETS HERE EVEN THOUGH THE FILE DOES EXIST
// Make sure the browser doesn't have to rename the download
fs.unlink(filename)
console.log('how about here?')
}
claims.downloadVizRecords()
browser.driver.wait(() => {
expect(fs.existsSync(filename)).toBe(true)
}, 10000)
})
答案 0 :(得分:0)
我的代码工作正常:
if (fs.existsSync('D:/CI/script/result/Report.html')) {
fs.unlinkSync('D:/CI/script/result/Report.html');
}