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.
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
I'm not sure if it is a bug or just me being stupid but here is the case.
I want to build my image based on StandaloneChromeDebug. Following the Wiki:
Pull the repo.
Generate image:
$ make standalone_chrome_debug
Build the Dockerfile to insure that no errors arise:
$ docker build --no-cache etc/docker-selenium/StandaloneChromeDebug/
Set up my image to the docker-compose.yml like:
selenium-hub:
container_name: selenium-hub
build: ./etc/docker-selenium/StandaloneChromeDebug/
volumes:
- /dev/shm:/dev/shm
ports:
- "4444:4444"
- "5900:5900"
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
And... nothing. The container is running (no errros) but Selenium doesn't work, container log is empty, /opt/ folder is empty. What am i doing wrong? How to debug the thing?
Path is wrong, use build: /etc/docker-selenium/StandaloneChromeDebug/ without .
If you try to cd to ./etc/docker-selenium/StandaloneChromeDebug/, you will get an error.
version: "3.5"
services:
selenium-hub:
container_name: selenium-hub
build: /etc/docker-selenium/StandaloneChromeDebug/
volumes:
- /dev/shm:/dev/shm
ports:
- "4444:4444"
- "5900:5900"
environment:
- HUB_HOST=selenium-hub
- HUB_PORT=4444
Exapmle:
I feel you are using "build" tag in your compose file rather than "image". Please use "image" tag instead and see if that runs your image correctly.
Also can you please show how you are launching your docker services and what the output is?
Reference to build command
i want to launch 5 chrome and 5 firefox in docker container. I am using the below command but its giving the following error
The scale command is deprecated. Use the up command with the --scale flag instead.
ERROR: No such service: nodechrome
docker-compose scale nodechrome=5 nodefirefox=5
My docker-compose.yml file
version: '2'
services:
firefoxnode:
image: selenium/node-firefox-debug
volumes:
- /dev/shm:/dev/shm
depends_on:
- hub
environment:
HUB_HOST: hub
ports:
- "32772:5900"
chromenode:
image: selenium/node-chrome-debug
volumes:
- /dev/shm:/dev/shm
depends_on:
- hub
environment:
HUB_HOST: hub
ports:
- "32773:5900"
hub:
image: selenium/hub
ports:
- "4444:4444"
From where these names came? nodechrome and nodefirefox
Correct your command instead:
from:
docker-compose scale nodechrome=5 nodefirefox=5
to:
docker-compose scale chromenode=5 firefoxnode=5
Try this command:
docker-compose up --scale chrome=5
Verify the Grid by visiting: http://localhost:4444/ui/index.html#/
Refer: Documentation
docker run -d -p 4444:4444 --name selenium-hub selenium/hub
docker run -d --link selenium-hub:hub -v /dev/shm:/dev/shm selenium/node-chrome
Ubuntu 16.04
after these 2 commands, I have successfully setup a selenium hub and a selenium node. however current maxSession of this node is set to 1, I need increase to 5. How can I do that?
Thanks.
I highly recommend you use a docker compose file.
Below is a simple example you can use.
Just change the MAX_SESSION and MAX_INSTANCES to what you need.
version: "3.1"
services:
hub:
image: selenium/hub
container_name: "hub"
ports:
- "4444:4444"
chrome:
image: selenium/node-chrome
volumes:
- /dev/shm:/dev/shm
shm_size: 2gb
depends_on:
- hub
environment:
- HUB_HOST=hub
- HUB_PORT=4444
- SCREEN_WIDTH=1920
- SCREEN_HEIGHT=1080
- NODE_MAX_INSTANCES=2
- NODE_MAX_SESSION=2
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"