MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / handleFile

Method handleFile

javascript/selenium-webdriver/remote/index.js:595–619  ·  view source on GitHub ↗

* Prepares a `file` for use with the remote browser. If the provided path * does not reference a normal file (i.e. it does not exist or is a * directory), then the promise returned by this method will be resolved with * the original file path. Otherwise, this method will upload the file to

(driver, file)

Source from the content-addressed store, hash-verified

593 * @override
594 */
595 handleFile(driver, file) {
596 return io.stat(file).then(
597 function (stats) {
598 if (stats.isDirectory()) {
599 return file // Not a valid file, return original input.
600 }
601
602 let zip = new Zip()
603 return zip
604 .addFile(file)
605 .then(() => zip.toBuffer())
606 .then((buf) => buf.toString('base64'))
607 .then((encodedZip) => {
608 let command = new cmd.Command(cmd.Name.UPLOAD_FILE).setParameter('file', encodedZip)
609 return driver.execute(command)
610 })
611 },
612 function (err) {
613 if (err.code === 'ENOENT') {
614 return file // Not a file; return original input.
615 }
616 throw err
617 },
618 )
619 }
620}
621
622// PUBLIC API

Callers

nothing calls this directly

Calls 6

addFileMethod · 0.95
toBufferMethod · 0.95
setParameterMethod · 0.80
isDirectoryMethod · 0.65
toStringMethod · 0.65
executeMethod · 0.65

Tested by

no test coverage detected