The path to the driver executable must be set by the webdriver.chrome.driver , selenium-grid on docker - java

I am using docker-containers to setup a selenium grid. Docker is installed as docker-quickstart on a windows 10 machine.
I have exposed the selenium hub container using docker run -d -p 4444:4444 --name selenium-hub selenium/hub and can access the console at http://192.168.99.102:4444/grid/console.
Linked a couple of chrome nodes to the selenium-hub using docker run -d --link selenium-hub:hub selenium/node-chrome-debug
I have made the following changes to my java code
DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setPlatform(Platform.LINUX);
dc.setBrowserName(“chrome”);
RemoteWebDriver driver=new RemoteWebDriver(new URL("http://192.168.99.102:4444/wd/hub"), dc);
setWebDriver(driver);
The tests are set to run parallel using maven-surefire plugin, and everything works fine when I run the tests using mvn clean install -f pom.xml -Denv=staging -Dbrowser=chrome -Dwebdriver.chrome.driver=c:\windows
The problem is, when I use RemoteWebDriver running in docker containers, I can not use -Dwebdriver.chrome.driver=c:\windows
If I run the command without the above parameter I get the following error.
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
What Should I provide in place of webdriver.chrome.driver ?

Related

How to configure docket to make my selenium hub accessible from outside?

I have a jenkins running some Junit tests connecting to a remote selenium hub.
On this hub I want to spawn a docker image representing a google chrome to run my tests against.
These are the commands I'm using to set up the environment:
sudo docker run -d -p 4444:4444 --name selenium-hub selenium/hub
sudo docker run -d --link selenium-hub:hub selenium/node-chrome
If I make a
curl -i http://localhost:4444/grid/console
it works fine! Anyway when trying to connect to this machine remotely I just get connection refused.
I'd say it's because the docker runs the whole thing on localhost, but I'd like to make this endpoint accessible at least for hosts in the local network.
Is this possible?

How to point RemoteWebDriver to one of the multiple standalone docker selenium standalone chrome browsers?

I've requirement to run test cases on separate chrome browsers running inside docker container.
I've install chrome docker containers as below
docker run -d -p 4444:4444 -p 5900:5900 -v /dev/shm:/dev/shm selenium/standalone-chrome-debug:3.8.1-francium
docker run -d -p 4444:4444 -p 5901:5900 -v /dev/shm:/dev/shm selenium/standalone-chrome-debug:3.8.1-francium
I have scripts which does unique tasks like analytics testing, performance testing etc so I can't use Grid approach here.
This is what I do in case of single chrome browser but I need to point to a particular docker container image
WebDriver driver = new RemoteWebDriver(
new URL("http://localhost:4444/wd/hub"),
DesiredCapabilities.firefox());
Got it working with help of comment from #Flore B.
docker run -d -p 5902:4444 -p 5903:5900 -v /dev/shm:/dev/shm selenium/standalone-chrome-debug:3.8.1-francium
RemoteWebDriver url
http://0.0.0.0:5902/wd/hub

Connection refused error with selenium running in docker

While trying nto dockerise selenium End2End tests using the selenium docker image 'selenium/standalone' i get the error : Error retrieving a new session from the selenium server Connection refused! Is selenium server started?
ye selenium server starts up according to the console output..any ideas ?
FROM selenium/standalone-chrome
USER root
# installing node
RUN apt-get update
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_7.x | bash
RUN apt-get install -y nodejs
RUN node -v
RUN npm -v
# Installing Yarn
#RUN rm -r /usr/local/bin/yarn
RUN npm install -g -y yarn
ENV PATH $PATH:/usr/local/bin/yarn
#copying files
WORKDIR /app
COPY . .
# debug
RUN ls -alh .
#installing yarn
RUN yarn install
EXPOSE 4444
RUN yarn
CMD yarn test
The problem is your approach of solving this. See you are inheriting your image from selenium/standalone-chrome which is supposed to run a Selenium browser. Now is this image you are adding your tests and specifying the CMD to run the tests.
When you build and launch this image, you don't get any browser because the CMD has been overridden by you to run the test. When we build in docker we keep dependent services in different containers. It is preferred to run 1 service/process per container in most case. In your case when the test is run the browser server process is missing, so that is the reason for connection refused.
So you need to be running two containers here. One for selenium/standalone-chrome and one for your test.
Also your image should inherit from node: and not from selenium chrome image. You should not have node -v and npm -v commands also while building images. They create extra layers in your final image
FROM node:7
USER root
# installing node
RUN apt-get update && apt-get install -y curl
# Installing Yarn
RUN npm install -g -y yarn
ENV PATH $PATH:/usr/local/bin/yarn
#copying files
WORKDIR /app
COPY . .
# debug
#installing yarn
RUN yarn install
RUN yarn
CMD yarn test
Now you need to create a docker-compose file to run a composition which has both your test and chrome
version: '3'
services:
chrome:
image: selenium/standalone-chrome
tests:
build: .
depends_on:
- chrome
Install docker-compose and run docker-compose up command to run the above composition. Also in your tests make sure to use the URL as http://chrome:4444/wd/hub and use the Remote webdriver and not the local driver.
i used a selenium/node-chrome image, but what resolved it was making sure my chromedriver + selenium server + nightwatch were set to the latest versions in my package.json

Selenium for docker issue

I have recently set up a selenium grid running in Docker. My current setup has the hub running in Docker on its own VM. I have another docker instance with 4 chrome nodes running on another VM. Both machines are running Docker toolbox for Windows (2012 Servers). I am able to get the hub and nodes to communicate properly but when I run my test suite all of my tests fail. I always get this error
Session [83a2a83d-9c59-45a7-a8ad-5a65e267fa9c] was terminated due to CLIENT_GONE
Here is the docker command I use to create the hub
docker run -d -p 4444:4444 -e JAVA_OPTS=-Xmx512m --name selenium-hub selenium/hub:3.0.1-aluminum
Here is the node command
docker run -d -p 5555:5555 -v /dev/shm:/dev/shm -e JAVA_OPTS=-Xmx512m -e SE_OPTS="-host IP -port 5555" -e HUB_PORT_4444_TCP_ADDR=IP -e HUB_PORT_4444_TCP_PORT=4444 --name Node1 selenium/node-chrome:3.0.1-aluminum
I use Specflow+ to run my tests with it set to run 4 test threads at a time.
<Environment platform="x64" testThreadIsolation="Process"/>
<Execution stopAfterFailures="0" retryFor="None" testThreadCount="4" testSchedulingMode="Adaptive"/>
Any help would be appreciated. Thanks
**
UPDATE
**
Here is the code I use to connect to the grid:
DesiredCapabilities dc = new DesiredCapabilities();
dc.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Linux));
dc.SetCapability(CapabilityType.BrowserName, "chrome");
driver = new RemoteWebDriver(new Uri("http:IPADDR/wd/hub"), dc);

How do you set up selenium grid using docker on windows?

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

Resources