Friday, February 06, 2015

Setting DISPLAY variable to avoid No protocol specified Error: Can't open display: :# Selenium UnknownError: unknown error: Chrome failed to start: exited abnormally

If Selenium server cannot open the current display the client will fail with an error similar to "UnknownError: unknown error: Chrome failed to start: exited abnormally". This is a common issue many people ask about when they try to either run X applications (like tests against selenium in a remote server) remotely or when they are logged in via VNC, XRDP etc. Basically the DISPLAY variable is assigned to the local terminal console and not really to the remote session. You need to find the proper DISPLAY variable for your remote session in order to resolve this problem.

Setting DISPLAY variable will avoid the typical problem "No protocol specified Error: Can't open display: :#" where # is usually 0.

If this variable is set incorrectly your session will have no access to run X applications in the visible display. Perhaps the fastest way to find out if your DISPLAY is correctly set is to run the xclock application. The commands below should be self explanatory about how it fails and how it should be corrected at least in Debian/Ubuntu: So all you really need to do in order to make sure your selenium server spawns the chrome browser successfully is to export the DISPLAY variable to the correct value before starting the selenium server. Keep that in mind specially after restarting.