Setup selenium headless browser on CentOS

1. Install Xvfb and dependencies:

    1) sudo yum -y install firefox Xvfb libXfont Xorg

    2) yum -y groupinstall "X Window System" "Desktop" "Fonts" "General Purpose Desktop"

2. Download and install chrome

    1) wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

    2) sudo yum install ./google-chrome-stable_current_*.rpm

3. Configure Xvfb

    1) vi /etc/init.d/Xvfb, paste the Xvfb script with following contents: 

 1 Xvfb script
 2 
 3 #!/bin/bash
 4 
 5 #
 6 
 7 # /etc/rc.d/init.d/Xvfbd
 8 
 9 #
10 
11 # chkconfig: 345 95 28
12 
13 # description: Starts/Stops X Virtual Framebuffer server
14 
15 # processname: Xvfb
16 
17 #
18 
19 . /etc/init.d/functions
20 
21 [ "${NETWORKING}" = "no" ] && exit 0
22 
23 PROG="Xvfb"
24 
25 PROG_OPTIONS=":7 -ac -screen 0 1024x768x24 +extension RANDR"
26 
27 PROG_OUTPUT="/tmp/Xvfb.out"
28 
29 case "$1" in
30 
31 start)
32 
33 echo -n "Starting : X Virtual Frame Buffer "
34 
35 $PROG $PROG_OPTIONS>>$PROG_OUTPUT 2>&1 &
36 
37 disown -ar
38 
39 /bin/usleep 500000
40 
41 status Xvfb & >/dev/null && echo_success || echo_failure
42 
43 RETVAL=$?
44 
45 if [ $RETVAL -eq 0 ]; then
46 
47 /bin/touch /var/lock/subsys/Xvfb
48 
49 /sbin/pidof -o%PPID -x Xvfb > /var/run/Xvfb.pid
50 
51 fi
52 
53 echo
54 
55 ;;
56 
57 stop)
58 
59 echo -n "Shutting down : X Virtual Frame Buffer"
60 
61 killproc $PROG
62 
63 RETVAL=$?
64 
65 [ $RETVAL -eq 0 ] && /bin/rm -f /var/lock/subsys/Xvfb /var/run/Xvfb.pid
66 
67 echo
68 
69 ;;
70 
71 restart|reload)
72 
73 $0 stop
74 
75 $0 start
76 
77 RETVAL=$?
78 
79 ;;
80 
81 status)
82 
83 status Xvfb
84 
85 RETVAL=$?
86 
87 ;;
88 
89 *)
90 
91 echo $"Usage: $0 (start|stop|restart|reload|status)"
92 
93 exit 1
94 
95 esac
96 
97 exit $RETVAL
Xvfb script

    2) Modify the script access

        (1) chmod +x /etc/init.d/Xvfb

        (2) chkconfig Xvfb on

        (3) service Xvfb start

    3) Configure DISPLAY environment variable in jenkins:

        (1) Manage Jenkins -> Configure System -> Global Properties -> Environment Variables

        (2) Add a variable: name=DISPLAY, value=:7

    4) (Optional) Try run: google-chrome   Just ignore the error message:Xlib:extension "RANDR" missing on display ":7".

4. Start selenium server

    1) In GCP terminal: cd to the selenium jar folder

    2) nohup java -jar ./lib/selenium-server-standalone-3.0.1.jar &

    3) Check the selenium server started status: ps -aux | grep java

    4) Add TargetURL as jenkins env, same as configure the DISPLAY in 4.3eg. For shareDev, TargetURL=https://target.url.com

5. Update job script

    1) Replace peggy URL in config.xml with ${TargetURL}

  find -name 'config.xml' | xargs perl -pi -e "s|Replace_With_Target_URL|${TargetURL}|g"

    2) Replace firebase URL and DB secret in FirebaseUtils.java with ${FIREBASE_URL} and ${FIREBASE_DB_SECRET}

  Using the same way as replacing the TargetURL

6. Add post action script for slack notification

    1) Refer to the setting:https://wiki.jenkins-ci.org/display/JENKINS/Slack+Plugin

    2) Custom message: "Job '${JOB_NAME} [${BUILD_NUMBER}]' (${BUILD_URL})"

    3) Other notification parameters refer to the "Jenkins”->“Manage Jenkins”->“Configure System”->”Global Slack Notifier Settings"

    4) Set job build trigger as ‘Projects to watch’ = 'folder_name/repo_name/master’, trigger when stable

 


 

posted @ 2017-03-29 13:54  Majesty  阅读(246)  评论(0编辑  收藏  举报