-
-
Notifications
You must be signed in to change notification settings - Fork 742
Open
Description
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' ] = new Date().getTime();
},
onResponse: (response) => {
console.log('onResponse');
const startTime = response.request.headers[ 'start-time' ];
const endTime = new Date().getTime();
const responseTime = endTime - startTime;
response. Headers[ 'x-response-time' ] = responseTime;
},
},
JSONResponse: {}
}
and then in my custom helper:
const response = 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
Metadata
Metadata
Assignees
Labels
No labels