This thread is trying to answer question "How can I use the `page.route()` API to mock different responses for GET and POST requests on the same endpoint?"
Something similar is in documentation here: https://playwright.dev/docs/api/class-route You can target by route.request().method() if it is POST or GET
// Handle GET requests.
await page.route('**/*', route => {
if (route.request().method() !== 'GET') {
route.fallback();
return;
}
// Handling GET only.
// ...
});
// Handle POST requests.
await page.route('**/*', route => {
if (route.request().method() !== 'POST') {
route.fallback();
return;
}
// Handling POST only.
// ...
});
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].