Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CampelloManuel committed Dec 5, 2022
1 parent bb6d43c commit e8bd3df
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard;
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.RootMatchers.isDialog;
import static androidx.test.espresso.matcher.ViewMatchers.isClickable;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.isRoot;
Expand All @@ -16,6 +17,7 @@
import android.app.UiAutomation;
import android.os.SystemClock;

import androidx.annotation.IdRes;
import androidx.test.espresso.AmbiguousViewMatcherException;
import androidx.test.espresso.Espresso;
import androidx.test.espresso.ViewInteraction;
Expand Down Expand Up @@ -107,20 +109,29 @@ public static void createTaskList(String taskListName) {
}

// TODO regularly crashes here in the google_apis - API23 emulator image
onView(withId(R.id.titleField)).check(matches(isDisplayed()));
onViewWithIdInDialog(R.id.titleField).check(matches(isDisplayed()));

// fill the popup
onView(withId(R.id.titleField)).perform(typeText(taskListName));
onView(withId(R.id.dialog_yes)).check(matches(isDisplayed()));
onView(withId(R.id.dialog_yes)).perform(click());
onViewWithIdInDialog(R.id.titleField).perform(typeText(taskListName));
onViewWithIdInDialog(R.id.dialog_yes).check(matches(isDisplayed()));
onViewWithIdInDialog(R.id.dialog_yes).perform(click());
try {
// check if the dialog is still visible (it shouldn't be)
onView(withId(R.id.dialog_yes)).check(matches(not(isDisplayed())));
onViewWithIdInDialog(R.id.dialog_yes).check(matches(not(isDisplayed())));
} catch (Exception ex) {
NnnLogger.exception(ex);
}
}

/**
* shorthand for onView(withId(viewId)).inRoot(isDialog())
*
* @param viewId it's R.id.something
*/
public static ViewInteraction onViewWithIdInDialog(@IdRes int viewId) {
return onView(withId(viewId)).inRoot(isDialog());
}

/**
* @return TRUE if the app is in tablet mode, FALSE in phone mode
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.RootMatchers.isDialog;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
Expand Down Expand Up @@ -44,11 +45,13 @@ public void testAddNoteLockWithPassword() {
onView(withId(R.id.passwordVerificationField)).perform(typeText(password));

onView(withId(R.id.dialog_yes)).perform(click());
EspressoHelper.waitUi();

// then it opens the popup again, to ask the password
onView(withId(R.id.passwordField)).perform(typeText(password));
onView(withId(R.id.dialog_yes)).check(matches(isDisplayed()));
onView(withId(R.id.dialog_yes)).perform(click());
EspressoHelper.onViewWithIdInDialog(R.id.passwordField).check(matches(isDisplayed()));
EspressoHelper.onViewWithIdInDialog(R.id.passwordField).perform(typeText(password));
EspressoHelper.onViewWithIdInDialog(R.id.dialog_yes).check(matches(isDisplayed()));
EspressoHelper.onViewWithIdInDialog(R.id.dialog_yes).perform(click());

// the note on the (custom) edittext should appear correctly
onView(withId(R.id.taskText)).check(matches(withText(fullNoteText1)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.scrollTo;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.RootMatchers.isDialog;
import static androidx.test.espresso.matcher.ViewMatchers.hasChildCount;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
Expand Down Expand Up @@ -65,8 +66,8 @@ public void testSaveLoadBackup() {
openContextualActionModeOverflowMenu();
String CLEAR_COMPLETED = getStringResource(R.string.menu_clearcompleted);
onView(withText(CLEAR_COMPLETED)).perform(click());
onView(withId(android.R.id.button1)).check(matches(isDisplayed()));
onView(withId(android.R.id.button1)).perform(click());
onView(withId(android.R.id.button1)).inRoot(isDialog()).check(matches(isDisplayed()));
onView(withId(android.R.id.button1)).inRoot(isDialog()).perform(click());

// restore the backup
openContextualActionModeOverflowMenu();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ private void assertUriReturnsResult(final Uri uri, final String[] fields) {
private void assertUriReturnsResult(final Uri uri, final String[] fields, final String where,
final String[] whereArgs, final int count) {
final Cursor c = mResolver.query(uri, fields, where, whereArgs, null);
NnnLogger.warning(DBProviderTest.class,
"'parameter' count = " + count + ", cursorCount = " + c.getCount());
if (count != c.getCount()) {
// will crash. Let's get more info
try {
Expand Down

0 comments on commit e8bd3df

Please sign in to comment.