Skip to content

Instantly share code, notes, and snippets.

@gunesmes
Last active January 21, 2022 09:02
Show Gist options
  • Save gunesmes/0e4e89f56562ac030048a3ce68005b69 to your computer and use it in GitHub Desktop.
Save gunesmes/0e4e89f56562ac030048a3ce68005b69 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Author: Mesut Güneş
set -e
cd $BITRISE_TEST_DIR_PATH
#-1 creating IPA
rm -rf Payload
mkdir Payload
cp -rf projectX.app Payload/
zip -r Payload.zip Payload/
mv Payload.zip projectX.ipa
#-2 zip tests
zip --symlinks -r projectXUITests-Runner.zip projectXUITests-Runner.app
#-3 upload app
upload_app=$(curl -u "$BROWSERSTACK_USER:$BROWSERSTACK_USER_TOKEN" -X POST "https://api-cloud.browserstack.com/app-automate/upload" -F "[email protected]")
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"
#-4 upload test
upload_test=$(curl -u "$BROWSERSTACK_USER:$BROWSERSTACK_USER_TOKEN" -X POST "https://api-cloud.browserstack.com/app-automate/xcuitest/test-suite" -F "[email protected]")
test_url=$(echo $upload_test | jq -r .test_url)
envman add --key BROWSERSTACK_TEST_URL --value $test_url
echo -e "\ntest_url: $test_url\n"
#-5 upload test
# we can filter the test for different purposes
# test_name="\"ProductCampaignScreenTests\", \"LoginScreenTests\"" ==> \"only-testing\": [$test_name]
test_name=""
trigger_tests=$(curl -u "$BROWSERSTACK_USER:$BROWSERSTACK_USER_TOKEN" \
-X POST "https://api-cloud.browserstack.com/app-automate/xcuitest/build" \
-d "{\"devices\": [\"iPhone 11 Pro-13\"], \"app\": \"$app_url\", \"deviceLogs\" : \"true\", \"testSuite\": \"$test_url\", \"only-testing\": [$test_name]}" \
-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"
#-6 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_USER_TOKEN" -X GET "https://api-cloud.browserstack.com/app-automate/xcuitest/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