Ruby Cucumber框架中Chrome Driver启动失败问题求助
Hey there, let's work through this Chrome driver issue you're hitting with your Ruby Cucumber setup. Reinstalling Chrome didn't cut it, so let's dive into the most likely fixes that usually resolve this:
1. Match ChromeDriver Version to Your Chrome Browser
This is the #1 culprit for this kind of error. When you reinstall Chrome, it updates to the latest version, but your existing ChromeDriver might be outdated. Here's how to fix it:
- Open Chrome, go to Settings > About Chrome to check your browser version (e.g., 125.0.6422.141).
- Download the exact matching ChromeDriver version (make sure the major version numbers align perfectly).
- Replace the
chromedriver.exein yourE:/path with the new one, or update thedriver_pathin yourenv.rbto point to the new file.
2. Verify Your Driver Path & File
Double-check that your driver_path is correct:
- Ensure the file exists at
E:/chromedriver.exe(no typos in the filename—sometimes the downloaded file has a suffix likechromedriver_win32.exethat you need to rename first). - On Windows, you can also use double backslashes if you prefer:
"E:\\chromedriver.exe"(though forward slashes should work too).
3. Tweak Your Code for Better Compatibility
Try updating your env.rb code with these adjustments to avoid common Windows-related issues:
require 'selenium-webdriver' Before do # Add Chrome options to bypass sandbox or resource limit issues options = Selenium::WebDriver::Chrome::Options.new options.add_argument('--no-sandbox') options.add_argument('--disable-dev-shm-usage') options.add_argument('--start-maximized') # Optional: Start browser in full screen # Set driver path (can skip this if you add ChromeDriver to system PATH) Selenium::WebDriver::Chrome.driver_path = "E:/chromedriver.exe" @driver = Selenium::WebDriver.for(:chrome, options: options) # Use instance variable instead of global $driver end After do @driver.quit if @driver # Ensure browser closes after each scenario to avoid leaks end
Note: Using @driver (instance variable) instead of $driver (global variable) is better practice—it prevents conflicts between test scenarios.
4. Check System Permissions & PATH
- If the driver still won't run, right-click
chromedriver.exeand go to Properties > Security to confirm your user account has "Read & Execute" permissions. - For easier setup long-term, add the folder containing
chromedriver.exeto your Windows System PATH. Then you can remove thedriver_pathline entirely—Selenium will automatically find the driver.
If you can share the full error message (the part after the initial WARNING), that would help narrow it down even more, but these steps should cover most cases where reinstalling Chrome didn't fix the issue.
内容的提问来源于stack exchange,提问作者Abdul Mukheem Shaik

