-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnglesWDIOReporter.ts
96 lines (86 loc) · 3.39 KB
/
AnglesWDIOReporter.ts
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
/* tslint:disable:no-console */
import WDIOReporter,{ RunnerStats, TestStats } from '@wdio/reporter'
import { Capabilities } from '@wdio/types';
import anglesReporter from 'angles-javascript-client';
import {Artifact} from "angles-javascript-client/dist/lib/models/Artifact";
import {Execution} from "angles-javascript-client/dist/lib/models/Execution";
import {extractPlatformFromCaps, ifSet} from "../utils/common-utils";
export class AnglesWDIOReporter extends WDIOReporter {
isEnabled: boolean;
baseUrl: string;
reportingUrl: string;
buildName: string;
team: string;
environment: string;
component: string;
phase: string;
artifacts: Artifact[];
capabilities: Capabilities.RemoteCapability;
constructor(options: any) {
super(options)
this.isEnabled = options.enabled || true;
this.baseUrl = options.baseUrl || 'http://127.0.0.1:3000/rest/api/v1.0/';
this.reportingUrl = options.reportingUrl || 'http://127.0.0.1:3001';
this.buildName = options.buildName || 'Test Automation Run';
this.team = options.team || 'angles';
this.environment = options.environment || 'qa';
this.component = options.component || 'wdio-example';
this.phase = options.phase || undefined;
this.artifacts = options.artifacts || undefined;
anglesReporter.setBaseUrl(this.baseUrl);
}
async onRunnerStart(runnerStats:RunnerStats) {
if (this.isEnabled && process.env.ANGLES_ID) {
await anglesReporter.setBaseUrl(this.baseUrl);
this.capabilities = runnerStats.capabilities;
await anglesReporter.setCurrentBuild(process.env.ANGLES_ID);
}
}
async onTestStart(test: TestStats) {
if (this.isEnabled && process.env.ANGLES_ID) {
await anglesReporter.setCurrentBuild(process.env.ANGLES_ID);
await anglesReporter.startTest(test.title, test.parent);
const caps = this.capabilities as Capabilities.DesiredCapabilities;
await anglesReporter.storePlatformDetails(extractPlatformFromCaps(caps));
}
}
async onTestPass(test: TestStats) {
if (this.isEnabled && process.env.ANGLES_ID) {
anglesReporter.pass(`Test ${test.title} has passed`, 'Test Passed', 'Test Passed', '');
}
}
async onTestFail(test: TestStats) {
if (this.isEnabled && process.env.ANGLES_ID) {
anglesReporter.fail(`Test ${test.title} has failed`, 'Test Passed', 'Test Failed', '');
}
}
async onTestSkip(test: TestStats) {
if (this.isEnabled && process.env.ANGLES_ID) {
anglesReporter.info(`Test ${test.title} has skipped`);
}
}
async onTestEnd() {
if (this.isEnabled && process.env.ANGLES_ID) {
anglesReporter.saveTest()
.then((execution: Execution) => {
console.debug(`Saved execution ${execution.title} with id ${execution._id}`)
})
.catch((error) => {
const { response } = error;
let { message } = error;
if (ifSet(response, 'data.message')) {
message = response.data.message;
}
console.error(`Unable to save test in Angles due to : ${message}`);
// TODO: find an error that will impact wdio.
throw new Error(`Unable to save test in Angles due to : ${message}`);
});
}
}
onRunnerEnd() {
if (this.isEnabled && process.env.ANGLES_ID) {
console.info(`Angles Dashboard Results: ${this.reportingUrl}/test-run/?buildId=${process.env.ANGLES_ID}`);
process.env.ANGLES_ID = undefined;
}
}
}