-
Notifications
You must be signed in to change notification settings - Fork 0
/
parallels.sh
executable file
·190 lines (165 loc) · 4.47 KB
/
parallels.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
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Faltou utilizar pelo menos um argumento!"
exit 1
fi
#global variables
# inputs
# -p [PLATFORM] -n [node number/ test number] -t [tags] -g group_by scenarios | steps | features -s Skin
while getopts "t:g:n:p:s:a:" OPTION
do
case $OPTION in
t) TAGS="--tags $OPTARG"
OTAG="-o"
;;
# scenarios | steps | features
g) GROUP_BY="-p --group-by $OPTARG"
;;
n) NODES="-n $OPTARG"
NODESN=$OPTARG
;;
p) PLATFORM=$OPTARG
;;
s) SKIN=$OPTARG
;;
a) API=$OPTARG
;;
esac
done
shift $((OPTIND-1))
# environment
function environments(){
if [ "$PLATFORM" == "ios" ]; then
name=$PLATFORM
export PLATAFORMAAPI=$PLATFORM$API
export PLATAFORMA=$PLATFORM$API
export PLATAFORMA_EX='android'
export SISTEMA='ios'
else
export PLATAFORMAAPI=$PLATFORM$API
export PLATAFORMA=$PLATFORM$API
export PLATAFORMA_EX='ios'
export SISTEMA='android'
name=$PLATFORM
fi
if [ "$API" == "10" ]; then
api=10-0
elif [ "$API" == "11" ]; then
api=11-4
elif [ "$API" == "19" ]; then
api='system-images;android-19;google_apis;x86'
aabi=google_apis/x86
portemulator="7"
elif [ "$API" == "26" ]; then
api='system-images;android-26;google_apis;x86_64'
aabi=google_apis/x86_64
portemulator="6"
else
echo "Versão de sistema não cadastrada"
fi
};
# create Android Emulators
# Skin 1: J5API19 WXGA 2: Nexus_5X
function create_android_emulator(){
if [ "$SKIN" == "1" ]; then
skin=J5API19
else
skin=10
fi
$ANDROID_HOME/tools/bin/avdmanager -s --silent create avd --force --name ${names[$i]} --abi $aabi --package $api --device $skin &>/dev/null
}
# start Android Emulators
function start_android_emulator(){
i2=0
for device in $(emulator -list-avds | GREP $name)
do
port=$(($i2*2))
emulator -avd $device -port 55$portemulator$port -no-snapshot &
let i2=$i2+1
done
}
function wait_android_emulator(){
i5=0
for device in $(emulator -list-avds | GREP $name)
do
port2=$(($i5*2))
while [ "`adb -s emulator-55$portemulator$port2 shell getprop sys.boot_completed | tr -d '\r' `" != "1" ] ; do sleep 1; done
let i5=$i5+1
done
}
# create iOS Emulators
function create_ios_emulator(){
if [ "$SKIN" == "1" ]; then
skin=iPhone-7
else
skin=iPhone-SE
fi
uuid[$i]=`xcrun simctl create ${names[$i]} com.apple.CoreSimulator.SimDeviceType.$skin com.apple.CoreSimulator.SimRuntime.iOS-$api`
}
# start iOS Emulators
# function start_ios_emulator(){
# # xcrun simctl boot ${uuid[$i2]}
# }
# start Appium Server
function appium_start(){
appium_stop
appium &>/dev/null &
}
# stop appium server
function appium_stop(){
ps aux | grep "bin/appium" | grep -v grep | awk '{print $2}' | xargs kill -9
}
# start functional tests
function start_cucumber_parallel(){
if [ "$OTAG" == "-o" ]; then
parallel_cucumber features/ $GROUP_BY $NODES $OTAG "$TAGS"
else
parallel_cucumber features/ $GROUP_BY $NODES
fi
}
# destroi android emulators
function delete_android_emulator(){
for DEVICE in `ps -ef |grep -v grep |grep emulator |awk '{print $2}'`; do kill -9 $DEVICE; done
$ANDROID_HOME/tools/bin/avdmanager delete avd -n ${names[$i1]} &>/dev/null &
}
# destroi ios emulators
function delete_ios_emulator(){
xcrun simctl shutdown ${uuid[$i1]}
sleep 20
xcrun simctl delete ${uuid[$i1]}
}
# generate report
function generate_report(){
report_builder -s 'report/' -o together.html
}
environments
i=0
while [ $i -lt $NODESN ]; do
names[$i]=$name$API$i
if [ "$PLATFORM" == "ios" ]; then
create_ios_emulator
else
create_android_emulator
fi
let i=$i+1
done
if [ "$PLATFORM" == "android" ]; then
start_android_emulator
fi
mkdir -p reports/"$PLATFORM$API"
appium_start
if [ "$PLATFORM" == "android" ]; then
wait_android_emulator
fi
start_cucumber_parallel
generate_report
appium_stop
i1=0
while [ $i1 -lt $NODESN ]; do
if [ "$PLATFORM" == "ios" ]; then
delete_ios_emulator
else
delete_android_emulator
fi
let i1=$i1+1
done