Problem: Error while running Selenium tests via Jenkins on a Ubuntu machine.
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
Why this post?
We faced this issue when we were trying to run our Selenium tests using Jenkins on an Ubuntu system. The same tests were working fine when we ran it through the terminal. We figured out that this was probably because Jenkins user did not have access to the appropriate display.
We solved the issue at first by making changes to the Jenkins start script. You can refer to this link for details. Then the client suggested (thanks, Prashanth!) using Xvfb. In rest of the post we will explain in detail how we solved this issue using Xvfb.
1. Xvfb installation:
Xvfb or X virtual framebuffer is a display server implementing the X11 display server protocol. In contrast to other display servers, Xvfb performs all graphical operations in memory without showing any screen output.
Make sure you have Xvfb installed in your Ubuntu system if not Install xvfb in ubuntu using below code
sudo apt-get install xvfb
2. Install Xvfb Plugin for Jenkins:
Xvfb Plugin for jenkins lets you control Xvfb virtual frame buffer X11 server with each build. It starts Xvfb before the build starts, and stops it with the build.
3. Configure Jenkins:
Start by going to Manage Jenkins / Configure System and setup your Xvfb installation. You need to give it a arbitrary name like default Xvfb and directory in which the Xvfb executable is located. Eg:/usr/bin.
4. Project Configuration:
On the job configuration page, enable the “Start Xvfb before the build, and shut it down after.” under the Build Environment. In case need you can customize defaults by clicking on Advanced… button.
5. Re-running the test:
After making the above changes the test ran fine. Note that the plugin starts Xvfb before the build starts, and stops it with the build
Well, that was cool. As always, we are happy to answer any questions you may have.
© 2013-2017, Avinash Shetty. All rights reserved.