Name: aws-device-farm-sample-app-for-android
Owner: Amazon Web Services - Labs
Owner: AWS Samples
Description: AWS Device Farm sample Android app
Created: 2015-08-07 23:17:36.0
Updated: 2017-12-25 06:56:35.0
Pushed: 2018-01-05 02:04:37.0
Size: 19960
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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.
This project uses Butterknife in order to create Android views and view listeners through annotations.
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.
|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|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 | |———-|———————-|———-|———-|——–| |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|
|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|
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.
Linux and OSX
Enter the following command inside the terminal prompt to build the project and test apks:
adlew cC
Windows
Enter the following command inside the command prompt to build the project and test apks:
lew.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:
Download the AWS Device Farm Android sample app from GitHub.
Open the project in Android Studio.
We will generate Instrumentation tests using Espresso Recorder.
Select Run ?> Record Espresso Test ?> Select Deployment target as Android emulator or a real physical device
Click Ok. This will open up the emulator where gradle will launch the app in the emulator. In addition it will open up a “Record your Test” window.
We will record a test for alert functionality within the app.
On the app running on emulator click on Menu button ?> Alerts. You will notice that the recorder window records the UI interactions as shown below.
We will add an assertion to check for the presence of “Alert” button on the page. In the “Record your Test” window click on “Add Assertion”. This will expand the Recorder window with a snapshot of the app running in the emulator as shown below.
Select “Alert” button in the recorder window. This will auto populate the id of Alert button in the edit assertion section as shown below. Keep the assertion selection to default “exists” and click on Save Assertion.
After you click on Ok in the recorder window it will ask for a test class name under which your recorded test will be stored. Enter MyAlertTest. This will generate the test code and save it under MyAlertTest.java which you can view in the project explorer.
Now we want to run the recorded tests locally. To do this we first want a configuration that will run Android Instrumented Tests.
Go to Run ?> Edit Configurations.
Click on '+' sign on the left hand top corner and select “Android Instrumented Tests” as shown below.
Name the configuration as “MyTestConfig”. For the Class we provide the name of the class “MyAlertTest” under which we saved our tests. A completed configuration will look like below. Click Ok to save the configuration.
Run the tests by selecting “MyTestConfig” as the configuration and clicking on play. This will invoke the emulator and run your tests.
We now want to build the app and tests apks so that you can run them on AWS Device Farm on multiple devices in parallel.
Open your terminal/command prompt and change your directory to your project folder.
For Mac/Linux run the following command inside the terminal prompt to build the project and test apks. This will run all the tests under the project on a connected device. Make sure you have at least one or emulator device connected.
adlew cC
For Windows run the following command inside the terminal prompt to build the project and test apks. This will run all the tests under the project on a connected device. Make sure you have at least one or emulator device connected.
lew.bat cC
The app and test apks will now be present under
aws-device-farm-sample-app-for-android/app/build/outputs/apk
We can upload the app and test apks to AWS Device Farm as Instrumentation tests and run them against hundreds of devices in parallel. The pre-built app and tests can be found here.