MCPcopy Create free account
hub / github.com/webdriverio/webdriverio / uploadFile

Function uploadFile

packages/webdriverio/src/node/uploadFile.ts:8–40  ·  view source on GitHub ↗
(
    this: WebdriverIO.Browser,
    localPath: string
)

Source from the content-addressed store, hash-verified

6 * Command implementation of the `saveRecordingScreen` command.
7 */
8export async function uploadFile (
9 this: WebdriverIO.Browser,
10 localPath: string
11): Promise<string> {
12 /**
13 * parameter check
14 */
15 if (typeof localPath !== 'string') {
16 throw new Error('number or type of arguments don\'t agree with uploadFile command')
17 }
18
19 /**
20 * check if command is available
21 */
22 if (typeof this.file !== 'function') {
23 throw new Error(`The uploadFile command is not available in ${(this.capabilities as WebdriverIO.Capabilities).browserName}`)
24 }
25
26 const zipData: Uint8Array[] = []
27 const source = fs.createReadStream(localPath)
28
29 return new Promise((resolve, reject) => {
30 archiver('zip')
31 .on('error', (err: Error) => reject(err))
32 .on('data', (data: Uint8Array) => zipData.push(data))
33 .on('end', () => (
34 this.file(Buffer.concat(zipData).toString('base64'))
35 .then((localPath) => resolve(localPath), reject)
36 ))
37 .append(source, { name: path.basename(localPath) })
38 .finalize()
39 })
40}

Callers

nothing calls this directly

Calls 3

resolveFunction · 0.85
thenMethod · 0.80
onMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…