@@ -7,63 +7,71 @@ test.use({
7
7
baseURL : process . env . API_BASE_URI . toString ( )
8
8
} )
9
9
10
- test ( "End to End api test in playwright" , async ( { request } ) => {
11
- // create post api request using playwright
12
- const postAPIResponse = await request . post ( "/booking" , {
13
- data : postRequest ,
10
+ test ( "End to End API testing using playwright" , async ( { request } ) => {
11
+
12
+ const tokenNo = null ;
13
+
14
+ const postAPIResponse = await test . step ( 'Create booking' , async ( ) => {
15
+ return await request . post ( "/booking" , {
16
+ data : postRequest ,
17
+ } ) ;
14
18
} ) ;
15
19
16
20
const bookingId = await postAPIResponse . json ( ) ;
17
21
const bId = bookingId . bookingid ;
18
22
19
- // create GET api request using playwright
20
- const getAPIResponse = await request . get ( "/booking/" , {
21
- params : {
22
- firstname : "testers talk playwright" ,
23
- lastname : "testers talk api testing" ,
24
- } ,
23
+ let getAPIResponse = await test . step ( 'Get booking details' , async ( ) => {
24
+ return await request . get ( "/booking/" , {
25
+ params : {
26
+ firstname : "testers talk playwright" ,
27
+ lastname : "testers talk api testing" ,
28
+ } ,
29
+ } ) ;
25
30
} ) ;
26
31
27
- // validate status code
28
- console . log ( await getAPIResponse . json ( ) ) ;
29
- expect ( getAPIResponse . ok ( ) ) . toBeTruthy ( ) ;
30
- expect ( getAPIResponse . status ( ) ) . toBe ( 200 ) ;
31
-
32
- // generate token
33
- const tokenAPIResponse = await request . post ( "/auth" , {
34
- data : tokenRequest ,
32
+ await test . step ( 'Validate status code' , async ( ) => {
33
+ console . log ( await getAPIResponse . json ( ) ) ;
34
+ expect ( getAPIResponse . ok ( ) ) . toBeTruthy ( ) ;
35
+ expect ( getAPIResponse . status ( ) ) . toBe ( 200 ) ;
35
36
} ) ;
36
- expect ( tokenAPIResponse . ok ( ) ) . toBeTruthy ( ) ;
37
- expect ( tokenAPIResponse . status ( ) ) . toBe ( 200 ) ;
38
37
39
- console . log ( await tokenAPIResponse . json ( ) ) ;
40
- const tokenResponseBody = await tokenAPIResponse . json ( ) ;
41
- const tokenNo = tokenResponseBody . token ;
38
+ const tokenAPIResponse = await test . step ( 'Generate token & Validate status code' , async ( ) => {
39
+ return await request . post ( "/auth" , {
40
+ data : tokenRequest ,
41
+ } ) ;
42
+ expect ( tokenAPIResponse . ok ( ) ) . toBeTruthy ( ) ;
43
+ expect ( tokenAPIResponse . status ( ) ) . toBe ( 200 ) ;
42
44
43
- // partial update booking details
44
- const patchAPIResponse = await request . patch ( `/booking/${ bId } ` , {
45
- headers : {
46
- "Content-Type" : "application/json" ,
47
- Cookie : `token=${ tokenNo } ` ,
48
- } ,
49
- data : {
50
- firstname : "testers talk postman" ,
51
- lastname : "testers talk rest assured" ,
52
- } ,
45
+ console . log ( await tokenAPIResponse . json ( ) ) ;
46
+ const tokenResponseBody = await tokenAPIResponse . json ( ) ;
47
+ tokenNo = tokenResponseBody . token ;
53
48
} ) ;
54
49
55
- console . log ( await patchAPIResponse . json ( ) ) ;
56
- expect ( patchAPIResponse . ok ( ) ) . toBeTruthy ( ) ;
57
- expect ( patchAPIResponse . status ( ) ) . toBe ( 200 ) ;
50
+ const patchAPIResponse = await test . step ( 'Partial update booking details & Validate status code' , async ( ) => {
51
+ return await request . patch ( `/booking/${ bId } ` , {
52
+ headers : {
53
+ "Content-Type" : "application/json" ,
54
+ Cookie : `token=${ tokenNo } ` ,
55
+ } ,
56
+ data : {
57
+ firstname : "testers talk postman" ,
58
+ lastname : "testers talk rest assured" ,
59
+ } ,
60
+ } ) ;
61
+
62
+ console . log ( await patchAPIResponse . json ( ) ) ;
63
+ expect ( patchAPIResponse . ok ( ) ) . toBeTruthy ( ) ;
64
+ expect ( patchAPIResponse . status ( ) ) . toBe ( 200 ) ;
65
+ } ) ;
58
66
59
- // DELETE api request
60
- // partial update booking details
61
- const deleteAPIResponse = await request . delete ( `/booking/${ bId } ` , {
62
- headers : {
63
- "Content-Type" : "application/json" ,
64
- "Cookie" : `token=${ tokenNo } ` ,
65
- } ,
67
+ const deleteAPIResponse = await test . step ( 'Delete booking & Validate status code' , async ( ) => {
68
+ return await request . delete ( `/booking/${ bId } ` , {
69
+ headers : {
70
+ "Content-Type" : "application/json" ,
71
+ "Cookie" : `token=${ tokenNo } ` ,
72
+ } ,
73
+ } ) ;
74
+ expect ( deleteAPIResponse . status ( ) ) . toBe ( 201 ) ;
75
+ expect ( deleteAPIResponse . statusText ( ) ) . toBe ( "Created" ) ;
66
76
} ) ;
67
- expect ( deleteAPIResponse . status ( ) ) . toBe ( 201 ) ;
68
- expect ( deleteAPIResponse . statusText ( ) ) . toBe ( "Created" ) ;
69
77
} ) ;
0 commit comments