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
Happy this video has been helpful!
This is so useful, thank you! I would love to see a video on checking payment transactions.
Happy the videos are useful. Could you explain a bit more detailed what process / transaction you'd like to see?
i am using it more than a year ...which is very useful on dynamically generating test data...
Great 👍 Yeah, that's a nice use case!
I did similar approach in my UI tests
Great content! Thanks!
Glad you liked it!
Thanks
Happy it's been valuable. :)
This is so useful, thank you! I have small doubt. How do I track the API response which is already invoked. Is it possible?
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 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.
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?
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 Thanks for confirming. Keep up the great videos
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
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.