bootstrap.js
1.7 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
const wd = require('wd');
const open = require('open');
const chalk = require('chalk');
const caseLayout = require('./case-layout');
const logger = require('debug')('tester');
const axios = require('axios');
const config = require('../config.json');
const post = (url, data) => {
return axios({
url,
method: 'POST',
data
})
}
const driverWork = async(config, scenes) => {
let driver
for (let si = 0; si < scenes.length; si++) {
const {scene, title, driverFn} = scenes[si];
logger(chalk.yellow(` ${si + 1}). 测试场景:${title}`));
await post('start-scene-case', {scene});
if (si === 0) {
driver = await wd.promiseChainRemote(config.serverConfig);
await driver.init(config.caps);
}
try {
await driverFn(driver);
} catch (error) {
logger(chalk.red(error.message));
}
if (si === scenes.length - 1) {
await driver.quit();
}
const {data} = await post('stop-scene-case', {scene});
if (data.code === 200) {
logger(chalk.green(`埋点数据检查: ${scene}-成功,${data.data.overLogs.length}项上报数据未匹配`));
} else {
logger(chalk.red(`埋点数据检查: ${scene}, ${data.data.notValidates.length}项规则失败`));
}
}
return true;
}
const invokeCases = async(cases) => {
for (let ci = 0; ci < cases.length; ci++) {
const {name, config, scenes} = cases[ci];
logger(chalk.yellow(`${ci + 1}. 编排任务:${name} 正在开始...`));
await driverWork(config, scenes);
}
logger(chalk.yellow('正在生成埋点测试报告...'));
setTimeout(() => {
open(`http://localhost:${config.port}/report`);
}, 1000);
}
const cases = caseLayout.getCases();
invokeCases(cases);