MCPcopy
hub / github.com/SeleniumHQ/selenium / handleFile

Method handleFile

javascript/selenium-webdriver/remote/index.js:586–610  ·  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

584 * @override
585 */
586 handleFile(driver, file) {
587 return io.stat(file).then(
588 function (stats) {
589 if (stats.isDirectory()) {
590 return file // Not a valid file, return original input.
591 }
592
593 let zip = new Zip()
594 return zip
595 .addFile(file)
596 .then(() => zip.toBuffer())
597 .then((buf) => buf.toString('base64'))
598 .then((encodedZip) => {
599 let command = new cmd.Command(cmd.Name.UPLOAD_FILE).setParameter('file', encodedZip)
600 return driver.execute(command)
601 })
602 },
603 function (err) {
604 if (err.code === 'ENOENT') {
605 return file // Not a file; return original input.
606 }
607 throw err
608 },
609 )
610 }
611}
612
613// 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