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

WebdriverIO Mocha框架下chromedriver报错ECONNREFUSED及会话请求失败求助

Troubleshooting WebdriverIO + Mocha Issues: Chromedriver Connection & Session Failures

Hey there, let’s break down the two issues you’re facing with WebdriverIO and Mocha, step by step.

1. Fixing ERROR: connect ECONNREFUSED 127.0.0.1:4444 (Chromedriver Issues)

This error almost always means WebdriverIO can’t reach a running Chromedriver instance on port 4444. Try these targeted fixes:

  • Verify Chromedriver compatibility & manual startup
    The #1 cause here is a mismatch between your Chrome browser version and Chromedriver version. Double-check they’re aligned, then download the exact Chromedriver version for your Chrome release if needed. Test manually starting it with:

    chromedriver --port=4444
    

    If you get version-related errors here, that’s your root problem.

  • Check WebdriverIO config for auto-start settings
    In your wdio.conf.js, make sure the Chromedriver service is set to auto-launch the driver (so you don’t have to run it manually):

    exports.config = {
      // ... other config
      services: ['chromedriver'],
      chromedriver: {
        start_process: true, // WebdriverIO handles launching Chromedriver
        port: 4444 // Match this to the port in your error
      }
    }
    

    If start_process was set to false, WebdriverIO expects you to run Chromedriver manually first.

  • Free up port 4444
    Another process might be hogging the port. On macOS, find the culprit with:

    lsof -i :4444
    

    Kill it using kill -9 <PID> (replace <PID> with the process ID from the output), then restart your tests.

2. Resolving Session Request Failures (Firefox Session)

Looking at your logs, you’re trying to spin up a Firefox session but it’s failing. Here’s how to debug this:

  • Ensure GeckoDriver is properly configured
    Firefox relies on GeckoDriver, not Chromedriver. Add the GeckoDriver service to your WebdriverIO config and update your capabilities to use modern syntax:

    exports.config = {
      // ... other config
      services: ['geckodriver'], // Add this if missing
      capabilities: [
        {
          browserName: 'firefox',
          platformName: 'macOS', // Use `platformName` instead of the outdated `platform`
          browserVersion: 'your-firefox-version' // Replace with your actual Firefox version (avoid `latest` on older macOS like 10.12)
        }
      ]
    }
    

    Note: desiredCapabilities is deprecated in newer WebdriverIO versions—switch to capabilities instead.

  • Match GeckoDriver to your Firefox version
    Older Firefox builds (especially those compatible with macOS 10.12) require specific GeckoDriver versions. Check the GeckoDriver release notes to find the right match for your installed Firefox.

  • Simplify your capabilities
    Your log shows extra fields like build, loggingPrefs, etc.—strip these down to the essentials first to rule out conflicting settings:

    capabilities: [
      {
        browserName: 'firefox',
        platformName: 'macOS',
        acceptSslCerts: true,
        pageLoadStrategy: 'normal'
      }
    ]
    

General Troubleshooting Tips

  • Update your WebdriverIO dependencies to compatible versions:
    npm install webdriverio@latest @wdio/mocha-framework@latest @wdio/chromedriver-service@latest @wdio/geckodriver-service@latest
    
  • Enable debug logging in wdio.conf.js (logLevel: 'debug') to get granular details about why the session is failing.
  • Clean and reinstall dependencies to rule out corrupt installs:
    rm -rf node_modules package-lock.json
    npm install
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 07:39:15