-
Notifications
You must be signed in to change notification settings - Fork 1
398 lines (341 loc) · 16.9 KB
/
Android_test.yml
File metadata and controls
398 lines (341 loc) · 16.9 KB
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
name: Alfie Android Test Automation
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
jobs:
android-tests:
runs-on: ubuntu-latest
env:
APP_URL: "https://github.com/Mindera/Alfie-UITests/releases/download/asdsad/Alfie.apk"
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: "17"
- name: Set up Android SDK
uses: android-actions/setup-android@v3
- name: Configure Android SDK
run: |
export ANDROID_HOME=$HOME/android-sdk
export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools
# Accept licenses and install required packages
yes | sdkmanager --licenses
sdkmanager "platform-tools" "platforms;android-35" "build-tools;31.0.0"
# Verify installation
adb --version
if [ $? -eq 0 ]; then
echo "✅ Android SDK setup complete"
else
echo "❌ Failed to setup Android SDK"
exit 1
fi
- name: Add emulator to PATH
run: echo "$ANDROID_HOME/emulator" >> $GITHUB_PATH
- name: Install Android system image (x86_64)
run: sdkmanager "system-images;android-35;google_apis;x86_64"
- name: Create AVD with proper env
run: |
mkdir -p ~/.android/avd
export ANDROID_SDK_HOME=$HOME
echo "no" | avdmanager create avd -n Medium_Phone_API_35 -k "system-images;android-35;google_apis;x86_64"
- name: Confirm AVD .ini files exist
run: |
ls -l ~/.android/avd
cat ~/.android/avd/*.ini || echo "No .ini found"
- name: List Android devices
run: |
echo "=== Emulator List ==="
emulator -list-avds
echo "=== AVD List ==="
avdmanager list avd
echo "=== Connected Devices ==="
adb devices
- name: Generate Gradle Wrapper
working-directory: Melmac
run: gradle wrapper --gradle-version 8.13
- name: Make Gradle Wrapper executable
working-directory: Melmac
run: chmod +x gradlew
- name: Build backend
working-directory: Melmac
run: ./gradlew build
- name: Prepare apps folder and download APK
working-directory: Melmac
run: |
mkdir -p src/main/resources/apps
echo "Downloading APK from $APP_URL"
curl -L "$APP_URL" -o src/main/resources/apps/Alfie.apk
ls -l src/main/resources/apps
- name: Start backend
working-directory: Melmac
run: ./gradlew run > $GITHUB_WORKSPACE/backend.log 2>&1 &
- name: Tail backend log
run: tail -f $GITHUB_WORKSPACE/backend.log &
- name: Wait for backend to be ready
run: |
for i in {1..31}; do
if curl -s http://localhost:8080/; then
echo "Backend is up!"
exit 0
fi
sleep 2
done
echo "Backend did not start in time" >&2
exit 1
- name: Create test suite
working-directory: Melmac
run: |
mkdir -p results
curl -s -X POST http://localhost:8080/test-suites \
-H "Content-Type: application/json" \
-d '{
"testSuiteName": "My Test Suite",
"testSuiteDescription": "Description of my test suite"
}' | tee results/test_suite.json
TEST_SUITE_ID=$(jq '.testSuiteId' results/test_suite.json)
echo "🧪 Extracted TEST_SUITE_ID: $TEST_SUITE_ID"
echo "TEST_SUITE_ID=$TEST_SUITE_ID" >> $GITHUB_ENV
- name: Create Android test plan
working-directory: Melmac
run: |
PLAN_INDEX=1
curl -s -X POST http://localhost:8080/test-plans \
-H "Content-Type: application/json" \
-d "{
\"notes\": \"Test plan for App Startup Time metric\",
\"testName\": \"Startup Time Plan\",
\"metricName\": \"App Startup Time\",
\"deviceName\": \"Medium_Phone_API_35\",
\"appName\": \"Alfie.apk\",
\"appVersion\": \"0.8.0\",
\"appPackage\": \"au.com.alfie.ecomm.debug\",
\"mainActivity\": \"au.com.alfie.ecomm.MainActivity\",
\"executionType\": \"Cold Start\",
\"thresholds\": [
{
\"targetValue\": 20000,
\"thresholdType\": \"Max\",
\"metricOutputMetricOutputId\": 1
}
],
\"metricParameters\": [
{
\"parameterValue\": \"home-tab\",
\"metricParameter\": \"elementToWaitFor\"
},
{
\"parameterValue\": \"200000\",
\"metricParameter\": \"timeout\"
}
],
\"executionTypeParameters\": [],
\"testSuiteVersionId\": ${TEST_SUITE_ID}
}" | tee results/test_plan_${PLAN_INDEX}.json
- name: Run Android test suite
working-directory: Melmac
run: |
mkdir -p results
echo "🚀 Running test suite with ID: $TEST_SUITE_ID"
echo "📡 Sending POST request to: http://localhost:8080/test-suites/$TEST_SUITE_ID/run"
: > results/suite_execution.json
http_code=$(curl -s -w "%{http_code}" -o results/suite_execution.json -X POST "http://localhost:8080/test-suites/$TEST_SUITE_ID/run")
echo "🔁 HTTP status code: $http_code"
echo "HTTP_CODE=$http_code" >> $GITHUB_ENV
echo "📄 Raw response body:"
cat results/suite_execution.json || echo "❌ suite_execution.json not found or empty"
if [ "$http_code" -ne 200 ]; then
echo "❌ Failed to run test suite. HTTP $http_code"
# Não termina o job para que o resumo corra
else
echo "✅ Suite execution request succeeded"
fi
- name: Generate summary
working-directory: Melmac
if: always()
run: |
mkdir -p results
http_status=$HTTP_CODE
if test -f results/suite_execution.json && [ "$http_status" = "200" ]; then
suiteExecutionId=$(jq '.suiteExecutionId' results/suite_execution.json)
testSuiteVersionId=$(jq '.testSuiteVersionTestSuiteVersionId' results/suite_execution.json)
echo "## Performance Test Suite Results (Android)" > results/summary.md
echo "" >> results/summary.md
echo "**Suite Execution:** $suiteExecutionId" >> results/summary.md
echo "**Test Suite Version:** $testSuiteVersionId" >> results/summary.md
echo "" >> results/summary.md
echo "### Test Execution Results" >> results/summary.md
# Build a map of testPlanVersionId to plan config (for multiple test plans)
declare -A PLAN_CONFIGS
for plan_file in results/test_plan_*.json; do
if [ -f "$plan_file" ]; then
planVersionId=$(jq '.testPlanVersionId // empty' "$plan_file")
if [ -n "$planVersionId" ]; then
PLAN_CONFIGS[$planVersionId]="$plan_file"
fi
fi
done
jq -c '.executionResults[]' results/suite_execution.json | while read -r exec; do
testPlanVersionId=$(echo "$exec" | jq '.testPlanVersionTestPlanVersionId')
passed=$(echo "$exec" | jq -r '.passed')
initialTimestamp=$(echo "$exec" | jq -r '.initialTimestamp')
endTimestamp=$(echo "$exec" | jq -r '.endTimestamp')
# Use stored plan config if available, else fallback to API
plan_file="${PLAN_CONFIGS[$testPlanVersionId]}"
if [ -n "$plan_file" ] && [ -f "$plan_file" ]; then
planVersion=$(cat "$plan_file")
else
planVersion=$(curl -s "http://localhost:8080/test-plan-versions/$testPlanVersionId")
fi
if ! echo "$planVersion" | jq empty > /dev/null 2>&1; then
echo "❌ Invalid JSON for planVersion: $planVersion" >> results/summary.md
continue
fi
appPackage=$(echo "$planVersion" | jq -r '.appPackage // "N/A"')
mainActivity=$(echo "$planVersion" | jq -r '.mainActivity // "N/A"')
executionTypeId=$(echo "$planVersion" | jq '.executionTypeExecutionTypeId')
appVersionId=$(echo "$planVersion" | jq '.appVersionAppVersionId')
deviceId=$(echo "$planVersion" | jq '.deviceDeviceId')
testPlanId=$(echo "$planVersion" | jq '.testPlanTestPlanId // .testPlanId')
appName=$(echo "$planVersion" | jq -r '.appName // "N/A"')
# Get testName and metricId from /test-plans/{id}
planInfo=$(curl -s "http://localhost:8080/test-plans/$testPlanId")
testName=$(echo "$planInfo" | jq -r '.testName // "N/A"')
metricId=$(echo "$planInfo" | jq -r '.metricMetricId')
# Get metric name
metricName=$(curl -s "http://localhost:8080/metrics/$metricId" | jq -r '.metricName // "N/A"')
# Get device name (using new endpoint)
deviceName=$(curl -s "http://localhost:8080/devices/$deviceId" | jq -r '.deviceName // "N/A"')
# Get app version and app name from DB
appVersionResp=$(curl -s "http://localhost:8080/apps/db/version/$appVersionId")
appVersion=$(echo "$appVersionResp" | jq -r '.appVersion // "N/A"')
appNameResp=$(curl -s "http://localhost:8080/apps/db/appByVersionId/$appVersionId")
appName=$(echo "$appNameResp" | jq -r '.appName // "N/A"')
# Get execution type name
executionTypesJson=$(curl -s "http://localhost:8080/metrics/$metricId/execution-types")
executionTypeName=$(echo "$executionTypesJson" | jq -r --arg id "$executionTypeId" '.[] | select(.executionTypeId == ($id|tonumber)) | .executionTypeName // "N/A"')
echo "#### Test Execution: $testName" >> results/summary.md
echo "- **Metric:** $metricName" >> results/summary.md
echo "- **Device:** $deviceName" >> results/summary.md
echo "- **App Name:** $appName" >> results/summary.md
echo "- **App Version:** $appVersion" >> results/summary.md
echo "- **App Package:** $appPackage" >> results/summary.md
echo "- **Main Activity:** $mainActivity" >> results/summary.md
echo "- **Execution Type:** $executionTypeName" >> results/summary.md
echo "" >> results/summary.md
# Table with execution-only values
echo "| Test Result | Start Time | End Time |" >> results/summary.md
echo "|-------------|------------|----------|" >> results/summary.md
echo "| $passed | $initialTimestamp | $endTimestamp |" >> results/summary.md
echo "" >> results/summary.md
# Always get metric outputs for this metric via /metrics/{id}/outputs
metricOutputsJson=$(curl -s "http://localhost:8080/metrics/$metricId/outputs")
if ! echo "$metricOutputsJson" | jq empty > /dev/null 2>&1; then
echo "❌ Invalid JSON for metric outputs: $metricOutputsJson" >> results/summary.md
continue
fi
# Thresholds (names only, using metricOutputsJson for output names)
echo "##### Thresholds" >> results/summary.md
echo "| Target Value | Threshold Type | Metric Output |" >> results/summary.md
echo "|--------------|---------------|--------------|" >> results/summary.md
for row in $(echo "$planVersion" | jq -c '.thresholds[]'); do
targetValue=$(echo "$row" | jq -r '.targetValue // "N/A"')
thresholdTypeId=$(echo "$row" | jq -r '.thresholdTypeThresholdTypeId // empty')
metricOutputId=$(echo "$row" | jq -r '.metricOutputMetricOutputId // empty')
thresholdTypeName="N/A"
if [ -n "$thresholdTypeId" ] && [ "$thresholdTypeId" != "null" ]; then
thresholdTypeResp=$(curl -s "http://localhost:8080/threshold-types/$thresholdTypeId")
if echo "$thresholdTypeResp" | jq empty > /dev/null 2>&1; then
thresholdTypeName=$(echo "$thresholdTypeResp" | jq -r '.thresholdTypeName // "N/A"')
fi
fi
metricOutputName="N/A"
if [ -n "$metricOutputId" ] && [ "$metricOutputId" != "null" ]; then
metricOutputName=$(echo "$metricOutputsJson" | jq -r --arg id "$metricOutputId" '.[] | select(.metricOutputId == ($id|tonumber)) | .outputName')
if [ -z "$metricOutputName" ]; then metricOutputName="N/A"; fi
fi
echo "| $targetValue | $thresholdTypeName | $metricOutputName |" >> results/summary.md
done
echo "" >> results/summary.md
# Metric Output Results (names only, using metricOutputsJson for output names)
echo "##### Metric Output Results" >> results/summary.md
echo "| Metric Output | Value |" >> results/summary.md
echo "|--------------|-------|" >> results/summary.md
outputsResp=$(curl -s "http://localhost:8080/test-executions/outputs?testExecutionId=$(echo "$exec" | jq '.testExecutionId')")
if ! echo "$outputsResp" | jq empty > /dev/null 2>&1; then
echo "❌ Invalid JSON for test execution outputs: $outputsResp" >> results/summary.md
continue
fi
echo "$outputsResp" | jq -c '.[]' | while read -r output; do
metricOutputId=$(echo "$output" | jq -r '.metricOutputMetricOutputId // empty')
value=$(echo "$output" | jq -r '.value // "N/A"')
metricOutputName="N/A"
if [ -n "$metricOutputId" ] && [ "$metricOutputId" != "null" ]; then
metricOutputName=$(echo "$metricOutputsJson" | jq -r --arg id "$metricOutputId" '.[] | select(.metricOutputId == ($id|tonumber)) | .outputName')
if [ -z "$metricOutputName" ]; then metricOutputName="N/A"; fi
fi
echo "| $metricOutputName | $value |" >> results/summary.md
done
echo "" >> results/summary.md
done
echo "✅ Summary generated"
else
echo "## Performance Test Suite Results (Android)" > results/summary.md
echo "" >> results/summary.md
echo "❌ Test suite execution failed." >> results/summary.md
echo "" >> results/summary.md
echo "**HTTP Status:** $http_status" >> results/summary.md
echo "" >> results/summary.md
if test -f results/suite_execution.json; then
echo '```json' >> results/summary.md
cat results/suite_execution.json >> results/summary.md
echo '```' >> results/summary.md
else
echo "No suite_execution.json found." >> results/summary.md
fi
fi
- name: Upload test results artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: Android-performance-test-results
path: Melmac/results/summary.md
- name: Add results to GitHub Actions summary
if: always()
run: |
if [ -f Melmac/results/summary.md ]; then
cat Melmac/results/summary.md >> $GITHUB_STEP_SUMMARY
else
echo "No summary file found." >> $GITHUB_STEP_SUMMARY
fi
- name: Comment results on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
let body = "No summary file found.";
if (fs.existsSync('Melmac/results/summary.md')) {
body = fs.readFileSync('Melmac/results/summary.md', 'utf8');
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `### 📝 Performance Test Results\n\n${body}`
});
- name: Upload backend log
if: always()
uses: actions/upload-artifact@v4
with:
name: android-backend-log
path: backend.log