automationflaky-tests

Why your Selenium tests fail intermittently: 5 reasons for flaky tests

Flaky tests are the biggest source of distrust in automation. Per the Google Testing Blog, about 1.5% of all green CI runs in their pipelines contained at least one flaky failure. And most often, the problem isnโ€™t in the product โ€” itโ€™s in the test itself.

โš ๏ธ Implicit + explicit waits in the same project. Selenium docs warn explicitly: donโ€™t mix them. Implicit wait blocks element lookup, explicit adds its own delay โ€” the total timeout becomes unpredictable. Keep only WebDriverWait with an explicit condition.

โš ๏ธ Tests with Thread.sleep(3000). Itโ€™s always either too short (under CI load) or too long (slows you down). Replace with waiting for a concrete DOM state: elementToBeClickable, presenceOfElementLocated, textToBe.

โš ๏ธ Test order dependency. Test A creates a user, test B logs in with the same email. If B runs first โ€” fail. Every test should be fully isolated: own fixture with a unique ID, or setUp/tearDown that cleans state.

โš ๏ธ Animations and transitions. Test clicks a button, checks the result โ€” but the button is still in its fade-in animation. Solution: either disable CSS animations in the test environment (* { animation: none !important; }), or wait for aria-busy="false".

โš ๏ธ Shared environment. A parallel CI runner changed data mid-test. Use data isolation: namespacing by test id, transactional rollback in the DB, or mocking external APIs via WireMock/MSW.

What to do right now

โœ… Run your most unstable test 50 times in a row โ€” the failure pattern will reveal the cause class.

โœ… Use runner-level retries ONLY as a temporary crutch, tagged and tracked in Jira โ€” otherwise itโ€™ll mask real bugs.

โœ… Disable implicit wait globally and see which tests immediately fail โ€” those are your growth areas.

More: Martin Fowler โ€” Eradicating Non-Determinism in Tests.