-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.js
More file actions
112 lines (94 loc) · 3 KB
/
helpers.js
File metadata and controls
112 lines (94 loc) · 3 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import crypto from "crypto";
import path from "path";
import fs from "fs";
import yaml from "js-yaml";
import logger from "@wdio/logger";
const _ = require("lodash");
const log = logger("Helpers");
export const rand = len =>
crypto
.randomBytes(Math.ceil(len / 2))
.toString("hex")
.slice(0, len);
export const sanitizeTable = table => {
const rows = table.hashes();
if (!rows.length) return;
return rows.map(row => {
Object.keys(row).forEach(key => {
if(!_.isEmpty(row[key]))
row[_.camelCase(key)] = row[key];
delete row[key];
});
const {
name,
birthYear, birth, year,
eyeColor, colorEye, eye,
skinColor, colorSkin, skin,
population, climate, gravity
} = row;
return _.pickBy({
...row,
name,
birthYear: birthYear || birth || year,
eyeColor: eyeColor || eye || colorEye,
skinColor: skinColor || skin || colorSkin,
population, climate, gravity
},
d => d !== undefined);
});
};
export const clearSession = () => {
["sessionStorage", "localStorage"].forEach(s =>
$(s => window && window[s] && window[s].clear(), s)
);
browser.deleteAllCookies();
};
export const buildScreenshotFilename = extra => {
const { browserName } = browser.capabilities;
const date = new Date(),
shortMonth = date.toLocaleString("default", { month: "short" }),
d = date.getDate(),
M = date.getMonth(),
y = date.getFullYear(),
h = date.getHours(),
m = date.getMinutes(),
s = date.getSeconds();
// Remove slashes because directories
extra = extra && extra.replace(/[/|\\]+/g, "");
const fileName = `${d} ${M}(${shortMonth}) ${y} @ ${h}H${m}m${s}s [ ${browserName} ] ${extra}.png`;
return path.join(browser.config._SHOTS || process.cwd(), fileName);
};
export const setAllureCustomLogo = (logoPath, collapsedLogo = logoPath, stylesheetPath ) => {
try {
const allureDir = path.resolve("node_modules/allure-commandline");
const configDir = path.join(allureDir, "dist/config");
const logoPlugin = path.join(
allureDir,
"dist/plugins/custom-logo-plugin"
);
const allureYml = path.join(configDir, "allure.yml");
const cucumberYml = path.join(configDir, "allure-cucumber.yml");
const placeholderLogo = path.join(logoPlugin, "static/custom-logo.svg");
const placeholderLogoCollapsed = path.join(logoPlugin, "static/custom-logo-collapsed.svg");
const placeholderStylesheet = path.join(
logoPlugin,
"static/styles.css"
);
const allureYmlFile = fs.readFileSync(allureYml, "utf8");
const ymlDocument = yaml.safeLoad(allureYmlFile);
const { plugins = [] } = ymlDocument;
const hasEntry = plugins.includes("custom-logo-plugin");
if (!hasEntry) {
plugins.push("custom-logo-plugin");
fs.writeFileSync(allureYml, yaml.safeDump(ymlDocument));
}
[
[allureYml, cucumberYml],
[logoPath, placeholderLogo],
[collapsedLogo, placeholderLogoCollapsed],
[stylesheetPath, placeholderStylesheet]
].forEach(([src, target]) => fs.copyFileSync(src, target))
} catch (error) {
log.error(`Could not apply custom logo to Allure report: ${error}`);
}
};