ਇਹ ਇੱਕ Slack ਮੈਸੇਜ ਨਾਲ ਸ਼ੁਰੂ ਹੁੰਦਾ ਹੈ। ਬਿਲਡ ਲਾਲ ਹੈ। ਤੁਸੀਂ ਫੇਲ੍ਹ ਹੋਏ ਟੈਸਟਾਂ ਨੂੰ ਦੇਖਦੇ ਹੋ, ਨਿਰਾਸ਼ ਹੁੰਦੇ ਹੋ, ਅਤੇ ਆਪਣੇ ਲੈਪਟਾਪ 'ਤੇ ਉਹੀ ਟੈਸਟ ਦੁਬਾਰਾ ਚਲਾਉਂਦੇ ਹੋ। ਹਰਾ (Green)। ਤੁਸੀਂ CI ਜੌਬ ਨੂੰ ਦੁਬਾਰਾ ਕੋਸ਼ਿਸ਼ ਕਰਦੇ ਹੋ। ਸ਼ਾਇਦ ਇਹ ਕੋਈ ਛੋਟੀ ਜਿਹੀ ਗਲਤੀ ਸੀ। ਪਰ ਫੇਲ੍ਹ ਹੋਣਾ ਵਾਪਸ ਆ ਜਾਂਦਾ ਹੈ, ਸਰਵਰ 'ਤੇ ਇਹ ਜ਼ਿੱਦੀ ਅਤੇ ਵਾਰ-ਵਾਰ ਹੋ ਰਿਹਾ ਹੈ ਪਰ ਤੁਹਾਨੂੰ ਦਿਖਾਈ ਨਹੀਂ ਦੇ ਰਿਹਾ।
ਇੱਕ ਬ੍ਰਾਊਜ਼ਰ ਟੈਸਟ ਜੋ CI ਵਿੱਚ ਫੇਲ੍ਹ ਹੁੰਦਾ ਹੈ ਪਰ ਸਥਾਨਕ (locally) ਤੌਰ 'ਤੇ ਪਾਸ ਹੋ ਜਾਂਦਾ ਹੈ, ਇਹ ਸਿਰਫ਼ ਇੱਕ ਪਰੇਸ਼ਾਨੀ ਤੋਂ ਵੱਧ ਹੈ। ਇਹ ਅਵਿਸ਼ਵਾਸ ਪੈਦਾ ਕਰਦਾ ਹੈ। ਟੀਮਾਂ ਟਾਈਮਿੰਗ ਨੂੰ ਦੋਸ਼ ਦੇਣਾ ਸ਼ੁਰੂ ਕਰ ਦਿੰਦੀਆਂ ਹਨ। ਉਹ ਅਜਿਹੇ ਅਸਥਾਈ ਹੱਲ (temporary fixes) ਲਾਗੂ ਕਰਦੇ ਹਨ ਜੋ ਕਦੇ ਹਟਾਏ ਨਹੀਂ ਜਾਂਦੇ। ਇੱਥੇ ਇੱਕ setTimeout, ਉੱਥੇ ਇੱਕ .wait(5000)। ਟੈਸਟ ਸੂਟ ਹੌਲੀ ਹੋ ਜਾਂਦਾ ਹੈ। ਫੇਲ੍ਹ ਹੋਣਾ ਜਾਰੀ ਰਹਿੰਦਾ ਹੈ। ਉਹ 'flaky' ਟੈਸਟ ਪੱਕੇ ਹਿੱਸੇ ਬਣ ਜਾਂਦੇ ਹਨ, ਅਤੇ ਅੰਤ ਵਿੱਚ ਹਰ ਕੋਈ ਲਾਲ ਪਾਈਪਲਾਈਨ (red pipeline) ਨੂੰ ਇੱਕ ਆਮ ਗੱਲ ਮੰਨ ਕੇ ਅਣਦੇਖਾ ਕਰਨ ਲੱਗ ਪੈਂਦਾ ਹੈ।
ਇਹ ਖ਼ਤਰਨਾਕ ਹੈ। ਤੁਸੀਂ ਅਜਿਹਾ ਟੈਸਟ ਸੂਟ ਨਹੀਂ ਚਾਹੁੰਦੇ ਜੋ ਬਿਨਾਂ ਵਜ੍ਹਾ ਖ਼ਤਰੇ ਦੀ ਚੇਤਾਵਨੀ ਦੇਵੇ (cries wolf)।
CI ਖ਼ਰਾਬ ਨਹੀਂ ਹੈ; ਇਹ ਸਿਰਫ਼ ਵੱਖਰਾ ਹੈ
CI ਵਾਤਾਵਰਣ (environments) ਅਚਾਨਕ ਨਹੀਂ ਹੁੰਦੇ। ਉਹ ਨਿਸ਼ਚਿਤ (deterministic) ਹੁੰਦੇ ਹਨ। ਸਮੱਸਿਆ ਇਹ ਹੈ ਕਿ ਉਹ ਇੱਕ ਅਜਿਹੇ ਸਿਸਟਮ ਬਾਰੇ ਨਿਸ਼ਚਿਤ ਹਨ ਜੋ ਤੁਹਾਡਾ MacBook ਜਾਂ ਤੁਹਾਡਾ Linux ਵਰਕਸਟੇਸ਼ਨ ਨਹੀਂ ਹੈ। ਤੁਹਾਡਾ ਸਥਾਨਕ ਸੈੱਟਅੱਪ ਉਹਨਾਂ ਅੰਤਰਾਂ ਨੂੰ ਲੁਕਾ ਲੈਂਦਾ ਹੈ ਜੋ ਇੱਕ ਸਾਫ਼ CI runner ਤੁਰੰਤ ਸਾਹਮਣੇ ਲਿਆਉਂਦਾ ਹੈ।
ਸੋਚੋ ਕਿ ਕਿੰਨੇ ਹਿੱਸੇ ਇੱਕ ਦੂਜੇ ਤੋਂ ਵੱਖਰੇ ਹੋ ਸਕਦੇ ਹਨ। ਤੁਹਾਡੀ ਸਥਾਨਕ ਮਸ਼ੀਨ 'hot module reloading' ਦੇ ਨਾਲ ਇੱਕ ਡਿਵੈਲਪਮੈਂਟ ਸਰਵਰ ਚਲਾ ਸਕਦੀ ਹੈ, ਜਦੋਂ ਕਿ CI 'tree shaking' ਅਤੇ 'minification' ਦੇ ਨਾਲ ਇੱਕ ਪ੍ਰੋਡਕਸ਼ਨ ਆਰਟੀਫੈਕਟ (production artifact) ਬਣਾਉਂਦਾ ਹੈ। ਇਹ ਇਕੱਲਾ ਕਾਰਨ ਹੀ ਕੋਡ ਪਾਥਾਂ ਨੂੰ ਹਟਾ ਸਕਦਾ ਹੈ ਜਾਂ ਚਲਾਉਣ ਦੇ ਕ੍ਰਮ (execution order) ਨੂੰ ਬਦਲ ਸਕਦਾ ਹੈ। ਡਿਪੈਂਡੈਂਸੀ ਟ੍ਰੀ (Dependency trees) ਬਦਲ ਜਾਂਦੇ ਹਨ। ਇੱਕ lockfile ਜੋ ਬਿਲਕੁਲ ਇੱਕੋ ਜਿਹੀ ਦਿਖਾਈ ਦਿੰਦੀ ਹੈ, ਉਹ ਵੱਖਰੇ ਤਰੀਕੇ ਨਾਲ ਹੱਲ ਹੋ ਸਕਦੀ ਹੈ ਜੇਕਰ ਪੈਕੇਜ ਮੈਨੇਜਰ ਦਾ ਵਰਜ਼ਨ ਇੱਕ ਮਾਈਨਰ ਰਿਲੀਜ਼ ਨਾਲ ਵੀ ਵੱਖਰਾ ਹੋਵੇ। ਨੈੱਟਵਰਕ ਕ੍ਰਮ ਬਦਲ ਜਾਂਦੇ ਹਨ। ਤੁਹਾਡਾ ਦਫ਼ਤਰ ਦਾ Wi-Fi ਇੱਕ ਸਟੇਜਿੰਗ API ਨੂੰ ਇੱਕ ਵਾਰ ਵਿੱਚ ਹੱਲ ਕਰ ਸਕਦਾ ਹੈ; CI runner ਇੱਕ ਲੋਡ ਬੈਲੈਂਸਰ ਦੇ ਪਿੱਛੇ ਇੱਕ ਵੱਖਰੇ ਕਲੱਸਟਰ ਨਾਲ ਜੁੜ ਸਕਦਾ ਹੈ, ਜਿਸ ਨਾਲ ਅਜਿਹੀ ਲੇਟੈਂਸੀ (latency) ਪੈਦਾ ਹੁੰਦੀ ਹੈ ਜੋ ਤੁਹਾਨੂੰ ਕਦੇ ਦਿਖਾਈ ਨਹੀਂ ਦਿੰਦੀ।
ਬ੍ਰਾਊਜ਼ਰ ਖੁਦ ਵੱਖ-ਵੱਖ ਵਾਤਾਵਰਣਾਂ ਵਿੱਚ ਵੱਖਰੇ ਤਰੀਕੇ ਨਾਲ ਕੰਮ ਕਰਦੇ ਹਨ। ਤੁਹਾਡਾ ਸਥਾਨਕ Chrome ਐਕਸਟੈਂਸ਼ਨਾਂ, ਕੈਸ਼ ਕੀਤੇ ਕ੍ਰੈਡੈਂਸ਼ੀਅਲਜ਼, ਪਰਮਾਨent ਲੋਕਲ ਸਟੋਰੇਜ, ਅਤੇ ਹਾਰਡਵੇਅਰ ਐਕਸਲੇਰੇਸ਼ਨ ਵਾਲੇ GPU ਨਾਲ ਚੱਲਦਾ ਹੈ। CI ਹਰ ਵਾਰ ਇੱਕ ਖਾਲੀ ਪ੍ਰੋਫਾਈਲ ਤੋਂ ਸ਼ੁਰੂ ਹੁੰਦਾ ਹੈ। ਬ੍ਰਾਊਜ਼ਰ ਲਾਈਫਸਾਈਕਲ ਵੱਖਰੇ ਹੁੰਦੇ ਹਨ। ਰੈਂਡਰਿੰਗ ਪਾਥ ਵੱਖਰੇ ਹੁੰਦੇ ਹਨ। ਜੋ ਫੌਂਟ ਤੁਹਾਡੇ ਸਿਸਟਮ 'ਤੇ ਹਨ, ਉਹ CI ਵਿੱਚ ਬਦਲ ਦਿੱਤੇ ਜਾਂਦੇ ਹਨ। Viewport ਦਾ ਆਕਾਰ ਅਤੇ ਡਿਵਾਈਸ ਪਿਕਸਲ ਰੇਸ਼ੀਓ ਵੱਖ-ਵੱਖ ਹੁੰਦੇ ਹਨ, ਜੋ ਕਿ ਰਿਸਪੌਂਸਿਵ ਬ੍ਰੇਕਪੁਆਇੰਟਸ (responsive breakpoints) ਨੂੰ ਬਦਲ ਸਕਦੇ ਹਨ ਜਾਂ lazy-loading ਵਿਵਹਾਰ ਨੂੰ ਪ੍ਰਭਾਵਿਤ ਕਰ ਸਕਦੇ ਹਨ।
ਇਹ ਖਾਮੀਆਂ ਅਸਲ ਹਨ। ਇਹ ਮਕੈਨੀਕਲ ਹਨ। ਇਹਨਾਂ ਨੂੰ ਅਚਾਨਕ ਮੰਨ ਲੈਣਾ ਇਹਨਾਂ ਨੂੰ ਖ਼ਤਮ ਨਹੀਂ ਕਰਦਾ।
ਪ੍ਰੀਵਿਊ ਵਾਤਾਵਰਣ (Preview Environments) ਝੂਠ ਬੋਲਦੇ ਹਨ
ਪ੍ਰੀਵਿਊ ਵਾਤਾਵਰਣ ਸਮੱਸਿਆ ਨੂੰ ਹੋਰ ਵਧਾ ਦਿੰਦੇ ਹਨ। ਉਹ ਮਨੁੱਖੀ ਸਮੀਖਿਆ ਲਈ ਲਾਭਦਾਇਕ ਹਨ, ਪਰ ਉਹ ਪ੍ਰੋਡਕਸ਼ਨ ਨਹੀਂ ਹਨ। ਉਹ ਅਕਸਰ ਅਸਲ API ਹੋਸਟ ਦੀ ਬਜਾਏ api-staging ਵੱਲ ਇਸ਼ਾਰਾ ਕਰਦੇ ਹਨ। ਫੀਚਰ ਫਲੈਗਸ (Feature flags) ਹਰ ਪ੍ਰਯੋਗ ਲਈ 'true' ਹੁੰਦੇ ਹਨ, ਜਿਸ ਨਾਲ ਉਹ ਕੰਡੀਸ਼ਨਲ ਲੌਜਿਕ (conditional logic) ਲੁਕ ਜਾਂਦੀ ਹੈ ਜੋ ਪ੍ਰੋਡਕਸ਼ਨ ਵਿੱਚ ਚੱਲਦੀ ਹੈ। ਅਥੈਂਟੀਕੇਸ਼ਨ (Authentication) ਇੱਕ ਕਦਮ ਛੱਡ ਸਕਦੀ ਹੈ ਜਾਂ ਇੱਕ ਮੌਕ ਟੋਕਨ (mock token) ਪਾ ਸਕਦੀ ਹੈ। ਕੁਕੀਜ਼ (Cookies) ਵੱਖਰੀਆਂ ਨੀਤੀਆਂ ਦੀ ਵਰਤੋਂ ਕਰ ਸਕਦੀਆਂ ਹਨ। ਡੇਟਾ ਸੈੱਟ ਬਹੁਤ ਛੋਟਾ ਹੋ ਸਕਦਾ ਹੈ, ਦਸ ਹਜ਼ਾਰ ਦੀ ਬਜਾਏ ਸਿਰਫ਼ ਦਸ ਰੋਅ (rows),
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
