I am using default REST helper for API testing, and I want to measure and assert the API's response time. For that I am trying following.
In my codecept.conf.ts:
helpers: {REST: {endpoint: 'https://myServerUrl',onRequest: (request)=>{console.log('onRequest');request.headers['start-time']=newDate().getTime();},onResponse: (response)=>{console.log('onResponse');conststartTime=response.request.headers['start-time'];constendTime=newDate().getTime();constresponseTime=endTime-startTime;response.Headers['x-response-time']=responseTime;},},JSONResponse: {}}and then in my custom helper:
constresponse=this.helpers.JSONResponse.response;console.log(`Response time: ${response.headers['x-response-time']} ms`);I can see that onRequest from REST config works as expected but onResponse does not work.
My output:
onRequest
Response time: undefined ms
I am using default REST helper for API testing, and I want to measure and assert the API's response time. For that I am trying following.
In my
codecept.conf.ts:and then in my custom helper:
I can see that
onRequestfrom REST config works as expected butonResponsedoes not work.My output: