I need to intercept network request and save it's response body to variable, so I can perform assertions with values, that are displayed on UI, but when I try to access variable which is supposed to contain saved response body I receive [object Object] instead of a valid body.
JSON.stringify also doesn't fix the problem, as my variable becomes {"_type":"Page","_guid":"page@"}
instead of an actual response.
Here's the code:
const resp = await page.on('response', async response => {
if (response.url().includes('/some_url/') && response.status() === 200) {
console.log('BODY() ' + (await response.body())); //logs valid JSON response body
return await response.body();
}
})
console.log('RESPONSE' + resp); //logs RESPONSE[object Object]