Developer Device Platform 裝置執行總覽

歡迎使用 Developer Device Platform Device Run,您可以在雲端中,對實體和虛擬 Android 裝置,以及實體 iOS 裝置執行測試。本頁面說明執行 Android 和 iOS 測試的共同點。如需平台專屬步驟,請參閱 Android 裝置執行和 iOS 裝置執行。

如要使用這個 Google Cloud CLI,您必須提供 Google Cloud 專案 ID。如需指令摘要,請參閱:gcloud beta device-run

請注意,這些旗標為必填:

  • 裝置:使用 --device 指定裝置:--device shiba-35 或 --device iphonese3-18-4
  • 測試:使用 --test 指定測試 APK 或 IPA:--test /path/to/test.apk 或 --test /path/to/test.ipa

Android 和 iOS 測試都有下列設定選項。

輸入和輸出 Cloud Storage 路徑

  • 自訂 Cloud Storage bucket:您可以指定輸入和輸出的自訂 Cloud Storage bucket:--bucket-name=my-custom-bucket 如果您未使用 --bucket-name= 旗標指定 Cloud Storage bucket,Google Cloud CLI 會使用名為 PROJECT_ID-devicerun 的預設 bucket。
  • 輸入檔案:使用 --test、--additional-apps 或 --xctestrun-file 旗標指定本機路徑時,Google Cloud CLI 會在每次執行指令時,自動將檔案複製到 gs://BUCKET_NAME/automation/inputs/DATE_TIME_FOUR_CHARS_SUFFIX/ 下的 Cloud Storage bucket,其中 BUCKET_NAME 預設為 PROJECT_ID-devicerun。
  • 雲端路徑:上傳大型檔案可能需要較長時間,因此您可以直接使用 Cloud Storage gs:// 路徑參照檔案,節省上傳時間。
  • 結果檔案:輸出構件會上傳至 Cloud Storage bucket 的 gs://BUCKET_NAME/automation/sessions/session-[SESSION_ID]/ 下方。

同步和非同步執行

根據預設,提交指令會封鎖 (同步)。這個指令會等待測試完成,並列印結果摘要表格。

如要提交工作階段,並在將檔案上傳至 Cloud Storage 後立即返回,請新增 --async 標記:

Android

gcloud beta device-run sessions submit instrumentation \
  --device shiba-35 \
  --test ./ANDROID_TESTS.apk \
  --async

iOS

gcloud beta device-run sessions submit xctest \
  --device iphonese3-18-4 \
  --test ./IOS_TESTS.zip \
  --async

這會立即傳回工作階段 ID。然後使用 sessions wait 指令等待:

gcloud beta device-run sessions wait SESSION_ID

指令會封鎖,直到工作完成為止。

多部裝置

如要在多部裝置上執行相同測試,請提供 --device 標記,並以半形逗號分隔多個裝置 ID,或提供多個 --device 標記,每個標記指定不同的裝置 ID。

Android

gcloud beta device-run sessions submit instrumentation \
  --device shiba-34,tokay-36 \
  --test ./ANDROID_TESTS.apk

或:

gcloud beta device-run sessions submit instrumentation \
  --device shiba-34 \
  --device tokay-36 \
  --test ./ANDROID_TESTS.apk

iOS

gcloud beta device-run sessions submit xctest \
  --device iphonese3-18-4,iphonese3-26-3 \
  --test ./IOS_TESTS.zip

或:

gcloud beta device-run sessions submit xctest \
  --device iphonese3-18-4 \
  --device iphonese3-26-3 \
  --test ./IOS_TESTS.zip

測試逾時

限制測試的執行時間:

Android

gcloud beta device-run sessions submit instrumentation \
  --device shiba-35 \
  --test ./ANDROID_TESTS.apk \
  --instrumentation-timeout=10m

iOS

gcloud beta device-run sessions submit xctest \
  --device iphonese3-18-4 \
  --test ./IOS_TESTS.zip \
  --xctest-timeout=10m

有效範圍為 1m 至 1h,預設值為 5m。

軟體版本

探索及使用 AndroidX Test Orchestrator 和 Apple Xcode 的可用軟體套件和版本,並在設定測試執行作業前,檢查這些套件和版本的生命週期、支援版本和中繼資料。

首先,請列出所有可用的軟體套件及其版本:

gcloud beta device-run software-versions list

輸出內容應大致如下:

ID                                NAME                              SOFTWARE_TYPE               VERSION  STATE   IS_DEFAULT
androidx-test-orchestrator-1-4-1  AndroidX Test Orchestrator 1.4.1  ANDROIDX_TEST_ORCHESTRATOR  1.4.1    ACTIVE  True
androidx-test-orchestrator-1-6-1  AndroidX Test Orchestrator 1.6.1  ANDROIDX_TEST_ORCHESTRATOR  1.6.1    ACTIVE
xcode-16-4                        Xcode 16.4                        XCODE                       16.4     ACTIVE
xcode-26-2                        Xcode 26.2                        XCODE                       26.2     ACTIVE  True

然後使用清單中的確切資源 ID,描述特定套件:

Android

gcloud beta device-run software-versions describe androidx-test-orchestrator-1-4-1

iOS

gcloud beta device-run software-versions describe xcode-16-4

輸出內容應大致如下:

Android

id: androidx-test-orchestrator-1-4-1
isDefault: true
lifecycle:
  state: ACTIVE
name: AndroidX Test Orchestrator 1.4.1
softwareType: ANDROIDX_TEST_ORCHESTRATOR
version: 1.4.1

iOS

id: xcode-16-4
lifecycle:
  state: ACTIVE
name: Xcode 16.4
softwareType: XCODE
supportedIosVersions:

-   '15.0'
-   '15.1'
-   '15.2'
-   '15.4'
-   '15.7'
-   '16.0'
-   '16.1'
-   '16.2'
-   '16.3'
-   '16.5'
-   '16.6'
-   '18.0'
-   '18.3'
-   '18.4'
version: '16.4'

現在您已知道可用的軟體版本,可以使用 --orchestrator-version 或 --xcode-version 旗標,在測試執行中使用這些版本,如下所示:

Android

gcloud beta device-run sessions submit instrumentation \
  --device shiba-35 \
  --test ./ANDROID_TESTS.apk \
  --orchestrator-version=1.4.1

詳情請參閱「啟用 Orchestrator」。

iOS

gcloud beta device-run sessions submit xctest \
  --device iphonese3-18-4 \
  --test ./IOS_TESTS.zip \
  --xcode-version=16.4

詳情請參閱「iOS Device Run」。

輸入驗證

Developer Device Platform 會嘗試驗證您的輸入內容 (包括構件),並在遇到錯誤輸入內容時傳回 ERROR,而非 PASSED 或 FAILED:

Session [session-94b57778] finished with result [ERROR].
JOB NAME  EXECUTION NAME  EXECUTION RESULT
job-000   execution-000   ERROR

現在將 --full 附加至 sessions describe 指令,即可查看工作階段的更多詳細資料:

gcloud beta device-run sessions describe --full session-94b57778

這會產生類似下列內容的輸出:

name: projects/user-test1/locations/global/sessions/session-94b57778
sessionConfig:
  displayName: instrumentation-session
  jobConfigs:
  -   action:
      androidInstrumentationTest:
        testInstallable:
          files:
          -   gcsInputFile:
              path: gs://user-test1-devicerun/automation/inputs/2026-09-16_18:55.17372947_EECF/my-test.apk
    allocationConfig:
      deviceConfigs:
      -   actions:
        -   androidLogcat: {}
        requirement:
          deviceId: mediumphone-arm-34
    displayName: job-000
  outputDirectoryConfig:
    gcsOutputDirectory:
      path: gs://user-test1-devicerun/automation/sessions
sessionReport:
  endTime: '2026-09-16T18:55:49.721Z'
  id: ed681f23-669b-4464-8a93-b28456e58136
  jobReports:
  -   displayName: job-000
    endTime: '2026-09-16T18:55:45.839Z'
    executionReports:
    -   displayName: execution-000
      endTime: '2026-09-16T18:55:46.694Z'
      id: ce370173-af94-4dd7-acc6-0863e4d2e9ec
      result:
        cause:
          summary:
            message: The instrumentation target package does not match any of the
              installable packages.
            reason: INSTRUMENTATION_TARGET_MISMATCH
            type: CUSTOMER
        resultType: ERROR
      startTime: '1970-01-01T00:00:00Z'
      status:
        statusType: PENDING
    id: 953b5106-3c20-40f0-aceb-18af89cd1b83
    result:
      cause:
        summary:
          message: The instrumentation target package does not match any of the installable
            packages.
          reason: INSTRUMENTATION_TARGET_MISMATCH
          type: CUSTOMER
      resultType: ERROR
    startTime: '2026-09-16T18:55:31.651Z'
    status:
      statusType: DONE
  result:
    resultType: ERROR
  startTime: '2026-09-16T18:55:24.442Z'
  status:
    statusType: DONE

後續步驟

使用開發人員裝置平台執行 Android 測試或執行 iOS 測試。