如何在GitHub Action中实现Expo EAS构建并对接Maestro Cloud测试
Expo + Maestro Cloud 自动化测试完整流程
以下是从构建Expo应用、下载构件到上传至Maestro Cloud的端到端流程,完全适配E2E测试需求:
1. 构建Expo应用并捕获输出
eas build --json会输出包含构建ID、构件链接等关键信息的JSON,结合jq工具可以轻松提取数据,同时处理异步构建的等待逻辑:
操作步骤:
- 确保本地/CI环境已配置
EXPO_TOKEN环境变量(用于非交互式构建授权) - 针对iOS模拟器、安卓分别构建,指定提前配置好的测试专属profile:
# 启动iOS模拟器包异步构建,输出日志到文件 eas build --platform ios --profile simulator --non-interactive --json | tee build-ios.json # 等待iOS构建完成,获取最终结果 eas build:wait --id $(jq -r '.id' build-ios.json) --json > build-ios-result.json # 启动安卓APK异步构建,输出日志到文件 eas build --platform android --profile preview --non-interactive --json | tee build-android.json # 等待安卓构建完成,获取最终结果 eas build:wait --id $(jq -r '.id' build-android.json) --json > build-android-result.json
关键profile配置(eas.json)
确保iOS构建输出模拟器可用的包:
{ "build": { "simulator": { "ios": { "simulator": true, "buildConfiguration": "Debug" } }, "preview": { "android": { "buildType": "apk" } } } }
2. 下载iOS模拟器包与APK文件
从构建结果中提取下载链接,用curl直接下载构件:
# 下载iOS模拟器包(格式为.app.zip) curl -L $(jq -r '.artifacts.buildUrl' build-ios-result.json) -o ios-sim-app.zip # 下载安卓APK文件 curl -L $(jq -r '.artifacts.buildUrl' build-android-result.json) -o android-app.apk
3. 上传至Maestro Cloud并运行测试
先安装Maestro CLI,再通过命令完成构件上传与测试执行:
安装Maestro CLI:
curl -Ls "https://get.maestro.mobile.dev" | bash
上传并执行测试:
需配置MAESTRO_CLOUD_API_KEY环境变量(从Maestro Cloud控制台获取):
# iOS模拟器包:上传并运行指定测试流程 maestro cloud test ./tests/your-e2e-flow.yaml ios-sim-app.zip --platform ios # 安卓APK:上传并运行指定测试流程 maestro cloud test ./tests/your-e2e-flow.yaml android-app.apk --platform android
如果仅需上传构件暂不执行测试,可使用:
maestro cloud upload ios-sim-app.zip --platform ios maestro cloud upload android-app.apk --platform android
CI环境完整示例(GitHub Actions)
jobs: e2e-test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: expo/expo-github-action@v8 with: eas-version: latest token: ${{ secrets.EXPO_TOKEN }} - name: Install project dependencies run: npm install - name: Install Maestro CLI run: curl -Ls "https://get.maestro.mobile.dev" | bash - name: Build iOS Simulator App run: eas build --platform ios --profile simulator --non-interactive --json | tee build-ios.json - name: Wait for iOS Build Completion run: eas build:wait --id $(jq -r '.id' build-ios.json) --json > build-ios-result.json - name: Download iOS Simulator Package run: curl -L $(jq -r '.artifacts.buildUrl' build-ios-result.json) -o ios-sim-app.zip - name: Build Android APK run: eas build --platform android --profile preview --non-interactive --json | tee build-android.json - name: Wait for Android Build Completion run: eas build:wait --id $(jq -r '.id' build-android.json) --json > build-android-result.json - name: Download Android APK run: curl -L $(jq -r '.artifacts.buildUrl' build-android-result.json) -o android-app.apk - name: Execute Maestro Cloud Tests env: MAESTRO_CLOUD_API_KEY: ${{ secrets.MAESTRO_CLOUD_API_KEY }} run: | maestro cloud test ./tests/e2e/main-flow.yaml ios-sim-app.zip --platform ios maestro cloud test ./tests/e2e/main-flow.yaml android-app.apk --platform android
内容的提问来源于stack exchange,提问作者R4Y
相关产品推荐
相关产品推荐

