-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_test.sh
executable file
·241 lines (210 loc) · 6.04 KB
/
run_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/bin/bash
trap tear_down INT TERM EXIT
set -e
export PATH=/usr/local/bin:$PATH
#BINs
git_bin=`which git`
kill_bin=`which kill`
curl_bin=`which curl`
find_bin=`which find`
mkdir_bin=`which mkdir`
unzip_bin=`which unzip`
# VARs
debug=false
clean_up=false
mvn_ver=3.5.2
skip_tests=false
test_name=ScriptTest
jenkins_ver=2.61
chromedriver_ver=2.36
no_color='\033[0m'
green_color='\e[92m'
java_home_18=$(find /Library/Java -name 'Home' | grep 1.8)
git_rev=63fa5aeaa3b59492ce4ea8f11ceab243e4a8afb8
# DIRs
base_dir=$( cd "$( dirname "$0" )" && pwd )
bin_dir=$base_dir/binaries
dw_dir=$base_dir/downloads
harness_dir=$base_dir/harness
usage()
{
echo "Usage: `basename $0` options (-c chromedriver_version) (-m mvn_version) (-j jenkins_version) (-t test_name) (-d) (-n) (-u) (-h)";
echo "-c chromedriver_version : specify chrome driver version (default $chromedriver_ver)"
echo "-m mvn_version : specify mvn version (default $mvn_ver)"
echo "-j jenkins_version : specify jenkins version (default $jenkins_ver)"
echo "-t test_name : specify test to run (default $test_name)"
echo "-d : enable verbose output"
echo "-n : skip tests and run IDE"
echo "-u : clean-up before testing"
echo "-h : show this help"
}
tear_down(){
# Tear-down environment
if [ ! -z "$JUT_PID" ]; then
$kill_bin -9 $JUT_PID
fi
pid_list=$(ps -ef | grep -i chrome | grep -v grep | awk '{print $2}')
if [ ! -z "$pid_list" ]; then
$kill_bin -9 $pid_list
fi
}
run_jut_server(){
# Setup jut server
counter=30
jut_server_log=$bin_dir/jut_server.log
jut_server_bin=$harness_dir/target/appassembler/bin/jut-server
export JENKINS_WAR=$jenkins_war
chmod u+x $jut_server_bin
($jut_server_bin &> $jut_server_log) &
jut_pid=$!
export JUT_PID=$jut_pid
while ! grep "Jenkins is running" $jut_server_log
do
sleep 1
let counter=counter-1
if [ $counter -eq 0 ]; then
break;
fi
done
}
run_ide(){
# Run IDE
idea_log=$bin_dir/idea.log
idea_bin=$($find_bin /Applications -type f -name idea -print -quit)
"$idea_bin" &> $idea_log
}
print_green(){
printf "$green_color$1$no_color\n"
}
while getopts "c:m:j:t:dnuh" option; do
case $option in
c )
chromedriver_ver=$OPTARG
;;
m )
mvn_ver=$OPTARG
;;
j )
jenkins_ver=$OPTARG
;;
t )
test_name=$OPTARG
;;
d )
set -x
debug=true
;;
n )
skip_tests=true
;;
u )
clean_up=true
;;
* | h )
usage
exit 0
;;
esac
done
mvn_ver_major=${mvn_ver%%.*}
#URLs
war_url="http://mirrors.jenkins.io/war/$jenkins_ver/jenkins.war"
repo_url="https://github.com/jenkinsci/acceptance-test-harness.git"
chromedriver_url="https://chromedriver.storage.googleapis.com/$chromedriver_ver/chromedriver_mac64.zip"
mvn_url="http://ftp.cixug.es/apache/maven/maven-$mvn_ver_major/$mvn_ver/binaries/apache-maven-$mvn_ver-bin.zip"
print_green "> Settings"
echo "> DEBUG=$debug"
echo "> TEST=$test_name"
echo "> MVN_VERSION=$mvn_ver"
echo "> JENKINS_VERSION=$jenkins_ver"
echo "> CHROMEDRIVER_VERSION=$chromedriver_ver"
echo "> GIT_REVISION=$git_rev"
# Cleanup
if [ $clean_up == true ]; then
print_green "> Cleanup dependencies"
rm -rf $bin_dir
rm -rf $harness_dir
fi
#Download dependencies
print_green "> Downloading dependencies"
$mkdir_bin -p $dw_dir
$mkdir_bin -p $bin_dir
# Setup maven
mvn_home=$bin_dir/apache-maven-$mvn_ver
if [ ! -d $mvn_home ]; then
# Download maven
mvn_zip=$dw_dir/apache-maven-$mvn_ver-bin.zip
print_green "> Setting Up Maven Version $mvn_ver"
if [ ! -f $mvn_zip ]; then
$curl_bin -s -o $mvn_zip $mvn_url
fi
# Extract maven
if [ -f $mvn_zip ]; then
$unzip_bin -qq -o $mvn_zip -d $bin_dir
fi
fi
# Add to path mvn home
if [ -d $mvn_home ]; then
export PATH=$mvn_home/bin:$PATH
fi
# Download jenkins
jenkins_war=$dw_dir/jenkins-$jenkins_ver.war
if [ ! -f $jenkins_war ] ; then
print_green "> Downloading Jenkins Version $jenkins_ver"
$curl_bin -L -s -o $jenkins_war $war_url
fi
# Setup chromedriver
chromedriver_home=$bin_dir/chrome_driver_$chromedriver_ver
if [ ! -d $chromedriver_home ]; then
# Download chromedriver
chromedriver_zip=$dw_dir/chromedriver_$chromedriver_ver.zip
print_green "> Setting Up Chrome Driver Version $chromedriver_ver"
if [ ! -f $chromedriver_zip ]; then
$curl_bin -s -o $chromedriver_zip $chromedriver_url
fi
# Extract maven
if [ -f $chromedriver_zip ]; then
$unzip_bin -qq -o $chromedriver_zip -d $chromedriver_home
fi
fi
# Add to path mvn home
if [ -d $chromedriver_home ]; then
export PATH=$chromedriver_home:$PATH
fi
# Code checkout
if [ ! -d $harness_dir ]; then
$git_bin clone $repo_url $harness_dir --quiet
fi
# Set specific revision
cd $harness_dir
$git_bin checkout $git_rev --quiet
# Set JAVA_HOME
export JAVA_HOME=$java_home_18
# Setup maven depencencies
mvn_bin=`which mvn`
# Maven cleanup
if [ $clean_up == true ]; then
print_green "> Run mvn cleanup"
$mvn_bin -q clean
fi
# Install maven depencencies
print_green "> Setup mvn dependencies"
$mvn_bin -q install -DskipTests
# Run JUT server
print_green "> Starting JUT server with Jenkins Version $jenkins_ver"
run_jut_server
print_green "> JUT server is ready!"
export BROWSER=chrome
if [ $skip_tests == true ]; then
print_green "> Starting IDE"
$mvn_bin -q generate-resources
run_ide
else
print_green "> Running $test_name"
$mvn_bin -q surefire-report:report -Dtest=$test_name
print_green "> Generate test report"
# Need to run site like this to avoid NoClassDefFoundError with DependencyFilter
$mvn_bin -q org.apache.maven.plugins:maven-site-plugin:2.2:site
print_green "> Open test report"
open $harness_dir/target/site/surefire-report.html
fi