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

本地启动Selenium正常,远程启动异常的问题求助

Fixing Unattended Selenium Server Startup for Remote Chrome Tests

Hey Bob, I’ve run into this exact scenario before—having to manually log into a machine to fire up Selenium every time tests need to run is a total pain. Let’s get this sorted so your Jenkins/Codeception setup can run tests without you being physically present.

The best long-term fix is to configure Selenium Server to start automatically as a system service, so it runs in the background even when no one’s logged into the machine. Here’s how to do it for common OSes:

Linux (Systemd)

  1. Create a systemd service file (replace paths and username with your actual details):
    # /etc/systemd/system/selenium-chrome.service
    [Unit]
    Description=Selenium Server with ChromeDriver
    After=network.target
    
    [Service]
    User=your-login-username
    ExecStart=/usr/bin/java -Dwebdriver.chrome.driver=/full/path/to/chromedriver238 -jar /full/path/to/selenium-server-3.11.jar
    Restart=always
    RestartSec=10
    # If your machine uses a desktop environment, add this to ensure Chrome can access the display
    Environment=DISPLAY=:0
    
    [Install]
    WantedBy=multi-user.target
    
  2. Reload systemd and enable the service:
    sudo systemctl daemon-reload
    sudo systemctl enable --now selenium-chrome.service
    

This will start Selenium immediately, and it’ll automatically restart if it crashes or the machine reboots.

Windows

  1. Use a tool like NSSM (Non-Sucking Service Manager) to wrap the Selenium command into a Windows service:
    • Download NSSM, open Command Prompt as admin, navigate to the NSSM folder.
    • Run nssm install SeleniumChrome
    • In the NSSM GUI:
      • Path: Browse to your java.exe (usually in C:\Program Files\Java\your-jdk-version\bin\java.exe)
      • Arguments: -Dwebdriver.chrome.driver=C:\path\to\chromedriver238.exe -jar C:\path\to\selenium-server-3.11.jar
      • Set a Display name like "Selenium Server with ChromeDriver"
    • Save the service, then start it from Services.msc. You can also set it to start automatically on boot.

Temporary Workaround: Background Processes (For Quick Testing)

If you need a quick fix without setting up a service, you can run Selenium in the background so it stays running after you log out:

Linux/macOS

  • Use nohup to detach the process from your terminal:
    nohup java -Dwebdriver.chrome.driver=chromedriver238 -jar selenium-server-3.11.jar > selenium-output.log 2>&1 &
    
    The output will be logged to selenium-output.log, and the process will keep running even after you exit the terminal.
  • Or use screen to create a persistent terminal session:
    screen -S selenium-session
    # Run your Selenium start command here
    # Press Ctrl+A then D to detach from the session
    # Later, reattach with: screen -r selenium-session
    

Critical Checks to Ensure Remote Access Works

Even if Selenium is running, double-check these to avoid connection issues:

  • Firewall Rules: Make sure the Selenium port (default 4444) is open on the dedicated machine so your Jenkins server can reach it.
  • User Permissions: If running as a system service, ensure the service user has access to ChromeDriver, Chrome, and any required directories. Manual runs use your user account, but services often run as root or a dedicated system user—test the command as that user to confirm it works.
  • Codeception Configuration: Verify your Jenkins/Codeception setup is pointing to the correct Selenium URL: http://[selenium-machine-ip]:4444/wd/hub

内容的提问来源于stack exchange,提问作者Bob Arezina

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 08:58:04