Zaczyna się od wiadomości na Slacku. Build jest czerwony. Przeglądasz błędy, marszczysz brwi i ponownie uruchamiasz ten sam test na swoim laptopie. Zielono. Ponawiasz zadanie CI. Może to był tylko chwilowy błąd. Błąd powraca – uparty i powtarzalny na serwerze, ale niewidoczny dla Ciebie.
Test przeglądarkowy, który kończy się błędem w CI, a przechodzi lokalnie, to coś więcej niż tylko irytacja. Buduje on nieufność. Zespoły zaczynają obwiniać kwestie czasowe. Wprowadzają tymczasowe poprawki, które zostają na zawsze. setTimeout tutaj, .wait(5000) tam. Zestaw testów zwalnia. Błędy wciąż powracają. Te niestabilne testy stają się stałym elementem krajobrazu, aż w końcu wszyscy zaczynają traktować czerwony pipeline jako szum informacyjny.
To niebezpieczne. Nie chcesz zestawu testów, który „woła wilka”.
CI nie jest zepsute; jest po prostu inne
Środowiska CI nie są losowe. Są deterministyczne. Problem polega na tym, że są deterministyczne względem systemu, którym nie jest Twój MacBook ani stacja robocza z Linuxem. Twoja lokalna konfiguracja ukrywa różnice, które czysty runner CI natychmiast ujawnia.
Pomyśl o tym, jak wiele elementów może się rozjechać. Twoja lokalna maszyna może uruchamiać serwer deweloperski z hot module reloadingiem, podczas gdy CI buduje artefakt produkcyjny z tree shakingiem i minifikacją. To samo w sobie może usunąć ścieżki kodu lub zmienić kolejność wykonywania. Drzewa zależności ulegają przesunięciom. Plik lock, który wygląda identycznie, może zostać rozwiązany inaczej, jeśli wersja menedżera pakietów różni się o jedną wersję minorową. Sekwencje sieciowe ulegają zmianie. Twoje biurowe Wi-Fi może rozwiązać stagingowe API w jednym skoku; runner CI może trafić do innego klastra za load balancerem, wprowadzając opóźnienia, których nigdy nie widzisz.
Same przeglądarki zachowują się inac
Build the exact artifact that CI produced. Download it if you must. Serve that artifact locally with a simple static file server, not with Vite or Webpack dev middleware. Use the same environment variables that CI injected. Match the browser version precisely. Run it in the same mode, headed or headless, because focus events, media queries, and autoplay policies still diverge between the two in subtle ways. If your CI uses a Docker container, run the same image locally. Remove your personal browser profile entirely.
When the local reproduction finally fails, you have a real debugging session. Until then, you are chasing shadows.
Stop Sleeping, Start Waiting
The most common response to a flaky browser test is to add delay. Wait five seconds. Wait ten. This is not a fix. It is a surrender. Arbitrary delays slow your suite, create false confidence, and still fail under load when the network hiccups.
Instead, wait for evidence of state. If a notification should appear after a form submission, do not wait for time to pass. Wait for a specific notification ID to exist in the DOM. If a counter should increment, wait for the text to change values. If a loading state blocks interaction, wait for the loading marker to disappear. If you are working with a WebSocket or server-sent events, wait for the network stream to produce a specific event.
Explicit waits turn your test from a guessing game into a contract. The test says: "I will proceed once the application confirms it is ready." That is far stronger than saying, "I will proceed once enough seconds have passed."
Hydration and the Disappearing Button
In modern React applications, hydration causes a specific class of failures that local dev servers often mask. The server sends HTML. React boots up in the browser and attaches event listeners. During that window, your test might click a button. React then replaces or restructures that DOM node during hydration. The element handle your test framework was holding now points to a detached node, and you get an error about interacting with a removed element.
The fix is not to write a more complex selector that digs deeper into the component tree. The fix is to look for readiness signals. Wait until a root element gains a hydrated attribute or a known data property. Wait for a skeleton loader to disappear. Wait for a client-side event handler to become active. Let the application announce that it is stable before you fire clicks.
Hidden Culprits: Dependencies and Third-Party Scripts
Sometimes the environment changes even though your application code did not. A transitive update in a small utility library, three levels deep in your node_modules, can alter browser behavior. It might change how promises resolve, how styles get injected, or how mocks intercept requests. When tests begin failing after a routine dependency update, record your package manager version and the lockfile checksum. You need to know whether you are looking at the same tree you were last week.
Third-party scripts are another frequent saboteur. Analytics trackers, payment SDKs, and chat widgets load asynchronously. They inject iframes, shift layout, or steal focus at moments your test does not expect. In CI, these scripts might load more slowly, or they might fail to load entirely because of network restrictions, causing your application to follow a different error-handling path. Log which third-party resources loaded and their HTTP status. If a payment iframe takes three seconds to mount in CI but loads instantly on your fast local connection, your "element not clickable" error suddenly has a clear cause.
And "element not clickable" is never a diagnosis. It is a symptom. Treat the cause.
Build an Evidence Kit
Every CI failure should be actionable. A stack trace alone is not enough. You need an evidence kit that lets another engineer, or yourself next month, reconstruct what happened.
Keep screenshots and video recordings from the failing run. Capture the full browser console output, not just errors but warnings too. Log network failures, including 404s, CORS rejections, and dropped connections. Preserve the build IDs and feature flags that were active. Take a DOM snapshot at the exact moment the assertion failed. A snapshot lets you inspect the HTML structure after the fact, rather
