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

基于Docker的WebdriverIO容器化应用测试配置求助

Solution to Run WebdriverIO Tests Against Dockerized App via Docker Compose

Let's fix your setup step by step so you can run docker-compose up --build and have your tests execute successfully against the containerized app.

Key Issue to Fix

In your current WebdriverIO test, you're using http://0.0.0.0:3000 to access the app—but within the Docker Compose network, containers can't reach each other via localhost or 0.0.0.0. Instead, you need to use the service name defined in docker-compose.yml (which is app) as the hostname.

Step 1: Update WebdriverIO Test URL

Change the URL in your test script to point to the app service's hostname and port:

it("check if submit button works", function(done) {
    // Use the Docker service name "app" instead of 0.0.0.0/localhost
    browser.url('http://app:3000');
    var title = browser.getTitle();
    browser.click('#submitButton');
    console.log('App Title is: ' + title);
    browser.pause(3000);
    done(); // Don't forget to call done() to signal test completion!
});

Note: I added done() at the end—this is critical for async test functions to let the runner know the test is finished.

Step 2: Adjust Docker Compose Configuration

Your docker-compose.yml needs small tweaks to ensure all containers communicate properly:

  • The test service needs access to both app and selenium (tests talk to Selenium, which in turn talks to the app)
  • We'll replace legacy links with depends_on for clearer startup ordering
  • Optional: Add healthchecks to ensure tests don't run before the app is fully ready

Here's the updated docker-compose.yml:

version: '3' # Specify a modern compose version for better compatibility
services:
  app:
    build: .
    command: "yarn start"
    ports:
      - "3000:3000"
    # Optional healthcheck to confirm app is ready (add if your app takes time to boot)
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000"]
      interval: 5s
      timeout: 5s
      retries: 5

  selenium:
    image: 'selenium/standalone-chrome:3.11.0-californium'
    depends_on:
      - app
    log_driver: "none"

  test:
    build: .
    command: "yarn test --host selenium"
    depends_on:
      app:
        condition: service_healthy # Wait for app to be fully ready
      selenium:
        condition: service_started # Just need selenium to be running

Changes explained:

  • depends_on ensures services start in the right order (app → selenium → tests)
  • The healthcheck for app prevents tests from running before the app is responsive
  • Removed redundant expose directives (ports already handle external/internal access)

Step 3: Verify Dockerfile (No Changes Needed)

Your existing Dockerfile is solid—it correctly builds the Node app and starts it:

FROM node:8.10.0
ADD . /app
WORKDIR /app
RUN yarn
CMD ["yarn", "start"]

How to Run

Execute this command from your project root:

docker-compose up --build

This will:

  1. Build the app and test images from your Dockerfile
  2. Start the app container and wait for it to be healthy
  3. Spin up the Selenium Chrome container
  4. Run your WebdriverIO tests in the test container—tests will connect to Selenium, which accesses the app via http://app:3000

内容的提问来源于stack exchange,提问作者Mad-D

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.12 03:43:13