Reputation: 103
I need to retrieve information from a POST call using Testcafe.
What I need to do manually is:
In the Request Payload I need to check flag of isMode.
{timestamp: 9017205278, master: "s",…}
> ads: [{format: 19521, tag: "19521", target: "", isMode: false},…]
> 0: {format: 19521, tag: "19521", target: "", isMode: false}
format: 19521
isMode: false
> 1: {format: 19522, tag: "19522", target: "", isMode: true}
> appName: ""
> master: "s"
> screen: {height: 1080, width: 1920}
> timestamp: 9017205278
I am able to get info from requests using this method https://devexpress.github.io/testcafe/documentation/guides/advanced-guides/intercept-http-requests.html#log-http-requests
but to be honest I have no idea how to retreive info like in this example as above.
Upvotes: 2
Views: 838
Reputation: 103
Ok finally I was able to solve this issue and retreive these data.
First, I had to create new RequestLogger where I checked that I need log request body and I want to store it in a string, not as a Buffer.
const headerLogger = RequestLogger(RegExp('call$'), {
logRequestHeaders: true,
logRequestBody: true,
stringifyRequestBody: true,
});
Then I changed an object to a string because it was easier to check if log contains specific string.
const requestPayloadString : string = headerLogger.requests[0].request.body.toString();
Finally, my assertion looks like this. I compare wheter actual string contains expected string.
await t.expect(requestPayload).contains(`{format: 19522, tag: "19522", target: "", isMode: true}`)
Upvotes: 2