Picture a scenario where you are on a webpage that lets you choose a vehicle such as a car, truck, or bike. After making your selection, you can save it by clicking a Save button. Depending on the type of vehicle chosen, the Save button will trigger an appropriate API call like POST /Inventory/AddCar
, /Inventory/AddTruck
, /Inventory/AddBike
. In Cypress, I aim to intercept these calls once the Save button is clicked and then wait for them to complete. Despite trying to use regex in my interception method as shown below, I ran into issues. How can I effectively intercept multiple similar API calls?
// A function within the (web) page object.
function saveVehicle()
{
const regex = `/[\/Inventory\/AddCar]|[\/Inventory\/AddTruck]|[\/Inventory\/AddBike]/`
cy.intercept("POST", regex).as("saveVehicle");
saveButton.click().wait("@saveVehicle");
}