0
我想運行一個測試,從我們的Web應用程序下載文件。然而,我遇到的問題是該文件已存在,並且我有一個if
語句來處理它並在下載另一個之前將其刪除。問題是,它永遠不會進入if
聲明。檢查文件是否使用量角器在Windows上下載
我知道我的文件路徑是正確的。還有什麼我在這裏做錯了嗎?
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)
})
我創造了我的文件下載測試前一段時間,所以我不記得我是如何得出這個結論,但我有一個額外的參數在我的'existsSync'函數中。 'fs.existsSync('filepath',fs.R_OK);',根據fs docs的是一個「標誌表明該文件可以被調用進程讀取」。這能解決你的問題嗎? – Gunderson
@Gunderson非常感謝您的建議,但是這並沒有解決問題。 – DarthOpto
@Gunderson因此,看起來我的程序正在運行測試。我從一個mac上運行一個windows計算機,不具有對該文件的讀/寫訪問權限。即使將目錄的權限更改爲「Everyone」具有完全訪問權限後也是如此。 – DarthOpto