webdriverio 8.37.0 → 8.38.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/commands/browser/downloadFile.d.ts +44 -0
- package/build/commands/browser/downloadFile.d.ts.map +1 -0
- package/build/commands/browser/downloadFile.js +89 -0
- package/build/commands/browser.d.ts +1 -0
- package/build/commands/browser.d.ts.map +1 -1
- package/build/commands/browser.js +1 -0
- package/package.json +9 -8
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Download a file from the remote computer running Selenium node to local file system
|
|
4
|
+
* by using the [`downloadFile`](https://webdriver.io/docs/api/selenium#downloadFile) command.
|
|
5
|
+
*
|
|
6
|
+
* :::info
|
|
7
|
+
* Note that this command is only supported if you use a
|
|
8
|
+
* [Selenium Grid](https://www.selenium.dev/documentation/en/grid/) with Chrome, Edge or Firefox.
|
|
9
|
+
* :::
|
|
10
|
+
*
|
|
11
|
+
* <example>
|
|
12
|
+
:downloadFile.js
|
|
13
|
+
it('should download a file', async () => {
|
|
14
|
+
// capabilities: [
|
|
15
|
+
// {
|
|
16
|
+
// browserName: 'chrome',
|
|
17
|
+
// se:downloadsEnabled': true
|
|
18
|
+
// }]
|
|
19
|
+
|
|
20
|
+
await browser.url('https://www.selenium.dev/selenium/web/downloads/download.html')
|
|
21
|
+
|
|
22
|
+
await $('#file-1').click()
|
|
23
|
+
|
|
24
|
+
await browser.waitUntil(async function () {
|
|
25
|
+
return (await browser.getDownloadableFiles()).names.includes('file_1.txt')
|
|
26
|
+
}, {timeout: 5000})
|
|
27
|
+
|
|
28
|
+
const files = await browser.getDownloadableFiles()
|
|
29
|
+
|
|
30
|
+
const downloaded = await browser.downloadFile(files.names[0], process.cwd())
|
|
31
|
+
|
|
32
|
+
await browser.deleteDownloadableFiles()
|
|
33
|
+
})
|
|
34
|
+
* </example>
|
|
35
|
+
*
|
|
36
|
+
* @alias browser.downloadFile
|
|
37
|
+
* @param {string} fileName remote path to file
|
|
38
|
+
* @param {string} targetDirectory target location on local computer
|
|
39
|
+
* @type utility
|
|
40
|
+
* @uses protocol/download
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
export declare function downloadFile(this: WebdriverIO.Browser, fileName: string, targetDirectory: string): Promise<object>;
|
|
44
|
+
//# sourceMappingURL=downloadFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"downloadFile.d.ts","sourceRoot":"","sources":["../../../src/commands/browser/downloadFile.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,wBAAsB,YAAY,CAC9B,IAAI,EAAE,WAAW,CAAC,OAAO,EACzB,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM,GACxB,OAAO,CAAC,MAAM,CAAC,CAgDjB"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import JSZip from 'jszip';
|
|
4
|
+
import logger from '@wdio/logger';
|
|
5
|
+
const log = logger('webdriverio');
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* Download a file from the remote computer running Selenium node to local file system
|
|
9
|
+
* by using the [`downloadFile`](https://webdriver.io/docs/api/selenium#downloadFile) command.
|
|
10
|
+
*
|
|
11
|
+
* :::info
|
|
12
|
+
* Note that this command is only supported if you use a
|
|
13
|
+
* [Selenium Grid](https://www.selenium.dev/documentation/en/grid/) with Chrome, Edge or Firefox.
|
|
14
|
+
* :::
|
|
15
|
+
*
|
|
16
|
+
* <example>
|
|
17
|
+
:downloadFile.js
|
|
18
|
+
it('should download a file', async () => {
|
|
19
|
+
// capabilities: [
|
|
20
|
+
// {
|
|
21
|
+
// browserName: 'chrome',
|
|
22
|
+
// se:downloadsEnabled': true
|
|
23
|
+
// }]
|
|
24
|
+
|
|
25
|
+
await browser.url('https://www.selenium.dev/selenium/web/downloads/download.html')
|
|
26
|
+
|
|
27
|
+
await $('#file-1').click()
|
|
28
|
+
|
|
29
|
+
await browser.waitUntil(async function () {
|
|
30
|
+
return (await browser.getDownloadableFiles()).names.includes('file_1.txt')
|
|
31
|
+
}, {timeout: 5000})
|
|
32
|
+
|
|
33
|
+
const files = await browser.getDownloadableFiles()
|
|
34
|
+
|
|
35
|
+
const downloaded = await browser.downloadFile(files.names[0], process.cwd())
|
|
36
|
+
|
|
37
|
+
await browser.deleteDownloadableFiles()
|
|
38
|
+
})
|
|
39
|
+
* </example>
|
|
40
|
+
*
|
|
41
|
+
* @alias browser.downloadFile
|
|
42
|
+
* @param {string} fileName remote path to file
|
|
43
|
+
* @param {string} targetDirectory target location on local computer
|
|
44
|
+
* @type utility
|
|
45
|
+
* @uses protocol/download
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
48
|
+
export async function downloadFile(fileName, targetDirectory) {
|
|
49
|
+
/**
|
|
50
|
+
* parameter check
|
|
51
|
+
*/
|
|
52
|
+
if (typeof fileName !== 'string' || typeof targetDirectory !== 'string') {
|
|
53
|
+
throw new Error('number or type of arguments don\'t agree with downloadFile command');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* check if command is available
|
|
57
|
+
*/
|
|
58
|
+
if (typeof this.download !== 'function') {
|
|
59
|
+
throw new Error(`The downloadFile command is not available in ${this.capabilities.browserName} and only available when using Selenium Grid`);
|
|
60
|
+
}
|
|
61
|
+
const response = await this.download(fileName);
|
|
62
|
+
const base64Content = response.contents;
|
|
63
|
+
if (!targetDirectory.endsWith('/')) {
|
|
64
|
+
targetDirectory += '/';
|
|
65
|
+
}
|
|
66
|
+
fs.mkdirSync(targetDirectory, { recursive: true });
|
|
67
|
+
const zipFilePath = path.join(targetDirectory, `${fileName}.zip`);
|
|
68
|
+
fs.writeFileSync(zipFilePath, Buffer.from(base64Content, 'base64'));
|
|
69
|
+
const zipData = fs.readFileSync(zipFilePath);
|
|
70
|
+
const filesData = [];
|
|
71
|
+
try {
|
|
72
|
+
const zip = await JSZip.loadAsync(zipData);
|
|
73
|
+
const keys = Object.keys(zip.files);
|
|
74
|
+
// Iterate through each file in the zip archive
|
|
75
|
+
for (let i = 0; i < keys.length; i++) {
|
|
76
|
+
const fileData = await zip.files[keys[i]].async('nodebuffer');
|
|
77
|
+
const dir = path.resolve(targetDirectory, keys[i]);
|
|
78
|
+
fs.writeFileSync(dir, fileData);
|
|
79
|
+
log.info(`File extracted: ${keys[i]}`);
|
|
80
|
+
filesData.push(dir);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
log.error('Error unzipping file:', error);
|
|
85
|
+
}
|
|
86
|
+
return Promise.resolve({
|
|
87
|
+
files: filesData
|
|
88
|
+
});
|
|
89
|
+
}
|
|
@@ -7,6 +7,7 @@ export * from './browser/custom$$.js';
|
|
|
7
7
|
export * from './browser/custom$.js';
|
|
8
8
|
export * from './browser/debug.js';
|
|
9
9
|
export * from './browser/deleteCookies.js';
|
|
10
|
+
export * from './browser/downloadFile.js';
|
|
10
11
|
export * from './browser/emulate.js';
|
|
11
12
|
export * from './browser/execute.js';
|
|
12
13
|
export * from './browser/executeAsync.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/commands/browser.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,2BAA2B,CAAA;AACzC,cAAc,yBAAyB,CAAA;AACvC,cAAc,2BAA2B,CA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AA;AACjC,cAAc,2BAA2B,CAAA;AACzC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA;AACpC,cAAc,qBAAqB,CAAA;AACnC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,sBAAsB,CAAA;AACpC,cAAc,kCAAkC,CAAA;AAChD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,qBAAqB,CAAA;AACnC,cAAc,yBAAyB,CAAA;AACvC,cAAc,yBAAyB,CAAA;AACvC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,2BAA2B,CAAA;AACzC,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,0BAA0B,CAAA;AACxC,cAAc,yBAAyB,CAAA;AACvC,cAAc,kBAAkB,CAAA;AAChC,cAAc,wBAAwB,CAAA"}
|
|
@@ -7,6 +7,7 @@ export * from './browser/custom$$.js';
|
|
|
7
7
|
export * from './browser/custom$.js';
|
|
8
8
|
export * from './browser/debug.js';
|
|
9
9
|
export * from './browser/deleteCookies.js';
|
|
10
|
+
export * from './browser/downloadFile.js';
|
|
10
11
|
export * from './browser/emulate.js';
|
|
11
12
|
export * from './browser/execute.js';
|
|
12
13
|
export * from './browser/executeAsync.js';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webdriverio",
|
|
3
3
|
"description": "Next-gen browser and mobile automation test framework for Node.js",
|
|
4
|
-
"version": "8.
|
|
4
|
+
"version": "8.38.2",
|
|
5
5
|
"homepage": "https://webdriver.io",
|
|
6
6
|
"author": "Christian Bromann <mail@bromann.dev>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -69,12 +69,12 @@
|
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
71
|
"@types/node": "^20.1.0",
|
|
72
|
-
"@wdio/config": "8.
|
|
73
|
-
"@wdio/logger": "8.
|
|
74
|
-
"@wdio/protocols": "8.
|
|
72
|
+
"@wdio/config": "8.38.2",
|
|
73
|
+
"@wdio/logger": "8.38.0",
|
|
74
|
+
"@wdio/protocols": "8.38.0",
|
|
75
75
|
"@wdio/repl": "8.24.12",
|
|
76
|
-
"@wdio/types": "8.
|
|
77
|
-
"@wdio/utils": "8.
|
|
76
|
+
"@wdio/types": "8.38.2",
|
|
77
|
+
"@wdio/utils": "8.38.2",
|
|
78
78
|
"archiver": "^7.0.0",
|
|
79
79
|
"aria-query": "^5.0.0",
|
|
80
80
|
"css-shorthand-properties": "^1.1.1",
|
|
@@ -83,6 +83,7 @@
|
|
|
83
83
|
"grapheme-splitter": "^1.0.2",
|
|
84
84
|
"import-meta-resolve": "^4.0.0",
|
|
85
85
|
"is-plain-obj": "^4.1.0",
|
|
86
|
+
"jszip": "^3.10.1",
|
|
86
87
|
"lodash.clonedeep": "^4.5.0",
|
|
87
88
|
"lodash.zip": "^4.2.0",
|
|
88
89
|
"minimatch": "^9.0.0",
|
|
@@ -91,7 +92,7 @@
|
|
|
91
92
|
"resq": "^1.9.1",
|
|
92
93
|
"rgb2hex": "0.2.5",
|
|
93
94
|
"serialize-error": "^11.0.1",
|
|
94
|
-
"webdriver": "8.
|
|
95
|
+
"webdriver": "8.38.2"
|
|
95
96
|
},
|
|
96
97
|
"peerDependencies": {
|
|
97
98
|
"devtools": "^8.14.0"
|
|
@@ -101,5 +102,5 @@
|
|
|
101
102
|
"optional": true
|
|
102
103
|
}
|
|
103
104
|
},
|
|
104
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "942ba6095b993a4ea5a893d4b935f5ab2ca04ab2"
|
|
105
106
|
}
|