In my upcoming application, there are two main pages: Login and Cars. On the Cars page, users can click on a specific car to view more details about it. The URL format is as follows: /cars
for the general cars page and /cars/car-id
for the individual car pages. When a user visits an individual car page, a request is made to retrieve data about that particular car. To achieve this functionality using Cypress, I utilized the visit
method as shown below:
cy.visit('http://localhost:3000/cars/1234') //navigate to specific car page by id (1234 represents the car id)
cy.route('GET', 'fixture:car.json').as('getCar') //make the API request
cy.wait('@getCar')
However, when implementing this, I encountered the following error message:
CypressError: Timed out retrying: cy.wait() timed out waiting 5000ms for the 1st request to the route: 'getCar'. No request ever occurred.
. Strangely, if I manually click on a menu item to navigate to the car page, everything works smoothly using: cy.get("a[href*=/car/1234]").click()
. Why does using visit
lead to this error? And what could be a potential solution in my case?