I have multiple jenkins jobs, each attempt to start a selenium standalone container, although when multiple jobs run in parallel in the same jenkins slave, it throws the following error:
0.0.0.0:4444 failed: port is already allocated
Which is fair enough because the default port for the selenium standalone is set to 4444. My question is how I override the selenium standalone port? I thought it was related to ports: ... but clearly not... any ideas?
Below is my docker-compose file:
maven:
build: "."
links:
- "selenium:selenium"
working_dir: /code/
volumes:
- ".:/code"
entrypoint:
- mvn
- verify
- -Dwebdriver.remote.url=http://selenium:4444/wd/hub
selenium:
image: selenium/standalone-chrome:latest
ports:
- "4444:4444"
I have for instance another docker-compose file, slightly different, for instance:
maven_2:
build: "."
links:
- "selenium_2:selenium_2"
working_dir: /code/
volumes:
- ".:/code"
entrypoint:
- mvn
- verify
- -Dsome.additional.tags=test
- -Dwebdriver.remote.url=http://selenium_2:4444/wd/hub
selenium_2:
image: selenium/standalone-chrome:latest
ports:
- "4444:4444"
Related
I want to run selenum grid containers in GitLab. They would be: one selenium hub and two chrome node containers connected by a shared network. I know how to deploy those using a yaml file, but I have no idea how to start those containers in gitlab.
Ideally, the 3 cotainers would be started in pipleine, and then I would execute a script that would run some Selenium tests using the grid.
There's my yml file that would start selenium grid locally:
version: '3.7'
services:
selenium-1:
image: selenium/node-chrome:latest
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
selenium-2:
image: selenium/node-chrome:latest
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
selenium-hub:
image: selenium/hub:latest
expose:
- 4444
There's the script that would start the selenium tests:
#!/usr/bin/env bash
set -e
python -m pytest
The .gitlab-ci.yml I have so far:
stages:
- e2e
e2e:
stage: e2e
interruptible: false
services:
- selenium/hub:latest
- selenium/node-chrome:latest
script:
- bash run_test_page.sh
i basically use dind to run the compose file.
in the snippets below, i am trying to mention the essential bits, you can see a full project example here
also, i am using java and maven, not much change should be needed for python in your case
docker-compose used by the gitlab pipeline -
version: "3"
services:
selenium-chrome-01: &selenium-chrome
image: selenium/node-chrome:4.3.0-20220726
shm_size: 2gb
depends_on:
- selenium-hub
environment:
SE_EVENT_BUS_HOST: ${SELENIUM_SERVER_NAME}
SE_EVENT_BUS_PUBLISH_PORT: 4442
SE_EVENT_BUS_SUBSCRIBE_PORT: 4443
selenium-chrome-02:
<<: *selenium-chrome
selenium-hub:
image: selenium/hub:4.3.0-20220726
shm_size: 2gb
container_name: ${SELENIUM_SERVER_NAME}
ping:
image: alpine/curl
tests:
image: openjdk:11
working_dir: /app
volumes:
- ${CI_PROJECT_DIR}:/app
environment:
ENVIRONMENT: remote
SELENIUM_SERVER_URL: ${SELENIUM_SERVER_URL}
the compose file has 4 containers - 2 worker nodes, 1 hub, 1 to check the status of the hub, and 1 to run the tests
gitlab pipeline file -
stages:
- test
variables:
SELENIUM_SERVER_NAME: selenium
SELENIUM_SERVER_URL: http://${SELENIUM_SERVER_NAME}:4444
DOCKER_HOST: tcp://docker:2375
services:
- docker:20.10.16-dind
test:
stage: test
image: docker/compose
before_script:
- docker-compose up -d selenium-hub selenium-chrome-01 selenium-chrome-02
- sleep 10
- docker-compose run ping curl ${SELENIUM_SERVER_URL}/status
script:
- docker-compose run tests ./mvnw test -Dtest=TestClass
i think if you can configure shm_size on the gitlab runner's config, you can run the selenium grid as services which i feel is a better solution
is there any way to mention which version of selenoid/video-recorder should be used while selenoid is started? either in docker-compose.yml or command line?
I get following error, due to the docker pull limit issue, so I need to mention the specific version i have pulled earlier.
2021/04/08 10:35:59 [909] [5.64s] [SESSION_FAILED] [test] [x.x.x.x] [chrome-89.0] [x.x.x.x:4444] [-] [6] [start video container: create video container: Error response from daemon: No such image: selenoid/video-recorder:latest-release]
Following is my docker compose file.
version: '3'
services:
selenoid:
network_mode: bridge
image: aerokube/selenoid:1.10.1
volumes:
- "/opt/selenoid:/etc/selenoid"
- "/var/run/docker.sock:/var/run/docker.sock"
- "/opt/selenoid/video:/opt/selenoid/video"
environment:
- OVERRIDE_VIDEO_OUTPUT_DIR=/opt/selenium/video
- TZ=America/Montreal
- limit=10
command: ["-conf", "/etc/selenoid/browsers.json", "-video-output-dir", "/opt/selenoid/video"]
ports:
- "4444:4444"
selenoid-ui:
image: "aerokube/selenoid-ui"
network_mode: bridge
links:
- selenoid
ports:
- "8080:8080"
command: ["--selenoid-uri", "http://selenoid:4444"]
Respective image can be specified with -video-recorder-image flag in in command section. All available flags are listed here: https://aerokube.com/selenoid/latest/#_selenoid_cli_flags
I am trying to execute my selenium test on Jenkins node (Ubuntu) which has docker already installed. I added docker-compose build step plugin to my Jenkins project. When i try to build the project, I am getting an error in console -
$ docker-compose -f /home/jenkins/workspace/OM/TestWDM/docker-compose.yml up -d
Build step 'Docker Compose Build Step' changed build result to FAILURE
I am able to execute the project successfully on my local machine. I do have docker-compose.yml file in the root directory. I tried docker ps -a command just to see if it's partially . working, but it's not.
docker-compose file:
version: "3"
services:
selenium-hub:
restart: always
image: selenium/hub:latest
ports:
- "4444:4444"
#selenium-chrome
selenium-chrome:
restart: always
image: selenium/node-chrome-debug
stdin_open: true
links:
- selenium-hub:hub
#selenium-firefox
selenium-firefox:
restart: always
image: selenium/node-firefox-debug
links:
- selenium-hub:hub
chrome:
image: selenium/node-chrome
depends_on:
- selenium-hub
environment:
- HUB_PORT_4444_TCP_ADDR=selenium-hub
- HUB_PORT_4444_TCP_PORT=4444
firefox:
image: selenium/node-firefox
depends_on:
- selenium-hub
environment:
- HUB_PORT_4444_TCP_ADDR=selenium-hub
- HUB_PORT_4444_TCP_PORT=4444
The reason I am trying to use docker here because I was facing an issue with chrome binary not found without it. My expectation over here was to have my test run successfully on Jenkins node.
I use Docker to start my Selenium grid in network_mode = "host" so that I can access my local development site.
Both the hub and node started, but when I check http://localhost:4444/grid/console, there's no node. I wonder if there is any way to solve it.
More info:
Image(s): hub, node-chrome-debug
Docker-Selenium Image Version(s): 3.14.0-arsenic
Docker Version: 18.06.0-ce, build 0ffa825
OS: Ubuntu 18.04
My docker-compose file:
version: "3"
services:
selenium-hub:
image: selenium/hub:latest
container_name: selenium-hub
network_mode: "host"
ports:
- "4444:4444"
chrome:
image: selenium/node-chrome-debug:latest
depends_on:
- selenium-hub
network_mode: "host"
ports:
- "5900:5900"
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
Diego Molina figured out why it did not work.
It is because Chrome container will try to register to the name selenium-hub, which does not exist in the "host" network, and would only exist in the network that docker-compose creates.
To make it works, just set HUB_HOST=localhost.
My Selenium tests are designed to take screenshots on failure and add them to the report. The screenshots are displaying perfectly for chrome browsers, but Firefox screenshots are just white rectangles.The changelog says something about a "pass through" mode https://github.com/SeleniumHQ/selenium/blob/master/java/CHANGELOG which I've tried to disable, but nothing seems to be working.
Here's my docker compose file:
seleniumhub:
image: selenium/hub
ports:
- 4444:4444
firefoxnode:
image: selenium/node-firefox-debug
ports:
- 4577
links:
- seleniumhub:hub
environment:
- enablePassThrough=false
- NODE_MAX_INSTANCES=5
- NODE_MAX_SESSION=5
chromenode:
image: selenium/node-chrome-debug
ports:
- 4578
links:
- seleniumhub:hub
environment:
- NODE_MAX_INSTANCES=5
- NODE_MAX_SESSION=5
I don't think enablePassThrough is a valid environment variable. The configuration is generated from https://github.com/SeleniumHQ/docker-selenium/blob/master/NodeFirefox/generate_config which only contains your NODE_MAX_INSTANCES and NODE_MAX_SESSION.
However, there is a SE_OPTS variable from the parent base image in the entrypoint at https://github.com/SeleniumHQ/docker-selenium/blob/master/NodeBase/entry_point.sh#L28-L30. You can use this to set -enablePassThrough false. Your service definition in Docker Compose would be something like this instead:
firefoxnode:
image: selenium/node-firefox-debug
ports:
- 4577
links:
- seleniumhub:hub
environment:
- SE_OPTS="-enablePassThrough false"
- NODE_MAX_INSTANCES=5
- NODE_MAX_SESSION=5