* 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)
| 154 | * @return {!Promise<string>} |
| 155 | */ |
| 156 | async 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 | |
| 178 | function isUnsupportedCommand(err) { |
| 179 | return ( |
no test coverage detected