In my project, I have a suite of end-to-end tests created using testcafe.
In some scenarios, the user/script has to do some operations on the page, like clicking on a button, that triggers an HTTP call to the BE to fetch some result.
Since it's an async operation (that can take a bit of time) I'm forced to put a wait(X) to be sure that the HTTP call has responded.
For example:
test("should render result with ascending order when lowerPrice option got selected", async (t) => {
const sortButton = Selector(".sortsortButton");
const lowerPriceSortSelector = Selector(".lowerPriceSortSelector");
const gridResult = Selector(".gridResult");
await t
.click(sortButton)
.click(lowerPriceSortSelector)
.wait(5000) //<--- I want to avoid this!
.expect(gridResult.exists).ok();
});
I've checked but in the documentation, I haven't found any utility that allows waiting until a given route has replied.
In the past, I've played with Cypress and there was this awesome feature: https://docs.cypress.io/api/commands/wait#Alias
// Wait for the route aliased as 'getAccount' to respond
// without changing or stubbing its response
cy.intercept('/accounts/*').as('getAccount')
cy.visit('/accounts/123')
cy.wait('@getAccount').then((interception) => {
// we can now access the low level interception
// that contains the request body,
// response body, status, etc
})
There is anything similar in Testcafe?
If not, how can I do to avoid waiting an arbitrary period of time?