{"id":40910,"date":"2016-09-28T10:58:25","date_gmt":"2016-09-28T05:28:25","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=40910"},"modified":"2016-12-19T15:04:03","modified_gmt":"2016-12-19T09:34:03","slug":"protractor-with-jenkins-and-headless-chrome-xvfb-setup","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/protractor-with-jenkins-and-headless-chrome-xvfb-setup\/","title":{"rendered":"Protractor with Jenkins and Headless Chrome (Xvfb) Setup"},"content":{"rendered":"<p><strong>&#8220;Protractor<\/strong> is an end-to-end test framework for <a title=\"Angular.js development\" href=\"http:\/\/www.tothenew.com\/front-end-angularjs-development\">AngularJS applications<\/a>. Protractor is to run one or multiple tests against your application running in a real browser, interacting with it as a user would.&#8221;<\/p>\n<p>It is easier to check on GUI based system because it launches a browser automatically during the test.<\/p>\n<p>But what about non-GUI? For example, we need to setup it up on Linux server in non-GUI mode or Jenkins server for CI\/CD. It is possible through Xvfb.<\/p>\n<p>&#8220;<strong>Xvfb<\/strong> (X virtual framebuffer) is an in-memory display server used in a\u00a0UNIX-like OS \u00a0(e.g., Linux). Xvfb\u00a0enables one to run graphical applications without a display.&#8221;<\/p>\n<p>Below are the steps which can help us to run Protractor test in non-GUI mode.<\/p>\n<p><strong>Prerequisites<\/strong><\/p>\n<p>1: &#8211; Install JAVA<br \/>\n2: &#8211; Install Jenkins and a configured build section in Jenkins job<br \/>\n3: &#8211; Installed NodeJS<\/p>\n<p><strong>Install Protractor and Selenium WebDriver<\/strong><\/p>\n<p>[js]curl -sL https:\/\/deb.nodesource.com\/setup_0.12 | sudo bash &#8211;<br \/>\nnpm install protractor -g<br \/>\nln \/usr\/lib\/node_modules\/protractor\/selenium\/chromedriver \/usr\/bin\/chromedriver<br \/>\nwebdriver-manager update<br \/>\nwebdriver-manager start[\/js]<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-40913 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Untitled1.png\" alt=\"Untitled\" width=\"1607\" height=\"415\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2016\/09\/Untitled1.png 1607w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Untitled1-300x77.png 300w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Untitled1-1024x264.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2016\/09\/Untitled1-624x161.png 624w\" sizes=\"(max-width: 1607px) 100vw, 1607px\" \/><br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\nNote: webdriver- If protractor installation fails with an error, Please check the ownership for logged in user, then execute above commands again<br \/>\nchown -R $(whoami) ~\/.npm<br \/>\nchown -R $(whoami) \/usr\/local\/lib\/node_modules<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p><strong>Setup Headless Chrome browser<\/strong><\/p>\n<p>[js]<br \/>\necho &quot;deb  stable main&quot; | sudo tee -a \/etc\/apt\/sources.list<br \/>\nwget -q -O &#8211; https:\/\/dl-ssl.google.com\/linux\/linux_signing_key.pub | sudo apt-key add &#8211;<br \/>\napt-get update<br \/>\napt-get install libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4<br \/>\napt-get install google-chrome-stable<br \/>\napt-get install xvfb gtk2-engines-pixbuf<br \/>\napt-get install xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable<br \/>\napt-get install imagemagick x11-apps dbus-x11<br \/>\n[\/js]<\/p>\n<p><strong>To launch the web driver with Xvfb at backend<br \/>\n<\/strong><br \/>\nScript is present in \u00a0\/etc\/init.d\/selenium:<\/p>\n<pre>#!\/bin\/sh\r\nXvfb -ac :99 -screen 0 1280x1024x16 &amp;\r\n#disown $1\r\nexport DISPLAY=:99\r\nwebdriver-manager start \/dev\/null 2&gt;&amp;1<\/pre>\n<p>Execute this script and verify the service on Port <strong>4444<\/strong>.<\/p>\n<p>Now, login into Jenkins and select associated job, where need to run this Protractor test.<\/p>\n<p>In <strong>Post Build<\/strong> section (execute shell) enter the following:<\/p>\n<p>[js]cd $CODE_PATH<br \/>\nprotractor protractor_conf.js[\/js]<\/p>\n<p>Hope this helps you to integrate protractor with Jenkins. Xvfb may be useful for other browser dependent applications in non-GUI mode.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;Protractor is an end-to-end test framework for AngularJS applications. Protractor is to run one or multiple tests against your application running in a real browser, interacting with it as a user would.&#8221; It is easier to check on GUI based system because it launches a browser automatically during the test. But what about non-GUI? For [&hellip;]<\/p>\n","protected":false},"author":959,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":19},"categories":[1439,1818,1,1816],"tags":[955,4048,4049],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/40910"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/959"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=40910"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/40910\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=40910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=40910"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=40910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}