

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

# 對 AWS Device Farm 中的 Appium Python 測試進行故障診斷
<a name="troubleshooting-appium-python"></a>

下列主題會列出在上傳 Appium Python 測試期間出現的錯誤訊息，並建議解決每個錯誤的解決方法。

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1UNZIP\$1FAILED
<a name="APPIUM_PYTHON_TEST_PACKAGE_UNZIP_FAILED"></a>

如果您看到下列訊息，請依照以下步驟修復問題。

**警告**  
無法開啟您的 Appium ZIP 檔。請確認檔案是否有效，然後再試一次。

請確認您可以正確解壓縮測試套件。在下列範例中，套件的名稱是 **test\$1bundle.zip**。

1. 將您的測試套件複製到工作目錄，然後執行下列命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 成功解壓縮套件後，您可以透過執行下列命令找到樹狀結構的工作目錄：

   ```
   $ tree .
   ```

   有效的 Appium Python 套件應產生輸出如下：

   ```
   .
   |-- requirements.txt
   |-- test_bundle.zip
   |-- tests (directory)
   |      `-- test_unittest.py
   `-- wheelhouse (directory)
          |-- Appium_Python_Client-0.20-cp27-none-any.whl
          |-- py-1.4.31-py2.py3-none-any.whl
          |-- pytest-2.9.0-py2.py3-none-any.whl
          |-- selenium-2.52.0-cp27-none-any.whl
          `-- wheel-0.26.0-py2.py3-none-any.whl
   ```

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

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1DEPENDENCY\$1WHEEL\$1MISSING
<a name="APPIUM_PYTHON_TEST_PACKAGE_DEPENDENCY_WHEEL_MISSING"></a>

如果您看到下列訊息，請依照以下步驟修復問題。

**警告**  
在 wheelhouse 目錄樹狀結構中找不到相依性 wheel 檔案。請解壓縮您的測試套件，開啟 wheelhouse 目錄，確認目錄中至少有一個 wheel 檔案，然後再試一次。

請確認您可以正確解壓縮測試套件。在下列範例中，套件的名稱是 **test\$1bundle.zip**。

1. 將您的測試套件複製到工作目錄，然後執行下列命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 成功解壓縮套件後，您可以透過執行下列命令找到樹狀結構的工作目錄：

   ```
   $ tree .
   ```

   如果 Appium Python 套件是有效的，您可以找到至少一個 *.whl* 檔案，類似於 *wheelhouse* 目錄中反白顯示的檔案。

   ```
   .
   |-- requirements.txt
   |-- test_bundle.zip
   |-- tests (directory)
   |      `-- test_unittest.py
   `-- wheelhouse (directory)
          |-- Appium_Python_Client-0.20-cp27-none-any.whl
          |-- py-1.4.31-py2.py3-none-any.whl
          |-- pytest-2.9.0-py2.py3-none-any.whl
          |-- selenium-2.52.0-cp27-none-any.whl
          `-- wheel-0.26.0-py2.py3-none-any.whl
   ```

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

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1INVALID\$1PLATFORM
<a name="APPIUM_PYTHON_TEST_PACKAGE_INVALID_PLATFORM"></a>

如果您看到下列訊息，請依照以下步驟修復問題。

**警告**  
至少有一個 wheel 檔案指定了我們不支援的平台。請解壓縮您的測試套件後開啟 wheelhouse 目錄，確認 wheel 檔案的名稱以 -any.whl 或 -linux\$1x86\$164.whl 結尾，然後再試一次。

請確認您可以正確解壓縮測試套件。在下列範例中，套件的名稱是 **test\$1bundle.zip**。

1. 將您的測試套件複製到工作目錄，然後執行下列命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 成功解壓縮套件後，您可以透過執行下列命令找到樹狀結構的工作目錄：

   ```
   $ tree .
   ```

   如果 Appium Python 套件是有效的，您可以找到至少一個 *.whl* 檔案，類似於 *wheelhouse* 目錄中反白顯示的檔案。檔案的名稱可能不同，但應以 *-any.whl* 或 *-linux\$1x86\$164.whl* 結尾 (用於指定平台)。不支援 `windows` 等任何其他平台。

   ```
   .
   |-- requirements.txt
   |-- test_bundle.zip
   |-- tests (directory)
   |      `-- test_unittest.py
   `-- wheelhouse (directory)
          |-- Appium_Python_Client-0.20-cp27-none-any.whl
          |-- py-1.4.31-py2.py3-none-any.whl
          |-- pytest-2.9.0-py2.py3-none-any.whl
          |-- selenium-2.52.0-cp27-none-any.whl
          `-- wheel-0.26.0-py2.py3-none-any.whl
   ```

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

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1TEST\$1DIR\$1MISSING
<a name="APPIUM_PYTHON_TEST_PACKAGE_TEST_DIR_MISSING"></a>

如果您看到下列訊息，請依照以下步驟修復問題。

**警告**  
在測試套件找不到測試目錄。請解壓縮您的測試套件，確認測試目錄位於套件中，然後再試一次。

請確認您可以正確解壓縮測試套件。在下列範例中，套件的名稱是 **test\$1bundle.zip**。

1. 將您的測試套件複製到工作目錄，然後執行下列命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 成功解壓縮套件後，您可以透過執行下列命令找到樹狀結構的工作目錄：

   ```
   $ tree .
   ```

   如果 Appium Python 套件是有效的，您可以在工作目錄中找到*測試*目錄。

   ```
   .
   |-- requirements.txt
   |-- test_bundle.zip
   |-- tests (directory)
   |      `-- test_unittest.py
   `-- wheelhouse (directory)
          |-- Appium_Python_Client-0.20-cp27-none-any.whl
          |-- py-1.4.31-py2.py3-none-any.whl
          |-- pytest-2.9.0-py2.py3-none-any.whl
          |-- selenium-2.52.0-cp27-none-any.whl
          `-- wheel-0.26.0-py2.py3-none-any.whl
   ```

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

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1INVALID\$1TEST\$1FILE\$1NAME
<a name="APPIUM_PYTHON_TEST_PACKAGE_INVALID_TEST_FILE_NAME"></a>

如果您看到下列訊息，請依照以下步驟修復問題。

**警告**  
在測試目錄樹狀結構中找不到有效的測試檔案。請解壓縮您的測試套件，開啟測試目錄，確認至少一個檔案的名稱以關鍵字「test」開頭或結尾，然後再試一次。

請確認您可以正確解壓縮測試套件。在下列範例中，套件的名稱是 **test\$1bundle.zip**。

1. 將您的測試套件複製到工作目錄，然後執行下列命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 成功解壓縮套件後，您可以透過執行下列命令找到樹狀結構的工作目錄：

   ```
   $ tree .
   ```

   如果 Appium Python 套件是有效的，您可以在工作目錄中找到*測試*目錄。檔案的名稱可能不同，但應以 *test\$1* 開頭，或以 *\$1test.py* 結尾。

   ```
   .
   |-- requirements.txt
   |-- test_bundle.zip
   |-- tests (directory)
   |      `-- test_unittest.py
   `-- wheelhouse (directory)
          |-- Appium_Python_Client-0.20-cp27-none-any.whl
          |-- py-1.4.31-py2.py3-none-any.whl
          |-- pytest-2.9.0-py2.py3-none-any.whl
          |-- selenium-2.52.0-cp27-none-any.whl
          `-- wheel-0.26.0-py2.py3-none-any.whl
   ```

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

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1REQUIREMENTS\$1TXT\$1FILE\$1MISSING
<a name="APPIUM_PYTHON_TEST_PACKAGE_REQUIREMENTS_TXT_FILE_MISSING"></a>

如果您看到下列訊息，請依照以下步驟修復問題。

**警告**  
在測試套件找不到 requirements.txt 檔案。請解壓縮您的測試套件，確認 requirements.txt 檔案位於套件中，然後再試一次。

請確認您可以正確解壓縮測試套件。在下列範例中，套件的名稱是 **test\$1bundle.zip**。

1. 將您的測試套件複製到工作目錄，然後執行下列命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 成功解壓縮套件後，您可以透過執行下列命令找到樹狀結構的工作目錄：

   ```
   $ tree .
   ```

   如果 Appium Python 套件是有效的，您可以在工作目錄中找到 *requirements.txt* 檔案。

   ```
   .
   |-- requirements.txt
   |-- test_bundle.zip
   |-- tests (directory)
   |      `-- test_unittest.py
   `-- wheelhouse (directory)
          |-- Appium_Python_Client-0.20-cp27-none-any.whl
          |-- py-1.4.31-py2.py3-none-any.whl
          |-- pytest-2.9.0-py2.py3-none-any.whl
          |-- selenium-2.52.0-cp27-none-any.whl
          `-- wheel-0.26.0-py2.py3-none-any.whl
   ```

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

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1INVALID\$1PYTEST\$1VERSION
<a name="APPIUM_PYTHON_TEST_PACKAGE_INVALID_PYTEST_VERSION"></a>

如果您看到下列訊息，請依照以下步驟修復問題。

**警告**  
pytest 版本低於支援的最低版本 2.8.0。請變更 requirements.txt 中的 pytest 版本，然後再試一次。

請確認您可以正確解壓縮測試套件。在下列範例中，套件的名稱是 **test\$1bundle.zip**。

1. 將您的測試套件複製到工作目錄，然後執行下列命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 成功解壓縮套件後，您可以透過執行下列命令找到樹狀結構的工作目錄：

   ```
   $ tree .
   ```

   您應該會在工作目錄中找到 *requirements.txt* 檔案。

   ```
   .
   |-- requirements.txt
   |-- test_bundle.zip
   |-- tests (directory)
   |      `--test_unittest.py
   `-- wheelhouse (directory)
          |-- Appium_Python_Client-0.20-cp27-none-any.whl
          |-- py-1.4.31-py2.py3-none-any.whl
          |-- pytest-2.9.0-py2.py3-none-any.whl
          |-- selenium-2.52.0-cp27-none-any.whl
          `-- wheel-0.26.0-py2.py3-none-any.whl
   ```

1. 若要取得 pytest 版本，您可以執行下列命令：

   ```
   $ grep "pytest" requirements.txt
   ```

   輸出應顯示如下：

   ```
   pytest==2.9.0
   ```

   系統會顯示 pytest 版本，在此範例中為 2.9.0。如果 Appium Python 套件是有效的，則 pytest 版本應高於或等於 2.8.0。

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

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1INSTALL\$1DEPENDENCY\$1WHEELS\$1FAILED
<a name="APPIUM_PYTHON_TEST_PACKAGE_INSTALL_DEPENDENCY_WHEELS_FAILED"></a>

如果您看到下列訊息，請依照以下步驟修復問題。

**警告**  
無法安裝相依性 wheel。請解壓縮您的測試套件，開啟 requirements.txt 檔案和 wheelhouse 目錄，確認 requirements.txt 檔案中指定的相依性 wheel 完全符合 wheelhouse 目錄中的相依性 wheel，然後再試一次。

我們強烈建議您設定 [Python virtualenv](https://pypi.python.org/pypi/virtualenv) 來封裝測試。以下是使用 Python virtualenv 建立虛擬環境然後啟用的範例流程：

```
$ virtualenv workspace
$ cd workspace 
$ source bin/activate
```

請確認您可以正確解壓縮測試套件。在下列範例中，套件的名稱是 **test\$1bundle.zip**。

1. 將您的測試套件複製到工作目錄，然後執行下列命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 若要測試安裝 wheel 檔案，您可以執行下列命令：

   ```
   $ pip install --use-wheel --no-index --find-links=./wheelhouse --requirement=./requirements.txt
   ```

   有效的 Appium Python 套件應產生輸出如下：

   ```
   Ignoring indexes: https://pypi.python.org/simple
   Collecting Appium-Python-Client==0.20 (from -r ./requirements.txt (line 1))
   Collecting py==1.4.31 (from -r ./requirements.txt (line 2))
   Collecting pytest==2.9.0 (from -r ./requirements.txt (line 3))
   Collecting selenium==2.52.0 (from -r ./requirements.txt (line 4))
   Collecting wheel==0.26.0 (from -r ./requirements.txt (line 5))
   Installing collected packages: selenium, Appium-Python-Client, py, pytest, wheel
     Found existing installation: wheel 0.29.0
       Uninstalling wheel-0.29.0:
         Successfully uninstalled wheel-0.29.0
   Successfully installed Appium-Python-Client-0.20 py-1.4.31 pytest-2.9.0 selenium-2.52.0 wheel-0.26.0
   ```

1. 若要停用虛擬環境，您可以執行下列命令：

   ```
   $ deactivate
   ```

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

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1PYTEST\$1COLLECT\$1FAILED
<a name="APPIUM_PYTHON_TEST_PACKAGE_PYTEST_COLLECT_FAILED"></a>

如果您看到下列訊息，請依照以下步驟修復問題。

**警告**  
無法在測試目錄中收集測試。請解壓縮您的測試套件，執行命令 `py.test --collect-only <path to your tests directory>`，確認測試套件是否有效，並在命令未列印任何錯誤後再試一次。

我們強烈建議您設定 [Python virtualenv](https://pypi.python.org/pypi/virtualenv) 來封裝測試。以下是使用 Python virtualenv 建立虛擬環境然後啟用的範例流程：

```
$ virtualenv workspace
$ cd workspace 
$ source bin/activate
```

請確認您可以正確解壓縮測試套件。在下列範例中，套件的名稱是 **test\$1bundle.zip**。

1. 將您的測試套件複製到工作目錄，然後執行下列命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 若要安裝 wheel 檔案，您可以執行下列命令：

   ```
   $ pip install --use-wheel --no-index --find-links=./wheelhouse --requirement=./requirements.txt
   ```

1. 若要收集測試，您可以執行下列命令：

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

   有效的 Appium Python 套件應產生輸出如下：

   ```
   ==================== test session starts ====================
   platform darwin -- Python 2.7.11, pytest-2.9.0, py-1.4.31, pluggy-0.3.1
   rootdir: /Users/zhena/Desktop/Ios/tests, inifile:
   collected 1 items
   <Module 'test_unittest.py'>
     <UnitTestCase 'DeviceFarmAppiumWebTests'>
       <TestCaseFunction 'test_devicefarm'>
   
   ==================== no tests ran in 0.11 seconds ====================
   ```

1. 若要停用虛擬環境，您可以執行下列命令：

   ```
   $ deactivate
   ```

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

## APPIUM\$1PYTHON\$1TEST\$1PACKAGE\$1DEPENDENCY\$1WHEELS\$1INSUFFICIENT
<a name="APPIUM_PYTHON_TEST_PACKAGE_DEPENDENCY_WHEELS_INSUFFICIENT"></a>

如果您看到下列訊息，請依照以下步驟修復問題。

**警告**  
我們在 wheelhouse 目錄中找不到足夠的 wheel 相依性。請解壓縮您的測試套件，然後開啟 wheelhouse 目錄。確認您已在 requirements.txt 檔案中指定所有 wheel 相依性。

請確認您可以正確解壓縮測試套件。在下列範例中，套件的名稱是 **test\$1bundle.zip**。

1. 將您的測試套件複製到工作目錄，然後執行下列命令：

   ```
   $ unzip test_bundle.zip
   ```

1. 檢查 *requirements.txt* 檔案的長度，以及 wheelhouse 目錄中的 *.whl* 相依檔案數目：

   ```
   $ cat requirements.txt | egrep "." |wc -l
   ﻿    12
   $ ls wheelhouse/ | egrep ".+\.whl" | wc -l
       11
   ```

   如果 *.whl* 相依檔案的數量少於您 *requirements.txt* 檔案中非空白資料列的數量，則您需要確保下列事項：
   + 有一個 *.whl* 相依檔案，對應至 *requirements.txt* 檔案中的每一列。
   + requirements.*txt* 檔案中沒有包含相依性套件名稱以外資訊的其他行。
   + requirements.*txt* 檔案的多行中不會複製任何相依性名稱，因此檔案中的兩行可能對應至一個 *.whl* 相依檔案。

   AWS Device Farm 不支援 *requirements.txt* 檔案中未直接對應至相依性套件的行，例如指定`pip install`命令全域選項的行。如需全域選項清單，請參閱[需求檔案格式](https://pip.pypa.io/en/stable/reference/requirements-file-format/#global-options)。

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