Created
January 21, 2022 11:08
-
-
Save gunesmes/67e8873416abe7a1442c63292e7afcb7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Author: Mesut Güneş | |
set -e | |
#-1 upload app | |
upload_app=$(curl -u "$BROWSERSTACK_USER:$BROWSERSTACK_ACCESS_KEY" -X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/app" -F "file=@$BITRISE_APK_PATH") | |
app_url=$(echo $upload_app | jq -r .app_url) | |
envman add --key BROWSERSTACK_APP_URL --value $app_url | |
echo -e "\napp_url: $app_url\n" | |
#-2 upload test | |
upload_test=$(curl -u "$BROWSERSTACK_USER:$BROWSERSTACK_ACCESS_KEY" -X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/test-suite" -F "file=@$BITRISE_TEST_APK_PATH") | |
test_url=$(echo $upload_test | jq -r .test_suite_url) | |
envman add --key BROWSERSTACK_TEST_URL --value $test_url | |
echo -e "\ntest_url: $test_url\n" | |
#-3 trigger test | |
# TODO: We must pass clearPackageData=true to clear app data between tests | |
# but this is not supported by Browserstack | |
trigger_tests=$(curl -u "$BROWSERSTACK_USER:$BROWSERSTACK_ACCESS_KEY" \ | |
-X POST "https://api-cloud.browserstack.com/app-automate/espresso/v2/build" \ | |
-d "{\"devices\": [\"Samsung Galaxy S9 Plus-9.0\"], \"app\": \"$app_url\", \"testSuite\": \"$test_url\"}" \ | |
-H "Content-Type: application/json") | |
build_id=$(echo $trigger_tests | jq -r .build_id) | |
envman add --key BROWSERSTACK_TEST_BUILD_ID --value $build_id | |
echo -e "\ntrigger_tests: $trigger_tests\n" | |
echo -e "\nbuild_id: $build_id\n" | |
#-4 wait tests until 30mins | |
end=$((SECONDS+1800)) | |
exit_code=1 | |
status="not run" | |
while true | |
do | |
if [ $SECONDS -gt $end ]; then | |
echo " - Timeout for Test RUN!" | |
break | |
fi | |
status=$( curl -u "$BROWSERSTACK_USER:$BROWSERSTACK_ACCESS_KEY" -X GET "https://api-cloud.browserstack.com/app-automate/espresso/v2/builds/$build_id" | jq -r .status ) | |
if [ "$status" == "running" ]; then | |
echo -e " - Still running, waiting . . ." | |
sleep 5; | |
elif [ "$status" == "passed" ]; then | |
exit_code=0 | |
break | |
else | |
break | |
fi | |
done; | |
test_result_url="https://app-automate.browserstack.com/dashboard/v2/builds/$build_id" | |
envman add --key BROWSERSTACK_TEST_RESULT_URL --value $test_result_url | |
echo "status: $status" | |
echo -e "\nCheck the test result from Browserstack: \n - $test_result_url" | |
exit $exit_code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment