Menu
AWS Device Farm
Developer Guide (API Version 2015-06-23)

Working with Appium Python for iOS Applications and AWS Device Farm

Device Farm provides support for Appium Python for iOS apps.

What Is Appium Python?

Appium is an open-source tool for automating native, mobile web, and hybrid applications on platforms like web applications. For more information, see About Appium.

Version Information

Currently, Device Farm supports Appium versions 1.6.3 (for iOS 10 and later) and 1.4.16 (for iOS 9 and earlier) and Python version 2.7.6 (pip version 1.5.4).

Prepare Your iOS Application Appium Python Tests

The Appium Python tests for your iOS application must be contained in a .zip file.

Build the Appium Python Test Package

The Appium Python test packages you upload to Device Farm must be in .zip format and contain all the dependencies of your test. The following instructions show you how to meet these requirements.

Note

The instructions below are based on Linux x86_64 and Mac. In the currently supported scheme, Device Farm requires that the packaging of your Appium Python tests be done on Linux x86_64 if your tests contain non-universal Python wheels dependencies. For the platform on which you execute a command, the wheels tools gather your .whl dependent files under the wheelhouse/ folder. When you execute the Python wheel command on any platform other than Linux x86_64, you would gather the flavor of a non-univesral wheel dependency for that particular platform and may cause undesired effects. This would most likely lead to errors when executing your tests on Device Farm.

  1. We strongly recommend that you set up Python virtualenv for developing and packaging tests so that unnecessary dependencies are not included in your app package.

    Tip

    • Do not create a Python virtualenv with the --system-site-packages option, because it will inherit packages from /usr/lib/pythonx.x/site-packages or wherever your global site-packages directory is. This can lead to you including dependencies in your virtual environment that are not needed by your tests.

    • You should also verify that your tests do not use dependencies that are dependent on native libraries, as these native libraries may or may not be present on the instance where these tests run.

  2. Install py.test in your virtual environment.

    An example flow of creating a virtual environment using Python virtualenv and installing pytest in that virtual environment would look like the following:

    Copy
    $ virtualenv workspace $ cd workspace $ source bin/activate $ pip install pytest
  3. Store all Python test scripts under the tests/ folder in your work space.

    Copy
    ─ workspace └─ tests/ (your tests go here)
  4. Make sure you have py.test installed in your virtual environment and test cases are discoverable by the following command, which you should run from your virtual environment workspace folder.

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

    Make sure the output of py.test command shows you the tests that you want to execute on Device Farm.

  5. Go to your work space and run the following command to generate the requirements.txt file:

    Copy
    $ pip freeze > requirements.txt
  6. Go to your work space and run the following command to generate the wheelhouse/ folder:

    Copy
    $ pip wheel --wheel-dir wheelhouse -r requirements.txt
  7. You can use the following commands to clean all cached files under your tests/ folder:

    Copy
    $ 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 {} +
  8. Zip the tests/ folder, wheelhouse/ folder, and the requirements.txt file into a single archive:

    Copy
    $ zip -r test_bundle.zip tests/ wheelhouse/ requirements.txt

    Your work space will eventually look like this:

    Copy
    ─ workspace ├─ tests/ ├─ test_bundle.zip ├─ requirements.txt └─ wheelhouse/

Upload Your iOS Application Appium Python Tests

Use the Device Farm console to upload your tests.

  1. Sign in to the Device Farm console at https://console.aws.amazon.com/devicefarm.

  2. If you see the AWS Device Farm console home page, choose Get started.

  3. If you already have a project, you can upload your tests to an existing project or choose Create a new project.

    
                Your projects page in the Device Farm console

    Tip

    If the list of projects is not displayed, then on the secondary navigation bar, for Projects, choose the name of the project where you want to upload your tests.

    To create a project, follow the instructions in Create a Project.

  4. If the Create a new run button is displayed, choose it.

  5. On the Choose your application page, choose Native Application (the Android and Apple logos).

    
                Choose the native (Android or iOS) application button in the Device Farm
                  console

  6. Next, choose Upload to upload your .ipa file.

    Device Farm processes your .ipa file before continuing.

  7. In the Run name field, type a name for your run.

    Tip

    Give the run a name that will help you identify a specific build of your app (for example, Beta-0.1). For more information, see Working with Test Runs.

  8. Choose Appium Python to configure your test.

  9. To add your Appium test scripts to the test run, choose Upload.

  10. Choose the Appium version you are using from the Appium version dropdown list.

  11. Choose Next step, and then complete the instructions to select devices and start the run.

Taking Screenshots in iOS Appium Python Tests

You can take screenshots as part of your iOS Appium Python tests.

When Device Farm runs your Appium Python test, the service sets the SCREENSHOT_PATH property to a fully qualified path on the local file system where Device Farm expects Appium screenshots to be saved. The test-specific directory where the screenshots are stored is defined at runtime. The screenshots are pulled into your Device Farm reports automatically. To view the screenshots, in the Device Farm console, choose the Screenshots section.

The following example shows how to use and consume the SCREENSHOT_PATH property to capture an Appium screenshot that is pulled into your Device Farm report.

Copy
screenshot_folder = os.getenv('SCREENSHOT_PATH', '') self.driver.save_screenshot(screenshot_folder + "/screenshot.png")

Additional Considerations for Android Appium Python Tests

Device Farm does not modify iOS Appium Python tests.