{"id":775,"date":"2013-07-09T14:49:28","date_gmt":"2013-07-09T12:49:28","guid":{"rendered":"http:\/\/blog.rabahi.net\/?page_id=775"},"modified":"2014-01-11T15:43:29","modified_gmt":"2014-01-11T14:43:29","slug":"maven-survival-guide","status":"publish","type":"page","link":"https:\/\/blog.rabahi.net\/?page_id=775","title":{"rendered":"Maven Selenium Survival Guide"},"content":{"rendered":"<h1>Integration Selenium with xvfb (X Virtual Framebuffer)<\/h1>\n<p>First, add this plugin in your pom.xml:<\/p>\n<pre lang=\"XML\">\r\n  <plugin>\r\n    <groupId>org.codehaus.mojo<\/groupId>\r\n    <artifactId>selenium-maven-plugin<\/artifactId>\r\n    <version>2.3<\/version>\r\n    <executions>\r\n\r\n      <execution>\r\n        <id>xvfb<\/id>\r\n        <phase>pre-integration-test<\/phase>\r\n        <goals>\r\n          <goal>xvfb<\/goal>\r\n        <\/goals>\r\n        <configuration>\r\n          <display>:1<\/display>\r\n        <\/configuration>\r\n      <\/execution>\r\n\r\n      <execution>\r\n        <id>start<\/id>\r\n        <phase>pre-integration-test<\/phase>\r\n        <goals>\r\n          <goal>start-server<\/goal>\r\n        <\/goals>\r\n        <configuration>\r\n          <background>true<\/background>\r\n        <\/configuration>\r\n      <\/execution>\r\n\r\n      <execution>\r\n        <id>stop<\/id>\r\n        <phase>post-integration-test<\/phase>\r\n        <goals>\r\n          <goal>stop-server<\/goal>\r\n        <\/goals>\r\n      <\/execution>\r\n    <\/executions>\r\n  <\/plugin>\r\n<\/pre>\n<p>Then, install xvfb and firefox:<\/p>\n<pre lang=\"bash\">\r\nyum install Xvfb firefox\r\n<\/pre>\n<p>Next, you have to create the Xvfb service (\/etc\/init.d\/xvfbd):<\/p>\n<pre lang=\"bash\">\r\n#!\/bin\/bash\r\n#\r\n# \/etc\/rc.d\/init.d\/xvfbd\r\n#\r\n# chkconfig: 345 95 28\r\n# description: Starts\/Stops X Virtual Framebuffer server\r\n# processname: Xvfb\r\n#\r\n\r\n. \/etc\/init.d\/functions\r\n\r\n[ \"${NETWORKING}\" = \"no\" ] && exit 0\r\n\r\nPROG=\"Xvfb\"\r\nPROG_OPTIONS=\":7 -ac -screen 0 1024x768x24\"\r\nPROG_OUTPUT=\"\/tmp\/Xvfb.out\"\r\n\r\ncase \"$1\" in\r\n    start)\r\n        echo -n \"Starting : X Virtual Frame Buffer \"\r\n        $PROG $PROG_OPTIONS>>$PROG_OUTPUT 2>&1 &\r\n        disown -ar\r\n        \/bin\/usleep 500000\r\n        status Xvfb & >\/dev\/null && echo_success || echo_failure\r\n        RETVAL=$?\r\n        if [ $RETVAL -eq 0 ]; then\r\n            \/bin\/touch \/var\/lock\/subsys\/Xvfb\r\n            \/sbin\/pidof -o  %PPID -x Xvfb > \/var\/run\/Xvfb.pid\r\n        fi\r\n        echo\r\n        ;;\r\n    stop)\r\n        echo -n \"Shutting down : X Virtual Frame Buffer\"\r\n        killproc $PROG\r\n        RETVAL=$?\r\n        [ $RETVAL -eq 0 ] && \/bin\/rm -f \/var\/lock\/subsys\/Xvfb \/var\/run\/Xvfb.pid\r\n        echo\r\n        ;;\r\n    restart|reload)\r\n        $0 stop\r\n        $0 start\r\n        RETVAL=$?\r\n        ;;\r\n    status)\r\n        status Xvfb\r\n        RETVAL=$?\r\n        ;;\r\n    *)\r\n     echo $\"Usage: $0 (start|stop|restart|reload|status)\"\r\n     exit 1\r\nesac\r\n\r\nexit $RETVAL\r\n<\/pre>\n<p>And launch the service:<\/p>\n<pre lang=\"bash\">\r\nchmod +x \/etc\/init.d\/xvfbd\r\nchkconfig xvfbd on\r\nservice xvfbd start\r\n\r\n#init dbus (deal with this error:Failed to open \"\/var\/lib\/dbus\/machine-id\")\r\ndbus-uuidgen > \/var\/lib\/dbus\/machine-id\r\n<\/pre>\n<p>Finally, run you maven project:<\/p>\n<pre lang=\"bash\">\r\nexport DISPLAY=:7\r\nmvn clean install\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Integration Selenium with xvfb (X Virtual Framebuffer) First, add this plugin in your pom.xml: org.codehaus.mojo selenium-maven-plugin 2.3 xvfb pre-integration-test xvfb :1 start pre-integration-test start-server true stop post-integration-test stop-server Then, install xvfb and firefox: yum install Xvfb firefox Next, you have to create the Xvfb service (\/etc\/init.d\/xvfbd): #!\/bin\/bash # # \/etc\/rc.d\/init.d\/xvfbd # # chkconfig: 345 95 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":884,"menu_order":4,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-775","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=775"}],"version-history":[{"count":7,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/775\/revisions"}],"predecessor-version":[{"id":879,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/775\/revisions\/879"}],"up":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/884"}],"wp:attachment":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}