1+ import { request , expect } from '@playwright/test' ;
2+ import dotenv from 'dotenv' ;
3+ dotenv . config ( ) ;
4+
5+ import axios from 'axios' ;
6+
7+ const credentials = Buffer . from ( `${ process . env . AZURE_DEVOPS_USER } :${ process . env . AZURE_DEVOPS_PASS } ` ) . toString ( 'base64' ) ;
8+
9+ /**
10+ * Testers Talk
11+ */
12+ class AzureDevOps {
13+ constructor ( ) { }
14+
15+ /**
16+ * Testers Talk
17+ */
18+ async updateTestCaseStatus ( testCaseId : string , testCaseStatus : string ) : Promise < void > {
19+ try {
20+ const testPlanId = process . env . TEST_PLAN_ID as string ;
21+ const testSuiteId = process . env . TEST_SUITE_ID as string ;
22+
23+ const testPointId = await this . getTestPoint ( testPlanId , testSuiteId , testCaseId ) ;
24+ await this . updateTestPointStatus ( testPlanId , testSuiteId , testPointId , testCaseStatus . charAt ( 0 ) . toUpperCase ( ) + testCaseStatus . slice ( 1 ) ) ;
25+
26+ console . log ( `Updated Test Case ID - ${ testCaseId } as ${ testCaseStatus } in test plan` ) ;
27+ } catch ( error ) {
28+ console . error ( 'Error in updating test case status:' , error ) ;
29+ }
30+ }
31+
32+ /**
33+ * Testers Talk
34+ */
35+ async getTestPoint ( testPlanId : string , testSuiteId : string , testCaseId : string ) : Promise < string > {
36+ const values = [ testPlanId , testSuiteId , testCaseId ] ;
37+ const URL = process . env . TEST_PLAN_GET_API ! . replace ( / { ( \d + ) } / g, ( match , number ) => values [ number ] || match ) ;
38+ const getTestPointResponse = await axios . get ( URL , {
39+ headers : {
40+ "Content-Type" : "application/json" ,
41+ 'Authorization' : `Basic ${ credentials } `
42+ } ,
43+ } ) ;
44+
45+ const jsonResponse = await getTestPointResponse . data ;
46+ expect ( getTestPointResponse . status ) . toBe ( 200 ) ;
47+ return jsonResponse . value [ 0 ] . id ;
48+ }
49+
50+ /**
51+ * Testers Talk
52+ */
53+ async updateTestPointStatus ( testPlanId : string , testSuiteId : string , testPointId : string , testCaseStatus : string ) : Promise < void > {
54+ const values = [ testPlanId , testSuiteId , testPointId ] ;
55+ const URL = process . env . TEST_PLAN_PATCH_API ! . replace ( / { ( \d + ) } / g, ( match , number ) => values [ number ] || match ) ;
56+
57+ const requestBody = {
58+ "outcome" : testCaseStatus // Passed, Failed, Blocked, etc.
59+ } ;
60+
61+ try {
62+ const patchAPIResponse = await axios . patch ( URL , requestBody , {
63+ headers : {
64+ "Content-Type" : "application/json" ,
65+ 'Authorization' : `Basic ${ credentials } `
66+ }
67+ } ) ;
68+ expect ( patchAPIResponse . status ) . toBe ( 200 ) ;
69+ } catch ( error : any ) {
70+ console . error ( 'Error occurred during API request:' , error . message ) ;
71+ console . error ( 'Stack trace:' , error . stack ) ;
72+ }
73+ }
74+ }
75+
76+ export default AzureDevOps ;
0 commit comments