

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 將 Appium 測試與 Device Farm 整合
<a name="test-types-appium-integrate"></a>

使用下列指示將 Appium 測試與 AWS Device Farm 整合。如需在 Device Farm 中使用 Appium 測試的詳細資訊，請參閱 [在 Device Farm 中自動執行 Appium 測試](test-types-appium.md)。

## 設定您的 Appium 測試套件
<a name="test-types-appium-prepare"></a>

使用以下指示來設定您的測試套件。

------
#### [ Java (JUnit) ]

1. 修改 `pom.xml` 以將封裝設定為 JAR 檔案：

   ```
   <groupId>com.acme</groupId>
   <artifactId>acme-myApp-appium</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>jar</packaging>
   ```

1. 修改 `pom.xml` 以使用 `maven-jar-plugin` 將測試建置到 JAR 檔案。

   下列外掛程式會將您的測試原始程式碼 (`src/test`目錄中的任何項目） 建置為 JAR 檔案：

   ```
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-jar-plugin</artifactId>
     <version>2.6</version>
     <executions>
       <execution>
         <goals>
           <goal>test-jar</goal>
         </goals>
       </execution>
     </executions>
   </plugin>
   ```

1. 修改 `maven-dependency-plugin` 以`pom.xml`使用 建置相依性做為 JAR 檔案。

   下列外掛程式會將您的相依性複製到 `dependency-jars`目錄：

   ```
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-dependency-plugin</artifactId>
     <version>2.10</version>
     <executions>
       <execution>
         <id>copy-dependencies</id>
         <phase>package</phase>
         <goals>
           <goal>copy-dependencies</goal>
         </goals>
         <configuration>
           <outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
         </configuration>
       </execution>
     </executions>
   </plugin>
   ```

1. 將下列 XML 組件儲存至 `src/main/assembly/zip.xml`。

   下列 XML 是組件定義，設定後會指示 Maven 建置 .zip 檔案，其中包含建置輸出目錄根目錄和`dependency-jars`目錄中的所有內容：

   ```
   <assembly
       xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
     <id>zip</id>
     <formats>
       <format>zip</format>
     </formats>
     <includeBaseDirectory>false</includeBaseDirectory>
     <fileSets>
       <fileSet>
         <directory>${project.build.directory}</directory>
         <outputDirectory>./</outputDirectory>
         <includes>
           <include>*.jar</include>
         </includes>
       </fileSet>
       <fileSet>
         <directory>${project.build.directory}</directory>
         <outputDirectory>./</outputDirectory>
         <includes>
           <include>/dependency-jars/</include>
         </includes>
       </fileSet>
     </fileSets>
   </assembly>
   ```

1. 修改 `pom.xml` 以使用 `maven-assembly-plugin` 將測試和所有相依性封裝到單一 .zip 檔案。

   下列外掛程式使用上述組件，在每次執行建置輸出目錄中建立名為 `zip-with-dependencies`的 **mvn package** .zip 檔案：

   ```
   <plugin>
     <artifactId>maven-assembly-plugin</artifactId>
     <version>2.5.4</version>
     <executions>
       <execution>
         <phase>package</phase>
         <goals>
           <goal>single</goal>
         </goals>
         <configuration>
           <finalName>zip-with-dependencies</finalName>
           <appendAssemblyId>false</appendAssemblyId>
           <descriptors>
             <descriptor>src/main/assembly/zip.xml</descriptor>
           </descriptors>
         </configuration>
       </execution>
     </executions>
   </plugin>
   ```

**注意**  
如果您收到錯誤，指明 1.3 中不支援註釋，請將以下內容新增至 `pom.xml`：  

```
<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>1.7</source>
    <target>1.7</target>
  </configuration>
</plugin>
```

------
#### [ Java (TestNG) ]

1. 修改 `pom.xml` 以將封裝設定為 JAR 檔案：

   ```
   <groupId>com.acme</groupId>
   <artifactId>acme-myApp-appium</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>jar</packaging>
   ```

1. 修改 `pom.xml` 以使用 `maven-jar-plugin` 將測試建置到 JAR 檔案。

   下列外掛程式會將您的測試原始程式碼 (`src/test`目錄中的任何項目） 建置為 JAR 檔案：

   ```
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-jar-plugin</artifactId>
     <version>2.6</version>
     <executions>
       <execution>
         <goals>
           <goal>test-jar</goal>
         </goals>
       </execution>
     </executions>
   </plugin>
   ```

1. 修改 `maven-dependency-plugin` 以`pom.xml`使用 建置相依性做為 JAR 檔案。

   下列外掛程式會將您的相依性複製到 `dependency-jars`目錄：

   ```
   <plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-dependency-plugin</artifactId>
     <version>2.10</version>
     <executions>
       <execution>
         <id>copy-dependencies</id>
         <phase>package</phase>
         <goals>
           <goal>copy-dependencies</goal>
         </goals>
         <configuration>
           <outputDirectory>${project.build.directory}/dependency-jars/</outputDirectory>
         </configuration>
       </execution>
     </executions>
   </plugin>
   ```

1. 將下列 XML 組件儲存至 `src/main/assembly/zip.xml`。

   下列 XML 是組件定義，設定後會指示 Maven 建置 .zip 檔案，其中包含建置輸出目錄根目錄和`dependency-jars`目錄中的所有內容：

   ```
   <assembly
       xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
     <id>zip</id>
     <formats>
       <format>zip</format>
     </formats>
     <includeBaseDirectory>false</includeBaseDirectory>
     <fileSets>
       <fileSet>
         <directory>${project.build.directory}</directory>
         <outputDirectory>./</outputDirectory>
         <includes>
           <include>*.jar</include>
         </includes>
       </fileSet>
       <fileSet>
         <directory>${project.build.directory}</directory>
         <outputDirectory>./</outputDirectory>
         <includes>
           <include>/dependency-jars/</include>
         </includes>
       </fileSet>
     </fileSets>
   </assembly>
   ```

1. 修改 `pom.xml` 以使用 `maven-assembly-plugin` 將測試和所有相依性封裝到單一 .zip 檔案。

   下列外掛程式使用上述組件，在每次執行建置輸出目錄中建立名為 `zip-with-dependencies`的 **mvn package** .zip 檔案：

   ```
   <plugin>
     <artifactId>maven-assembly-plugin</artifactId>
     <version>2.5.4</version>
     <executions>
       <execution>
         <phase>package</phase>
         <goals>
           <goal>single</goal>
         </goals>
         <configuration>
           <finalName>zip-with-dependencies</finalName>
           <appendAssemblyId>false</appendAssemblyId>
           <descriptors>
             <descriptor>src/main/assembly/zip.xml</descriptor>
           </descriptors>
         </configuration>
       </execution>
     </executions>
   </plugin>
   ```

**注意**  
如果您收到錯誤，指明 1.3 中不支援註釋，請將以下內容新增至 `pom.xml`：  

```
<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <configuration>
    <source>1.7</source>
    <target>1.7</target>
  </configuration>
</plugin>
```

------
#### [ Node.JS ]

若要封裝 Appium Node.js 測試並將其上傳至 Device Farm，您必須在本機電腦上安裝下列項目：
+ [Node Version Manager (nvm)](https://github.com/nvm-sh/nvm) 

  請使用此工具開發和封裝測試，以便在測試套件中排除不必要的相依性。
+ Node.js
+ npm-bundle (全域安裝)

1. 確認 nvm 已存在

   ```
   command -v nvm
   ```

   您應該會在輸出中看到 `nvm`。

   如需詳細資訊，請參閱 GitHub 上的 [nvm](https://github.com/nvm-sh/nvm)。

1. 執行此命令以安裝 Node.js：

   ```
   nvm install node
   ```

   您可以指定特定版本的 Node.js：

   ```
   nvm install 11.4.0
   ```

1. 確認使用的是正確版本的節點：

   ```
   node -v
   ```

1. 全域安裝 **npm-bundle**：

   ```
   npm install -g npm-bundle
   ```

------
#### [ Python ]

1. 強烈建議您設定 [Python virtualenv](https://pypi.python.org/pypi/virtualenv) 來進行開發和封裝測試，這樣您的應用程式套件就不會包含不必要的相依性。

   ```
   $ virtualenv workspace
   $ cd workspace
   $ source bin/activate
   ```
**提示**  
請不要使用 `--system-site-packages` 選項建立 Python virtualenv，因為它會從全域 site-packages 目錄繼承套件。這可能會導致您的虛擬環境包含測試不需要的相依性。
您還必須驗證您的測試未使用相依於原生程式庫的相依性，因為這些原生程式庫可能不會出現在執行測試的執行個體上。

1. 將 **py.test** 安裝到虛擬環境中。

   ```
   $ pip install pytest
   ```

1. 在您的虛擬環境中安裝 Appium Python 用戶端。

   ```
   $ pip install Appium-Python-Client
   ```

1. 除非您在自訂模式中指定不同的路徑，否則 Device Farm 預期您的測試會存放在 中`tests/`。您可以使用 `find` 來顯示資料夾內的所有檔案：

   ```
   $ find tests/
   ```

   確認這些檔案包含您要在 Device Farm 上執行的測試套件

   ```
   tests/
   tests/{{my-first-tests.py}}
   tests/{{my-second-tests/py}}
   ```

1. 從虛擬環境工作區資料夾中執行此命令，以顯示測試的清單而不予以執行。

   ```
   $ py.test --collect-only tests/
   ```

   確認輸出顯示您想要在 Device Farm 上執行的測試。

1. 清理您的測試資料夾下的所有快取檔案：

   ```
   $ find . -name '__pycache__' -type d -exec rm -r {} +
   $ find . -name '*.pyc' -exec rm -f {} +
   $ find . -name '*.pyo' -exec rm -f {} +
   $ find . -name '*~' -exec rm -f {} +
   ```

1. 在工作區中執行下列命令，以產生 requirements.txt 檔案：

   ```
   $ pip freeze > requirements.txt
   ```

------
#### [ Ruby ]

若要封裝 Appium Ruby 測試並將其上傳至 Device Farm，您必須在本機電腦上安裝下列項目：
+ [Ruby Version Manager (RVM)](https://rvm.io/rvm/install)

  請使用此命令列工具開發和封裝測試，以便在測試套件中排除不必要的相依性。
+ Ruby
+ Bundler (此 gem 套件通常會隨 Ruby 安裝)。

1. 安裝所需的金鑰、RVM 和 Ruby。如需詳細資訊，請參閱 RVM 網站上的[安裝 RVM](https://rvm.io/rvm/install)。

   在安裝完成時，藉由登出再重新登入，來重新載入終端機。
**注意**  
RVM 只會做為 bash shell 的函數載入。

1. 確認已正確安裝 **rvm**

   ```
   command -v rvm
   ```

   您應該會在輸出中看到 `rvm`。

1. 如果您想要安裝特定版本的 Ruby，例如 {{2.5.3}}，請執行下列命令：

   ```
   rvm install ruby 2.5.3 --autolibs=0
   ```

   確認使用的是要求的 Ruby 版本：

   ```
   ruby -v
   ```

1. 設定 Bundler 來編譯所需測試平台的套件：

   ```
   bundle config specific_platform true
   ```

1. 更新您的 .lock 檔案，以新增執行測試所需的平台。
   + 如果您要編譯測試以在 Android 裝置上執行，請執行此命令來設定 Gemfile 以使用 Android 測試主機的相依性：

     ```
     bundle lock --add-platform x86_64-linux
     ```
   + 如果您要編譯測試以在 iOS 裝置上執行，請執行此命令來設定 Gemfile 以使用 iOS 測試主機的相依性：

     ```
     bundle lock --add-platform x86_64-darwin
     ```

1. 通常預設為安裝 **bundler** gem。如果不是，請安裝它：

   ```
   gem install bundler -v 2.3.26
   ```

------

## 建立壓縮測試套件檔案
<a name="test-types-appium-create-a-zip"></a>

**警告**  
在 Device Farm 中，壓縮測試套件中檔案的資料夾結構很重要，有些封存工具會隱含地變更 ZIP 檔案的結構。我們建議您遵循以下指定的命令列公用程式，而不是使用本機桌面 （例如 Finder 或 Windows Explorer) 的檔案管理員內建的封存公用程式。

現在，針對 Device Farm 將您的測試綁定在一起。

------
#### [ Java (JUnit) ]

建置並封裝您的測試：

```
$ mvn clean package -DskipTests=true
```

結果會建立檔案 `zip-with-dependencies.zip`。這是您的測試套件。

------
#### [ Java (TestNG) ]

建置並封裝您的測試：

```
$ mvn clean package -DskipTests=true
```

結果會建立檔案 `zip-with-dependencies.zip`。這是您的測試套件。

------
#### [ Node.JS ]

1. 檢查您的專案。

   確定您位於專案的根目錄。您可以在根目錄看到 `package.json`。

1. 執行此命令來安裝本機相依性。

   ```
   npm install
   ```

   此命令也會在目前的目錄中建立 `node_modules` 資料夾。
**注意**  
此時，您應該能夠在本機執行測試。

1. 執行此命令將目前資料夾中的檔案封裝成 \*.tgz 檔案。檔案會使用 `package.json` 檔案中的 `name` 屬性來命名。

   ```
   npm-bundle
   ```

   這個 tarball (.tgz) 檔案包含所有程式碼和相依性。

1. 執行此命令將前一步驟所產生的 tarball (\*.tgz 檔案) 套裝成單一壓縮的存檔：

   ```
   zip -r {{MyTests.zip}} *.tgz
   ```

   這是您在下列程序中上傳至 Device Farm `MyTests.zip` 的檔案。

------
#### [ Python ]

Python 2  
使用 pip 產生所需 Python 套件的存檔 (稱為「wheelhouse」)：  

```
$ pip wheel --wheel-dir wheelhouse -r requirements.txt
```
針對 Device Farm 將您的 wheelhouse、測試和 pip 要求封裝到 zip 存檔中：  

```
$ zip -r {{test_bundle.zip}} tests/ wheelhouse/ requirements.txt
```

Python 3  
將您的測試和 pip 要求封裝到一個 zip 檔案中：  

```
$ zip -r {{test_bundle.zip}} tests/ requirements.txt
```

------
#### [ Ruby ]

1. 執行此命令來建立虛擬 Ruby 環境：

   ```
   # myGemset is the name of your virtual Ruby environment
   rvm gemset create {{myGemset}}
   ```

1. 執行此命令來使用您剛建立的環境：

   ```
   rvm gemset use {{myGemset}}
   ```

1. 檢查您的原始程式碼。

   確定您位於專案的根目錄。您可以在根目錄看到 `Gemfile`。

1. 執行此命令從 `Gemfile` 安裝本機相依性和所有 gem 套件：

   ```
   bundle install
   ```
**注意**  
此時，您應該能夠在本機執行測試。使用此命令從本機執行測試：  

   ```
   bundle exec $test_command
   ```

1. 將您的 gem 套件封裝在 `vendor/cache` 資料夾中。

   ```
   # This will copy all the .gem files needed to run your tests into the vendor/cache directory
   bundle package --all-platforms
   ```

1. 執行以下命令將您的原始程式碼及所有相依性套裝到單一壓縮的存檔：

   ```
   zip -r MyTests.zip Gemfile vendor/ $(any other source code directory files)
   ```

   這是您在下列程序中上傳至 Device Farm `MyTests.zip` 的檔案。

------

## 執行您的 Appium 測試
<a name="test-types-appium-upload"></a>

您可以使用 Device Farm 主控台上傳您的測試。

1. 登入 Device Farm 主控台，網址為 https：//[https://console.aws.amazon.com/devicefarm](https://console.aws.amazon.com/devicefarm)。

1. 在導覽窗格中，選擇**行動裝置測試**，然後選擇**專案**。

1. 如果您是新使用者，請選擇**新增專案**，輸入專案的名稱，然後選擇**提交**。如果您已經有專案，您可以選擇它來上傳您的測試。

1. 開啟您的專案，然後選擇**建立執行**。

1. 在**選取應用程式和執行類型**下，於**執行類型**區段中，選取您的執行類型。如果您要測試 **Android 應用程式** (.apk 檔案格式），請選取 Android 應用程式。如果您要測試 **iOS 應用程式** (.ipa 檔案格式），請選取 iOS 應用程式。如果您要測試行動 **Web 應用程式**，請選取 Web 應用程式。

1. 在**選取應用程式**下，在**應用程式選取選項**區段中，如果您沒有應用程式，請選擇**選取 Device Farm 提供的範例**應用程式。如果您要使用自己的應用程式，請選取**上傳自己的應用程式**。然後選擇 Android 的 APK (.apk 檔案格式） 或 iOS 的 IPA (.ipa 檔案格式）。如果您要上傳 iOS 應用程式，請確定您選擇的是 **iOS 裝置**，而不是模擬器。

1. 在**設定測試**下，在**選取測試架構**區段中，選擇您使用的測試 Appium 架構，然後選取**上傳您自己的測試套件**。瀏覽並選擇包含測試的 .zip 檔案。.zip 檔案必須遵循[設定您的 Appium 測試套件](#test-types-appium-prepare)中所述的格式。

1. 您可以使用預設測試規格，或選擇**上傳自己的測試規格**來提供自己的測試規格。

1. 在**選取裝置**下，選擇裝置選擇方法。選取**使用裝置集區**，從您建立的裝置精選集合或自訂裝置集區中進行選擇。選取**手動選取裝置**以挑選要執行測試的個別裝置。**裝置相容性**區段顯示所選集區中有多少裝置與您的應用程式相容。如需詳細資訊，請參閱[AWS Device Farm 中的裝置支援](devices.md)。

1. （選用） 若要設定執行層級屬性，請更新**執行設定**區段：
   + Device Farm 目前僅支援 的測試洞見Appium TestNG。若要讓 Device Farm 在執行完成後產生測試報告，請選取**產生測試報告**。此選項僅適用於自訂測試環境。

     適用下列先決條件：
     + 您的測試必須產生`testng-results.xml`檔案並寫入 `$DEVICEFARM_LOG_DIR`。例如，將 傳遞`-d $DEVICEFARM_LOG_DIR/test-output`至測試規格檔案中的 TestNG命令。如果您保留預設組態，預設 Appium Java TestNG測試規格會自動產生和存放此檔案。

1. 選擇 **Confirm and start run (確認並開始執行)**。如需詳細資訊，請參閱[在 Device Farm 中建立測試執行](how-to-create-test-run.md)。

**注意**  
Device Farm 不會修改 Appium 測試。

## 檢視測試報告
<a name="test-types-appium-view-insights"></a>

執行完成後，Device Farm 會為每個裝置產生測試報告。報告會顯示每個測試明細，包括每個測試的名稱、類別、結果和持續時間，以及任何失敗測試的堆疊追蹤。您可以在 主控台中檢視測試報告，或透過 API 擷取。

若要在 Device Farm 主控台中開啟已完成的任務：

1. 登入 Device Farm 主控台，網址為 https：//[https://console.aws.amazon.com/devicefarm](https://console.aws.amazon.com/devicefarm)。

1. 在導覽窗格中，選擇**行動裝置測試**，然後選擇**專案**。

1. 選擇包含您要檢查之執行的專案。

1. 選擇已完成的執行以開啟其詳細資訊。

1. 選擇其中一個已完成的任務，以開啟該裝置的結果。

您在任務結果中看到的內容取決於測試架構，以及您是否啟用了測試洞見。選擇您的架構索引標籤以檢視結果。

------
#### [ Java (TestNG) ]

任務結果包含**測試報告**索引標籤。選擇它以查看每個測試的明細。下列螢幕擷取畫面顯示**測試報告**索引標籤。

![已完成 Appium Java TestNG 任務的測試報告索引標籤。](https://docs.aws.amazon.com/zh_tw/devicefarm/latest/developerguide/images/aws-device-farm-test-insights/appium-testng-insights-enabled-test-report-column.png)


標籤顯示每個測試的下列欄位：

`testName`  
測試方法的名稱。

`testClass`  
測試類別的名稱。

`result`  
測試的 Device Farm 結果。

`frameworkResult`  
TestNG 報告的結果 (`PASS`、 `FAIL`或 `SKIP`)。Device Farm 會將此值映射至標準化`result`欄位。

`durationSeconds`  
測試的持續時間，以秒為單位。

`startTimestamp`  
測試開始的時間。

`endTimestamp`  
測試結束的時間。

`params`  
對於參數化測試，TestNG 傳遞給測試的參數值。

`stackTrace`  
對於失敗的測試，則為失敗的堆疊追蹤。

若要將完整測試報告下載為 JSON 檔案，請選擇任務詳細資訊頂端的**下載完整摘要**。

若要選擇顯示的資料欄，請選擇齒輪圖示。在設定中，您可以選取要顯示的資料欄，並開啟或關閉**依類別分組**。**依類別分組**預設為開啟，這會依其測試類別分組測試。關閉以查看所有測試的平面清單，如下列螢幕擷取畫面所示。

![關閉依類別分組的測試報告索引標籤，顯示一般的測試清單。](https://docs.aws.amazon.com/zh_tw/devicefarm/latest/developerguide/images/aws-device-farm-test-insights/appium-testng-insights-enabled-test-report-without-grouping.png)


任務結果會顯示標準測試輸出和成品，但沒有**測試報告**索引標籤。若要產生測試報告，請排程啟用測試洞見的新執行。

![已完成 Appium Java TestNG 任務的任務結果，未啟用測試洞見。](https://docs.aws.amazon.com/zh_tw/devicefarm/latest/developerguide/images/aws-device-farm-test-insights/console-instrumentation-insights-disabled-test-report.png)


執行**get-job**並指定任務 ARN：

```
aws devicefarm get-job --arn {{arn:aws:devicefarm:us-west-2:123456789012:job:PROJECT_ID/RUN_ID/00000}}
```

如果您未啟用測試洞見，回應會包含標準任務欄位，例如任務狀態、結果、計數器和裝置：

```
{
    "job": {
        "arn": "arn:aws:devicefarm:us-west-2:123456789012:job:EXAMPLE-PROJECT/EXAMPLE-RUN/00000",
        "name": "Example Android Phone",
        "created": "2026-07-31T16:58:20.000000-07:00",
        "status": "COMPLETED",
        "result": "FAILED",
        "counters": {
            "total": 3,
            "passed": 1,
            "failed": 1,
            "warned": 0,
            "errored": 0,
            "stopped": 0,
            "skipped": 1
        },
        "device": {
            "arn": "arn:aws:devicefarm:us-west-2::device:EXAMPLEDEVICEID",
            "name": "Example Android Phone",
            "platform": "ANDROID",
            "os": "14",
            "formFactor": "PHONE",
            "fleetType": "PUBLIC"
        },
        "deviceMinutes": {
            "total": 1.42,
            "metered": 0.0,
            "unmetered": 1.17
        },
        "videoCapture": true
    }
}
```

如果您啟用測試洞見，回應也會包含 `insights` 物件。此物件包含測試報告狀態、高階指標，以及詳細報告的預先簽章 URL：

```
{
    "job": {
        "arn": "arn:aws:devicefarm:us-west-2:123456789012:job:EXAMPLE-PROJECT/EXAMPLE-RUN/00000",
        "status": "COMPLETED",
        "result": "FAILED",
        "counters": { ... },
        "device": { ... },
        "deviceMinutes": { ... },
        "videoCapture": true,
        "insights": {
            "status": "COMPLETED",
            "testReport": {
                "message": "Results: 3 Executed | 1 passed, 1 failed, 1 skipped. Median test duration: 1.83 seconds.",
                "metrics": {
                    "testsTotal": 3,
                    "testsPassed": 1,
                    "testsFailed": 1,
                    "testsSkipped": 1,
                    "testsErrored": 0,
                    "testsOther": 0,
                    "testsPassedPercentage": 33.33
                },
                "testDetailsUrl": "https://EXAMPLE-PRESIGNED-URL"
            }
        }
    }
}
```

`testDetailsUrl` 欄位是完整測試報告 JSON 的預先簽章 URL。下載以取得每個測試的明細：

```
curl -o test-report.json "{{PRESIGNED_URL}}"
```

以下是 Appium Java TestNG 任務的測試報告範例：

```
{
  "version": "1.0",
  "jobArn": "arn:aws:devicefarm:us-west-2:123456789012:job:EXAMPLE-PROJECT/EXAMPLE-RUN/00000",
  "deviceName": "Google Pixel 7",
  "deviceArn": "arn:aws:devicefarm:us-west-2::device:EXAMPLEDEVICEID",
  "deviceOsVersion": "14",
  "metrics": {
    "testsTotal": 3,
    "testsPassed": 1,
    "testsFailed": 1,
    "testsSkipped": 1,
    "testsErrored": 0,
    "testsOther": 0,
    "testsPassedPercentage": 33.33,
    "totalTestExecutionDurationSeconds": 5.421,
    "medianTestExecutionDurationSeconds": 1.83
  },
  "testDetails": [
    {
      "testName": "testValidLogin",
      "testClass": "com.example.app.LoginTest",
      "frameworkResult": "PASS",
      "result": "PASSED",
      "durationSeconds": 1.83,
      "startTimestamp": "2026-07-31T16:58:26.646000Z",
      "endTimestamp": "2026-07-31T16:58:28.476000Z"
    },
    {
      "testName": "testCheckout",
      "testClass": "com.example.app.CheckoutTest",
      "frameworkResult": "FAIL",
      "result": "FAILED",
      "durationSeconds": 3.102,
      "startTimestamp": "2026-07-31T16:58:28.500000Z",
      "endTimestamp": "2026-07-31T16:58:31.602000Z",
      "stackTrace": "java.lang.AssertionError: expected [true] but found [false]\n\tat org.testng.Assert.fail(Assert.java:99)\n\t...",
      "params": ["premium-user", "US"]
    },
    {
      "testName": "testLogout",
      "testClass": "com.example.app.LoginTest",
      "frameworkResult": "SKIP",
      "result": "SKIPPED",
      "durationSeconds": 0.489,
      "startTimestamp": "2026-07-31T16:58:31.700000Z",
      "endTimestamp": "2026-07-31T16:58:32.189000Z"
    }
  ]
}
```

報告包含下列最上層欄位：

`version`  
報告結構描述版本。

`jobArn`  
工作的 ARN。

`deviceName`, `deviceArn`, `deviceOsVersion`  
測試執行的裝置及其作業系統版本。

`metrics`  
彙總任務的結果。`metrics` 物件包含下列欄位：    
`testsTotal`  
任務中的測試總數。  
`testsPassed`  
通過的測試數量。  
`testsFailed`  
失敗的測試數量。  
`testsSkipped`  
略過的測試數量。  
`testsErrored`  
發生錯誤的測試數量。  
`testsOther`  
具有另一個結果的測試數量。  
`testsPassedPercentage`  
通過的測試百分比。  
`totalTestExecutionDurationSeconds`  
所有測試的總持續時間，以秒為單位。  
`medianTestExecutionDurationSeconds`  
測試的持續時間中位數，以秒為單位。

`testDetails`  
每個測試結果的清單。中的每個項目`testDetails`都包含下列欄位：    
`testName`  
測試方法的名稱。  
`testClass`  
測試類別的名稱。  
`result`  
測試的 Device Farm 結果。  
`frameworkResult`  
TestNG 報告的結果 (`PASS`、 `FAIL`或 `SKIP`)。Device Farm 會將此值映射至標準化`result`欄位。  
`durationSeconds`  
測試的持續時間，以秒為單位。  
`startTimestamp`  
測試開始的時間。  
`endTimestamp`  
測試結束的時間。  
`params`  
對於參數化測試，TestNG 傳遞給測試的參數值。  
`stackTrace`  
對於失敗的測試，則為失敗的堆疊追蹤。

------

## 擷取測試的螢幕擷取畫面 （選用）
<a name="test-types-appium-screenshots"></a>

您可以在測試時取得螢幕擷取畫面。

Device Farm 會將 `DEVICEFARM_SCREENSHOT_PATH` 屬性設為本機檔案系統上的完整路徑，這是 Device Farm 預期的 Appium 螢幕擷取畫面儲存位置。用於存放螢幕擷取畫面的測試專用目錄是在執行時間定義。系統會自動將螢幕擷取畫面提取到您的 Device Farm 報告。若要檢視螢幕擷取畫面，在 Device Farm 主控台中選擇 **Screenshots (螢幕擷取畫面)** 區段。

 如需在 Appium 測試中擷取螢幕擷取畫面的詳細資訊，請參閱 Appium API 文件中的 [擷取螢幕擷取畫面](http://appium.io/docs/en/commands/session/screenshot/)。