How to wait for a specific API response in your Playwright end-to-end tests

2024 ж. 14 Мам.
3 105 Рет қаралды

Learn in this video how to monitor network HTTP calls in your end-to-end tests and use Playwright's "waitForResponse" method to capture specific network responses. This approach allows you to wait for specific API calls to validate if you website or app shows the correct data.
Playwright docs: playwright.dev/docs/api/class...
Checkly Playwright monitoring: www.checklyhq.com/product/syn...
#playwright

Пікірлер
  • this video actually came in clutch

    @kkrkkr5093@kkrkkr50933 ай бұрын
    • Happy this video has been helpful!

      @ChecklyHQ@ChecklyHQ3 ай бұрын
  • This is so useful, thank you! I would love to see a video on checking payment transactions.

    @pineapplesoda@pineapplesoda3 ай бұрын
    • Happy the videos are useful. Could you explain a bit more detailed what process / transaction you'd like to see?

      @ChecklyHQ@ChecklyHQ3 ай бұрын
  • i am using it more than a year ...which is very useful on dynamically generating test data...

    @sheiksadakkathulla7364@sheiksadakkathulla73643 ай бұрын
    • Great 👍 Yeah, that's a nice use case!

      @ChecklyHQ@ChecklyHQ3 ай бұрын
  • I did similar approach in my UI tests

    @leonidvr6455@leonidvr6455Ай бұрын
  • Great content! Thanks!

    @EricWilliamsonTech@EricWilliamsonTech3 ай бұрын
    • Glad you liked it!

      @ChecklyHQ@ChecklyHQ3 ай бұрын
  • Thanks

    @pabloortiz6031@pabloortiz60313 ай бұрын
    • Happy it's been valuable. :)

      @ChecklyHQ@ChecklyHQ3 ай бұрын
  • This is so useful, thank you! I have small doubt. How do I track the API response which is already invoked. Is it possible?

    @_firearmy@_firearmy29 күн бұрын
    • In this situation, the described approach wouldn't work well. But can you describe the scenario you're trying to test? Because I can't think of a case when it would be impossible to attach the network event handler. 🤔

      @ChecklyHQ@ChecklyHQ29 күн бұрын
    • @@ChecklyHQ Thank you for your attention. I require certain metadata from the app that will be captured with every full page load. I need this information to develop test cases. While I can obtain this metadata by either moving a global variable or invoking the metadata API, my objective is to accomplish this without directly modifying the app's code.

      @_firearmy@_firearmy27 күн бұрын
  • Great video! What would happen in a scenario where the api doesn’t get called or it returns an error (ie. Never resolves with success) will it just hit the test timeout?

    @ShaneMcTV@ShaneMcTV3 ай бұрын
    • Great question! Your assumption is correct and the error handling depends on your project configuration. `waitForResponse()` has a timeout setting to limit the waiting for a particular API response. If this setting isn't set, the general test timeout will be hit eventually. :) It's up to you and the project requirements to find what works best.

      @ChecklyHQ@ChecklyHQ3 ай бұрын
    • @@ChecklyHQ Thanks for confirming. Keep up the great videos

      @ShaneMcTV@ShaneMcTV2 ай бұрын
  • Hey I have a scenario where I need to click on next button and there is navigation happens which sometimes takes more than 15s and I need to do some assertions but these navigations provides a lot of intermittent issues. Is the issue because of API calls. Please guide me on this

    @AvinashKumar-rk5fz@AvinashKumar-rk5fz2 ай бұрын
    • Ideally would check if you could work around these without listening for the network (users wouldn't watch and check the network either). So if you're having a long lasting navigation you could increase the timeout for the assertions / actions on the slow page. :) The overall recommandation is to only listen to the network when you really have to. Hope this helps.

      @ChecklyHQ@ChecklyHQ2 ай бұрын
KZhead