WebdriverIO从V6升级至V7后执行脚本遇TimeoutError及Selenium连接失败问题求助
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 theservicesarray 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 usingchromedriver@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-serviceis on7.19.5while other WDIO packages are on7.19.7. Minor version mismatches can cause compatibility issues — update all WDIO-related dependencies to the same version in yourpackage.json, then reinstall.
2. Validate WDIO Server Configuration
Double-check your wdio.conf.js for correct connection parameters:
- Ensure the
hostname,port, andpathare set properly (WDIO v7 still uses/wd/hubby default, but it's good to confirm):hostname: 'localhost', port: 4444, path: '/wd/hub', - Confirm the
runnerproperty 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-infobarsflag: It should be--disable-infobars(with double hyphens) instead ofdisable-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 :4444to find the process ID, then kill it via Task Manager. On Mac/Linux, uselsof -i :4444andkill <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:
- Install the service:
npm install @wdio/chromedriver-service --save-dev - Update your
wdio.conf.jsservices: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

