我有一个任务在docker中运行Python硒测试。 首先,我使用docker-compose运行Selenium网格:
version: "3"
services:
selenium-hub:
image: selenium/hub:3.141.59-gold
container_name: selenium-hub
ports:
- "4444:4444"
chrome:
image: selenium/node-chrome-debug
volumes:
- /dev/shm:/dev/shm
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
ports:
- 4577
firefox:
image: selenium/node-firefox-debug
volumes:
- /dev/shm:/dev/shm
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
ports:
- 4578
然后我在安装pytest并复制我的测试框架的地方构建容器
FROM python:3.7-alpine3.8
COPY . .
RUN pip install -r requirements.txt
# update apk repo
RUN echo "http://dl-4.alpinelinux.org/alpine/v3.8/main" >> /etc/apk/repositories && \
echo "http://dl-4.alpinelinux.org/alpine/v3.8/community" >> /etc/apk/repositories
# install chromedriver
RUN apk update
RUN apk add chromium chromium-chromedriver
EXPOSE 3000
ENV PORT 3000
# install selenium
RUN pip install selenium==3.13.0
然后我尝试在容器中运行测试文件:
docker run 3ae7b37d8a7f pytest tests/basic_smoke_test.py --browser docker -v
结果我看到网络错误:
urllib.error.URLError: