awslabs/aws-device-farm-sample-web-app-using-appium-python

Name: aws-device-farm-sample-web-app-using-appium-python

Owner: Amazon Web Services - Labs

Owner: AWS Samples

Description: How to test a web application using AWS Device Farm and Appium Python

Created: 2016-01-30 00:07:03.0

Updated: 2018-01-11 11:45:32.0

Pushed: 2016-03-08 19:26:06.0

Homepage: null

Size: 11

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Appium Web tests for AWS Device Farm

This test demonstrates how to test a web application using AWS Device Farm and Appium Python. You can use these tests as a reference for your own AWS Device Farm Appium Python tests.

Background

What Is Appium Python?

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

Getting started

  1. Follow the official Appium getting started guide and install the Appium server and dependencies.

    AWS Device Farm supports Appium version 1.4.10. Using a different version locally may cause unexpected results when running Appium tests on AWS Device Farm.

  2. In order to use 1.4.10, download Appium through NPM with this command:

    install -g appium@1.4.10
    
  3. Verify that you have Appium installed with this command: appium -v You should get “1.4.10” as the output

Steps to package your tests

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 for Linux x86_64 and Mac. In the current scheme of things Device Farm requires that the packaging of your Appium Python Tests be done on Linux x86_64 if your tests contain non-universal wheels dependencies. The reason for this is that Python wheel gathers the dependencies, your .whl files under the wheelhouse/ folder, for the platform on which you execute the command. Executing the python wheel command on any platform other than Linux x86_64 would gather the flavor of a non-univesral wheel dependency for that particular platform and may cause undesired effects which most likely will lead to errors while executing your tests on Device Farm

  1. It is highly recommended that you set up Python virtualenv for developing and packaging tests so that the unnecessary dependencies are not included in your test package.

  2. Do not create a Python virtualenv with ?–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.

  3. 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.

  4. Install py.test in your virtual environment

    An example flow of creating a virtual environment using Python virtualenv would look like:

    rtualenv workspace
     workspace
    urce bin/activate
    p install pytest
    
  5. Store all python test scripts under the tests/ folder in your work space.

  6. workspace |

    • tests/ (your tests go here)

    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. Make sure the output of py.test command below shows you the tests that you want to execute on Device Farm

    .test --collect-only tests/
    
  7. Go to your work space and run the following command to generate the requirements.txt file.

    p freeze > requirements.txt
    
  8. Go to your work space and run the following command to generate the wheelhouse/ folder:

    p wheel --wheel-dir wheelhouse -r requirements.txt
    
  9. You can clean all cached files under your tests/ folder with the following commands:

    nd . -name '__pycache__' -type d -exec rm -r {} +
    nd . -name '*.pyc' -exec rm -f {} +
    nd . -name '*.pyo' -exec rm -f {} +
    nd . -name '*~' -exec rm -f {} +
    
  10. Zip the tests/ folder, wheelhouse/ folder, and the requirements.txt file into a single archive:

    p -r test_bundle.zip tests/ wheelhouse/ requirements.txt
    
  11. Your workspace would eventually look like:

  12. workspace |

    • tests/ |
    • test_bundle.zip |
    • requirements.txt |
    • wheelhouse/
Upload and Run your Web Application Appium Python Tests

Use the Device Farm console to upload your tests:

  1. Sign in to the Device Farm console.

  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.

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

  5. On the Choose your application page, choose Web Application (the HTML5 button)

  6. Provide a name for your run in the Run name field.

  7. Configure your test by choosing Appium Python.

  8. Next, choose Upload to upload your .zip file. Device Farm processes your .zip file before continuing.

  9. Choose Next step, and then complete the remaining on-screen instructions to select devices and start the run.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.