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

在Docker(Codeship)中运行WebdriverIO遇到的问题

Hey Max, let's work through your WebdriverIO + Cucumber Docker issue step by step—this is a super common pain point with containerized E2E testing, but we can nail it down.

1. Fix the Java Installation Error First

The Java install fail is probably tied to your base Docker image choice. Different distros use different package managers, so let's align your Dockerfile with the right commands:

  • If you're using a Debian/Ubuntu-based Node image (like node:18-bullseye), use this to install OpenJDK:
    RUN apt-get update && \
        apt-get install -y --no-install-recommends openjdk-11-jre-headless curl && \
        apt-get clean && \
        rm -rf /var/lib/apt/lists/*
    
    ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk-amd64
    
  • If you're using an Alpine-based Node image (lighter weight, but stricter), use:
    RUN apk add --no-cache openjdk11-jre-headless curl
    
    ENV JAVA_HOME /usr/lib/jvm/java-11-openjdk
    

The --no-install-recommends and cleanup steps keep your image small, and setting JAVA_HOME ensures WebdriverIO can find Java correctly.

2. Fix Your wdio-docker-service Configuration

Even if you added the service, misconfigs often break containerized tests. Here's a validated setup for your wdio.conf.js:

exports.config = {
  // ... your existing config
  logLevel: 'debug', // Turn this on to get more detailed error logs
  services: [
    ['docker', {
      containers: [{
        image: 'selenium/standalone-chrome:114.0', // Match your WebdriverIO version
        portBindings: { '4444/tcp': 4444 },
        healthCheck: 'curl -s http://localhost:4444/wd/hub/status | grep "ready"',
        healthCheckInterval: 500,
        startupTimeout: 30000 // Give Selenium time to boot up
      }]
    }]
  ],
  capabilities: [{
    browserName: 'chrome',
    'goog:chromeOptions': {
      args: ['--no-sandbox', '--headless', '--disable-gpu', '--window-size=1920,1080']
      // --no-sandbox is critical for Chrome to run in Docker
    }
  }],
  baseUrl: 'http://your-react-container-name:3000' // Use container name, not localhost!
};

Key notes:

  • Never use localhost for your React app URL inside Docker—use the container name (from Docker Compose) or internal IP, since each container has its own localhost.
  • The --no-sandbox flag is non-negotiable for Chrome in containers (Docker doesn't provide full OS sandboxing).
3. Align Your Docker Environment with Local

Local vs Docker discrepancies are usually the root cause:

  • Match your Node version exactly: Use the same Node image tag in your Dockerfile as you have locally (e.g., node:18-bullseye instead of just node).
  • Ensure dependencies are fully installed: Use npm ci instead of npm install in your Dockerfile to get exact dependency versions from package-lock.json.
  • Wait for your React app to be ready: If your React app is also in Docker, use Docker Compose's depends_on with health checks to avoid running tests before the app is live. Example docker-compose.yml:
    version: '3.8'
    services:
      react-app:
        build: ./your-react-app-folder
        command: npm start
        healthcheck:
          test: ["CMD", "curl", "-f", "http://localhost:3000"]
          interval: 5s
          timeout: 5s
          retries: 5
      e2e-tests:
        build: ./your-e2e-folder
        depends_on:
          react-app:
            condition: service_healthy
        environment:
          - BASE_URL=http://react-app:3000
    
4. Troubleshooting to Pinpoint Exact Errors

If you're still stuck, debug inside the container:

  1. Spin up the container in interactive mode: docker run -it --rm <your-image> bash
  2. Run your test command manually: npm run wdio
  3. Check the exact error logs—this will tell you if it's a Selenium connection issue, Chrome startup fail, or something else.
  4. Verify Selenium is reachable: Inside the test container, run curl http://localhost:4444/wd/hub/status—you should get a JSON response saying ready: true.

Let me know if you share the specific error messages (from Java install or WebdriverIO runs) and I can help you drill down even further!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 07:11:18