This is a sample native Android app that contains most of the stock Android components and elements. Example Appium, Calabash, and Espresso tests have been written for this app.
Please use this app and example test suites as a reference for your own Device Farm tests.
This project uses Butterknife in order to create Android views and view listeners through annotations.
In order to run this app within Device Farm you can either use the preassembled APK or open and build the APK yourself from source.
Component | Android 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 |
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 |
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 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 writting 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 resized elements within the layouts so that views completely fill all types of screens sizes. Remember if a element/view isn't completely on the screen during testing it cannot be verified.
First read this guide.
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"
You will need two APKs: the app apk and the Espresso (Instrumentation) test apk.
Open your terminal/command prompt and change your directory to your project folder.
OSX/Linux
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
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.
Use Idling Resources in order to wait for elements within Espresso.
Examples of custom Idling Resources used within the Espresso tests:
Use custom matchers in order to match your views to custom elements within your tests.
Examples of custom Matchers used within the Espresso tests: RegularExpressionMatcher
- If you are receiving 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 may not run.