Skip to content

jamesknowsbest/aws-device-farm-sample-app-for-android

 
 

Repository files navigation

AWS Device Farm Sample App for Android | fork

I forked this project to hardcode a popup to appear where a dialoge box asks for permission.

Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. This approach streamlines the app install process, since the user does not need to grant permissions when they install or update the app. It also gives the user more control over the app's functionality; for example, a user could choose to give a camera app access to the camera but not to the device location. The user can revoke the permissions at any time, by going to the app's Settings screen.

source: https://stackoverflow.com/a/36354478/8016330

When uploading apps to Device Farm some appium tests fail because a popup appear. This app is designed to make the popup so that tests can be written around it to dismiss the popup.

Appium java/python

Java link

MobileElement el3 = (MobileElement) driver.findElementById("com.android.packageinstaller:id/permission_allow_button");
    if (el3.isDisplayed()){
    	el3.click();
    }else{
    	System.out.println("Permission is not displayed");
}

Python link

el3 = driver.find_element_by_id("com.android.packageinstaller:id/permission_deny_button")
el3.click()

Instrumentation

TODO: need to implement solution from this project:

Calabash

Here are the steps to run the calabash tests using the Gemfile and bundler

bundle exec calabash-android resign ./app/build/outputs/apk/debug/app-debug.apk
bundle exec calabash-android run ./app/build/outputs/apk/debug/app-debug.apk

Gemfile contents:

gem 'calabash-cucumber'
gem 'calabash-android'

You may need to use install these before running the bundler commands with:

  gem install calabash-cucumber
  gem install calabash-android

This is a sample native Android app that contains many of the stock Android components and elements, along with example Appium, Calabash, and Espresso tests. You can use the app and example tests as a reference for your own AWS Device Farm test scripts.

Notes

This project uses Butterknife in order to create Android views and view listeners through annotations.

Getting Started

In order to run this app on Device Farm, you will first need to create a local copy of this repository, open the project, and then build the APK from the source.

Examples for Testing Specific Scenarios

Component App Implementation Espresso Calabash Appium
Alerts: Toasts and Dialogs source code source code source code source code
Fixtures source code source code source code source code
Static Page: TextView source code source code source code source code
Login Page source code source code source code source code
Nested Views: Back and Up Navigation source code source code source code source code
Web Views
An Expected Crash source code source code Not implemented Not implemented

Examples for Native Features

Feature Android Implementation Espresso Calabash Appium
Camera source code source code source code source code
Image Collection Grid source code source code source code source code
Scroll View source code source code source code source code
Out of View Content source code source code source code source code
Video source code source code source code source code

Examples for Inputs

Component Android Implementation Espresso Calabash Appium
Checkbox source code source code source code source code
DatePicker source code source code source code Not implemented (not directly supported by Appium)
EditText source code source code source code source code
Gestures Input source code source code source code source code
Pull to Refresh source code source code source code source code
Radio Buttons source code source code source code source code
TimePicker source code source code source code Not implemented (not directly supported by Appium)
Toggle Button source code source code source code source code
Spinner Input source code source code source code source code
Buttons source code source code source code source code

Examples for Navigation

Component Android Implementation Espresso Calabash Appium
Navigation Drawer source code source code source code source code
ViewPager source code source code source code source code

Android Tips and Tricks

  • Android Devices come in many different screen sizes. Make sure to properly layout your views within your Android XML file. Follow this guide in order to learn more about writing code to support different screen sizes. Here is an example in the Android code where there are different defined values depending on the screen-size. This automatically resizes elements within the layouts so that views adapt to all screens sizes. Remember if an element/view isn't completely on the screen during testing it cannot be verified.

Espresso

Setting Up and Running Espresso Tests

If you're just getting started, first read this guide.

Configuring Android Studio to Run Espresso Locally

You must set a custom Instrumentation run configuration to run your Espresso tests locally. You need to set the instrumentation runner to "android.support.test.runner.AndroidJUnitRunner"

Building the App and Test APK to Run on Device Farm

You will need two APKs: the app apk and the Espresso (Instrumentation) test apk.

Step 1: Go to your project directory

Open your terminal/command prompt and change your directory to your project folder.

Step 2: Build the project

Linux and OSX

Enter the following command inside the terminal prompt to build the project and test apks:

./gradlew cC

Windows

Enter the following command inside the command prompt to build the project and test apks:

gradlew.bat cC

Step 3: Find the APKS

The app APK is called app-debug.apk and the test apk is app-debug-androidTest-unaligned.apk.

Follow the Device Farm Directions for Instrumentation in order to upload the APKs into the console and perform a test.

Strategies for Espresso

Waiting for Elements

Use Idling Resources in order to wait for elements within Espresso.

Examples of custom Idling Resources used within the Espresso tests:

Custom Matchers

Use custom matchers in order to match your views to custom elements within your tests.

Examples of custom Matchers used within the Espresso tests:

Tips

  • If you see threading errors make sure to run the test code in the UI thread. Use the UiThreadTest annotation. Due to security concerns tests that run on threads outside of the UI thread cannot communicate with the UI.
  • Your app's package name must match your app's applicationId that is defined in your gradle file. If the two names do not match tests will not run.

About

AWS Device Farm sample Android app

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 85.1%
  • Ruby 13.7%
  • Other 1.2%