[ACA-833] automate tests for download as zip (#968)

* add tests for downloading a single file

* automate tests for download as zip
This commit is contained in:
Adina Parpalita
2019-02-23 17:42:18 +02:00
committed by Cilibiu Bogdan
parent 8f00aa77f1
commit 88ca0cb886
4 changed files with 418 additions and 128 deletions
+41 -2
View File
@@ -28,6 +28,7 @@ import { BROWSER_WAIT_TIMEOUT, E2E_ROOT_PATH, EXTENSIBILITY_CONFIGS } from '../c
const path = require('path');
const fs = require('fs');
const StreamZip = require('node-stream-zip');
export class Utils {
@@ -91,9 +92,9 @@ export class Utils {
}
}
static async fileExistsOnOS(fileName: string) {
static async fileExistsOnOS(fileName: string, folderName: string = '', subFolderName: string = '') {
const config = await browser.getProcessedConfig();
const filePath = path.join(config.params.downloadFolder, fileName);
const filePath = path.join(config.params.downloadFolder, folderName, subFolderName, fileName);
let tries = 15;
@@ -116,6 +117,44 @@ export class Utils {
});
}
static async renameFile(oldName: string, newName: string) {
const config = await browser.getProcessedConfig();
const oldFilePath = path.join(config.params.downloadFolder, oldName);
const newFilePath = path.join(config.params.downloadFolder, newName);
const fileExists = await this.fileExistsOnOS(oldName);
if (fileExists) {
fs.rename(oldFilePath, newFilePath, function (err) {
if (err) {
console.log('==== rename err: ', err);
}
});
}
}
static async unzip(filename: string, unzippedName: string = '') {
const config = await browser.getProcessedConfig();
const filePath = path.join(config.params.downloadFolder, filename);
const output = path.join(config.params.downloadFolder, unzippedName ? unzippedName : '');
const zip = new StreamZip({
file: filePath,
storeEntries: true
});
await zip.on('error', err => { console.log('=== unzip err: ', err) });
await zip.on('ready', async () => {
if (unzippedName) {
await fs.mkdirSync(output);
}
await zip.extract(null, output, async () => {
await zip.close();
});
});
}
static async pressEscape() {
return await browser.actions().sendKeys(protractor.Key.ESCAPE).perform();
}