Execute a Firefox Browser in a Docker Container for Selenium testing - selenium

I have a Java Application, which controls an automated GUI test in a FF-Browser via Selenium WebDriver Libraray. The Java App reads test cases from a database and executes them according to the code logic.
For instance, if the app reads in a Field, it'll search it by using the "findElement"-method from the Selenium framework. I do not use any test scripts for Selenium.
Currently this is happening on a local workingstation of an employee.
Now I want to move this whole environment into a Docker container.
Is it even possible to instantiate a Firefox Browser in a Container?
btw: I do not need to see the actual GUI of my browser.
And secondly:
There are several containers with selenium on dockerhub ready to use, but these do not fit my surroundings am I right?
As far as I know the SeleniumGrid expects testscripts and cannot be executed through runtime.
I open up a Linux VM (Debian:Jessie distribution) with Vagrant, in which then runs Docker.
I am still a beginner with Docker.
I couldn't find any question around here regarding my purpose.
Thanks in advance!

Is it even possible to instantiate a Firefox Browser in a Container?
Yes. The simplest way to do this is would be using the selenium images on Docker Hub.
There are several containers with selenium on dockerhub ready to use, but these do not fit my surroundings am I right?
If you think the Selenium images don't work for you because they are all based on Selenium Grid, you can use the StandaloneFirefox and StandaloneChrome images instead. These are individual instances, they do not use Selenium Grid.
BTW, the non-Debug Selenium images do not have a GUI. You mentioned you didn't need to see the browsers running so these should be fine. If you do need to see the browsers, the Debug images have a VNC server installed so you can run the image, connect with a VNC client, and watch the browsers run the tests.

Related

see firefox when executing robot test in docker

I'm using robotframework with selenium and firefox.
I'm running test in a docker.
But for debugging purpose I want to see sometimes what's happen on the UI.
So is there a way to get the UI of firefox launch when test are running in docker.
thanks
You can use VNC to see what is actually happening over docker. It's like remote access where you can see everything on docker image
Download VNC viewer :
https://www.realvnc.com/en/connect/download/viewer/
Some tutorial :
Click Here
Article
https://medium.com/#shivam.somani09/running-automated-test-cases-on-vnc-viewer-using-docker-16656c3d1d87
OR if you don't want VNC
You can take screenshot if you just want an image on a particular place.
You can also use driver.getPageSource(); to get the HTML code

Is there a way to test web application using Selenium and either Driver Firefox or Chrome on a server Centos7 without graphical interface?

On my local machine, I arrived to test my applications with Selenium with any problems.
But, when I'm doing the same operations on a server Centos7 (I have no graphical interface), I've many errors such as web element not found.
I'm using Docker containers for selenium (hub and nodes). The installation is OK and I can see my drivers on Http://:4444/grid/console.
Does Selenium require a graphical interface for its work?
Yes. Selenium requires the browser GUI to be present - which is also called viewport.
If you want that Selenium execution happen, without the browser GUI to be present, then you need to use a headless browser, which , as the name suggests is headless, which means there would be no GUI for them.
Examples of these headless browser include PhantomJS- link. Now Chrome also has a headless mode - link, which you can specify using ChromeOptions. Cheers!

Firefox in a docker container accessible from selenium in another

I have a docker container running a rails app (let's call it container A) that needs to do some scraping with watir webdriver using firefox as backend.
I have firefox installed in another container (container B) and I want to be able to pass in container A something like:
Selenium::WebDriver::Firefox::Binary.path= $DOCKER_RUN_CONTAINER_A
So, each time watir launches firefox a new instance of CONTAINER_A launches a new firefox.
I know it's easy to make containers communicate using ports, but how about executables?
And, by the way, does it look like a good design idea isolating firefox in a separate container?
Yes, this is easy to do. Just run an instance of Selenium Grid (which is a grid-node hybrid combo by default) , in the foreground on the docker server (on port 5555 or whatever). Then you can use Ruby with Selenium bindings (not WatiR) to drive the firefox browser on the remote box.

Executing the selenium tests from remote java application

We have are planning to design a system where we are planning to invoke the Selenium test that is present in a remote machine with url for testing. The selenium program should open 3 browsers for example IE, FF and Chrome and open the page and take a screenshot of it. Later These screenshots should be sent from this machine to the java application.
Is it possible to achieve this functionality ? If so could you please guide me on how to do this ?
Yes, you need to start a Selenium Grid/Node server on the remote machine that is configured to run all 3 browser types. That configuration isn't easy but it involves launching the grid from a .json config file. Then, your local program needs to just run the 3 tests either in 3 simultaneous threads, or one at a time using typical Selenium code.
Each test needs to define a Selenium Augmenter to get screenshots. There are lots of examples on Google.

Selenium tests and continuous integration (Running browser in background)

We have Xserver-less CentOS system for continuous integration. So no UI.
I want to run selenium test cases on it. I am using new Alpha version of Selenium2 which has WebDriver integration. It starts and ends browser by its own. Now, How do I start that in background? Something similar is possible with Internet Explorer?
I am able to run correctly on local machine. But it opens Firefox UI.
Are you able to run a virtual frame buffer? That way, all the GUI programs can believe there's graphics happening, even if there's no actual screen. You may wish to search for the term "headless". One example.
Another possibility may be to use Celerity - a ruby-based "headless browser". It uses the Watir interface (originally a competitor to selenium), which I understand to be merging with webdriver.