When we just started with UI Automation using Selenium the tests were only running on a laptop specifically dedicated to UI Automation. As part of our continuous integration environment the total execution time was reached after some time. On extending the amount of servers on which the tests could run we had to realize it wasn’t an easy task since there is no display output for the browser to launch in.
In order to run the tests on the CI servers it is needed to configure the tests to launch the browser virtually (e.g. using something like Xvfb). Short for x virtual framebuffer, Xvfb can run on machines with no display hardware and no physical input devices. It emulates a dumb framebuffer using virtual memory.
For some versions X11 was included in OS X, however this is no longer the case. But no worries, there is an alternative to it called XQuartz. Once installed a virtual display is simply created by:
& export DISPLAY=:
This command starts Xvfb on the specific display port 1337, backgrounds the process and tells the terminal session to use this display port.
An alternative solution could be running Xvfb as part of the Jenkins job with a plugin.
Once in a while you might run into the following error:
_XSERVTransmkdir: ERROR: euid !=
,directory /tmp/.X11-unix will not be created.
_XSERVTransSocketUNIXCreateListener: mkdir(/tmp/.X11-unix) failed, errno =
_XSERVTransMakeAllCOTSServerListeners: failed to create listener
(EE) Fatal server error:
(EE) Cannot establish any listening sockets - Make sure an X server isn't already running(EE)
To solve it just a few commands are needed, it’s just a workaround but worked every time so far:
sudo chown root /tmp/.X11-unix/
Fatal server error:
Server is already active
server is no longer running, remove /tmp/.X1337-lock
and start again.