You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:Selenium在Ubuntu Jenkins环境启动失败(UnreachableBrowserException)

Troubleshooting Jenkins + Selenium ChromeDriver UnreachableBrowserException on Ubuntu

Hey there! Let's work through this issue you're hitting when running Selenium tests on Jenkins. First, let's recap your environment setup to make sure we're aligned:

  • OS: ubuntu-18.04
  • Chrome: 68.0.3440.84
  • ChromeDriver: 2.41.578700
  • Jenkins: ver.2.193
  • Selenium: 3.13.0
  • Java: OpenJDK 1.8

And here's the error you're seeing:

Opening chrome driver
Oct 30, 2019 1:26:49 PM org.openqa.selenium.remote.DesiredCapabilities chrome INFO: Using new ChromeOptions() is preferred to DesiredCapabilities.chrome()
[ERROR] Tests run: 3, Failures: 1, Errors: 0, Skipped: 2, Time elapsed: 0.998 s <<< FAILURE! - in TestSuite
[ERROR] setUp(com.test.WebAppTitleTestOnChrome) Time elapsed: 0.895 s <<< FAILURE!
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure

Let's go through the most common fixes for this issue:

1. Switch to Headless Chrome (Critical for Server Environments)

Jenkins runs in a headless server environment—meaning there's no graphical desktop to render Chrome. You must configure Chrome to run in headless mode, plus a few other flags to avoid sandbox/permission issues on Ubuntu.

Update your test code to use ChromeOptions (as the warning suggests) instead of DesiredCapabilities, and add these essential arguments:

// Set ChromeDriver path first (if not in system PATH)
System.setProperty("webdriver.chrome.driver", "/path/to/your/chromedriver");

ChromeOptions options = new ChromeOptions();
// Run in headless mode
options.addArguments("--headless");
// Bypass OS security restrictions (critical for Jenkins user)
options.addArguments("--no-sandbox");
// Fixes /dev/shm memory limit issues on Ubuntu
options.addArguments("--disable-dev-shm-usage");
// Simulate a standard window size
options.addArguments("--window-size=1920,1080");

// Initialize driver with these options
WebDriver driver = new ChromeDriver(options);

2. Verify File Permissions for Jenkins User

Jenkins typically runs under the jenkins system user, which might not have access to Chrome or ChromeDriver:

  • Ensure ChromeDriver has executable permissions:
    chmod +x /path/to/your/chromedriver
    
  • Check that the jenkins user can access Chrome's installation path (usually /usr/bin/google-chrome):
    ls -l /usr/bin/google-chrome
    
  • Test launching Chrome manually as the Jenkins user to catch permission errors:
    su - jenkins -c "/usr/bin/google-chrome --headless --no-sandbox --dump-dom https://google.com"
    

If this command fails, it will give you specific errors (like missing libraries) to fix.

3. Install Missing Chrome Dependencies

Ubuntu servers often lack some libraries required for Chrome to run. Install these common missing packages:

sudo apt-get update && sudo apt-get install -y libnss3 libgconf-2-4 libxi6 libxrender1 libxss1

4. Confirm ChromeDriver-Chrome Version Compatibility

While Chrome 68 and ChromeDriver 2.41 are technically compatible (2.41 supports Chrome 67-69), double-check that you're using the exact matching minor version if issues persist.

5. Check System PATH Configuration

If you're not specifying the ChromeDriver path in your code, make sure the directory containing ChromeDriver is added to the system PATH that Jenkins uses:

  • In Jenkins, go to Manage Jenkins > Configure System
  • Under Global properties, check "Environment variables"
  • Add a variable named PATH with the value: $PATH:/path/to/chromedriver-directory

Start with the headless mode and permission checks—those are the most likely culprits here. If you still hit issues, share the full console output from Jenkins (including any Chrome startup errors) and we can dig deeper.

内容的提问来源于stack exchange,提问作者Moumita Das

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:23:33