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 Introduction to Appium on the Appium website.

Version Information

Currently, Device Farm supports Python version 2.7.6 (pip version 1.5.4).

Device Farm supports Appium server versions 1.7.2, 1.7.1, and 1.6.5. You can also use newer versions with the avm command in a custom test environment. For example, to use Appium server version 1.8.1, add these commands to your test spec YAML file:

phases: install: commands: # To install a newer version of Appium such as version 1.8.1: - export APPIUM_VERSION=1.8.1 - avm $APPIUM_VERSION - ln -s /usr/local/avm/versions/$APPIUM_VERSION/node_modules/.bin/appium /usr/local/avm/versions/$APPIUM_VERSION/node_modules/appium/bin/appium.js

Note

You can use the rules field in the create-device-pool command or the CreateDevicePool API to specify the APPIUM_VERSION.

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.

Note

The following instructions are based on Linux x86_64 and macOS. In the currently supported scheme, Device Farm requires that the packaging of your Appium Python tests is 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. If you execute the Python wheel command on a platform other than Linux x86_64, you gather the flavor of a non-universal wheel dependency for the platform, which might cause undesired effects. This would most likely lead to errors when you execute 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 the location of your global site-packages directory. This can result in including dependencies in your virtual environment that are not required by your tests.

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

  2. Install py.test in your virtual environment.

    Here is an example flow of using Python virtualenv to create a virtual environment and installing pytest:

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

    ─ workspace └─ tests/ (your tests go here)
  4. Make sure you have py.test installed in your virtual environment. Your test cases must be discoverable by the following command. Run this command from your virtual environment workspace folder.

    $ 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. Run the following command in your workspace to generate the requirements.txt file:

    $ pip freeze > requirements.txt
  6. Run the following command in your workspace to generate the wheelhouse/ folder:

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

    $ 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:

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

    Your workspace should look like this:

    ─ 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. 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. Choose Upload to upload your .ipa file.

    Device Farm processes your .ipa file before it continues.

  7. In Run name, enter a name for your run.

    Tip

    Give the run a name that helps 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.

  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.

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.