Consider a page which allows you to select a vehicle like car, truck and bike. You can save the selection by pressing a Save button. The save button will trigger the appropriate api call depending on the type of vehicle you selected i.e. POST
/Inventory/AddCar
, /Inventory/AddTruck
, /Inventory/AddBike
. In cypress, I want to intercept all these calls when the save button is clicked and then wait for the calls to complete. I tried using regex in my intercept as follows, but it did not work. How do I intercept multiple api calls which essentially do the same thing?
// A (web) page object function.
function saveVehicle()
{
const regex = `/[\/Inventory\/AddCar]|[\/Inventory\/AddTruck]|[\/Inventory\/AddBike]/`
cy.intercept("POST", regex).as("saveVehicle");
saveButton.click().wait("@saveVehicle");
}