Rayrun
← Back to Discord Forum

How to assert multi requests?

I have a app that consumes a POST to the same api twice. How can I assert multiple request bodies in this manner?

https://dpaste.org/3sxmj

This thread is trying to answer question "How can I assert multiple request bodies when my app makes two POST requests to the same API endpoint?"

11 replies

maybe write your custom matcher that takes in array of requests and iterates over them verifying that all look good

https://playwright.dev/docs/test-assertions#add-custom-matchers-using-expectextend

thanks, but I don't see how this would allow to catch 2 requests of the same url. At the lower level I still need away for it to wait for two requests going to the same api (in the same action)

That works, thanks. However, I do not really have a way to assert the data like that

what do you mean

I can not do the below in the callback of the on event.... the same event fires twice and there is no way to for me to assert these separately

const assert1 = JSON.stringify({name: 'attr1', description: 'desc1' });
      const assert2 = JSON.stringify({name: 'attr2', description: 'desc2' });
      expect(response1.postData()).toEqual(assert1);
      expect(response2.postData()).toEqual(assert2);

Can't page.on collect all the requests, and then you put all of those requests into a custom matcher

well, the problem I see is that you can not make the execution wait for page.on() to be complete... it is non blocking

yeah, dunno then, not sure you I can figure out how to make the code for stuff you do much better than it already is

well, actually is it possible to make the test wait for page.on() to be completed?

I thing that is what you already do with waitForResponse

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].