On Android stacks we have the gcloud and gsutil tools pre-installed, this guide is based on these tools. If you want to use it on other stacks, you will need to install these first.
###What you’ll need
a Google Cloud Platform service account and its JSON key file.
the project to be linked to Firebase gsutil and gcloud use Google services, so the best is if you create the project on Google Cloud Platform Console, and then import this project into Firebase
Running Firebase TestLab tests is similar to the initial Android build workflow, but some modifications will be needed.
###Modify the workflow to use Firebase for tests (in this case: espresso instrumentation)
Upload your service account’s JSON key file on Code Signing tab, under Generic File Storage: name it SERVICE_ACCOUNT_KEY and drop the file into the box, so the downloadable environment variable that contains the url will be: $BITRISEIO_SERVICE_ACCOUNT_KEY_URL
Create a new variable under Env Vars tab. Name it GCP_PROJECT and set its value to the project ID used in Firebase Console and/or in Google Cloud Platform Console.
In the Gradle Runner step We will need two APKs exported to BITRISE_DEPLOY_DIR: both unaligned, one test apk and the other a debug apk.
Change gradle_task to: "assembleDebug assembleDebugAndroidTest"
Remove everything from apk_file_exclude_filter, leave it empty
Set apk_file_include_filter to: "*-unaligned.apk"
Add a script step after your gradle-runner step, and set it’s content to:
#!/bin/bash
set -ex
#Download service account key
curl -o /tmp/sacc_key.json $BITRISEIO_SERVICE_ACCOUNT_KEY_URL
#Activate cloud client with the service account
gcloud auth activate-service-account -q --key-file /tmp/sacc_key.json
#Set the project's id used on Google Cloud Platform
gcloud config set project $GCP_PROJECT
RESULT_DIR="build-$BITRISE_BUILD_NUMBER"
APK="--app=$BITRISE_DEPLOY_DIR/app-debug-unaligned.apk --test=$BITRISE_DEPLOY_DIR/app-debug-androidTest-unaligned.apk"
TYPE="instrumentation"
DEVICES="--device model=Nexus6,version=21,locale=en,orientation=portrait"
gcloud firebase test android run $APK $DEVICES --type=$TYPE --results-dir=$RESULT_DIR/ >>$BITRISE_DEPLOY_DIR/gcloudlog.log 2>&1
SRCPTH=$BITRISE_DEPLOY_DIR/test_results
EXPPTH=$BITRISE_DEPLOY_DIR
mkdir $SRCPTH
#Download test results
FB_BUCKET=$(grep -oP "(?<=browser\/).*(?<=\/$RESULT_DIR)" $BITRISE_DEPLOY_DIR/gcloudlog.log)
gsutil -m cp -R gs://$FB_BUCKET $SRCPTH
for file in $(find $SRCPTH -type f)
do
if [[ -f $file ]]; then
f=$(echo ${file//$SRCPTH\/$RESULT_DIR\/})
mv $file $(echo $EXPPTH/${f//\//_})
fi
done
If everything is configured correctly, you should see your test results among build artifacts.
If you encounter any issues or have a question, please drop a line here and we’ll figure it out as fast as possible.
I am trying to apply your tutorial but I am kind of stuck to the script step.
It seems that I cannot use “Cloud Tool Result API”.
Here is the log of my “script step” :
+------------------------------------------------------------------------------+
| (5) script@1.1.4 |
+------------------------------------------------------------------------------+
| id: script |
| version: 1.1.4 |
| collection: https://github.com/bitrise-io/bitrise-steplib.git |
| toolkit: bash |
| time: 2017-07-14T15:19:29Z |
+------------------------------------------------------------------------------+
| |
+ curl -o /tmp/sacc_key.json 'https://concrete-userfiles-production.s3-us-west-
2.amazonaws.com/project_file_storage_documents/uploads/4504/original/google_play_api_key.json?X-Amz-
Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKFZGFGFDF256G7J2W2TQ%2F20170714%2Fus-west-
2%2Fs3%2Faws4_request&X-Amz-Date=20170714T151601Z&X-Amz-Expires=86400&X-Amz-
SignedHeaders=host&X-Amz-
Signature=af5c077789217ace95b721ac2e8615653538ff2732f1423bb29150096a3dc49b'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 2386 100 2386 0 0 3338 0 --:--:-- --:--:-- --:--:-- 3337
+ gcloud auth activate-service-account -q --key-file /tmp/sacc_key.json
Activated service account credentials for: [bitrise-developer@api-6348956192866480301-
420807.iam.gserviceaccount.com]
+ gcloud config set project cidemo-66b1d
Updated property [core/project].
++ printf %q android_test_automation
+ RESULT_BUCKET=gs://android_test_automation
+ RESULT_DIR=build-19
+ APK='--app=/bitrise/deploy/app-debug-unaligned.apk --test=/bitrise/deploy/app-debug-androidTest-unaligned.apk'
+ TYPE=instrumentation
+ DEVICES='--device model=Nexus6,version=21,locale=en,orientation=portrait --device
model=Nexus7,version=19,locale=fr,orientation=landscape'
+ gcloud firebase test android run --app=/bitrise/deploy/app-debug-unaligned.apk --test=/bitrise/deploy/app-debug-
androidTest-unaligned.apk --device model=Nexus6,version=21,locale=en,orientation=portrait --device
model=Nexus7,version=19,locale=fr,orientation=landscape --type=instrumentation --results-
bucket=gs://android_test_automation --results-dir=build-19/
Have questions, feedback, or issues? Get support by visiting:
Creating results bucket [gs://android_test_automation] in project [cidemo-66b1d].
ERROR: (gcloud.firebase.test.android.run) Permission denied while creating bucket [android_test_automation]. Is billing enabled for project: [cidemo-66b1d]?
Yes, I have been to the console and enabled both “Google Cloud Testing API and Cloud Tool Results API”.
To enable them I have just click on the “enable” blue button.
Is there something more to do ?
No, it absolutely seem to be something to fix in the how-to. The reason of this error message is because I thought it is a good idea to set an own bucket for storage. But thats requires a blaze plan. So I am testing now using the built in firebase bucket to store results.
#Download test results
FB_BUCKET=$(grep -oP "(?<=browser\/).*(?<=\/$RESULT_DIR)" $BITRISE_DEPLOY_DIR/gcloudlog.log)
gsutil -m cp -R gs://$FB_BUCKET $SRCPTH
for file in $(find $SRCPTH -type f)
do
if [[ -f $file ]]; then
f=$(echo ${file//$SRCPTH\/$RESULT_DIR\/})
mv $file $(echo $EXPPTH/${f//\//_})
fi
done
downloads everything from the bucket object. If there is a video, it should be downloaded also.
The place where it will be downloaded is: EXPPTH=$BITRISE_DEPLOY_DIR
So simply put a Deploy to Bitrise.io step if not already.
Can’t see enough info from this log. Could you please contact us on our on-site chat with enabled Bitrise Support user and the app’s url? So we can have a closer look
I know it’s an old thread but this was the most relevant I could find. Following the steps described above I can indeed get the “gcloud run” instrumentation test goodies and save them as artifacts.
Using the “Export test results” step I can also publish the JUNIT XML into the Test Reports tab but it does not link up any of the other test run artifacts (logs, videos, etc).
I know there’s a dedicated step - virtual device testing - but we felt running the gcloud commands directly would give us more flexibility. So is there a way to publish the other test artifacts from Google Cloud into the Test Reports tab of a build?