Jenkins(2.107.2)运行Maven-Selenium测试失败求助
Hey there, let's work through troubleshooting your Selenium Maven test failure on Jenkins 2.107.2 running on Linux. Since you've already tried cleaning pre-run directories and setting universal folder permissions, let's dive into other common issues tied to Xvfb and the Jenkins-Selenium integration:
1. Verify Xvfb is Properly Set Up & Configured
- First, confirm Xvfb is installed and accessible to the Jenkins user. Switch to your test user (or the
jenkinssystem user) and run this quick check:xvfb-run --server-args="-screen 0 1024x768x24" echo "Xvfb is working" - If this command fails, install Xvfb via your Linux package manager:
- For Debian/Ubuntu:
sudo apt-get install xvfb - For RHEL/CentOS:
sudo yum install xorg-x11-server-Xvfb
- For Debian/Ubuntu:
- Double-check your Jenkins Xvfb plugin settings: Ensure the screen resolution matches what your Selenium tests expect (low resolutions can break some UI tests) and that Xvfb is set to start before your Maven build step, not mid-build.
2. Dig Deeper Into Jenkins User Permissions
- Folder access is good, but the Jenkins user might lack permissions for other critical resources:
- Check if the user can access the Xvfb display port (usually :99). Run
xauth listas the Jenkins user to verify X authority entries exist. - Make sure browser drivers (like chromedriver or geckodriver) are executable. Run
chmod +x /path/to/your/driverif needed, and confirm the driver's path is included in the Jenkins user's$PATHenvironment variable.
- Check if the user can access the Xvfb display port (usually :99). Run
3. Get the Full Error Log Details
- The log snippet you shared cuts off at "Xvfb启动中..." — you need the full stack trace from the Maven test step. Look for specific errors like:
org.openqa.selenium.WebDriverException: Failed to connect to localhost port 9515
or
Caused by: java.awt.AWTError: Can't connect to X11 window server using ':99' as the value of the DISPLAY variable. - These lines will pinpoint whether the issue is a driver connection problem, Xvfb display misconfiguration, or something else entirely.
4. Validate Selenium, Driver, and Browser Compatibility
- Ensure your Selenium version in
pom.xmlmatches the browser driver version (e.g., ChromeDriver must be compatible with the installed Chrome version on your Jenkins server). - Confirm the browser is actually installed on the Linux server — Jenkins runs headless, but the browser binary still needs to exist. For Chrome, run
google-chrome --versionas the Jenkins user to check.
5. Test the Build Locally as the Jenkins User
- SSH into your Linux server, switch to the Jenkins user with
sudo su - jenkins, navigate to your workspace directory, and run the Maven test command directly:mvn test -Dwebdriver.chrome.driver=/path/to/chromedriver -Ddisplay=:99 - If this fails locally, the problem is system-level or test-config related (not Jenkins-specific). If it works locally but fails in Jenkins, the issue is tied to Jenkins environment variables or plugin settings.
内容的提问来源于stack exchange,提问作者Mark H
相关产品推荐
相关产品推荐

