【问题标题】:Why Cypress can't detect running webserver?为什么赛普拉斯无法检测到正在运行的网络服务器?
【发布时间】:2021-11-29 05:11:26
【问题描述】:

我的容器都在运行,我正在尝试针对它运行 Cypress 测试:

docker-compose.yml:

version: '3.7'

services:
  
  users:
    build:
      context: ./services/users
      dockerfile: Dockerfile
    volumes:
      - './services/users:/usr/src/app'
    expose:
      - 5000
    environment:
      - FLASK_APP=project/__init__.py
      - FLASK_ENV=development
      - APP_SETTINGS=project.config.DevelopmentConfig
      - DATABASE_URL=postgresql://postgres:postgres@users-db:5432/users_dev
      - DATABASE_TEST_URL=postgresql://postgres:postgres@users-db:5432/users_test
      - SECRET_KEY='hakuna matata'
    depends_on:
      - users-db

  client:
    build:
      context: ./services/client
      dockerfile: Dockerfile
    volumes:
      - './services/client:/usr/src/app'
      - '/usr/src/app/node_modules'
    ports:
      - 3007:3000
    environment:
      - CHOKIDAR_USEPOLLING=true
      - NODE_ENV=development
      - REACT_APP_USERS_SERVICE_URL=${REACT_APP_USERS_SERVICE_URL}
    depends_on:
      - users

  users-db:
    build:
      context: ./services/users/project/db
      dockerfile: Dockerfile
    expose:
      - 5432
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres

  nginx:
    build:
      context: ./services/nginx
      dockerfile: Dockerfile
    restart: always
    ports:
      - 80:80
    depends_on:
      - users
      - client

cypress.json:

{
    "baseUrl": "http://nginx:80",
    "video": false
}

码头工人ps:

CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS          PORTS                                       NAMES
97f91a4b3a81   tdd_nginx      "/docker-entrypoint.…"   56 minutes ago   Up 56 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp           tdd_nginx_1
089cd20326c1   tdd_client     "npm start"              56 minutes ago   Up 56 minutes   0.0.0.0:3007->3000/tcp, :::3007->3000/tcp   tdd_client_1
85dc333cc487   tdd_users      "/usr/src/app/entryp…"   56 minutes ago   Up 56 minutes   5000/tcp                                    tdd_users_1
696298d0ab2c   tdd_users-db   "docker-entrypoint.s…"   56 minutes ago   Up 56 minutes   5432/tcp                                    tdd_users-db_1

错误输出:

Cypress could not verify that the server set as your `baseUrl` is running:           

> http://nginx:80                                                                  
                                                                                                                                                 
Your tests likely make requests to this `baseUrl` and these tests will fail if you do
n't boot your server.                                                                
                                                                                                                                                 
Please start this server and then run Cypress again.

给它http://localhost 也没有用。 我正在从容器中运行测试运行器:docker run -it -v $PWD:/e2e -w /e2e cypress/included:3.2.0

环境:

docker 版本 20.10.11,构建 dea9396

赛普拉斯 3.2.0

操作系统:Ubuntu Linux 20.04

欢迎提出任何建议。

【问题讨论】:

  • 当所有容器都在运行时,打开浏览器并转到http://nginx:80http://localhost:80,它们可以工作吗?

标签: docker cypress


【解决方案1】:

在这种情况下,您必须在运行 Cypress 时使用您的 host network,因为如果您不使用相同的 docker network,则无法从赛普拉斯访问 http://nginx:80。您要么必须使用 Docker Compose 创建的同一网络运行它,要么通过以下方式将赛普拉斯容器网络绑定到主机网络:

docker run -it -v $PWD:/e2e -w /e2e --network=host --ipc=host cypress/included:3.2.0

现在定位到localhost:80,而不是nginx:80

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-10
    • 1970-01-01
    • 2023-02-10
    • 2020-12-23
    • 2019-05-29
    • 2022-09-30
    • 2023-04-04
    • 2019-12-27
    相关资源
    最近更新 更多