使用量角器检查文件是否在Windows上下载

时间:2017-04-18 17:59:08

标签: javascript typescript protractor

我正在尝试运行从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)
    })

1 个答案:

答案 0 :(得分:0)

我的代码工作正常:

if (fs.existsSync('D:/CI/script/result/Report.html')) {
   fs.unlinkSync('D:/CI/script/result/Report.html');
}
相关问题