简而言之,有一个额外的容器作为测试运行器,它不能到达selenium-hub。因此,测试失败。
添加此容器用于使用云构建在云上运行测试。
我创建的docker-compose如下:
version: "3"
services:
selenium-hub:
image: selenium/hub:4.0.0-rc-1-prerelease-20210804
container_name: selenium-hub
ports:
- "4444:4444"
expose:
- 4444
chrome:
image: selenium/node-chrome:4.0.0-rc-1-prerelease-20210804
shm_size: 2gb
depends_on:
- selenium-hub
environment:
- SE_EVENT_BUS_HOST=selenium-hub
- SE_EVENT_BUS_PUBLISH_PORT=4442
- SE_EVENT_BUS_SUBSCRIBE_PORT=4443
ports:
- "6900:5900"
chrome_video:
image: selenium/video:ffmpeg-4.3.1-20210804
volumes:
- /Users/videos:/videos
depends_on:
- chrome
environment:
- DISPLAY_CONTAINER_NAME=chrome
- FILE_NAME=chrome_video.mp4
容器开始工作成功后,当我运行npm run test
运行selenium js测试时,我得到了成功的结果,并在预期的目录中录制了视频。但它也应该是自动化的。npm run test
应该被触发。
在我们的CI/CD过程中,cloudbuild。为在云上运行添加了Yaml文件。
steps:
- name: 'docker/compose:1.29.2'
args: ['run','test']
- name: 'docker/compose:1.29.2'
args: ['stop']
timeout: 60s
云构建应该触发下面添加到docker-compose文件中作为测试运行器的新容器:
test:
image: node:16-alpine
entrypoint:
- sh
- -c
- |-
cd /test
npm install
sleep 3
npm run test
volumes:
- .:/test
depends_on:
- selenium
network_mode: host
但是对于测试容器,测试失败并得到以下错误:
24 packages are looking for funding run `npm fund` for details 2 moderate severity vulnerabilities To address all issues, run: npm audit fix Run `npm audit` for details. > js_mocha_selenium@1.0.0 test > mocha test Preliminary steps for End to End Tests initalising the session... 1) Login closing the session... 2) "after each" hook for "Login" 0 passing (108ms) 2 failing 1) Preliminary steps for End to End Tests Login: Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444 at ClientRequest.<anonymous> (node_modules/selenium-webdriver/http/index.js:273:15) at ClientRequest.emit (node:events:394:28) at Socket.socketErrorListener (node:_http_client:447:9) at Socket.emit (node:events:394:28) at emitErrorNT (node:internal/streams/destroy:157:8) at emitErrorCloseNT (node:internal/streams/destroy:122:3) at processTicksAndRejections (node:internal/process/task_queues:83:21) 2) Preliminary steps for End to End Tests "after each" hook for "Login": Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444 at ClientRequest.<anonymous> (node_modules/selenium-webdriver/http/index.js:273:15) at ClientRequest.emit (node:events:394:28) at Socket.socketErrorListener (node:_http_client:447:9) at Socket.emit (node:events:394:28) at emitErrorNT (node:internal/streams/destroy:157:8) at emitErrorCloseNT (node:internal/streams/destroy:122:3) at processTicksAndRejections (node:internal/process/task_queues:83:2
容器:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7ca30366bc09 node:16-alpine "sh -c 'cd /testnnpm…" About a minute ago Up About a minute e2e-tests_test_1
fdf43be1b4da selenium/video:ffmpeg-4.3.1-20210804 "/opt/bin/entry_poin…" 16 minutes ago Up About a minute 9000/tcp e2e-tests_chrome_video_1
92c023b15cb6 selenium/node-chrome:4.0.0-rc-1-prerelease-20210804 "/opt/bin/entry_poin…" 16 minutes ago Up About a minute 0.0.0.0:6900->5900/tcp, :::6900->5900/tcp e2e-tests_chrome_1
86002f3d1eb9 selenium/hub:4.0.0-rc-1-prerelease-20210804 "/opt/bin/entry_poin…" 16 minutes ago Up About a minute 4442-4443/tcp, 0.0.0.0:4444->4444/tcp, :::4444->4444/tcp selenium-hub
我可以pingselenuim-hub从e2e-tests_test_1pinge2e-tests_test_1从selenium-hub) .
关于当前网络:
>> % docker network inspect -v host
[
{
"Name": "host",
"Id": "36e4060f18be618399692294d10cf6be3478c1bf5190ea035b002ca87c18276b",
"Created": "2021-06-30T10:36:33.170635189Z",
"Scope": "local",
"Driver": "host",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": []
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {},
"Labels": {}
}
]
测试节点似乎无法到达127.0.0.1:4444
我该怎么做才能解决这个问题?如果能听到其他的解决方案就好了。
提前感谢。
在运行测试之前需要等待网格准备好。我在项目的README中记录了一些方法,请查看https://github.com/seleniumhq/docker-selenium/#waiting-for-the-grid-to-be-ready