-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.js
47 lines (38 loc) · 1.25 KB
/
utilities.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const fs = require('fs');
const Path = require('path');
const allure = require('@wdio/allure-reporter').default;
class Utilities {
static takeScreenshot(name, failure = false) {
const path = './testsResults/screenshots/';
if (!fs.existsSync(path)) {
fs.mkdirSync(path, { recursive: true });
}
if (failure) {
name = name + '_fail';
}
name = name.replace(/ /g, '_') + '.png';
browser.pause(500);
browser.saveScreenshot(path + name);
const data = fs.readFileSync(`${path}/${name}`);
allure.addAttachment(name, data, 'image/png');
}
static deleteFolderRecursive(path) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach((file, index) => {
const curPath = Path.join(path, file);
if (fs.lstatSync(curPath).isDirectory()) { // recurse
this.deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
// fs.rmdirSync(path);
}
}
static deleteFile(path) {
if (fs.existsSync(path)) {
fs.unlinkSync(path)
}
}
}
module.exports = Utilities;