AusfĂŒhren von UI-Tests fĂŒr GitHub-Aktionen
In diesem Teil beschÀftigen wir uns weiterhin mit der Automatisierung eines Android-Projekts auf GitHub-Aktionen:
Beginnen wir ein neues Projekt fĂŒr UI-Tests in Firebase Test Lab
Richten Sie die Integration von GitHub Actions und Test Lab ein
Mal sehen, wie Sie UI-Tests in einem Workflow auf CI / CD ausfĂŒhren können.
Wenn Sie den ersten Teil der Geschichte verpasst haben, der sich mit Unit-Tests in einem Android-Projekt befasste, können Sie damit beginnen.
Um Unit-Tests ausfĂŒhren zu können, benötigen wir lediglich eine konfigurierte Java-Umgebung. Alle Tests bestehen innerhalb der JVM sehr schnell, alles ist einfach und die Situation von Flacky-Tests ist fast ausgeschlossen. Solche Tests sollten 70-80% der Gesamtzahl der Tests im Projekt ausmachen. ZunĂ€chst lohnt es sich, die GeschĂ€ftslogik mit ihnen zu behandeln.
Aber manchmal möchten Sie mehr - Tests, die die Aktionen realer Benutzer simulieren und die Erwartungen mit der RealitÀt vergleichen.
UI- . -, . , . , UI- , , /- . , - - . , .
Firebase Test Lab - Google, . 10 5 . 1$ - , .
Test Lab :
checkout Java-
unit-. , UI-.
Gradle- UI-
APK-, .
Firebase Test Lab .
command line gcloud, Test Lab APK.
, , workflow GitHub Actions.
Firebase GitHub.
https://console.firebase.google.com Google-.
, .
Google- , Test Lab . , .
, GitHub Actions Test Lab.
â â (âProject settingsâ), â â (âService accountsâ). â â (âManage service account permissionsâ).
, CI/CD GitHub Actions. UI- ââ. .
ââ. , Firebase 403.
ERROR: (gcloud.firebase.test.android.run) Unable to access the test environment catalog: ResponseError 403: Not authorized for project ***
ââ
CI/CD . â â (âCreate keyâ).
JSON, . , , - . private_key.
, JSON . Base64.
:
1)
base64 github-actions-sample-key.json > base64-key.txt
github-actions-sample-key.json - JSON, base64-key â , .
2) https://www.base64encode.org/
GitHub Secrets GitHub.
Firebase base64-key.
Project ID Firebase. Project number.
, GitHub Actions Test Lab. workflow giithub/workflows.
workflow, UI- Test Lab .
ERROR: (gcloud.firebase.test.android.run) User [github-actions-ci-cd@***.iam.gserviceaccount.com] does not have permission to access project [***:initializeSettings] (or it may not exist): Cloud Tool Results API has not been used in project 254361894337 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/toolresults.googleapis.com/overview?project=254361894337 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
- API toolresults.googleapis.com, , API . âEnable APIs and servicesâ.
API . Cloud Tool Result API .
- , workflow.
name: UI_tests_on_release
on:
pull_request:
branches:
- 'main'
jobs:
assemble_ui_test_artifacts:
if: startsWith(github.head_ref, 'release/') == true
name: Build artifacts
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with: {java-version: 1.8}
- name: Build APK for UI test after Unit tests
run: |
./gradlew test
./gradlew assembleDebug
./gradlew assembleDebugAndroidTest
- name: Upload app-debug APK
uses: actions/upload-artifact@v2
with:
name: app-debug
path: app/build/outputs/apk/debug/app-debug.apk
- name: Upload app-debug-androidTest APK
uses: actions/upload-artifact@v2
with:
name: app-debug-androidTest
path: app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk
run_ui_tests_on_firebase:
runs-on: ubuntu-20.04
needs: assemble_ui_test_artifacts
steps:
- uses: actions/checkout@v2
- name: Download app-debug APK
uses: actions/download-artifact@v1
with:
name: app-debug
- name: Download app-debug-androidTest APK
uses: actions/download-artifact@v1
with:
name: app-debug-androidTest
- name: Firebase auth with gcloud
uses: google-github-actions/setup-gcloud@master
with:
version: '290.0.1'
service_account_key: ${{ secrets.FIREBASE_KEY }}
project_id: ${{ secrets.FIREBASE_PROJECT_ID }}
- name: Run Instrumentation Tests in Firebase Test Lab
run: |
gcloud firebase test android models list
gcloud firebase test android run --type instrumentation --use-orchestrator --app app-debug/app-debug.apk --test app-debug-androidTest/app-debug-androidTest.apk --device model=Pixel2,version=28,locale=en,orientation=portrait
,
1
name: UI_tests_on_release
on:
pull_request:
branches:
- 'main'
jobs:
assemble_ui_test_artifacts:
if: startsWith(github.head_ref, 'release/') == true
name: Build artifacts
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with: {java-version: 1.8}
workflow, . Pull request main , release/.
checkout Java 8.
2
- name: Build APK for UI test after Unit tests
run: |
./gradlew test
./gradlew assembleDebug
./gradlew assembleDebugAndroidTest
- name: Upload app-debug APK
uses: actions/upload-artifact@v2
with:
name: app-debug
path: app/build/outputs/apk/debug/app-debug.apk
- name: Upload app-debug-androidTest APK
uses: actions/upload-artifact@v2
with:
name: app-debug-androidTest
path: app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk
unit- APK - app-debug.apk app-debug-androidTest.apk. ? APK - , APK instrumentation-, .
upload-artifact@v2.
3
run_ui_tests_on_firebase:
runs-on: ubuntu-20.04
needs: assemble_ui_test_artifacts
steps:
- uses: actions/checkout@v2
- name: Download app-debug APK
uses: actions/download-artifact@v1
with:
name: app-debug
- name: Download app-debug-androidTest APK
uses: actions/download-artifact@v1
with:
name: app-debug-androidTest
Job workflow (assemble_ui_test_artifacts), , .
.
needs: assemble_ui_test_artifacts
action download-artifact@v1 APK Job.
4
- Test Lab .
- name: Firebase auth with gcloud
uses: google-github-actions/setup-gcloud@master
with:
version: '290.0.1'
service_account_key: ${{ secrets.FIREBASE_KEY }}
project_id: ${{ secrets.FIREBASE_PROJECT_ID }}
- name: Run Instrumentation Tests in Firebase Test Lab
run: |
gcloud firebase test android models list
gcloud firebase test android run --type instrumentation --use-orchestrator --app app-debug/app-debug.apk --test app-debug-androidTest/app-debug-androidTest.apk --device model=Pixel2,version=28,locale=en,orientation=portrait
action setup-gcloud, ID Base64 , , .
.
gcloud firebase test android models list SDK. , .
workflow , .
, , UI- ! Test Lab . Project ID ( ID) .
orchestrator, --use-orchestrator.
UI- , .
--num-flaky-test-attempts - Flaky .
--network-profile - . , .
:
https://cloud.google.com/sdk/gcloud/reference/firebase/test/android/run
https://firebase.google.com/docs/test-lab/android/instrumentation-test#sharding
https://github.com/Flank/flank
- :
1) UI- Test Lab , MacOS. https://github.com/ReactiveCircus/android-emulator-runner
2) UI-. Android SDK .
UI- GitHub Actions :)