Skip to content

Commit

Permalink
feat(android): test emulator recording on ubuntu-latest
Browse files Browse the repository at this point in the history
  • Loading branch information
fanch committed Sep 23, 2024
1 parent c9ced59 commit 1eeb78e
Show file tree
Hide file tree
Showing 24 changed files with 344 additions and 0 deletions.
116 changes: 116 additions & 0 deletions .github/workflows/run-maestro-scrcpy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
name: Run Maestro with srcpy

on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true


jobs:
run-with-video-recording:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4


- name: Install srcpy
if: steps.ffmpeg-cache.outputs.cache-hit != 'true'
run: |
sudo apt-get update
sudo apt-get install -y scrcpy
whereis scrcpy
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

# - name: Cache Maestro
# id: maestro-cache
# uses: actions/cache@v4
# with:
# path: ~/.maestro/bin/maestro
# key: maestro-${{ runner.os }}-${{ hashFiles('**/maestro') }}
# restore-keys: |
# maestro-${{ runner.os }}-
#
# - name: Install Maestro
# if: steps.maestro-cache.outputs.cache-hit != 'true'
# run: |
# curl -Ls "https://get.maestro.mobile.dev" | bash
# echo "${HOME}/.maestro/bin" >> $GITHUB_PATH

- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Setup Android SDK
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: android-actions/setup-android@v3

- name: Gradle cache
uses: gradle/actions/setup-gradle@v3

- name: AVD cache
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-29-${{ runner.os }}

- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."

- name: run tests
uses: reactivecircus/android-emulator-runner@v2
with:
cores: 8
ram-size: 9000M
heap-size: 8192
api-level: 29
force-avd-creation: false
emulator-options: -verbose -memory 16384 -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
profile: pixel_6
disable-animations: true
script: |
#!/bin/sh
set +e
export DISPLAY=:1
scrcpy --record output.mp4 &
adb shell input keyevent 82 &
sleep 15 # Ajuste la durée de l'enregistrement
pkill scrcpy # Stopper scrcpy après l'enregistrement
echo "ok"



- name: Upload Maestro artifacts (report/video)
if: always()
uses: actions/upload-artifact@v3
with:
name: maestro-report
path: |
screenshot.png
maestro-report.xml
screenrecord.mp4
output.mp4
# maestro test android-lbc-ad-insertion.yaml --format junit --output maestro-report.xml
# adb shell monkey -p fr.leboncoin.delivery -c android.intent.category.LAUNCHER 1
Binary file added sample.apk
Binary file not shown.
12 changes: 12 additions & 0 deletions samples/android-advanced-flow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
appId: org.wikipedia
tags:
- android
- passing
- advanced
---
- runFlow: subflows/onboarding-android.yaml
- tapOn:
id: "org.wikipedia:id/search_container"
- runScript: scripts/getSearchQuery.js
- inputText: ${output.result}
- assertVisible: ${output.result}
6 changes: 6 additions & 0 deletions samples/android-flow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
appId: org.wikipedia
tags:
- android
- passing
---
- launchApp
22 changes: 22 additions & 0 deletions samples/ios-advanced-flow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
appId: org.wikimedia.wikipedia
tags:
- ios
- passing
- advanced
---
- runFlow: subflows/onboarding-ios.yaml

# Dismiss the auth modal if visible
- runFlow:
when:
visible: "You have been logged out"
commands:
- tapOn:
text: "Continue without logging in"

- tapOn: Search Wikipedia
- runScript: scripts/getSearchQuery.js
- inputText: ${output.result}
- eraseText
- inputText: qwerty
- assertVisible: ${output.result}
6 changes: 6 additions & 0 deletions samples/ios-flow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
appId: org.wikimedia.wikipedia
tags:
- ios
- passing
---
- launchApp
Binary file added samples/sample.apk
Binary file not shown.
1 change: 1 addition & 0 deletions samples/scripts/getSearchQuery.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output.result = 'qwerty';
12 changes: 12 additions & 0 deletions samples/subflows/onboarding-android.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
appId: org.wikipedia
---
- launchApp:
clearState: true
- tapOn:
id: "org.wikipedia:id/fragment_onboarding_forward_button"
- tapOn:
id: "org.wikipedia:id/fragment_onboarding_forward_button"
- tapOn:
id: "org.wikipedia:id/fragment_onboarding_forward_button"
- tapOn:
id: "org.wikipedia:id/fragment_onboarding_done_button"
12 changes: 12 additions & 0 deletions samples/subflows/onboarding-ios.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
appId: org.wikimedia.wikipedia
---
- launchApp:
clearState: true
- repeat:
times: 3
commands:
- swipe:
direction: LEFT
duration: 400
- waitForAnimationToEnd
- tapOn: Get started
14 changes: 14 additions & 0 deletions samples/wikipedia-android-advanced/auth/login.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
appId: org.wikipedia
---
- tapOn: "More"
- tapOn: "LOG IN.*"
- tapOn:
id: ".*create_account_login_button"
- runScript: "../scripts/fetchTestUser.js"
- tapOn: "Username"
- inputText: "${output.test_user.username}"
- tapOn: "Password"
- inputText: "No provided"
- tapOn: "LOG IN"
- back
- back
17 changes: 17 additions & 0 deletions samples/wikipedia-android-advanced/auth/signup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
appId: org.wikipedia
---
- tapOn: "More"
- tapOn: "LOG IN.*"
- runScript: "../scripts/generateCredentials.js"
- tapOn: "Username"
- inputText: "${output.credentials.username}"
- tapOn: "Password"
- inputText: "${output.credentials.password}"
- tapOn: "Repeat password"
- inputText: "${output.credentials.password}"
- tapOn: "Email.*"
- inputText: "${output.credentials.email}"

# We won't actually create the account
- back
- back
13 changes: 13 additions & 0 deletions samples/wikipedia-android-advanced/dashboard/copy-paste.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
appId: org.wikipedia
---
- tapOn: "Explore"
- scrollUntilVisible:
element: "Top read"
- copyTextFrom:
id: ".*view_list_card_item_title"
index: 0
- tapOn: "Explore"
- tapOn: "Search Wikipedia"
- inputText: "${maestro.copiedText}"
- back
- back
7 changes: 7 additions & 0 deletions samples/wikipedia-android-advanced/dashboard/feed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: org.wikipedia
---
- tapOn: "Explore"
- scrollUntilVisible:
element: "Today on Wikipedia.*"
- tapOn: "Today on Wikipedia.*"
- back
6 changes: 6 additions & 0 deletions samples/wikipedia-android-advanced/dashboard/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
appId: org.wikipedia
---
- runFlow: "search.yml"
- runFlow: "saved.yml"
- runFlow: "feed.yml"
- runFlow: "copy-paste.yml"
7 changes: 7 additions & 0 deletions samples/wikipedia-android-advanced/dashboard/saved.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appId: org.wikipedia
---
- tapOn: "Saved"
- tapOn: "Default list for your saved articles"
- assertVisible: "Sun"
- assertVisible: "Star at the center of the Solar System"
- back
12 changes: 12 additions & 0 deletions samples/wikipedia-android-advanced/dashboard/search.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
appId: org.wikipedia
---
- tapOn: "Search Wikipedia"
- inputText: "Sun"
- assertVisible: "Star at the center of the Solar System"
- tapOn:
id: ".*page_list_item_title"
- tapOn:
id: ".*page_save"
- back
- back
- back
10 changes: 10 additions & 0 deletions samples/wikipedia-android-advanced/onboarding/add-language.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
appId: org.wikipedia
---
- tapOn: "ADD OR EDIT.*"
- tapOn: "ADD LANGUAGE"
- tapOn:
id: ".*menu_search_language"
- inputText: "Greek"
- assertVisible: "Ελληνικά"
- tapOn: "Ελληνικά"
- tapOn: "Navigate up"
11 changes: 11 additions & 0 deletions samples/wikipedia-android-advanced/onboarding/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
appId: org.wikipedia
---
- runFlow: "add-language.yml"
- runFlow: "remove-language.yml"
- tapOn: "Continue"
- assertVisible: "New ways to explore"
- tapOn: "Continue"
- assertVisible: "Reading lists with sync"
- tapOn: "Continue"
- assertVisible: "Send anonymous data"
- tapOn: "Get started"
13 changes: 13 additions & 0 deletions samples/wikipedia-android-advanced/onboarding/remove-language.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
appId: org.wikipedia
---
- tapOn: "ADD OR EDIT.*"
- tapOn: "More options"
- tapOn: "Remove language"
- tapOn:
id: ".*wiki_language_checkbox"
index: 1
- tapOn:
id: ".*menu_delete_selected"
- tapOn: "OK"
- assertNotVisible: "Ελληνικά"
- tapOn: "Navigate up"
11 changes: 11 additions & 0 deletions samples/wikipedia-android-advanced/run-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
appId: org.wikipedia
tags:
- android
- passing
---
- launchApp:
clearState: true
- runFlow: "onboarding/main.yml"
- runFlow: "dashboard/main.yml"
- runFlow: "auth/signup.yml"
- runFlow: "auth/login.yml"
13 changes: 13 additions & 0 deletions samples/wikipedia-android-advanced/scripts/fetchTestUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Fetches test user from API
function getTestUserFromApi() {
const url = `https://jsonplaceholder.typicode.com/users/1`;
var response = http.get(url);
var data = json(response.body);

return {
username: data.username,
email: data.email,
};
}

output.test_user = getTestUserFromApi();
23 changes: 23 additions & 0 deletions samples/wikipedia-android-advanced/scripts/generateCredentials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function username() {
var date = new Date().getTime().toString();
var username = `test_user_placeholder`.replace("placeholder", date);
return username;
}

function email() {
var date = new Date().getTime().toString();
var email = `[email protected]`.replace("placeholder", date);
return email;
}

function password() {
var date = new Date().getTime().toString();
var password = `test-user-password-placeholder`.replace("placeholder", date);
return password;
}

output.credentials = {
email: email(),
password: password(),
username: username(),
};
Binary file added samples/wikipedia.apk
Binary file not shown.

0 comments on commit 1eeb78e

Please sign in to comment.