{"id":2810,"date":"2014-03-22T14:51:57","date_gmt":"2014-03-22T14:51:57","guid":{"rendered":"https:\/\/supportex.net\/?p=2810"},"modified":"2019-05-10T15:50:14","modified_gmt":"2019-05-10T13:50:14","slug":"selenium-installation-centos-6-5","status":"publish","type":"post","link":"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/","title":{"rendered":"Headless Selenium testing environment on Centos 6.5"},"content":{"rendered":"<p><a href=\"http:\/\/docs.seleniumhq.org\">Selenium<\/a> is a set of tools which allows to test web applications automatically. Here&#8217;s a way to get it working on Centos 6. At the end we should be able to run headless Selenium tests with Firefox. Please note that as X11 disaplay server we will use Xvfb.<\/p>\n<p>At first let&#8217;s install required packages and prepare directories.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">yum install firefox Xvfb libXfont Xorg\nmkdir \/usr\/lib\/selenium \/var\/log\/selenium \/var\/log\/Xvfb\nchown screener.screener  \/usr\/lib\/selenium \/var\/log\/selenium \/var\/log\/Xvfb<\/pre>\n<p>&#8220;screener&#8221; is a regular user we use for running Selenium and X server, you can use any user you want, but please do not use root.<br \/>Now we can download selenium standalone server:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">cd \/usr\/lib\/selenium ; wget http:\/\/selenium-release.storage.googleapis.com\/2.40\/selenium-server-standalone-2.40.0.jar<\/code><\/p>\n<p>Make sure you downlowd the latest version.<br \/>Besides we definitely need Java:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">yum install jre<\/code><br \/><br \/>To manage Selenium and Xvfb we use two simple scripts. Put them to \/etc\/init.d\/selenium and \/etc\/init.d\/Xvfb respectively.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#!\/bin\/bash\n# selenium - this script starts and stops the selenium grid\n#\n# chkconfig:   - 85 15\n# description: Selenium Grid is a distributed testing platform for browser-based automation.\n# processname: selenium\n# pidfile:     \/etc\/selenium\/tmp\/selenium.pid\n\n# Source function library.\n. \/etc\/rc.d\/init.d\/functions\nselenium_dir=\/usr\/lib\/selenium\nlog_dir=\/var\/log\/selenium\/\nerror_log=$log_dir\/selenium_error.log\nstd_log=$log_dir\/selenium_std.log\npid_file=\/var\/log\/selenium\/selenium.pid\njava=\/usr\/bin\/java\nselenium=\"$selenium_dir\/selenium-server-standalone-2.40.0.jar\"\nuser=screener\n\nstart() {\n    if test -f $pid_file\n    then\n        PID=`cat $pid_file`\n        if  ps --pid $PID &amp;amp;gt;\/dev\/null;\n            then\n                echo \"Selenium is already running: $PID\"\n                exit 0\n            else\n                echo \"Removing stale pid file: $pid_file\"\n        fi\n    fi\n\n    echo -n \"Starting Selenium...\"\n    su $user -c \"$java -jar $selenium -host 127.0.0.1 &amp;amp;gt;$std_log 2&amp;amp;gt;$error_log &amp;amp;amp;\"\n\n    if [ $? == \"0\" ]; then\n        success\n    else\n        failure\n    fi\n    echo\n    ps  -C java -o pid,cmd | grep $selenium  | awk {'print $1 '} &amp;amp;gt; $pid_file\n}\n\nstop() {\n    if test -f $pid_file\n    then\n        echo -n \"Stopping Selenium...\"\n        PID=`cat $pid_file`\n        su $user -c \"kill -3 $PID\"\n        if kill -9 $PID ;\n                then\n                        sleep 2\n                        test -f $pid_file &amp;amp;amp;&amp;amp;amp; rm -f $pid_file\n                        success\n                else\n                        echo \"Selenium could not be stopped...\"\n                        failure\n                fi\n    else\n            echo \"Selenium is not running.\"\n            failure\n    fi\n    echo\n}\n\nstatus() {\n    if test -f $pid_file\n    then\n        PID=`cat $pid_file`\n        if  ps --pid $PID &amp;amp;gt;\/dev\/null ;\n        then\n            echo \"Selenium is running...$PID\"\n        else\n            echo \"Selenium isn't running...\"\n        fi\n    else\n            echo \"Selenium isn't running...\"\n    fi\n}\n\ncase \"$1\" in\n    start)\n        $1\n        ;;\n    stop)\n        $1\n        ;;\n    restart)\n        stop\n        start\n        ;;\n    status)\n        $1\n        ;;\n    *)\n        echo \"Usage: $SELF start|stop|restart|status\"\n        exit 1\n    ;;\nesac<\/pre>\n<p>Xvfb init.d script:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#!\/bin\/bash\n# selenium - this script starts and stops Xvfb\n#\n# chkconfig:   - 85 15\n# description: Xvfb\n# processname: Xvfb\n# pidfile:    \/var\/log\/Xvfb\/Xvfb.pid\n\n# Source function library.\n. \/etc\/rc.d\/init.d\/functions\n\n#selenium_dir=\/usr\/lib\/selenium\nlog_dir=\/var\/log\/Xvfb\nerror_log=$log_dir\/Xvfb_error.log\nstd_log=$log_dir\/Xvfb_std.log\npid_file=\/var\/log\/selenium\/Xvfb.pid\njava=\/usr\/bin\/java\nxvfb=$( which Xvfb )\nuser=screener\n\nstart() {\n    if test -f $pid_file\n    then\n        PID=`cat $pid_file`\n        if  ps --pid $PID &amp;amp;amp;gt;\/dev\/null;\n            then\n                echo \"Xvfb is already running: $PID\"\n                exit 0\n            else\n                echo \"Removing stale pid file: $pid_file\"\n        fi\n    fi\n\n    echo -n \"Starting Xvfb...\"\n    su $user -c \"$xvfb :99 -ac -screen 0 1280x1024x24 -nolisten tcp &amp;amp;amp;gt;$std_log 2&amp;amp;amp;gt;$error_log &amp;amp;amp;amp;\"\n\n    if [ $? == \"0\" ]; then\n        success\n    else\n        failure\n    fi\n    echo\n    ps  -C Xvfb -o pid,cmd | grep Xvfb  | awk {'print $1 '} &amp;amp;amp;gt; $pid_file\n}\n\nstop() {\n    if test -f $pid_file\n    then\n        echo -n \"Stopping Xvfb...\"\n        PID=`cat $pid_file`\n        su $user -c \"kill -15 $PID\"\n        if kill -9 $PID ;\n                then\n                        sleep 2\n                        test -f $pid_file &amp;amp;amp;amp;&amp;amp;amp;amp; rm -f $pid_file\n                        success\n                else\n                        echo \"Xvfb could not be stopped...\"\n                        failure\n                fi\n    else\n            echo \"Xvfb is not running.\"\n            failure\n    fi\n    echo\n}\n\nstatus() {\n    if test -f $pid_file\n    then\n        PID=`cat $pid_file`\n        if  ps --pid $PID &amp;amp;amp;gt;\/dev\/null ;\n        then\n            echo \"Xvfb is running...$PID\"\n        else\n            echo \"Xvfb isn't running...\"\n        fi\n    else\n            echo \"Xvfb isn't running...\"\n    fi\n}\n\ncase \"$1\" in\n    start)\n        $1\n        ;;\n    stop)\n        $1\n        ;;\n    restart)\n        stop\n        start\n        ;;\n    status)\n        $1\n        ;;\n    *)\n        echo \"Usage: $SELF start|stop|restart|status\"\n        exit 1\n    ;;\nesac<\/pre>\n<p>Now we are ready to start them both:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">\/etc\/init.d\/Xvfb start\n\/etc\/init.d\/selenium start<\/pre>\n<p>Let&#8217;s check if it works using selenium wrapper for Python:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">python-pip install -U selenium<\/code><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">!\/usr\/bin\/env python\n   from selenium import webdriver\n   browser = webdriver.Firefox()\n   browser.get('http:\/\/supportex.net')\n   browser.save_screenshot('supportex.png')\n   browser.quit()<\/pre>\n<p>Now you should get supportex.png in your current directory.<\/p>\n<p>Please also note that by default S<em>elenium opens TCP port 4444 on all network interfaces<\/em>. So for security reasons it&#8217;s strongly reccomended to limit an access to these port by firewall. For instance this way,<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">iptables -N SELENIUM\niptables -A INPUT -p tcp --dport 4444 -j SELENIUM\niptables -A SELENIUM -p tcp --dport 4444 -s 127.0.0.1 -j ACCEPT\niptables -A SELENIUM -p tcp --dport 4444 -j DROP<\/pre>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Selenium is a set of tools which allows to test web applications automatically. Here&#8217;s a way to get it working on Centos 6. At the end we should be able to run headless Selenium tests with Firefox. Please note that as X11 disaplay server we will use Xvfb. At first let&#8217;s install required packages and&hellip; <\/p>\n<div class=\"readmore-wrapper\"><a href=\"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/\" class=\"more-link\">Read <\/a><\/div>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[152],"tags":[212,275,270],"class_list":["post-2810","post","type-post","status-publish","format-standard","hentry","category-linux","tag-centos-en","tag-linux","tag-selenium"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Headless Selenium testing environment on Centos 6.5 &#8211; Supportex.NET blog<\/title>\n<meta name=\"description\" content=\"How to headless Selenium testing environment on CentOS 6.5. Selenium CentOS.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Headless Selenium testing environment on Centos 6.5 &#8211; Supportex.NET blog\" \/>\n<meta property=\"og:description\" content=\"How to headless Selenium testing environment on CentOS 6.5. Selenium CentOS.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/\" \/>\n<meta property=\"og:site_name\" content=\"Supportex.NET blog\" \/>\n<meta property=\"article:published_time\" content=\"2014-03-22T14:51:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-05-10T13:50:14+00:00\" \/>\n<meta name=\"author\" content=\"Oleksii Tykhonov\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Oleksii Tykhonov\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/\"},\"author\":{\"name\":\"Oleksii Tykhonov\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251\"},\"headline\":\"Headless Selenium testing environment on Centos 6.5\",\"datePublished\":\"2014-03-22T14:51:57+00:00\",\"dateModified\":\"2019-05-10T13:50:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/\"},\"wordCount\":200,\"keywords\":[\"CentOS\",\"linux\",\"Selenium\"],\"articleSection\":[\"linux\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/\",\"url\":\"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/\",\"name\":\"Headless Selenium testing environment on Centos 6.5 &#8211; Supportex.NET blog\",\"isPartOf\":{\"@id\":\"https:\/\/supportex.net\/blog\/en\/#website\"},\"datePublished\":\"2014-03-22T14:51:57+00:00\",\"dateModified\":\"2019-05-10T13:50:14+00:00\",\"author\":{\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251\"},\"description\":\"How to headless Selenium testing environment on CentOS 6.5. Selenium CentOS.\",\"breadcrumb\":{\"@id\":\"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/supportex.net\/blog\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Headless Selenium testing environment on Centos 6.5\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#website\",\"url\":\"https:\/\/supportex.net\/blog\/en\/\",\"name\":\"Supportex.NET blog\",\"description\":\"Server and network management company\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/supportex.net\/blog\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251\",\"name\":\"Oleksii Tykhonov\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g\",\"caption\":\"Oleksii Tykhonov\"},\"url\":\"https:\/\/supportex.net\/blog\/author\/oleksiitykhonov\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Headless Selenium testing environment on Centos 6.5 &#8211; Supportex.NET blog","description":"How to headless Selenium testing environment on CentOS 6.5. Selenium CentOS.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/","og_locale":"en_US","og_type":"article","og_title":"Headless Selenium testing environment on Centos 6.5 &#8211; Supportex.NET blog","og_description":"How to headless Selenium testing environment on CentOS 6.5. Selenium CentOS.","og_url":"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/","og_site_name":"Supportex.NET blog","article_published_time":"2014-03-22T14:51:57+00:00","article_modified_time":"2019-05-10T13:50:14+00:00","author":"Oleksii Tykhonov","twitter_misc":{"Written by":"Oleksii Tykhonov","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/#article","isPartOf":{"@id":"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/"},"author":{"name":"Oleksii Tykhonov","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251"},"headline":"Headless Selenium testing environment on Centos 6.5","datePublished":"2014-03-22T14:51:57+00:00","dateModified":"2019-05-10T13:50:14+00:00","mainEntityOfPage":{"@id":"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/"},"wordCount":200,"keywords":["CentOS","linux","Selenium"],"articleSection":["linux"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/","url":"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/","name":"Headless Selenium testing environment on Centos 6.5 &#8211; Supportex.NET blog","isPartOf":{"@id":"https:\/\/supportex.net\/blog\/en\/#website"},"datePublished":"2014-03-22T14:51:57+00:00","dateModified":"2019-05-10T13:50:14+00:00","author":{"@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251"},"description":"How to headless Selenium testing environment on CentOS 6.5. Selenium CentOS.","breadcrumb":{"@id":"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/supportex.net\/blog\/2014\/03\/selenium-installation-centos-6-5\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/supportex.net\/blog\/en\/"},{"@type":"ListItem","position":2,"name":"Headless Selenium testing environment on Centos 6.5"}]},{"@type":"WebSite","@id":"https:\/\/supportex.net\/blog\/en\/#website","url":"https:\/\/supportex.net\/blog\/en\/","name":"Supportex.NET blog","description":"Server and network management company","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/supportex.net\/blog\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/0690c26a0266603129fc15eae6243251","name":"Oleksii Tykhonov","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/supportex.net\/blog\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4fd5f58002717075c88963469b9babef?s=96&d=mm&r=g","caption":"Oleksii Tykhonov"},"url":"https:\/\/supportex.net\/blog\/author\/oleksiitykhonov\/"}]}},"_links":{"self":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/2810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/comments?post=2810"}],"version-history":[{"count":5,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/2810\/revisions"}],"predecessor-version":[{"id":3133,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/posts\/2810\/revisions\/3133"}],"wp:attachment":[{"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/media?parent=2810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/categories?post=2810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/supportex.net\/blog\/wp-json\/wp\/v2\/tags?post=2810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}