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

WebdriverIO从V6升级至V7后执行脚本遇TimeoutError及Selenium连接失败问题求助

Troubleshooting WebdriverIO v7 Connection Failure to Selenium Server

After upgrading from WebdriverIO v6 to v7 (along with Node.js and npm versions), you're hitting a connection error to the Selenium server on localhost:4444 with ECONNREFUSED and timeout errors. Let's walk through the most likely fixes for this issue:

1. Verify Selenium Standalone Service Setup & Driver Compatibility

First, ensure your Selenium service is configured correctly and your drivers match your browser versions:

  • Check service configuration: In your wdio.conf.js, confirm the services array includes 'selenium-standalone' and there are no typos. Add verbose logging to debug service startup:
    services: [
      ['selenium-standalone', {
        logPath: './logs',
        args: { seleniumArgs: ['-debug'] }
      }]
    ]
    
  • Manual service test: Try starting the Selenium service manually with npx selenium-standalone start — if this fails, the issue is likely a driver-browser mismatch. You're using chromedriver@101.0.0, so confirm your local Chrome browser is on version 101.x. If not, update Chromedriver to match your current Chrome version (or vice versa).
  • Unify WDIO dependency versions: Your @wdio/selenium-standalone-service is on 7.19.5 while other WDIO packages are on 7.19.7. Minor version mismatches can cause compatibility issues — update all WDIO-related dependencies to the same version in your package.json, then reinstall.

2. Validate WDIO Server Configuration

Double-check your wdio.conf.js for correct connection parameters:

  • Ensure the hostname, port, and path are set properly (WDIO v7 still uses /wd/hub by default, but it's good to confirm):
    hostname: 'localhost',
    port: 4444,
    path: '/wd/hub',
    
  • Confirm the runner property is set to 'local' (default for WDIO v7, but worth verifying).

3. Clean Up ChromeOptions Parameters

Some Chrome flags in your configuration might be outdated or misformatted:

  • Remove --test-type=browser — this flag is deprecated in newer Chrome versions and unnecessary for testing.
  • Fix the disable-infobars flag: It should be --disable-infobars (with double hyphens) instead of disable-infobars=true.
    Updated ChromeOptions example:
    'goog:chromeOptions': {
      prefs: {
        download: {
          default_directory: 'xyzpath\\downloads',
          directory_upgrade: true,
          prompt_for_download: false
        },
        credentials_enable_service: false
      },
      localState: {
        'browser.enabled_labs_experiments': ['calculate-native-win-occlusion@2']
      },
      args: [
        '--window-size=1366,768',
        '--disable-infobars'
      ]
    }
    

4. Resolve Dependency & Environment Issues

  • Clean reinstall dependencies: Corrupted node_modules or lock files can cause unexpected issues. Run these commands to reset:
    rm -rf node_modules package-lock.json
    npm install
    
  • Update Node.js: You're on Node.js 14.15.1 — while WDIO v7 supports Node 14+, upgrading to the latest stable 14.x release (e.g., 14.21.3) can fix potential network-related bugs in older Node versions.
  • Check port occupancy: Ensure no other process is using port 4444. On Windows, run netstat -ano | findstr :4444 to find the process ID, then kill it via Task Manager. On Mac/Linux, use lsof -i :4444 and kill <PID>.

5. Try Alternative Driver Setup

If the Selenium Standalone service continues to fail, consider switching to WDIO's direct driver services (like chromedriver service) which don't require a separate Selenium server:

  1. Install the service: npm install @wdio/chromedriver-service --save-dev
  2. Update your wdio.conf.js services:
    services: ['chromedriver']
    

This bypasses the Selenium server entirely and connects directly to ChromeDriver, which can resolve connection issues related to Selenium standalone.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.28 20:39:10