Create Dockerfile that includes Firefox and Chrome drivers for Selenium - selenium

I have the following Dockerfile which will build a Selenium server
FROM selenium/standalone-firefox:3.4.0-chromium
FROM selenium/standalone-chrome
USER root
ENV NODE_ENV test
RUN mkdir -p /usr/local/cdt-tests/csv-data
COPY ./csv-data /usr/local/cdt-tests/csv-data
USER seluser
obviously the two FROM statements is incorrect => How can I create a Selenium server container that has both a Chrome driver and Firefox driver for Selenium. As far as I can tell, the selenium/standalone-firefox:3.4.0-chromium image only works for Firefox.

There is no inheritance type setup for Dockerfiles like you are suggesting.
To implement a combined build you would need find the common FROM ancestor of the standalone-firefox and standalone-chrome, which is selenium/node-base and create your own Docker file to reapply all the build steps that selenium/standalone-chrome applies. Then keep it in sync whenever Selenium update their builds.
Dockerfile Hierarchy:
selenium/node-base
/ \
selenium/node-chrome selenium/node-firefox
| |
selenium/standalone-chrome selenium/standalone-firefox
The problem is these builds have been designed to be seperate, so there is significant overlap in the variables and settings that the images use that you would also need to unpick in your custom build to control and run both chrome and firefox at the same time. You will probably end up having to do everything from scratch.
Selenium Grid
Running individual Selenium grid node's behind a grid hub is the standard way to do multi browser testing from a single endpoint. You can run Firefox, Chrome or Phantom JS nodes in Docker or connect standard nodes from anywhere else.
Poor mans grid
You can always run a container for Chrome and Firefox on seperate ports and point the same test suite at a different port if setting up a Grid is a lot of work for the simple case of running some tests against each browser.

You cannot merge two docker files likes that. You can use one as a base for your docker file, then copy the important bits from the other into your one.
However you shouldn't really need to. There are images out there with multiple browsers and drivers included. Or better, you could set up a grid with the hub image and some driver images.
You might even consider a library such as Serenity or a product such as Katalon, both of which do it all for you. There is even a Katalon docker image designed for use in CI: it's command-line + headless only, but that's all you need for most of your CI-driven regression testing.

Related

How does appium and selenium grid function together

So I have tested an appium script and it's running fine but I want to run it with selenium grid so I can run this on a different machine but I am not clear on if I need to keep the hub machine always active or it can be powered off after a certain while or if I can make another hub on my node machine. If an alternative means is possible for achieving this can I know too? Thank you.

How can I run Chrome headless from protractor WITHOUT using a Selenium server

I have Chrome working headless via a Selenium server by running xvfb bound to DISPLAY:10 and then running Selenium with a DISPLAY=:10 webdriver-manager start. So that's all fine.
I also have Chromedriver running directly from protractor by specifying directConnect: true in my protractor.conf.
What I'd like to do is a combination of the two, ie. run chromedriver directly (NO SELENIUM!), but somehow instruct it to run headless on DISPLAY :10.
In terms of topology, everything is run on the developer's PC. There are no servers involved. In a comment below, I mention a node server: this is being used to launch protractor instead of the more usual launching from the command line. I want protractor to be running on DISPLAY:0 so I can see its output, test failures etc. When it spawns chrome using chromedriver, I want chrome to be running on DISPLAY:10. My reason for doing this is that I want the chrome window to be bigger than my physical screen. See How can I screenshot the full height of a mobile form factor? for background.
I'm guessing the topology is like this:
Box A: xvfb, DISPLAY=:10, Selenium Server, chromedriver
Box B: DISPLAY=:0, node, protractor (directConnect: true), chromedriver
Box C: test runner.
I don't know how else it could be laid out, given that DISPLAY is an environment variable, not a parameter to be passed.
In which case, assuming you don't want a separate xvfb installed on Box B, and A is reachable (plus a decent connection) from B, the solution is simply to set:
DISPLAY=boxAHost:10
on Box B.
If A isn't reachable from B, it might be simplest to just duplicate the xvfb setup on both A and B, and have DISPLAY=:10 on both.
I had a "Doh!!!" moment of zen and the whole thing is much easier that I thought it would be.
I had conflated the stdout of node/protractor (which I want on my screen) with the X display of chrome (which I want headless on DISPLAY:10). Of course they are totally different!!!!
Simply prefixing protractor with DISPLAY=:10 eg.
DISPLAY=:10 protractor /installation_test/conf-c-direct-noserver.js
or, in my case since I'm running a node server which in turn spawns protractor, ...
DISPLAY=:10 npm start
So protractor runs in my terminal and I can watch stdout, whereas the DISPLAY=:10 is inherited down through the call layers and is eventually seen and understood by Chrome.

Selenium Tests on company Jenkins CI

I have been running Selenium test cases successfully on my local Jenkins. When I run test cases on my local jenkins it opens up chrome/safari or any specified browser on my machine to run.
Now I would like to run the same job on my company Jenkins. But Jenkins is not set up on real machine. So it does not have browser.
How do I run my suite on company Jenkins. I do not want to run headless.
Thanks
You need to run selenium grid on your server machine, where jenkins is installed. After that you need to run a register script to your grid in the machine where you will run browsers.
Before run the browser, get some files ready in a folder. Selenium-server and the browser driver (chromedriver, iedriver whichever you want to use. You don't need firefox)
Script should be like this
cd /path/path/selenium
java -jar selenium-server-standalone-2.46.0.jar -role node -hub http://your.ip.address:4444/grid/register -browser "browserName=firefox,maxInstances=10,platform=MAC" -browser "browserName=chrome,maxInstances=10,platform=MAC" -maxSession 20 -Dwebdriver.chrome.driver=/path/path/selenium/chromedriver
You can edit the script according to your system (MAC/Windows, file paths. file names)
Install the required browsers on Company Jenkins:
It may be the good and effective option, but in case it can't be done refer other options.
Use Headless Browsers Like PhantomJS, etc:
These browsers are good for testing simple features but not meant for advanced feature testing. Headless browsers are not equivalent to real browsers.
Setup a Selenium Grid on Company Jenkins:
You can distribute your tests over different nodes and run tests parallel as well using the Grid. Make your Jenkins machine the Hub and add different Nodes to run your tests, Refer this.
Create Virtual Machines to run your tests:
Virtual machine can help you save the Hardware cost by creating virtual servers for running your tests. This can also be done in conjunction with Selenium Grid. Refer this.
Run your tests on cloud services platform like Saucelabs, BrowserStack, etc:
Best is to use cloud for running your tests. You need not worry about the testing environment like browsers and platforms as they have almost every possible browser + platform combination to run your test.

Selenium testing machine

--- TL;DR
At this point I suggest everyone to tied their Continuous Integration server/service to https://ghostinspector.com/
OLD QUESTION
after three days googling and testing I gave up, and I need help.
My objective is allow my co-workers to record one or more tests with Selenium IDE. Export them, upload them into a server, and get this server running these tests using the webdriver with htmlunit. As we build or fix the app, we will upload the tests to make out test library.
Record a test with Selenium IDE is okay. But getting it running is the problem. The machine we intend to let the tests is an linux amazon server. No front-end stuff, no kde, gtk, so no firefox, chrome, etc... This is why I've specified the htmlunit driver.
So far I wasn't able to get this task running even into my machine - Ubuntu 12.04 x86_64.
I downloaded the selenium-server tarball, and tried running:
java -jar selenium-server.jar -htmlSuite "*webdriver" "our.site.org" "/path/to/testsuite1.html" "/path/to/report1.html"
No success. Even changing the "*webdriver" (using other pops-up a browser screen).
I've tried running the server and the standalone server and connecting via browser.
I've tried PHP bindings by facebook.
I've tried PHPUnit and Testing Selenium classes - along with their respectives exported scripts from Selenium Formatters.
I really do not know where I'm slipping. Can anyone give me a safe direction, tutorial, etc, to follow with?
--- EDIT
Okay, my question may be resumed to:
What si the command line that would allow me to run selenese scripts with selenium-server, using the HtmlUnit driver?
Are you using Continuous Integration?
If so, you should consider getting a plugin to have your CI software run the Selenium tests. Works like a charm for me with Jenkins.
Considering your particular setup, you could both have the amazon linux server run the tests with HTMLUnitDriver, and declare other machines (with a GUI and proper browser) as "nodes" to run your test on other browsers.
Link to a tutorial
Have you read this blog post by David Burns (Automated Tester):
http://www.theautomatedtester.co.uk/tutorials/selenium/selenium_rc_setup.htm
He describes the way to run selenese tests using HTMLSuite.
We are going to use the HTMLSuite commands of the Selenium Remote
Control. This allows you run your Selenese Test Suites as is. The
command should look like java -jar selenium-servre.jar -htmlsuite
. Browser
could be : -*firefox
-*chrome
-*iexplore
-*iehta
-*safari
-*custom /path/to/browser
The path to the test suite and the results file should be a full path.
Here is an example command; java -jar selenium-server.jar -htmlsuite
*iexplore http://www.theautomatedtester.co.uk c:\testsuite\testsuite.html c:\testsuite\results.html
I would point out that htmlunit does not seem to be a supported option so I would expect to use -*custom and provide a path to htmlunit.
This is legacy functionality so there is a chance it doesn't work as expected any more. HTMLSuite expects the tests to be in Selenese (HTML table) format, you mention trying with the PHP binding, I would not expect this to work. If you do want to use some PHP bindings I would suggest using Adam Saunter's fork of the facebook bindings, they are the most up to date and best supported.
https://github.com/Element-34/saunter.php
With Selenium WebDriver you can point to start a HtmlUnit in a already started node
In Java you'll do something like this:
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), DesiredCapabilities.HtmlUnit());
To start the node just make sure to set browserName to 'htmlunit'.

Running Selenium Suites on a Selenium Grid

Does anyone know how to run a selenium test suite from a selenium grid.
I know you can do it programatically with a single test, but I was wondering if there was an easy way to do it with a full test suite.
Something like java -jar selenium-server.jar -host -htmlSuite .
Thanks for the help.
This page will help you a lot. It demonstrates how to set up a hub and nodes which connect to it registering their 'configurations' (what browsers/'capabilities' they have). And the last piece of the jigsaw which is having code programmatically connect to the hub and run tests on it (the hub will forward stuff to a relevant node so the tests get performed there).
No. Selenium Grid is a facility for Selenium RC users to run their tests across a variety of machines with fine-grained configurations (e.g., a particular version of a browser). As far as I know, there's no ability to specify that in the htmlSuite. If there were, you might be able to make it work. But running just a suite like this is not supported and likely never will be because that's not what it was designed for.