MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / waitForFile

Method waitForFile

lib/helper/FileSystem.js:101–114  ·  view source on GitHub ↗

* Waits for the file to be present in the current directory. * * ```js * I.handleDownloads('downloads/largeFilesName.txt'); * I.click('Download large File'); * I.amInPath('output/downloads'); * I.waitForFile('largeFilesName.txt', 10); // wait 10 seconds for file * ``` * @para

(name, sec = 1)

Source from the content-addressed store, hash-verified

99 * @param {number} [sec=1] seconds to wait
100 */
101 async waitForFile(name, sec = 1) {
102 if (sec === 0) assert.fail('Use `seeFile` instead of waiting 0 seconds!')
103 const waitTimeout = sec * 1000
104 this.file = path.join(this.dir, name)
105 try {
106 this.debugSection('File', this.file)
107 } catch (e) {
108 // Fallback debug for ESM transition
109 console.log(`[File] ${this.file}`)
110 }
111 return isFileExists(this.file, waitTimeout).catch(() => {
112 throw new Error(`file (${name}) still not present in directory ${this.dir} after ${waitTimeout / 1000} sec`)
113 })
114 }
115
116 /**
117 * Checks that file with a name including given text exists in the current directory.

Callers 3

failed_test.jsFile · 0.80
fs_test.jsFile · 0.80
Playwright_test.jsFile · 0.80

Calls 3

isFileExistsFunction · 0.85
failMethod · 0.80
logMethod · 0.80

Tested by

no test coverage detected