-
Notifications
You must be signed in to change notification settings - Fork 2
/
testrail.js
175 lines (161 loc) · 3.89 KB
/
testrail.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
const axios = require("axios");
const fs = require("fs");
const path = require("path");
class TestRail {
constructor(config) {
this.host = config.host;
this.user = config.user;
this.password = config.password;
this.uri = "/index.php?/api/v2/";
axios.defaults.baseURL = this.host + this.uri;
axios.defaults.auth = {
username: this.user,
password: this.password,
};
axios.defaults.headers.get["Content-Type"] = "application/json";
}
async addPlan(projectId, data) {
try {
const res = await axios({
method: "post",
url: `add_plan/${projectId}`,
data,
});
return res.data;
} catch (error) {
console.error(`Cannnot add new plan due to ${error}`);
}
}
async addPlanEntry(planId, data) {
try {
const res = await axios({
method: "post",
url: `add_plan_entry/${planId}`,
data,
});
return res.data;
} catch (error) {
console.error(
`Cannnot add new test run to existing test plan due to ${error}`
);
}
}
async getSuites(projectId) {
try {
const res = await axios({
method: "get",
url: `get_suites/${projectId}`,
headers: {
"content-type": "application/json",
},
});
return res.data;
} catch (error) {
console.error(`Cannnot get suites due to ${error}`);
}
}
async getConfigs(projectId) {
try {
const res = await axios({
method: "get",
url: `get_configs/${projectId}`,
headers: {
"content-type": "application/json",
},
});
return res.data;
} catch (error) {
console.error(`Cannnot get configs due to ${error}`);
}
}
async addRun(projectId, data) {
try {
const res = await axios({
method: "post",
url: `add_run/${projectId}`,
data,
});
return res.data;
} catch (error) {
console.error(`Cannnot add new run due to ${error}`);
}
}
async updateRun(runId, data) {
try {
const res = await axios({
method: "post",
url: `update_run/${runId}`,
data,
});
console.log(`The run with id: ${runId} is updated`);
return res.data;
} catch (error) {
console.error(`Cannnot update run due to ${error}`);
}
}
async getTests(runId) {
try {
const res = await axios({
method: "get",
url: `get_tests/${runId}`,
});
return res.data;
} catch (error) {
console.error(`Cannnot get tests of ${runId} due to ${error}`);
}
}
async getResultsForCase(runId, caseId) {
try {
const res = await axios({
method: "get",
url: `get_results_for_case/${runId}/${caseId}`,
headers: {
"content-type": "application/json",
},
});
return res.data;
} catch (error) {
console.error(
`Cannnot get results for case ${caseId} on run ${runId} due to ${error}`
);
}
}
async addResultsForCases(runId, data) {
try {
const res = await axios({
method: "post",
url: `add_results_for_cases/${runId}`,
data,
});
return res.data;
} catch (error) {
console.error(
`Cannnot add result for case due to ${error}. \n${JSON.stringify(
error,
null,
2
)}`
);
}
}
async addAttachmentToResult(resultId, imageFile) {
var form = new FormData();
form.append(
"attachment",
fs.createReadStream(path.join(global.output_dir, imageFile.toString()))
);
await axios({
method: "post",
data: form,
url: "add_attachment_to_result/" + resultId,
headers: form.getHeaders(),
}).catch((err) => {
console.error(`Cannot attach file due to ${err}`);
});
}
}
module.exports = {
createClient(config) {
return new TestRail(config);
},
};