

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

# 在 Device Farm 中自動執行 Appium 測試
<a name="test-types-appium"></a><a name="test-types-ios-appium-java-testng"></a><a name="test-types-ios-appium-java-junit"></a><a name="test-types-ios-appium-python"></a><a name="test-types-ios-appium-ruby"></a><a name="test-types-ios-appium-node"></a><a name="test-types-android-appium-java-testng"></a><a name="test-types-android-appium-java-junit"></a><a name="test-types-android-appium-python"></a><a name="test-types-android-appium-ruby"></a><a name="test-types-android-appium-node"></a><a name="test-types-web-app-appium-java-testng"></a><a name="test-types-web-app-appium-java-junit"></a><a name="test-types-web-app-appium-python"></a><a name="test-types-web-app-appium-ruby"></a><a name="test-types-web-app-appium-node"></a>

**注意**  
此頁面涵蓋在 Device Farm 的受管**伺服器端**執行環境中執行 Appium 測試。若要在遠端存取工作階段期間從本機**用戶端**環境執行 Appium 測試，請參閱[用戶端 Appium 測試](appium-endpoint.md)。

本節說明如何設定、封裝和上傳 Appium 測試，以便在 Device Farm 的受管伺服器端環境中執行。Appium 是一種開放原始碼工具，用於自動化原生和行動 Web 應用程式。如需詳細資訊，請參閱 [Appium 網站上的 Appium 簡介](http://appium.io/docs/en/latest/intro)。

如需範例應用程式和工作測試的連結，請參閱 GitHub 上的適用於 [Android 的 Device Farm Sample App](https://github.com/aws-samples/aws-device-farm-sample-app-for-android) 和[適用於 iOS 的 Device Farm Sample App](https://github.com/aws-samples/aws-device-farm-sample-app-for-ios)。

如需在 Device Farm 中測試及伺服器端運作方式的詳細資訊，請參閱 [AWS Device Farm 中的測試架構和內建測試](test-types.md)。

## 選取 Appium 版本
<a name="w2aac24c15c41"></a>

**注意**  
 支援特定的 Appium 版本、Appium 驅動程式或程式設計 SDKs 將取決於為測試執行選取的裝置和測試主機。

 Device Farm 測試主機已預先安裝 Appium，以便針對更直接的使用案例更快速地設定測試。不過，使用測試規格檔案可讓您視需要安裝不同版本的 Appium。

### 案例 1：預先設定的 Appium 版本
<a name="w2aac24c15c41b7b1"></a>

 Device Farm 根據測試主機預先設定不同的 Appium 伺服器版本。主機隨附工具，可啟用具有裝置平台預設驅動程式的預先設定版本 （適用於 Android 的 UiAutomator2 和適用於 iOS 的 XCUITest)。

```
phases:
  install:
    commands:
      - export APPIUM_VERSION=2
      - devicefarm-cli use appium $APPIUM_VERSION
```

 若要檢視支援的軟體清單，請參閱 上的 主題[自訂測試環境中支援的軟體](custom-test-environments-hosts-software.md)。

### 案例 2：自訂 Appium 版本
<a name="w2aac24c15c41b7b3"></a>

 若要選取自訂版本的 Appium，請使用 `npm`命令來安裝它。下列範例示範如何安裝最新版的 Appium 2。

```
phases:
  install:
    commands:
      - export APPIUM_VERSION=2
      - npm install -g appium@$APPIUM_VERSION
```

### 案例 3：舊版 iOS 主機上的 Appium
<a name="w2aac24c15c41b7b5"></a>

 在 上[舊版 iOS 測試主機](custom-test-environments-hosts-ios.md#legacy-ios-host)，您可以選擇具有 的特定 Appium 版本`avm`。例如，若要使用 `avm`命令將 Appium 伺服器版本設定為 `2.1.2`，請將這些命令新增至您的測試規格 YAML 檔案。

```
phases:
  install:
    commands:
      - export APPIUM_VERSION=2.1.2
      - avm $APPIUM_VERSION
```

## 為 iOS 測試選取 WebDriverAgent 版本
<a name="test-types-appium-select-wda"></a>

 若要在 iOS 裝置上執行 Appium 測試，必須使用 WebDriverAgent。此應用程式必須經過簽署，才能安裝在 iOS 裝置上。Device Farm 提供預先簽章的 WebDriverAgent 版本，可在自訂測試環境執行期間使用。

 下列程式碼片段可用於在與 XCTestUI 驅動程式版本相容的測試規格檔案中，選取 Device Farm 上的 WebDriverAgent 版本。

```
phases:
  pre_test:
    commands:
      - |-
        APPIUM_DRIVER_VERSION=$(appium driver list --installed --json | jq -r ".xcuitest.version" | cut -d "." -f 1);
        CORRESPONDING_APPIUM_WDA=$(env | grep "DEVICEFARM_APPIUM_WDA_DERIVED_DATA_PATH_V${APPIUM_DRIVER_VERSION}")
        if [[ ! -z "$APPIUM_DRIVER_VERSION" ]] && [[ ! -z "$CORRESPONDING_APPIUM_WDA" ]]; then
          echo "Using Device Farm's prebuilt WDA version ${APPIUM_DRIVER_VERSION}.x, which corresponds with your driver";
          DEVICEFARM_APPIUM_WDA_DERIVED_DATA_PATH=$(echo $CORRESPONDING_APPIUM_WDA | cut -d "=" -f2)
        else
          LATEST_SUPPORTED_WDA_VERSION=$(env | grep "DEVICEFARM_APPIUM_WDA_DERIVED_DATA_PATH_V" | sort -V -r | head -n 1)
          echo "Unknown driver version $APPIUM_DRIVER_VERSION; falling back to the Device Farm default version of $LATEST_SUPPORTED_WDA_VERSION";
          DEVICEFARM_APPIUM_WDA_DERIVED_DATA_PATH=$(echo $LATEST_SUPPORTED_WDA_VERSION | cut -d "=" -f2)
        fi;
```

 如需 WebDriverAgent 的詳細資訊，請參閱 Appium [的文件](https://appium.github.io/appium-xcuitest-driver/9.10/guides/run-prebuilt-wda/)。

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

使用下列指示將 Appium 測試與 AWS Device Farm 整合。如需在 Device Farm 中使用 Appium 測試的詳細資訊，請參閱 [在 Device Farm 中自動執行 Appium 測試將 Appium 測試與 Device Farm 整合](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. 執行此命令將目前資料夾中的檔案封裝成 \$1.tgz 檔案。檔案會使用 `package.json` 檔案中的 `name` 屬性來命名。

   ```
   npm-bundle
   ```

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

1. 執行此命令將前一步驟所產生的 tarball (\$1.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` 的檔案。

------

## 將您的測試套件上傳至 Device Farm
<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. 在 Device Farm 導覽面板上，選擇**行動裝置測試**，然後選擇**專案**。

1. 如果您是新使用者，請選擇**新增專案**，輸入專案的名稱，然後選擇**提交**。

   如果您已經有專案，您可以選擇它來上傳您的測試到該專案。

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

1. 在**執行設定**下，為您的測試指定適當的名稱。這可包含空格或標點符號的任何組合。

1.   
若是原生 Android 和 iOS 測試  
在**執行設定**下，如果您要測試 **Android** (.apk) 應用程式，請選擇 Android 應用程式；如果您要測試 **iOS** (.ipa) 應用程式，請選擇 iOS 應用程式。然後，在**選取應用程式**下，選取**上傳自己的應用程式**以上傳應用程式的可分發套件。  
 檔案必須是 Android `.apk` 或 iOS `.ipa`。iOS 應用程式必須是專為真實裝置建置，而不是專為模擬器建置。  
若是行動 Web 應用程式測試  
在**執行設定**下，選擇 **Web 應用程式**。

1. 在**設定測試**下，在**選取測試架構**區段中，選擇您使用的測試 Appium 架構，然後**上傳您自己的測試套件**。

1. 瀏覽並選擇包含測試的 .zip 檔案。.zip 檔案必須遵循[設定您的 Appium 測試套件](#test-types-appium-prepare)中所述的格式。

1. 依照指示選取裝置並開始執行。如需詳細資訊，請參閱[在 Device Farm 中建立測試執行](how-to-create-test-run.md)。

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

## 擷取測試的螢幕擷取畫面 （選用）
<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/)。