This repository has been archived by the owner on Mar 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
FormatJavaCucumber.js
113 lines (92 loc) · 3.62 KB
/
FormatJavaCucumber.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
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
113
const { Webhooks } = require('@qasymphony/pulse-sdk');
exports.handler = function ({ event: body, constants, triggers }, context, callback) {
function emitEvent(name, payload) {
let t = triggers.find(t => t.name === name);
return t && new Webhooks().invoke(t, payload);
}
// Payload to be passed in: json style cucumber for java test results
var payload = body;
var testResults = payload.result;
var projectId = payload.projectId;
var cycleId = payload["test-cycle"];
var testLogs = [];
testResults.forEach(function (feature) {
var featureName = feature.name;
feature.elements.forEach(function (testCase) {
if (!testCase.name)
testCase.name = "Unnamed";
TCStatus = "passed";
var reportingLog = {
exe_start_date: new Date(), // TODO These could be passed in
exe_end_date: new Date(),
module_names: [
'Test Scenarios'
],
name: testCase.name,
automation_content: feature.uri + "#" + testCase.name
};
var testStepLogs = [];
order = 0;
stepNames = [];
attachments = [];
testCase.steps.forEach(function (step) {
stepNames.push(step.name);
var status = step.result.status;
var actual = step.name;
if (TCStatus == "passed" && status == "skipped") {
TCStatus = "skipped";
}
if (status == "failed") {
TCStatus = "failed";
actual = step.result.error_message;
}
if (status == "undefined") {
TCStatus = "failed";
status = "failed";
}
// Are there an attachment for this step?
if ("embeddings" in step) {
console.log("Has attachment");
attCount = 0;
step.embeddings.forEach(function (att) {
attCount++;
var attachment = {
name: step.name + " Attachment " + attCount,
"content_type": att.mime_type,
data: att.data
};
console.log("Attachment: " + attachment.name)
attachments.push(attachment);
});
}
var expected = step.keyword + " " + step.name;
if ("location" in step.match) {
expected = step.match.location;
}
var stepLog = {
order: order,
description: step.name,
expected_result: step.keyword,
actual_result: actual,
status: status
};
testStepLogs.push(stepLog);
order++;
});
reportingLog.attachments = attachments;
reportingLog.description = stepNames.join("<br/>");
reportingLog.status = TCStatus;
reportingLog.test_step_logs = testStepLogs;
reportingLog.featureName = featureName;
testLogs.push(reportingLog);
});
});
var formattedResults = {
"projectId": projectId,
"test-cycle": cycleId,
"logs": testLogs
};
// Pulse Version
// Emit next fxn to upload results/parse
emitEvent('UpdateQTestWithFormattedResultsEvent', formattedResults);
}