A mineral named for Neptune, Roman god of the sea because of its association with aegirine from Àgir, the Scandinavian sea-god
This is a sample test framework for android, work-in-progress
- JAVA JDK v. 8, verify w. the command
java -version
- Gradle 6.3, verify w. the command
gradle -v
- Android Studio 3.6.1
- Android SDK
- Adroid AVD
- Android Emulator w. Android SDK 9.0(API Level +28)
- Use the Device manager and set up a device based on current Android API
- Connect the device to your machine using USB cable
- Enable developer options and USB debugging
- If Android 9 (API Level 28) and Android, go to
Settings > About Phone > Build Number
- If Android 9 (API Level 28) and Android, go to
- Avoid flakiness with devices during testing by turning off system animations. Disable the following in
Settings > Developer > Options
:- Window animation scale
- Transition animation scale
- Animator duration scale
When building an application, if you get the Kotlin duplication ..
error, simply
open build.gradle(Module:app) and add the following line to the end:
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
}
... then rebuild the project
private static final String myText = "my text";
replace String with proper data type
Launch the application in your emulator then:
Tools > Layout Inspector > Attributes
As you navigate through the app, the screens will be reflected in the layout inspector window This allows you to interact with the elements shown and find their respective ids
@Test
public void descriptiveTestName(){ ... arrange / act / assert ...}
*** ESPRESSO VIEW MATCHERS ***
ViewInteraction test = onView(withId(R.id.someId));
ViewInteraction done = onView(withText("Done"));
ViewInteraction profile = onView(withContentDescription("profile"));
ViewInteraction hint = onView(withHint("Simple hint"));
ViewInteraction spinnerText = onView(withSpinnerText("Spinner_Text"));
ViewInteraction linkName = onView(hasLinks(##));
onView(withClassName(endsWith("EditText")));
onView(withClassName(startsWith("Hello")));
*** DATA / LIST ADAPTER VIEW
onData(withId("Listview_id")).atPosition(2).check(matches(isDisplayed()));
onView(withText("name")).perform(typeText("sample text"));
onView(withText("search")).perform(typeTextIntoFocusedView("sample text"));
onView(withText("name")).perform(clearText());
onView(withText("submit")).perform(click());
onView(withText("submit")).perform(doubleClick());
onView(withText("submit")).perform(longClick());
onView(withId(R.id.sampleView)).perform(swipeUp());
onView(withId(R.id.sampleView)).perform(swipeDown());
onView(withId(R.id.sampleView)).perform(swipeLeft());
onView(withId(R.id.sampleView)).perform(swipeRight());
onView(withId(R.id.listView)).perform(scrollTo());
onView(withId(R.id.listView)).perform(scrollTo(), click());
closeSoftKeyboard();
pressBack();
pressMenuKey();
keycodepressKey(37);
let url = 'https://www.google.com
onView(withText(url)).perform(openLinkWithText(url));
*** ESPRESSO COMMON ASSERTIONS ***
onView(withId(R.id.anyElement)).check(matches(isDisplayed()));
onView(withId(R.id.anyElement)).check(doesNotExist());
onView(withId(R.id.anyString)).check(matches(withText(R.string.custom_string)));
onView(withId(R.id.anyText)).check(matches(withText("custom string")));
onView(withId(R.id.textView)).check(isLeftOf(withText("foo!")));
onView(withId(R.id.textView)).check(isRightOf(withText("foo!")));
onView(withId(R.id.textView)).check(isAbove(withText("foo!")));
onView(withId(R.id.textView)).check(isBelow(withText("foo!")));
onView(withId(R.id.anyInput)).check(matches(isFocusable()));
onView(withId(R.id.button)).check(matches(isClickable()));
onView(withId(R.id.checkbox)).check(matches(isNotChecked()));
ESPRESSO CUSTOM MATCHER Use when the UIAutomator is not working. To do so, do the following:
- In the project structure:
app > src > androidTest > java
create a new package with something descriptive like "x.espress.errormatcher" - Add a New Class like "ErrorTextMatcher"
- In the file, add different parameters to suit your needs (Plain Text, String Matcher, and Resource ID)
- In the test, import the package and use accordingly
onView(withId(R.id.Element)).check(matches(CustomMatcher.withWhatever("myText")));
onView(withId(R.id.Element)).check(ViewAssertion.matches(CustomMatcher.withWhatever(R.string.id)));
onView(withId(R.id.Element)).check(ViewAssertion.matches(CustomMatcher.withWhatever(Matcher.containsString("my string"))));