我创建了一个docker-compose.yml文件来运行一些存储在公共repo中的量角器测试。yml文件中创建了几个容器:
- shared_repo:在其中克隆测试
- 硒集线器:带有硒图像的容器
- chrome:带有selenium/nodechrome调试的容器
- 量角器:带节点的容器:12.14图像
Docker组成文件为:
version: '2.4'
services:
shared_repo:
image: library/postgres:13.2-alpine
container_name: shared_repo
command: bash -c "apk add git && sleep 5s && git clone -b main https://github.com/AlfredoBazo/opwDocker.git && mv /opwDocker /shared_repository && echo "TEST" && sleep 100s"
ports:
- 1603:1603
volumes:
- shared_repository:/e2e-shared
selenium-hub:
image: selenium/hub
container_name: selenium-hub
ports:
- "4444:4444"
chrome:
image: selenium/node-chrome-debug
container_name: chrome
volumes:
- /dev/shm:/dev/shm
ports:
- "5900:5900"
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
- CHROME_DRIVER_VERSION=chromedriver_81.0.4044.69
protractor:
image: node:12.14
container_name: protractor
working_dir: /e2e/
volumes:
- .:/e2e
ports:
- "9229:9229"
command: bash -c "npm install && npm i protractor && ./node_modules/protractor/bin/webdriver-manager update && ls -haltr && node node_modules/protractor/bin/protractor e2e/protractor.conf.js --cucumberOpts.tags=@docker"
depends_on:
- selenium-hub
- chrome
volumes:
shared_repository:
执行docker-compose up
时,出现错误通知:
[09:09:18]I/launcher-运行WebDriver量角器的1个实例
|[09:09:17]I/direct-直接使用ChromeDriver。。。量角器
|[09:09:18]E/runner-无法启动WebDriver会话。量角器|[09:09:18]E/launcher-错误:错误:服务器提前终止,状态为127量角器|在/e2e/node_modules/selement-webdriver/remote/index.js:252:52量角器|正在处理Ticks和Rejections(internal/process/task_queues.js:94:5(量角器|[09:09:18]E/launcher-进程退出,错误代码为100
这个项目有一些误解,但我认为主要问题是您使用的是本地Web驱动程序,而不是您提出的Selenium Hub实例。我认为我们可以将docker-compose.yaml文件简化为:
version: '2.4'
services:
selenium-hub:
image: selenium/hub
container_name: selenium-hub
ports:
- "4444:4444"
chrome:
image: selenium/node-chrome-debug
container_name: chrome
volumes:
- /dev/shm:/dev/shm
ports:
- "5900:5900"
depends_on:
- selenium-hub
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
- CHROME_DRIVER_VERSION=chromedriver_81.0.4044.69
protractor:
image: node:12.14
container_name: protractor
ports:
- "9229:9229"
command: bash -c "apt update && apt install -y git && git clone -b main https://github.com/AlfredoBazo/opwDocker.git && cd opwDocker && npm install && node node_modules/protractor/bin/protractor e2e-tests/protractor.conf.js --cucumberOpts.tags=@docker"
depends_on:
- selenium-hub
- chrome
您需要修改您的量角器.conf.js,添加以下行:
seleniumAddress: 'http://selenium-hub:4444/wd/hub'
并删除下一个:
directConnect: true
无论如何,我将包括一些其他的更改,这将是必要的,使它在这个拉请求中运行