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.
Note: We think you would be interested in our open-sourced Selenium + Python test automation framework based on the page object pattern.
Qxf2 provides QA for startups – hire us!
Qxf2 is the home of the technical tester. We are early-adopters of tooling and techniques in the QA space. Contact us to work with the experts at providing QA for startups.
I am a dedicated quality assurance professional with a true passion for ensuring product quality and driving efficient testing processes. Throughout my career, I have gained extensive expertise in various testing domains, showcasing my versatility in testing diverse applications such as CRM, Web, Mobile, Database, and Machine Learning-based applications. What sets me apart is my ability to develop robust test scripts, ensure comprehensive test coverage, and efficiently report defects. With experience in managing teams and leading testing-related activities, I foster collaboration and drive efficiency within projects. Proficient in tools like Selenium, Appium, Mechanize, Requests, Postman, Runscope, Gatling, Locust, Jenkins, CircleCI, Docker, and Grafana, I stay up-to-date with the latest advancements in the field to deliver exceptional software products. Outside of work, I find joy and inspiration in sports, maintaining a balanced lifestyle.
Hi, I am facing the same issue, but unable to resolve the problem on following the steps you mentioned. I added the plugin on the jenkins and installed xvfb on the jenkins machine as well.
I’ll take a shot in the dark. Can you make sure that the path for your xvfb executable is correct in Step 3? To find your xvfb executable, type in ‘which xvfb’ on your command prompt.
If the path to your xvfb executable is set correctly, can you post the Jenkins console output?
Hi, Could you please elaborate. I am not getting ,in which directory is that xvfb executable. And unable to set directory path while installing xvfb. Thanks in Advance.
If you have installed xvfb in your machine and if you run ‘which xvfb’ on your command prompt, you should see the path where xvfb is installed.
Great article, Put me into the correct path.
xvnc plugin is not working properly in mac slaves and was struggling a bit..and the find the solution with xvfb
Good one
Getting an error while running test on jenkins
Xlib: extension “RANDR” missing on display “:51”.
Xlib: extension “RANDR” missing on display “:51”.
Jithin, try looking at the answers in this thread: http://stackoverflow.com/questions/17944234/xlib-extension-randr-missing-on-display-21-trying-to-run-headless-googl
The error is most likely related to a Selenium version mismatch.