I am trying to Run Behat BDD Tests using docksal/behat docker-compose ( ref: https://github.com/docksal/behat
Looking at the Zalenium documentation
Pull docker-selenium
docker pull elgalu/selenium
# Pull Zalenium
docker pull dosel/zalenium
# Run it!
docker run --rm -ti --name zalenium -p 4444:4444 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /tmp/videos:/home/seluser/videos \
--privileged dosel/zalenium start
# Point your tests to http://localhost:4444/wd/hub and run them
integrating docksal/behat and zelenium is not clear
using. the. following docker-compose.yml
# The purpose of this -test example is for the e2e tests of this project
#
# Usage:
# docker-compose -p grid up --force-recreate
# docker-compose -p grid scale mock=1 hub=1 chrome=3 firefox=3
version: '2.1'
services:
hub:
image: elgalu/selenium
ports:
- ${VNC_FROM_PORT-40650}-${VNC_TO_PORT-40700}:${VNC_FROM_PORT-40650}-${VNC_TO_PORT-40700}
zalenium:
image: "dosel/zalenium"
container_name: zalenium
hostname: zalenium
tty: true
volumes:
- /tmp/videos:/home/seluser/videos
- /var/run/docker.sock:/var/run/docker.sock
privileged: true
ports:
- 4444:4444
command: >
start --desiredContainers 2
--maxDockerSeleniumContainers 8
--screenWidth 800 --screenHeight 600
--timeZone "America/New_York"
--videoRecordingEnabled false
--sauceLabsEnabled false
--browserStackEnabled false
--testingBotEnabled false
--cbtEnabled false
--startTunnel false
behat:
hostname: behat
image: docksal/behat
volumes:
- .:/src
# Run a built-in web server for access to HTML reports
ports:
- 8000:8000
entrypoint: "php -S 0.0.0.0:8000"
# browser:
# hostname: browser
# Pick/uncomment one
# image: selenium/standalone-chrome
#image: selenium/standalone-firefox
I can bring up the following containers:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9a1620da4c71 elgalu/selenium:latest "entry.sh" 4 seconds ago Up 4 seconds 40001/tcp, 50001/tcp zalenium_52g9tn
82975a246be8 elgalu/selenium:latest "entry.sh" 5 seconds ago Up 4 seconds 40000/tcp, 50000/tcp zalenium_fdCCbk
862017957ba1 docksal/behat "php -S 0.0.0.0:8000" 2 days ago Up 8 seconds 0.0.0.0:8000->8000/tcp behat-selenium_behat_1
2da2c165a211 elgalu/selenium "entry.sh" 4 days ago Up 6 seconds 0.0.0.0:40650-40700->40650-40700/tcp behat-selenium_hub_1
10df443d8378 dosel/zalenium "entry.sh start --de…" 4 days ago Up 8 seconds 0.0.0.0:4444->4444/tcp, 4445/tcp zalenium
now looking at run-behat in examples directory:
basically executing
$docker exec $(docker-compose ps -q behat) behat --colors --format=pretty --out=std --format=html --out=html_report "$#"
I get an error:
Error response from daemon: Container 411c6b89d8f382a64ed567dbe4d02a2840f06d4778f1ce7bcf955e720d96ab02 is not running
whereas:
$ docker-compose ps -q behat
411c6b89d8f382a64ed567dbe4d02a2840f06d4778f1ce7bcf955e720d96ab02
Perhaps in behat.yml wd_host: http://localhost:4444/wd/hub
it should not point to localhost, but rather the hub? since wd_host should point to the selenium grid running in the container?
This
hub:
image: elgalu/selenium
ports:
- ${VNC_FROM_PORT-40650}-${VNC_TO_PORT-40700}:${VNC_FROM_PORT-40650}-${VNC_TO_PORT-40700}
is not needed at all.
Just point your tests to the zalenium service, since you are using docker-compose.
http://zalenium:4444/wd/hub
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
docker pull elgalu/selenium
docker pull dosel/zalenium
docker run --rm --name zalenium -p 4444:4444
-v /var/run/docker.sock:/var/run/docker.sock
-e "zalenium_http_proxy=http://example.com:80"
-e "zalenium_https_proxy=http://example.com:80"
-e zalenium_no_proxy="localhost,127.0.0.1,http://example.com"
--privileged dosel/zalenium start --desiredContainers 2 --maxDockerSeleniumContainers 2 --maxTestSessions 5
On using proxy while running zalenium container ,the node container closes abruptly and new one created after every 2 minutes.So if test take more than 2 minutes then getting failed with below error
WebDriverError: cannot forward the request Failed to connect to /192.168.64.4:40000
After every 2 minutes seeing node get restarted
zalenium | 20:16:50.110 [Thread-10] INFO d.z.e.z.registry.ZaleniumRegistry - Registered a node http://172.18.0.5:40000
zalenium | 20:16:50.899 [Thread-11] INFO d.z.e.z.registry.ZaleniumRegistry - Registered a node http://172.18.0.6:40001
zalenium | 20:18:52.592 [http://172.18.0.5:40000] INFO d.z.e.z.p.DockerSeleniumRemoteProxy - Marking node down.
zalenium | 20:18:52.637 [http://172.18.0.6:40001] INFO d.z.e.z.p.DockerSeleniumRemoteProxy - Marking node down.
zalenium | 20:19:08.529 [Thread-12] INFO d.z.e.z.registry.ZaleniumRegistry - Registered a node http://172.18.0.5:40002
zalenium | 20:19:09.735 [Thread-13] INFO d.z.e.z.registry.ZaleniumRegistry - Registered a node http://172.18.0.6:40003
Please let me know the solution for this issue.
Try the below command with the latest docker and images
docker run --rm --name zalenium -p 4444:4444 -v /var/run/docker.sock:/var/run/docker.sock -e "zalenium_http_proxy=http://example.com:80" -e "zalenium_https_proxy=http://example.com:80" -e zalenium_no_proxy="localhost,127.0.0.1,http://example.com,172.*" --privileged dosel/zalenium start --desiredContainers 2 --maxDockerSeleniumContainers 2 --maxTestSessions 5
Tests are written with python behave and executed with Docker. Locally on Mac/Windows/Linux all 110 test steps complete under 4 minutes using the same sites whereas on CI agent (AWS) it takes 120-160 mins. Video showed that browser is spinning for about 4 minutes between steps. Is there a way to debug selenium to find out what resource is loading slow?
Selenium DEBUG logging is not helpful. After submit it took 4 minutes for a POST request to complete:
04-Apr-2018 20:13:01 DEBUG:selenium.webdriver.remote.remote_connection:POST http://127.0.0.1:4444/wd/hub/session/a6975e2107e574693fb48f21420c1850/element {"using": "id", "value": "submit", "sessionId": "a6975e2107e574693fb48f21420c1850"}
04-Apr-2018 20:13:01 DEBUG:selenium.webdriver.remote.remote_connection:Finished Request
04-Apr-2018 20:13:01 DEBUG:selenium.webdriver.remote.remote_connection:POST http://127.0.0.1:4444/wd/hub/session/a6975e2107e574693fb48f21420c1850/element/0.7198908368495902-4/click {"id": "0.7198908368495902-4", "sessionId": "a6975e2107e574693fb48f21420c1850"}
04-Apr-2018 20:17:00 DEBUG:selenium.webdriver.remote.remote_connection:Finished Request
docker-compose.yml:
version: '3.4'
services:
test:
build:
context: .
image: qa-automation
network_mode: host
environment:
LOCAL: "false"
BROWSER: "${TEST_BROWSER:-chrome}"
SERVER: "${TEST_URL:-https://example.com}"
selenium:
image: elgalu/selenium:3.11.0-p5
shm_size: 2g
ports:
- 4444:24444
- 6000:25900
environment:
SCREEN_WIDTH: 1920
SCREEN_HEIGHT: 1080
TZ: "US/Central"
VIDEO_FILE_NAME: "${TEST_BROWSER:-chrome}"
volumes:
- ./target/videos:/videos
Dockerfile:
FROM python:3.6.4-alpine3.7
# Install utilities
RUN apk --update --no-cache add bash curl git && rm -rf /var/cache/apk/*
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
# see .dockerignore
COPY . .
ENTRYPOINT ["bin/docker-entrypoint.sh"]
CMD ["behave"]
requirements.txt:
appdirs==1.4.3
behave==1.2.6
packaging==16.8
pyparsing==2.2.0
requests==2.13.0
selenium==3.11.0
six==1.11.0
test.sh:
#!/usr/bin/env bash
docker-compose up -d selenium
docker-compose exec selenium wait_all_done 30s
docker-compose exec selenium start-video
# run tests
docker-compose build test
docker-compose run test bash -c "behave"
ret_code=$?
echo "===== Auto Tests COMPLETED ====="
# clean up containers
docker-compose exec selenium stop-video
docker-compose exec selenium stop
docker-compose down
exit $ret_code
Steps I have taken already
1. Downloaded and installed Docker Toolbox for windows
2. Open Docker Quickstart terminal
3. Entered the below commands to pull the docker images from dockerhub and run them
docker pull selenium/hub
docker pull selenium/node-chrome
docker pull selenium/node-firefox
docker run -d -P \--name hub selenium/hub
docker run -d --link hub:hub -P \--name chrome selenium/node-chrome
docker run -d --link hub:hub -P \--name firefox selenium/node-firefox
It appears to be running when I type docker logs hub but I am unable to route my tests to the hub's address on the virtualbox VM using seleniumAddress in my conf.js file or see it using http://ipAddress:4444/grid/console .
Ideally I would like to use this set up to expand the amount of parallel test instances I can run.
Unfortunately the selenium docker image might be broken since 4 days ago but you can try my alternative one:
Pull the image and run as many containers as you need
docker pull elgalu/selenium
docker run -d --name=grid4 -p 4444:24444 -p 5904:25900 \
-v /dev/shm:/dev/shm -e VNC_PASSWORD=hola elgalu/selenium
docker run -d --name=grid5 -p 4445:24444 -p 5905:25900 \
-v /dev/shm:/dev/shm -e VNC_PASSWORD=hola elgalu/selenium
docker run -d --name=grid6 -p 4446:24444 -p 5906:25900 \
-v /dev/shm:/dev/shm -e VNC_PASSWORD=hola elgalu/selenium
Wait until the all the grids started properly before starting the tests (Optional but recommended)
docker exec grid4 wait_all_done 30s
docker exec grid5 wait_all_done 30s
docker exec grid6 wait_all_done 30s
After this, Selenium should be up and running at http://localhost:4444/wd/hub. Open the url in your browser to confirm it is running.
If you are using Mac (OSX) or Microsoft Windows localhost won't work! Find out the correct IP through boot2docker ip or docker-machine ip default.
So set the selenium port accordingly for each of your test:
1st test should connect to http://ipAddress:4444/wd/hub
2nd test to http://ipAddress:4445/wd/hub
3rd test to http://ipAddress:4446/wd/hub
You can run as many as your hardware can take.
Take a look at the Protractor Cookbook w/ Docker. The instructions are listed step-by-step using selenium-grid and docker compose. Docker-selenium issue #208 has been fixed.
So you'll need to pull down the latest images*:
docker pull selenium/hub:latest
docker pull selenium/node-chrome-debug:latest
Start the selenium grid:
docker run -d -p 4444:4444 --name selenium-hub selenium/hub:latest
Then add selenium nodes. I like to use the chrome-debug and firefox-debug versions to VNC to watch the tests.
docker run -d -p <port>:5900 --link selenium-hub:hub selenium/node-chrome-debug:latest
After linking your selenium grid, this should be enough to run your Protractor test using the seleniumAddress: 'http://localhost:4444/wd/hub'.
For debugging, find the VNC port for the container with:
docker port <container-name or container-id> 5900
and access it via VNC Viewer.
Note:
At the time of this writing, 'latest' appears to be tied to a ~2.53.1 version of selenium server. As of Protractor 4.0.11 (the latest version of Protractor), this is the supported version that should be used. Note that the instructions on the Selenium-docker GitHub appear to be for tailored for selenium server 3.0.1.
You can use below compose file to setup grid and access via VNC
**# To execute this docker-compose yml file use docker-compose -f up
**# Add the "-d" flag at the end for deattached execution****
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"
command I use:
docker-compose -f .\docker-compose.yml up -d
Source :
https://github.com/SeleniumHQ/docker-selenium
I write the test on Mac and everything works well.
Then I migrated the test script to server's (ubuntu on Linode) docker container.
The test was failed,
#driver.current_url will show me https://m.flyscoot.com/
but actually I gave the url http://www.flyscoot.com/index.php/en/ to open.
My test was failed by unexpectedly redirected to https://m.flyscoot.com/
I've no idea why this happened?
I guess the web driver was be thought a mobile version browser.
How could I cheat the website so that I can get the identical test result ?
Test failed environment is running on selenium/node-firefox-debug and selenium/hub from this repo https://github.com/SeleniumHQ/docker-selenium
Dockerfile
FROM selenium/node-firefox-debug
....
CMD ["/bin/bash", "/opt/bin/entry_point.sh"]
docker-compose
hub:
image: selenium/hub
ports:
- 4444:4444
web:
build: .
volumes:
- .:/crawler
ports:
- 5900:5900
links:
- hub:hub
entry_point.sh
#!/bin/bash
# RUN THE CRON JOB
export GEOMETRY="$SCREEN_WIDTH""x""$SCREEN_HEIGHT""x""$SCREEN_DEPTH"
xvfb-run --server-args="$DISPLAY -screen 0 $GEOMETRY -ac +extension RANDR" \
java -jar /opt/selenium/selenium-server-standalone.jar \
-role node \
-hub http://$HUB_1_PORT_4444_TCP_ADDR:$HUB_1_PORT_4444_TCP_PORT/grid/register \
-browser browserName=firefox
--background