forked from dhis2/dhis2-android-capture-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowserstackJenkinsForm.sh
More file actions
64 lines (53 loc) · 2.64 KB
/
browserstackJenkinsForm.sh
File metadata and controls
64 lines (53 loc) · 2.64 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
#!/bin/bash
set -ex
source config_jenkins.init
echo "Uploading form test APK to Browserstack..."
upload_form_apk_test_response="$(curl -u $BROWSERSTACK_USR:$BROWSERSTACK_PSW -X POST https://api-cloud.browserstack.com/app-automate/espresso/v2/module-app -F file=@$form_apk_path)"
module_url=$(echo "$upload_form_apk_test_response" | jq .module_url)
# Prepare json and run tests
echo "Starting execution of tests..."
json=$(jq -n \
--argjson module_url $module_url \
--argjson devices ["$browserstack_device_list"] \
--arg video "$browserstack_video" \
--arg deviceLogs "$browserstack_deviceLogs" \
--arg singleRunnerInvocation "$browserstack_singleRunnerInvocation" \
--arg buildTag "$buildTag" \
'{devices: $devices, testSuite: $module_url, video: $video, deviceLogs: $deviceLogs, singleRunnerInvocation: $singleRunnerInvocation, buildTag: $buildTag}')
test_execution_response="$(curl -X POST https://api-cloud.browserstack.com/app-automate/espresso/v2/module-build -d \ "$json" -H "Content-Type: application/json" -u "$BROWSERSTACK_USR:$BROWSERSTACK_PSW")"
# Get build
build_id=$(echo "$test_execution_response" | jq -r .build_id)
echo "build id running: $build_id"
# Monitor build status
build_status="running"
sleep $build_time_average_short
echo "Monitoring build status started...."
while [[ $build_status = "running" ]];
do
# Get build status
build_status_response="$(curl -u "$BROWSERSTACK_USR:$BROWSERSTACK_PSW" -X GET "https://api-cloud.browserstack.com/app-automate/espresso/builds/$build_id")"
build_status=$(echo "$build_status_response" | jq -r .status)
echo "current build status: $build_status"
# Sleep until next poll
sleep $polling_interval
done
# Export test reports to bitrise
test_reports_url="https://app-automate.browserstack.com/dashboard/v2/builds/$build_id"
# weird behavior from Browserstack api, you can have "done" status with failed tests
# "devices" only show one device result which is inconsistance
# then "device_status" is checked
if [[ $build_status = "failed" || $build_status = "error" ]];
then
echo "Browserstack build failed, please check the execution of your tests $test_reports_url"
exit 1
else
device_status=$(echo "$build_status_response" | jq -r '.device_statuses.error | to_entries[].value')
if [[ $device_status = "Failed" ]]; # for this Failed Browserstack used bloq mayus
then
echo "Browserstack build failed, please check the execution of your tests $test_reports_url"
exit 1
else
echo "Browserstack build passed, please check the execution of your tests $test_reports_url"
exit 0
fi
fi