Remove azure storage logic from UI tests

This commit is contained in:
Guillaume Perrot 2017-12-08 15:52:43 -08:00
Родитель 75cb704df8
Коммит 2743fe5f99
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 9C234D95CFD46DA9
2 изменённых файлов: 4 добавлений и 207 удалений

Просмотреть файл

@ -1,153 +0,0 @@
#!/bin/bash
# Script usage:
# Running locally: ./get-ui-test-results.sh {ANDROID_TEST_RUN_ID} {IOS_TEST_RUN_ID}
# Running on bitrise: ./get-ui-test-results.sh
# The APP_CENTER_USERNAME environment variable must be set
if [ -z ${APP_CENTER_USERNAME+x} ]; then
echo "Error - the environment variable APP_CENTER_USERNAME must be set."
exit 1
fi
# Define constants
# App Center constants
ANDROID_APP_NAME="appcenter-xamarin-testing-app-android"
IOS_APP_NAME="appcenter-xamarin-testing-app-ios"
ANDROID_APP="$APP_CENTER_USERNAME/$ANDROID_APP_NAME"
IOS_APP="$APP_CENTER_USERNAME/$IOS_APP_NAME"
ANDROID_PORTAL_URL="https://appcenter.ms/users/$APP_CENTER_USERNAME/apps/$ANDROID_APP_NAME/test/runs/"
IOS_PORTAL_URL="https://appcenter.ms/users/$APP_CENTER_USERNAME/apps/$IOS_APP_NAME/test/runs/"
# Text attribute constants
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
BOLD=$(tput bold)
UNATTRIBUTED=$(tput sgr0)
# Platform name constants
IOS_NAME="iOS"
ANDROID_NAME="Android"
# Define functions
# This function downloads a file containing specified file (containing a test run id)
# from Azure Storage
# Usage: download_file {FILE_NAME} {PLATFORM_NAME}
download_file() {
FILE_NAME="$1"
PLATFORM_NAME="$2"
azure storage blob download -q $AZURE_STORAGE_CONTAINER $FILE_NAME
if [ $? -ne 0 ]; then
echo "Error downloading $PLATFORM_NAME test run ID."
exit 1
fi
}
# This function prints the test results for a given platform and return code
# Usage: print_results {PLATFORM_NAME} {RETURN_CODE}
print_results () {
PLATFORM_NAME="$1"
RETURN_CODE=$2
if [ $RETURN_CODE -eq 1 ]; then
echo "${BOLD}$PLATFORM_NAME test results: ${GREEN}passed! ${UNATTRIBUTED}"
fi
if [ $RETURN_CODE -eq 2 ]; then
echo "${BOLD}$1 test results: ${RED}failed. ${UNATTRIBUTED}"
fi
}
# This function contacts the App Center backend to determine the specified test's current
# status. Echoes 0 for in progress, 1 for passed, 2 for failed.
# Usage: test_status {TEST_RUN_ID} {APP_NAME}
test_status() {
TEST_RUN_ID="$1"
APP_NAME="$2"
# If and only if we see this text in the report, test is done
TEST_STATUS_DONE_TEXT="Current test status: Done"
RESULTS_FILE="results_file.txt"
TEST_DONE=0
appcenter test status --test-run-id $TEST_RUN_ID --app "$APP_NAME" > $RESULTS_FILE
RETURN_CODE=$?
if grep -q "$TEST_STATUS_DONE_TEXT" "$RESULTS_FILE"; then
TEST_DONE=1
fi
rm $RESULTS_FILE
if [ $TEST_DONE -eq 0 ]; then # still running
echo 0
else
if [ $RETURN_CODE -eq 0 ]; then # passed
echo 1
fi
if [ $RETURN_CODE -ne 0 ]; then # failed
echo 2
fi
fi
}
# Log in to App Center
./appcenter-login.sh
if [ $? -ne 0 ]; then
exit 1
fi
# If script is running in bitrise environment, then test run ids must be downloaded
if ! [ -z ${IN_BITRISE+x} ]; then # We are in bitrise environment
echo "Bitrise environment detected. Retrieving test run IDs from Azure Storage..."
# Download iOS test run ID from Azure Storage
download_file $IOS_TEST_RUN_ID_FILE $IOS_NAME
download_file $ANDROID_TEST_RUN_ID_FILE $ANDROID_NAME
IOS_TEST_RUN_ID=$(cat "$IOS_TEST_RUN_ID_FILE")
ANDROID_TEST_RUN_ID=$(cat "$ANDROID_TEST_RUN_ID_FILE")
echo "Test run IDs successfully retrieved."
else # Not in bitrise environment
# Make sure there are two arguments
if [ -z ${2+x} ]; then
echo "Error - usage: ./get-ui-test-results.sh {ANDROID_TEST_RUN_ID} {IOS_TEST_RUN_ID}"
exit 1
fi
ANDROID_TEST_RUN_ID="$1"
IOS_TEST_RUN_ID="$2"
fi
# Wait for results to become available, checking every ten seconds
IOS_RESULT=0
ANDROID_RESULT=0
while [ $IOS_RESULT -eq 0 ] || [ $ANDROID_RESULT -eq 0 ]; do
echo "Checking results..."
# Get iOS test status
if [ $IOS_RESULT -eq 0 ]; then #iOS is still running
IOS_RESULT=$(test_status "$IOS_TEST_RUN_ID" "$IOS_APP")
if [ $IOS_RESULT -ne 0 ]; then
echo "$IOS_NAME test is done."
fi
fi
# Get android test status
if [ $ANDROID_RESULT -eq 0 ]; then #Android is still running
ANDROID_RESULT=$(test_status "$ANDROID_TEST_RUN_ID" "$ANDROID_APP")
if [ $ANDROID_RESULT -ne 0 ]; then
echo "$ANDROID_NAME test is done."
fi
fi
# If tests are not done, wait ten seconds before continuing
if [ $IOS_RESULT -eq 0 ] || [ $ANDROID_RESULT -eq 0 ]; then
echo "Waiting 10 seconds..."
sleep 10
fi
done
# Print results
print_results $ANDROID_NAME $ANDROID_RESULT
print_results $IOS_NAME $IOS_RESULT
echo "Full $IOS_NAME test results at $IOS_PORTAL_URL$IOS_TEST_RUN_ID"
echo "Full $ANDROID_NAME test results at $ANDROID_PORTAL_URL$ANDROID_TEST_RUN_ID"
# If either test was unsuccsessful, exit failure
if [ $IOS_RESULT -eq 2 ] || [ $ANDROID_RESULT -eq 2 ]; then
exit 1
fi
exit 0

Просмотреть файл

@ -57,46 +57,16 @@ fi
# Define functions
# This function extracts the test run ID from an information file, and then echoes it
# Usage: get_test_run_id {INFORMATION_FILE}
get_test_run_id() {
INFORMATION_FILE="$1"
while read -r line
do
if [ $(expr "$line" : "Test run id: ") -ne 0 ]; then
echo $(echo $line | cut -d'"' -f 2)
break
fi
done < $INFORMATION_FILE
}
# This function prints the results of test initialization
# Usage: print_initialization_results {RETURN_CODE} {PLATFORM_NAME} {PORTAL_URL} {TEST_RUN_ID}
print_initialization_results() {
RETURN_CODE=$1
PLATFORM_NAME="$2"
PORTAL_URL="$3"
TEST_RUN_ID="$4"
if [ $RETURN_CODE -ne 0 ]; then
echo "$PLATFORM_NAME test failed to initiate."
fi
if [ $RETURN_CODE -eq 0 ]; then
echo "$PLATFORM_NAME test run ID: $TEST_RUN_ID"
echo "$PLATFORM_NAME test results: $PORTAL_URL$TEST_RUN_ID"
fi
}
# This function initializes tests for the given parameters
# Usage: initialize_tests {APP_NAME} {DEVICES_CODE} {APP_PACKAGE} {INFORMATION_FILE}
# Usage: initialize_tests {APP_NAME} {DEVICES_CODE} {APP_PACKAGE}
initialize_tests() {
APP_NAME="$1"
DEVICES_CODE="$2"
APP_PACKAGE="$3"
INFORMATION_FILE="$4"
appcenter test run uitest --app $APP_NAME\
--devices $DEVICES_CODE --app-path $APP_PACKAGE\
--test-series $TEST_SERIES --locale $LOCALE\
--build-dir $UITEST_BUILD_DIR --async true > $INFORMATION_FILE
--build-dir $UITEST_BUILD_DIR --async true
echo $?
}
@ -126,33 +96,13 @@ popd
# Run Android tests
echo "Initializing Android tests..."
ANDROID_RETURN_CODE=$(initialize_tests $ANDROID_APP $ANDROID_DEVICES $TEST_APK $ANDROID_INFORMATION_FILE)
ANDROID_TEST_RUN_ID=$(get_test_run_id $ANDROID_INFORMATION_FILE)
echo $ANDROID_TEST_RUN_ID
print_initialization_results $ANDROID_RETURN_CODE "$ANDROID_PLATFORM_NAME" "$ANDROID_PORTAL_URL" "$ANDROID_TEST_RUN_ID"
cat $ANDROID_INFORMATION_FILE
rm $ANDROID_INFORMATION_FILE
ANDROID_RETURN_CODE=$(initialize_tests $ANDROID_APP $ANDROID_DEVICES $TEST_APK)
# Run iOS tests
echo "Initializing iOS tests..."
IOS_RETURN_CODE=$(initialize_tests $IOS_APP $IOS_DEVICES $TEST_IPA $IOS_INFORMATION_FILE)
IOS_TEST_RUN_ID=$(get_test_run_id $IOS_INFORMATION_FILE)
print_initialization_results $IOS_RETURN_CODE "$IOS_PLATFORM_NAME" "$IOS_PORTAL_URL" "$IOS_TEST_RUN_ID"
cat $IOS_INFORMATION_FILE
rm $IOS_INFORMATION_FILE
IOS_RETURN_CODE=$(initialize_tests $IOS_APP $IOS_DEVICES $TEST_IPA)
# If iOS or Android tests failed to be initiated, exit failure. Otherwise exit success
if [ $IOS_RETURN_CODE -ne 0 ] || [ $ANDROID_RETURN_CODE -ne 0 ]; then
exit 1
fi
# If enabled, upload test run IDs to Azure Storage
if [ "$UPLOAD_RUN_IDS_TO_STORAGE" == "true" ]; then
echo "Writing test run IDs to files..."
echo "$IOS_TEST_RUN_ID" > $IOS_TEST_RUN_ID_FILE
echo "$ANDROID_TEST_RUN_ID" > $ANDROID_TEST_RUN_ID_FILE
azure storage blob upload -q $IOS_TEST_RUN_ID_FILE $AZURE_STORAGE_CONTAINER
azure storage blob upload -q $ANDROID_TEST_RUN_ID_FILE $AZURE_STORAGE_CONTAINER
fi
exit 0