{"id":2946,"date":"2015-06-14T11:51:10","date_gmt":"2015-06-14T15:51:10","guid":{"rendered":"http:\/\/qxf2.com\/blog\/?p=2946"},"modified":"2024-10-15T16:14:15","modified_gmt":"2024-10-15T20:14:15","slug":"xvfb-plugin-for-jenkins-selenium","status":"publish","type":"post","link":"https:\/\/qxf2.com\/blog\/xvfb-plugin-for-jenkins-selenium\/","title":{"rendered":"Xvfb plugin for Jenkins"},"content":{"rendered":"<p><strong>Problem:<\/strong> Error while running Selenium tests via Jenkins on a Ubuntu machine.<br \/>\n<\/p>\n<div style=\"background-color: #ffff99;\">\nWebDriverException(&#8220;The browser appears to have exited &#8221;<br \/>\nselenium.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.\n<\/div>\n<p><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Error.jpg\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Error-1024x482.jpg\" alt=\"Error\" width=\"1024\" height=\"482\" class=\"aligncenter size-large wp-image-2954\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Error-1024x482.jpg 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Error-300x141.jpg 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Error.jpg 1280w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><br \/>\n<\/p>\n<hr>\n<h3>Why this post?<\/h3>\n<p>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. <\/p>\n<p>We solved the issue at first by making changes to the Jenkins start script. You can refer to this <a href=\"http:\/\/stackoverflow.com\/questions\/22773363\/error-cannot-open-display-0-for-selenium-tests\">link<\/a> for details. Then the <a href=\"http:\/\/mangaloreinfotech.in\/\">client<\/a> suggested (thanks, Prashanth!) using <a href=\"http:\/\/en.wikipedia.org\/wiki\/Xvfb\">Xvfb<\/a>. In rest of the post we will explain in detail how we solved this issue using Xvfb.<\/p>\n<hr>\n<p><strong>1. Xvfb installation:<\/strong><br \/>\nXvfb 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.<br \/>\nMake sure you have Xvfb installed in your Ubuntu system if not Install xvfb in ubuntu using below code<\/p>\n<p><code>sudo apt-get install xvfb<\/code><\/p>\n<hr>\n<p><strong>2. Install Xvfb Plugin for Jenkins:<\/strong><\/p>\n<p><a href=\"https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Xvfb+Plugin\">Xvfb Plugin<\/a> 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.<br \/>\n<a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Xvfb_Plugin.jpg\" data-rel=\"lightbox-image-1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Xvfb_Plugin-1024x224.jpg\" alt=\"Xvfb plugin\" width=\"1024\" height=\"224\" class=\"aligncenter size-large wp-image-2960\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Xvfb_Plugin-1024x224.jpg 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Xvfb_Plugin-300x66.jpg 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Xvfb_Plugin.jpg 1264w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<hr>\n<p><strong>3. Configure Jenkins:<\/strong><br \/>\nStart 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.<\/p>\n<p><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Xvfb_Configuration.jpg\" data-rel=\"lightbox-image-2\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Xvfb_Configuration-1024x281.jpg\" alt=\"Jenkins Configuration\" width=\"1024\" height=\"281\" class=\"aligncenter size-large wp-image-2961\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Xvfb_Configuration-1024x281.jpg 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Xvfb_Configuration-300x82.jpg 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Xvfb_Configuration.jpg 1266w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<hr>\n<p><strong>4. Project Configuration:<\/strong><br \/>\nOn the job configuration page, enable the &#8220;Start Xvfb before the build, and shut it down after.&#8221; under the Build Environment. In case need you can customize defaults by clicking on Advanced&#8230; button.<\/p>\n<p><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Project_Configuration.jpg\" data-rel=\"lightbox-image-3\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Project_Configuration-1024x476.jpg\" alt=\"Project Configuration\" width=\"1024\" height=\"476\" class=\"aligncenter size-large wp-image-2962\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Project_Configuration-1024x476.jpg 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Project_Configuration-300x140.jpg 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Project_Configuration.jpg 1298w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<hr>\n<p><strong>5. Re-running the test:<\/strong><br \/>\nAfter making the above changes the test ran fine. Note that the plugin starts Xvfb before the build starts, and stops it with the build<br \/>\n<a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Success.jpg\" data-rel=\"lightbox-image-4\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Success-1024x347.jpg\" alt=\"Rerun the Jenkins test\" width=\"1024\" height=\"347\" class=\"aligncenter size-large wp-image-2965\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Success-1024x347.jpg 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Success-300x102.jpg 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2015\/06\/Success.jpg 1291w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<hr>\n<p>Well, that was cool. As always, we are happy to answer any questions you may have.<\/p>\n<p><strong>Note: <\/strong>We think you would be interested in our open-sourced <a href=\"https:\/\/github.com\/qxf2\/qxf2-page-object-model\">Selenium + Python test automation framework<\/a> based on the page object pattern.<\/p>\n<h3>Qxf2 provides QA for startups &#8211; hire us!<\/h3>\n<p>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 <a href=\"https:\/\/qxf2.com\/?utm_source=xvfb-jenkins&#038;utm_medium=click&#038;utm_campaign=From%20blog\">experts at providing QA for startups<\/a>.<\/p>\n<hr>\n<script>(function() {\n\twindow.mc4wp = window.mc4wp || {\n\t\tlisteners: [],\n\t\tforms: {\n\t\t\ton: function(evt, cb) {\n\t\t\t\twindow.mc4wp.listeners.push(\n\t\t\t\t\t{\n\t\t\t\t\t\tevent   : evt,\n\t\t\t\t\t\tcallback: cb\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n})();\n<\/script><!-- Mailchimp for WordPress v4.10.1 - https:\/\/wordpress.org\/plugins\/mailchimp-for-wp\/ --><form id=\"mc4wp-form-1\" class=\"mc4wp-form mc4wp-form-6165 mc4wp-form-theme mc4wp-form-theme-blue\" method=\"post\" data-id=\"6165\" data-name=\"Newsletter\" ><div class=\"mc4wp-form-fields\"><div style=\"border:3px; border-style:dashed;border-color:#56d1e1;padding:1.2em;\">\r\n  <h1 style=\"text-align: center; padding-top: 20px; padding-bottom: 20px; color: #592b1b;\">Subscribe to our weekly Newsletter<\/h1>\r\n  <input style=\"margin: auto;\" type=\"email\" name=\"EMAIL\" placeholder=\"Your email address\" required \/>\r\n  <br>\r\n  <p style=\"text-align: center;\">\r\n    <input style=\"background-color: #890c06 !important; border-color: #890c06;\" type=\"submit\" value=\"Sign up\" \/>\r\n    \r\n  <\/p>\r\n  <p style=\"text-align: center;\">\r\n    <a href=\"http:\/\/mailchi.mp\/c9c7b81ddf13\/the-informed-testers-newsletter-20-oct-2017\"><small>View a sample<\/small><\/a>\r\n  <\/p>\r\n  <br>\r\n<\/div><\/div><label style=\"display: none !important;\">Leave this field empty if you're human: <input type=\"text\" name=\"_mc4wp_honeypot\" value=\"\" tabindex=\"-1\" autocomplete=\"off\" \/><\/label><input type=\"hidden\" name=\"_mc4wp_timestamp\" value=\"1776728392\" \/><input type=\"hidden\" name=\"_mc4wp_form_id\" value=\"6165\" \/><input type=\"hidden\" name=\"_mc4wp_form_element_id\" value=\"mc4wp-form-1\" \/><div class=\"mc4wp-response\"><\/div><\/form><!-- \/ Mailchimp for WordPress Plugin -->\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>Problem: Error while running Selenium tests via Jenkins on a Ubuntu machine. WebDriverException(&#8220;The browser appears to have exited &#8221; 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 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51,30,92],"tags":[],"class_list":["post-2946","post","type-post","status-publish","format-standard","hentry","category-jenkins","category-selenium","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/2946","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/comments?post=2946"}],"version-history":[{"count":19,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/2946\/revisions"}],"predecessor-version":[{"id":22907,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/2946\/revisions\/22907"}],"wp:attachment":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/media?parent=2946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/categories?post=2946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/tags?post=2946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}