Once you have uploaded the recorded test from your Android device, Barista will generate the test and send an email with a link to the test.
From the link, you can download the test in Java for multiple frameworks. Read the corresponding section below for running tests on the framework of your choice.
Pre-requisite:
UI Tests run on a physical android device or an emulator. Connect your device to the computer and make sure you can communicate to it via adb. Runningadb devices
on the command line should show your phone connected to the computer.
The Espresso test framework is part of the Android testing support library that allows testing single apps. The tests run as an instrumentation test and have access to the app's internals.
-
You will first need to set up Espresso for your app's project -- Follow this tutorial.
You can refer to the BasicSample for Espresso source code on GitHub for sample Espresso setup.
-
Then, you need to move the test to the
androidTest
folder inside your app. -
Barista comes with a library that extends Espresso's functionality in allowing you to select elements using additional selectors like XPath, helping take screenshots etc. You will need to download and copy our crema library jar file in the
lib
folder of your Android app. You can then add crema dependency in your app's gradle file to load up the library.Download crema from https://github.com/moquality/crema/releases
The resulting
app/build.gradle
should look like this:dependencies { // Other app dependencies ... // Espresso test dependencies androidTestCompile 'com.android.support.test:runner:0.5' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' androidTestCompile files('libs/crema-1.0.jar') }
-
You can run the test from within Android Studio or from gradle by running
./gradlew connectedCheck
The UIAutomator framework is also part of the Android testing support library, but also allows testing multiple apps. The tradeoff is that it is slower than Espresso but allows for blackbox testing of the app.
-
You will first need to setup UIAutomator for your app's project -- Follow this tutorial.
You can refer to the BasicSample for UIAutomator source code on GitHub for sample UIAutomator setup.
-
Paste the test inside the app's
androidTest
folder -
You can run the test from within Android Studio or from gradle by running
./gradlew connectedCheck
Appium is an open source test framework built using the WebDriver protocol. So, just like Selenium, you can write tests in any language with a WebDriver client.
-
Appium tests run on your computer and not on the phone. You can install appium using nodejs like:
npm install -g appium
-
To start the appium server, simply run the installed binary.
appium
-
Get the appium java-client and run your test
- If using Maven or Gradle:
- Follow these instructions on the java-client wiki.
- Run the test using the build system
- For command line, use these instructions:
-
First download all dependencies of java-client or simply build a farJar using instructions in this PR).
-
Compile the generated Appium test in Java against the Appium java-client and JUnit.
# Unix, Mac OSX javac -cp .:lib/java-client-5.0.0-BETA1-all.jar MyTest.java
# Windows javac -cp ".;lib/java-client-5.0.0-BETA1-all.jar" MyTest.java
-
Run the java test by running this file.
# Unix, Mac OSX java -cp .:lib/java-client-5.0.0-BETA1-all.jar MyTest
# Windows java -cp ".;lib/java-client-5.0.0-BETA1-all.jar" MyTest
-
- If using Maven or Gradle:
- Official Appium-Java Tutorial
- Refer to Appium test samples in Java
- Appium's Java-Client Wiki also has some tutorials