Selenium side runner + chromedriver tests with docker not running - selenium

I am trying to get selenium side runner to run some tests using docker, to include in our CI.
I am able to run the tests locally in my machine by running:
selenium-side-runner C:\path-to-tests\tests-selenium.side
This is windows host.
I am trying to do the same using docker locally, so afterwards I will migrate this to our Teamcity.
First I am running the selenium server container:
docker run -d -p 4444:4444 --name chromedriver selenium/standalone-chrome:3.4.0
Afterwards I run the selenium side runner container:
docker run -v C:\path-to-tests:/sides --link chromedriver:chromedriver nixel2007/docker-selenium-side-runner
I have to link the containers otherwise I get an error saying that the container can't connect to chromedriver:4444
I also have to mount the volume where my tests are.
When I do this and run, I get the following error:
Test suite failed to run
WebDriverError: Unable to parse new session response
What am I missing here?
UPDATE:
I also tried different versions of the selenium/standalone-chrome container, selenium/standalone-chrome:3.4.0, selenium/standalone-chrome:3.141.59-xenon and selenium/standalone-chrome:latest
All fail with different errors.
SECOND UPDATE:
I have been able to get the tests to run, both locally and in teamcity. One of the issues that I am facing right now is that docker-compose seems to hang. Not sure if this is container related, or docker-compose related.
When I run the tests, the selenium side runner container exits with code 1 and I do not get back to the host console prompt, it stays forever waiting for something to happen.
The error is this:
selenium_selenium-side-runner_1 exited with code 1
I have gotten the docker-compose file from here:
https://github.com/nixel2007/docker-selenium-side-runner/blob/master/docker-compose.yml
Any clues on what I might be missing?

Related

How to run Selenium server (RC) via Jenkins on a virtual machine?

I'm trying to automate tests using Jenkins. The principle of operation is as follows:
There is a main machine (ubuntu 22) on which tests (pyTest) are stored and virtual machines (Ubuntu 18 and 20) are created, and jenkins is connected to the main machine.
The problem is the following, I am trying to run Selenium Server from Jenkins on a virtual machine by running the command:
sh '''ssh user#ip java -jar ~/selenium_driver/selenium-server-4.3.0.jar standalone -p 1234 > logs.log 2>&1'''
Although I got rid of the data output to the console, but the step in jenkins still "freezes" waiting for the command to complete and does not proceed to the next step.
How can this problem be solved? To perform the next step, after executing the selenium server startup command. Maybe you can move on to the next step without waiting for the previous one to be completed. I use PipeLine
Decided so:
stage('NameStage') {
timeout(time: 20, unit: 'SECONDS') {
sh """
ssh user#ip 'java -jar ~/selenium_driver/selenium-server-4.3.0.jar standalone -p 1234 > ~/logs.log 2>&1'
"""
}
}
After 20 seconds, the step is completed, while selenium remains working in the background

Getting Protractor.js to run on Jenkins build failing -- Error forwarding the new session empty pool of VM for setup capabilities

I am trying to get Protactor.js unit testing up and running with Jenkins on a windows server but I am having trouble getting it to run.
Currently this is the steps I have so far:
#install protractor via package.json
cd ./src/My\ Editor/WebApp/Scripts/protractor && D:Jenkins/nodesjs/npm install
[other build steps here]
#start webdriver-manager
./src/My\ Editor/WebApp/Scripts/protractor/node_modules/protractor/bin/webdriver-manager start > /dev/null 2>&1 &
#wait until selenium up
while ! curl http://localhost:4444/wd/hub/status &>/dev/null
do
true
done
#run protractor
cd ./src/My\ Editor/WebApp/Scripts/protractor/node_modules/protractor/bin/
./protractor ../../../conf.js
#stop selenium
curl -s -L http://localhost:4444/selenium-server/driver?cmd-shutDownSeleniumServer > /dev/null 2>&1
everything works well until the command 'protractor conf.js'. I get this output:
[21:12:34] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
[21:12:34] I/launcher - Running 1 instances of WebDriver
[21:12:34] E/launcher - Error forwarding the new session empty pool of VM for setup capabilities [{count=1, browserName=chrome}]
Any help for what I am doing wrong is appreciated, thank you.
Is there a specific need to start a Selenium Server/hub?
If you dont have a plan to setup a Selenium GRID and you just need to run protractor test scripts stand-alone you can skip the part where you are starting server.
Can you leave the remove seleniumAddress option in Protractor.conf.js. This will enable Protractor to start its own selenium server & wait till server is completely up and execute and will shutdown the server once execution is done
More information here
/**
* The address of a running Selenium Server. If specified, Protractor will
* connect to an already running instance of Selenium. This usually looks like
* seleniumAddress: 'http://localhost:4444/wd/hub'
*/
seleniumAddress?: string;
just have the step #run protractor and rest is taken care by Protractor

Running headless firefox Xvfb with Jenkins to run selenium tests

I face with Error: no display specified error when running play framework tests in Jenkins at FreeBSD server.
So every time I face with timeout
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox
Jenkins has:
1) Xvfb plugin installed
2) Play Framework installed
Tests are written using selenide library and selenide module for play framework.
Xvfb configured and enabled in job configuration.
Job console output is:
Checking out Revision 3f485bd2e3dbcfa058fc19f89ab18020e36707d8 (origin/trunk)
...
Xvfb starting$ /usr/local/bin//Xvfb :1 -screen 0 -fbdir /usr/local/jenkins/xvfb-9-786185694297443042.fbdir
...
Command detected: clean
Command detected: deps --sync
Command detected: precompile
Command detected: auto-test
[YalsTests] $ /srv/java/play/play clean
...
~ using java version "1.8.0_72"
[YalsTests] $ /srv/java/play/play auto-test
~ 14 tests to run:
~
~ selenium/front/CorrectInput... org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
Error: no display specified
at org.openqa.selenium.firefox.internal.NewProfileExtensionConnection.start(NewProfileExtensionConnection.java:113)
at org.openqa.selenium.firefox.FirefoxDriver.startClient(FirefoxDriver.java:271)
Job configuration:
[X] Start Xvfb before the build, and shut it down after.
Xvfb specific display name 1
Xvfb display name offset 0
Invoke Play Framework
Command set Play 1.x
Goals
Clean project [clean]
Custom parameter
Custom command deps --sync
Precompile all Java sources and templates [precompile]
Automatically run all application tests [auto-test]
The selenium tasks needs to know the DISPLAY that it shall connect to.
You can set it e.g. as an environment variable (don't forget to export it, if you do that in .profile)
export DISPLAY=:10
This is for bash, other shells might need a 2 step process:
DISPLAY=:10
export DISPLAY
You can also specify the variable at the command line before the command:
DISPLAY=:10 java -jar mySelenium.jar
You could avoid all these issues by using Selenoid project which starts headless browsers in parallel in Docker containers. Container images are created by considering compatible version of webdriver and browser. They also include fonts, flashplayer and so on. Just choose one of already existing images and run your tests. No need to install Java to run Selenium tests.
I tend to supply this if I'm running my tests via Jenkins:
xvfb-run --server-args="-screen 0, 1920x1080x16" mvn clean install...
One thing that has tripped me up in the past is that while xvfb-run will create a virtual display, it can really screw up your screenshots and web interactions if it isn't sized correctly, so it's usually advisable to supply a resolution size which will suitably display your browser.

Docker: Unable to view running container despite successful demo example

When I run the example from the Docker doc in the "Viewing our web application container" section, i.e.,
docker run -d -P training/webapp python app.py
...I'm able to view the "Hello World" output in a browser. Success. This seems to indicate that the network I'm on may not be the problem.
Now I'm trying to view a container that runs a webdriver suite (test automation of a browser). Based on the output in docker logs -f, the webdriver suite runs to completion. But when I try to point a browser at the webdriver container (which is running the browser), I get a error saying:
ERR_CONNECTION_REFUSED
Here are the steps I'm following:
Start webdriver container with this command
docker run -d -p 8080:5000 "/bin/bash" "-c" "/dir1/dir2/filename.sh $PARAMETER1 $PARAMETER2"
point a browser to:
http://subdomain.mydomain.com:5000
Docker output:
user#server$ docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2fa83fc0401a 65525ab9ad78 "/bin/bash -c '/opt/y" 55 minutes ago Up 55 minutes 2222/tcp, 0.0.0.0:8080->5000/tcp
user#server$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' 2fa83fc0401a
111.22.33.4444
Other info:
Server config: Ubuntu 14.04
Docker version: 1.8.1, build d12ea79
I've reviewed the following questions but I'm not running on a VM and I'm not running NodeJS.
Unable to view rails app running in docker container from browser
Docker: Unable to specify port for a running container
Does anyone have suggestions on how I might troubleshoot this problem? Any assistance gratefully accepted.
:) jay
Update 1:
Based on the NodeJS question noted above, I'm thinking that I'm not setting a port correctly in the Dockerfile. Maybe this is as simple as setting the correct port for Selenium?
Update 2: as #hunter noted, I had the ports in the wrong order, but switching the ports does not resolve the problem. I think the bigger problem is that I was assigning the wrong port. So, I changed docker run -d -p 8080:5000 to docker run -d -P. When I did that, I got the following output:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
f375251b61d7 65525ab9ad78 "/bin/bash -c '/opt/y" About an hour ago Up About an hour 0.0.0.0:33073->2222/tcp
I then pointed the browser to that port: http://subdomain.mydomain.com:33073
But I still get the same error: ERR CONNECTION REFUSED
I think you're using the wrong port - the external port is 8080 not 5000.

Codeception auto start and auto shutdown selenium server?

I'm using Codeception and I want to do Selenium tests.
Obviously, I need Selenium server running and I can spin it up with:
java -jar ./path/to/selenium/binary
However, I've used another testing framework in past which allowed me to specify this path in config file. Then, whenever I did something like codecept run, the framework automatically started selenium server and also shutted it down after all tests were completed.
Can I do this with Codeception? I tried to put exec() in _bootstrap file but it didn't work..
I'm using phantomjs - headless alternative to selenium. This extension starts phantomjs automatically with codecept run. Also phantomjs is faster than selenium.
You can write your own extension for running selenium - have a look at this file.
I start my tests with a bash script and then start and stop selenium via screen:
#!/usr/bin/env bash
# Start selenium in detached screen
screen -d -m -S "selenium" java -Dwebdriver.chrome.driver=./path/to/chromedriver -jar ./path/to/selenium/binary || true
./vendor/bin/codecept run -c codeception.yml --fail-fast --coverage --steps --coverage-html --html || error=true
# quit selenium
screen -S selenium -X quit || true
This might not fit the use-case but I can execute my code in my bash on Windows and Ubuntu as well as via my jenkins build process.