Typing into search during Cypress test is flaky

Viewed 47

I have an issue testing a search functionality. From time to time a character in the search is dropped. I guess it's because the search is fetching some results before the complete string is typed?

Do I need to intercept the API? If so how would it work.

Test:

cy.get('my-search-selector').type('my-search-string')
1 Answers

It sounds like you just need to add a delay (between characters) to the .type() command.

This idea is to allow enough time for the app to receive intermediate results and update it's suggestion list.

You will need to try out different delay periods depending on how slow the network is.
To do that use burn testing with cypress-grep.

cy.get('my-search-selector').type('my-search-string', {delay:300});
Related