1

Please help me to sole this problem. I have the case where I need to get the last response of the same API call, but it's async call and I don't know how to handle this. The problem is that I can have more than one requests for the same 'API/someEvent' but I need to validate the response data of the last one only.

var postData;

page.Response += (_, response) =>
{
  if (response.Url.Contains('API/someEvent'))
  {
    postData = response.Request.PostData;
  }
};

if (isDataValid(postData)) {
 return true;
} else {
 return false;
}

private Task<bool> isDataValid(){}

Any advice would be very helpful thanks!

  • A similar question has been asked already; I think tweaking the answer a bit should solve your problem: https://stackoverflow.com/questions/72202651/how-can-i-check-if-a-response-has-already-been-received-for-playwright – Christian Baumann Jul 08 '22 at 07:32
  • Thank you for referring this to me! but it looks exactly the same what I did tracking all the traffic of the page by page.Response listener. But my case is really different and tricky. Let's say you have an API call to "http://api/user/data" more than once but you need to get the response of the last request to do something, but page.Response is emitted asynchrony from your code so somehow you need to await until all the requests are finished to be able get the last one. – Vahe Mikayelyan Jul 08 '22 at 19:04
  • Welcome to SO @VaheMikayelyan ! Can not you make a separate call after all call is being made by the page itself? that way you know for sure all asynchronous calls made by page are completed. – Amol Chavan Jul 09 '22 at 06:14
  • @AmolChavan - That would be the best solution on my opinion too but I couldn't find such callback event in the framework (https://playwright.dev/dotnet/docs/api/class-page) which is invoked after all the requests are finished. – Vahe Mikayelyan Jul 11 '22 at 02:33

0 Answers0