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

Function uploadDirectory

javascript/selenium-webdriver/lib/web_extension.js:156–176  ·  view source on GitHub ↗

* Uploads `dir` to the remote end and returns the path it was unpacked to there. * @param {!./webdriver.WebDriver} driver * @param {string} dir absolute path of the directory. * @return {!Promise }

(driver, dir)

Source from the content-addressed store, hash-verified

154 * @return {!Promise<string>}
155 */
156async function uploadDirectory(driver, dir) {
157 // The endpoint returns the path of the archive's single top-level entry, so keep the
158 // directory itself as that entry rather than flattening its contents.
159 const zip = new Zip()
160 await zip.addDir(dir, path.basename(dir))
161 const encoded = (await zip.toBuffer('DEFLATE')).toString('base64')
162 try {
163 return await driver.execute(new command.Command(command.Name.UPLOAD_FILE).setParameter('file', encoded))
164 } catch (err) {
165 if (!isUnsupportedCommand(err)) {
166 throw err
167 }
168 const unsupported = new error.UnsupportedOperationError(
169 'Could not upload the extension directory to the remote end. Installing an unpacked ' +
170 'extension over a remote session needs a remote end that accepts file uploads, such as ' +
171 'the Selenium Grid.',
172 )
173 unsupported.cause = err
174 throw unsupported
175 }
176}
177
178function isUnsupportedCommand(err) {
179 return (

Callers 1

extensionDataFunction · 0.85

Calls 6

addDirMethod · 0.95
toBufferMethod · 0.95
isUnsupportedCommandFunction · 0.85
setParameterMethod · 0.80
toStringMethod · 0.65
executeMethod · 0.65

Tested by

no test coverage detected