Our team tested our application with Selenium, as it was heavily dependent on JavaScript, and we always had testing problems that sometimes did not work. As the number of tests increased, the likelihood that at least one of the two tests would fail in a full run became a confidence.
What we recently found out is that we probably have a race condition in which selenium will click links before initializing JavaScript to have the ability to attach event handlers to the element that is clicked. Of course, at this moment the effects that we are looking for do not happen, and we get a failed test.
Currently, we have added a slight delay before clicks to give the initialization time of the JavaScript code to complete, this is obviously a bit hacky, it adds time to the overall test execution and does not guarantee that the tests will not fail yet, so we are looking for the best solution.
The best idea we have come up with so far is to insert a hidden element in the DOM that Selenium can wait for before it fires a click event to know that it is ready. This will be a lot of additional overhead in terms of development time when we work on our asynchronous events by deleting and adding this element. He also adds additional materials to our pages, which are really not needed for the application.
Does anyone have any better strategies? What have you done to effectively solve this problem?
source share