In the manual the steps required to install headless Firefox on CentOS 6 are described. Headless Firefox may be needed to perform GUI automated testing.
All steps of this manual have been validated on CentOS 6.8. It should not be a problem to adapt the solution to other distros.
yum upgrade
Note: it may not be the latest version.
yum install -y firefox
Your Firefox installation probably needs Adobe Flash plugin to render flash objects.
yum -y install http://linuxdownload.adobe.com/linux/x86_64/adobe-release-x86_64-1.0-1.noarch.rpm
yum install flash-plugin
yum groupinstall "X Window System" "Desktop" "Fonts"
Assuming you're working from Linux, use your terminal to get into your remote host with X tunneling enabled issuing
ssh -X root@host
Being inside the remote host, issue
firefox
to run host's Firefox on your desktop.
You probably need to wait several seconds (or minutes, depending on your connection speed) to get host's Firefox to be running on your machine.
Install all needed extensions, e.g. Adblock Plus.
You have only two ways to get the feedback from your headless Firefox: (1) take a screenshot from the virtual display it runs on or (2) get Firefox's console logs to some server you arranged for that. To take screenshot you need ImageMagick utility.
yum install -y ImageMagick
This is virtual display driver that allows Firefox to send its GUI output to virtual display.
yum install -y Xvfb
Xvfb :19 -screen 0 1024x768x16 &
DISPLAY=:19 firefox "http://www.yahoo.com"
This will force Firefox to run on virtual display 19 created by Xvfb.
DISPLAY=:19 import -window root screenshot.png
You may absolutely want to install consoleexport extension to be able to send Firefox's console logs to some remote server. There is no other convineint way to get console logs from headless Firefox.
consoleexport is firebug's friend therefore you install first firebug and then consoleexport:
- Install firebug: https://addons.mozilla.org/en-US/firefox/addon/firebug/
- Install consoleexport: https://addons.mozilla.org/en-US/firefox/addon/consoleexport/?src=userprofile
To make consoleexport to send logs automatically to remote server you need to set three things in Firefox's about:config:
- extensions.firebug.consoleexport.active = true to activate atomatic sending of logs to the remote server
- extensions.firebug.consoleexport.serverURL = ip:port to set remote server to which the logs are sent
- extensions.firebug.allPagesActivation = on to enable firebug on every page; only in that case cosoleexport will send automatically console logs to remote server
Note: DNS names are not resolved on the serverURL field, so you need to put IP there.
The above settings will cause headless Firefox to send console logs to the supplied remote server in XML format. Here is the code of the server written in NodeJS that prints sent log messages:
/* File: server.js
Run with: node server.js
*/
const express = require('express');
const XmlStream = require('xml-stream');
const bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.post('/', (req,res)=>{
req.setEncoding('utf8');
var xml = new XmlStream(req);
xml.on('endElement: msg', data=>{
console.log(data);
});
xml.on('end', ()=>{
res.end();
});
});
app.listen(8100);
If that server runs on 34.2.3.5:8080 then set extensions.firebug.consoleexport.serverURL=34.2.3.5:8080.
Get Java from https://www.java.com/en/download/manual.jsp#lin and install it. For example, JDK8u112 RPM is installed as
rpm -ivh jdk-8u112-linux-x64.rpm
Verify Java version you're running after installation:
[root@NQPC003 ~]# java -version
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
[root@NQPC003 ~]#
Get Selenium from http://www.seleniumhq.org/download/. Running Selenium 3.0.1:
java -jar selenium-server-standalone-3.0.1.jar &
Make sure Selenium listens to connections:
[root@NQPC003 ~]# netstat -tlpn | grep 4444
tcp 0 0 0.0.0.0:4444 0.0.0.0:* LISTEN 29040/java
[root@NQPC003 ~]#
I am installing firefox slightly differently. I'm manually putting it in
/usr/local/
because there is an existing firefox installation that is being used by other automation tests. Did you have any issues with GTK3 not being available?