In a nutshell, there is additional container as a test runner which cannot reach the selenium-hub. So, tests are failed.
This container was added for running test on cloud by using cloud build.
I created docker-compose as below:
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
After containers start to work successfully, when I run npm run test
for running selenium js tests, I got successful results and video recording in expected directory. But it should be automated as well. npm run test
should be triggered somehow.
In our CI/CD process, cloudbuild.yaml file is added for running on cloud.
steps:
- name: 'docker/compose:1.29.2'
args: ['run','test']
- name: 'docker/compose:1.29.2'
args: ['stop']
timeout: 60s
Cloud build should trigger the new container below which is added to docker-compose file as test runner:
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
However with test container, tests are failed and get the error below:
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. > [email protected] 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
Containers:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7ca30366bc09 node:16-alpine "sh -c 'cd /test\nnpm…" 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
I can ping selenuim-hub from e2e-tests_test_1 container, but cannot do it reverse(ping e2e-tests_test_1 from selenium-hub).
About current network:
>> % 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": {}
}
]
It seems test node cannot reach to 127.0.0.1:4444
What should I do for solving this issue? It'd be good to hear alternative solutions.
Thanks in advance.
You need to wait for the Grid to be ready before running tests. I documented a few approaches for this on the project's README, please check https://github.com/seleniumhq/docker-selenium/#waiting-for-the-grid-to-be-ready