-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathAzureDevOpsHelper.ts
76 lines (64 loc) · 2.69 KB
/
AzureDevOpsHelper.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
import { request, expect } from '@playwright/test';
import dotenv from 'dotenv';
dotenv.config();
import axios from 'axios';
const credentials = Buffer.from(`${process.env.AZURE_DEVOPS_USER}:${process.env.AZURE_DEVOPS_PASS}`).toString('base64');
/**
* Testers Talk
*/
class AzureDevOps {
constructor() { }
/**
* Testers Talk
*/
async updateTestCaseStatus(testCaseId: string, testCaseStatus: string): Promise<void> {
try {
const testPlanId = process.env.TEST_PLAN_ID as string;
const testSuiteId = process.env.TEST_SUITE_ID as string;
const testPointId = await this.getTestPoint(testPlanId, testSuiteId, testCaseId);
await this.updateTestPointStatus(testPlanId, testSuiteId, testPointId, testCaseStatus.charAt(0).toUpperCase() + testCaseStatus.slice(1));
console.log(`Updated Test Case ID - ${testCaseId} as ${testCaseStatus} in test plan`);
} catch (error) {
console.error('Error in updating test case status:', error);
}
}
/**
* Testers Talk
*/
async getTestPoint(testPlanId: string, testSuiteId: string, testCaseId: string): Promise<string> {
const values = [testPlanId, testSuiteId, testCaseId];
const URL = process.env.TEST_PLAN_GET_API!.replace(/{(\d+)}/g, (match, number) => values[number] || match);
const getTestPointResponse = await axios.get(URL, {
headers: {
"Content-Type": "application/json",
'Authorization': `Basic ${credentials}`
},
});
const jsonResponse = await getTestPointResponse.data;
expect(getTestPointResponse.status).toBe(200);
return jsonResponse.value[0].id;
}
/**
* Testers Talk
*/
async updateTestPointStatus(testPlanId: string, testSuiteId: string, testPointId: string, testCaseStatus: string): Promise<void> {
const values = [testPlanId, testSuiteId, testPointId];
const URL = process.env.TEST_PLAN_PATCH_API!.replace(/{(\d+)}/g, (match, number) => values[number] || match);
const requestBody = {
"outcome": testCaseStatus // Passed, Failed, Blocked, etc.
};
try {
const patchAPIResponse = await axios.patch(URL, requestBody, {
headers: {
"Content-Type": "application/json",
'Authorization': `Basic ${credentials}`
}
});
expect(patchAPIResponse.status).toBe(200);
} catch (error: any) {
console.error('Error occurred during API request:', error.message);
console.error('Stack trace:', error.stack);
}
}
}
export default AzureDevOps;