πŸ’‘ If you like this website, please share it with your friends and network! πŸš€
Back to All Scenarios
Scenario 6 of 100
CI/CD
Advanced

Test Passes Locally but Fails in Headless CI/CD

πŸ”§Scenario Overview

Test Passes Locally but Fails in Headless CI/CD

Key Takeaways & Cheat Sheet

  • βœ“Configure explicit window-size arguments to match desktop resolutions
  • βœ“Align local browser version with CI/CD runner browser binary version
  • βœ“Increase explicit timeouts slightly in CI to account for resource limits
  • βœ“Implement automatic screenshot capturing on test failure listener

Short Direct Answer

CI/CD servers are usually headless (no GUI) and operate on shared virtualized hardware with lower resource allocations. These differences often lead to timing inconsistencies, responsive layouts breaking (hiding desktop menus), or dynamic components failing to load in time. To fix this, always set explicit viewport arguments, ensure environment versions align, and capture screen states on failures.

⚠️ Senior Warning (Red Flag)

Do not rely on driver.manage().window().maximize() in headless CI pipelines. In virtual environments, maximize() often defaults to a very small, restricted layout (like 800x600), hiding responsive menus.

πŸ’‘ STAR Deep Dive Explanation & Pro Tip

Setting a fixed screen resolution like 1920x1080 is critical. Modern web pages are responsive, and if your headless browser defaults to a small size, elements will collapse into hamburger menus, breaking your desktop locators.

SeleniumAutomation.java
Selenium 4 + Java
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriver;

// βœ… Configure Headless options properly for CI pipeline
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless=new"); // Use modern headless engine
options.addArguments("--window-size=1920,1080"); // Force standard desktop layout
options.addArguments("--no-sandbox"); // Required for Linux container permission bypass
options.addArguments("--disable-dev-shm-usage"); // Prevents shared memory crashes in Docker
options.addArguments("--disable-gpu"); // Recommended for server execution

WebDriver driver = new ChromeDriver(options);