Home

Awesome

Appium Sample Tests for AWS Device Farm Sample App

This is a collection of example Appium TestNG tests written for the AWS Device Farm Android sample app. Please use these tests as a reference for your own AWS Device Farm Appium TestNG tests.

This test suite uses the Appium page model in order to separate the tests from the logic.

Android

Getting Started

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

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

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

    npm install -g appium@1.7.2
    
  3. Verify that you have Appium installed with this command:

    appium -v
    

    You should get "1.7.2" as the output

Creating a new Java Appium Test Project Using Maven

  1. Create a new Maven project using a Java IDE. The example in this tutorial is for IntelliJ IDEA Community Edition.

  2. Set up your POM file using the official AWS Device Farm documentation for TestNG

    • You will need the following dependencies in your POM file

      <dependencies>
          <dependency>
      	    <groupId>org.testng</groupId>
          	<artifactId>testng</artifactId>
              <version>6.11</version>
              <scope>test</scope>
      	</dependency>
          <dependency>
              <groupId>io.appium</groupId>
      	    <artifactId>java-client</artifactId>
          	<version>4.1.2</version>
          </dependency>
      </dependencies>
      

Running Your Tests Locally

First, make sure that you have followed all the steps in the Appium getting started guide.

Use the script start-appium-android.sh to run the Appium server locally. Once the server has started, run the TestNG tests within your IDE.

For example, if your package name is com.appium.example, your main activity name is .Activities.MainActivity, and the absolute filepath to your APK is ~/Desktop/appium/app.apk, you would run the following command.

appium --pre-launch --app-pkg com.appium.example --app-activity .Activities.MainActivity --platform-name Android --app ~/Desktop/appium/app.apk

Running Your Tests on AWS Device Farm

Step 1: Verify the Project Set-up

First Read the Device Farm documentation. Ensure that all the steps are completed and that your project and POM file are set up correctly.

Step 2: Go into your Maven Appium Directory

Go into your Appium Maven project directory in the terminal or command prompt.

Step 3: Package the Test Content

Run the following Maven command to package the test content.

mvn clean package -DskipTests=true

Step 4: Locate the zip-with-dependencies.zip file

Once the Maven command above is finished it will produce a "zip-with-dependencies.zip" file in your target folder. You will upload this file when creating a run on AWS Device Farm.

<img src="https://github.com/awslabs/aws-device-farm-appium-tests-for-sample-app/blob/master/readme_images/appium-tests.gif" width="400">

Examples For Android

Examples for Testing Specific Scenarios

ComponentAndroid ImplementationTests
Alerts: Toasts and Dialogssource codesource code
Fixturessource codesource code
Static Page: TextViewsource codesource code
Login Pagesource codesource code
Nested Views: Back and Up Navigationsource codesource code
Web Views<ul><li><a href ="https://github.com/awslabs/aws-device-farm-sample-app-for-android/blob/master/app/src/main/java/com/amazonaws/devicefarm/android/referenceapp/Fragments/LocalWebView.java">Hybrid Web Views</a></li><li><a href="https://github.com/awslabs/aws-device-farm-sample-app-for-android/blob/master/app/src/main/java/com/amazonaws/devicefarm/android/referenceapp/Fragments/WebViewFragment.java">Web View</a></li></ul><ul><li>Hybrid Web Views (Not implemented)</li><li><a href="https://github.com/awslabs/aws-device-farm-appium-tests-for-sample-app/blob/master/src/test/java/Tests/WebViewTest.java">Web View</a></li></ul>
An Expected Crashsource codeNot implemented

Strategies for Native Features

FeatureAndroid ImplementationTests
Camerasource codesource code
Image Collection Gridsource codesource code
Scroll Viewsource codesource code
Out of View Contentsource codesource code
Videosource codesource code

Examples for Testing Inputs

ComponentAndroid ImplementationTests
Checkboxsource codesource code
DatePickersource codeNot implemented (not directly supported by Appium)
EditTextsource codesource code
Gestures Inputsource codesource code
Pull to Refreshsource codesource code
Radio Buttonssource codesource code
TimePickersource codeNot implemented (not directly supported by Appium)
Toggle Buttonsource codesource code
Spinner Inputsource codesource code
Buttonssource codesource code

Examples for Automated Navigation

ComponentAndroid ImplementationTests
Navigation Drawersource codesource code
ViewPagersource codesource code

Tips and Tricks

Driver Configuration

Remember to set up your Appium driver correctly. AWS Device Farm takes care of the configuration for you, and you don't need to set any of the DesiredCapabilities when creating the driver. Refer to this example.