Debugging CI/CD Test Failures (Local Passes, Jenkins Fails)
Debugging CI/CD Test Failures (Local Passes, Jenkins Fails)
Key Takeaways & Cheat Sheet
- βAcknowledge Jenkins servers run headless on lower hardware specs
- βCapture visual screenshots and HTML DOM sources at failure moments
- βEnforce standardized screen dimensions for headless chrome arguments
- βIncrease explicit timeouts dynamically to accommodate slower CI runner threads
Short Direct Answer
When tests pass locally but fail on Jenkins, it is usually due to timing mismatches on slower virtual hardware, responsive layout breaks in headless mode, or version conflicts between the browser binary and webdriver. To debug this, configure standard browser options (like `1920x1080` screen size), increase explicit timeouts in CI, and capture screenshots on failures to review the exact state of the page.
β οΈ Senior Warning (Red Flag)
Never write off Jenkins execution failures as mere "flakiness" or blame the server. A professional engineer digs into failure logs, viewport configurations, and timing to pinpoint the root cause.
π‘ STAR Deep Dive Explanation & Pro Tip
Setting a explicit desktop viewport size (like 1920x1080) prevents headless browsers from defaulting to low resolutions that collapse your navigation elements.
// β
Standardize Headless Viewports and Linux sandbox permissions
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless=new");
options.addArguments("--window-size=1920,1080");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage"); // Fixes memory crashes on Docker/Jenkins
WebDriver driver = new ChromeDriver(options);
// β
Dynamically scale timeouts for slow Jenkins workers
int ciTimeoutMultiplier = System.getenv("JENKINS_HOME") != null ? 2 : 1;
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10 * ciTimeoutMultiplier));