Skip to content

Commit

Permalink
fix flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
owencooke committed Dec 4, 2023
1 parent 7ed917a commit 28e5401
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public void navigateToEditItemFragment() throws Exception {
// Create mock initial item in DB
database.addTestItem(mockData);
// Click to view the item page
waitFor(() -> onData(anything())
.inAdapterView(withId(R.id.item_list))
.atPosition(0)
.perform(click()));
// Click on edit button
waitFor(() -> onView(withId(R.id.edit_button)).perform(scrollTo()));
onView(withId(R.id.edit_button)).perform(click());
waitFor(() -> {
onData(anything())
.inAdapterView(withId(R.id.item_list))
.atPosition(0)
.perform(click());
onView(withId(R.id.edit_button)).perform(scrollTo(), click());
});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.clearText;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.action.ViewActions.scrollTo;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.hasErrorText;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
Expand Down Expand Up @@ -41,16 +41,16 @@ public void setUp() {

@Test
public void testUsername() {
onView(withId(R.id.signup_username)).perform(typeText("antonio2"));
enterText(R.id.signup_username, "antonio2");
onView(withId(R.id.signup_username)).perform(clearText());
onView(withId(R.id.signup_username)).check(matches(hasErrorText("username cannot be empty")));
onView(withId(R.id.signup_username)).perform(typeText("antonio2$"));
enterText(R.id.signup_username, "antonio2$");
onView(withId(R.id.signup_username)).check(matches(hasErrorText("only alphanumeric, underscore, or period")));
}

@Test
public void testEmail() {
onView(withId(R.id.signup_email)).perform(typeText("antonio2"));
enterText(R.id.signup_email, "antonio2");
onView(withId(R.id.signup_email)).check(matches(hasErrorText("not a valid email")));
onView(withId(R.id.signup_email)).perform(clearText());
onView(withId(R.id.signup_email)).check(matches(hasErrorText("email cannot be empty")));
Expand All @@ -65,27 +65,27 @@ public void testConfirmedPassword() {

@Test
public void testRegister() {
onView(withId(R.id.signup_username)).perform(typeText("ESPRESSO_GENERAL_USER"));
onView(withId(R.id.signup_email)).perform(typeText("espresso_general_user@example.com"));
enterText(R.id.signup_username, "ESPRESSO_GENERAL_USER");
enterText(R.id.signup_email, "espresso_general_user@example.com");
enterText(R.id.signup_password, "12345");
enterText(R.id.signup_confirm_password, "12345");
onView(withId(R.id.signup_button)).perform(click());
waitFor(() -> onView(withId(R.id.signup_username)).check(matches(hasErrorText("username already exists"))));
onView(withId(R.id.signup_button)).perform(scrollTo(), click());
waitFor(()->onView(withId(R.id.signup_username)).check(matches(hasErrorText("username already exists"))));
enterText(R.id.signup_username, "a");
onView(withId(R.id.signup_button)).perform(click());
waitFor(() -> onView(withId(R.id.signup_password)).check(matches(hasErrorText("The given password is invalid. [ Password should be at least 6 characters ]"))));
onView(withId(R.id.signup_button)).perform(scrollTo(), click());
waitFor(() -> onView(withId(R.id.signup_password)).check(matches(hasErrorText("The given password is invalid. [ Password should be at least 6 characters ]"))));
onView(withId(R.id.signup_confirm_password)).check(matches(hasErrorText("The given password is invalid. [ Password should be at least 6 characters ]")));
enterText(R.id.signup_password, "123456");
enterText(R.id.signup_confirm_password, "123456");
onView(withId(R.id.signup_button)).perform(click());
onView(withId(R.id.signup_button)).perform(scrollTo(), click());
waitFor(() -> onView(withId(R.id.signup_email)).check(matches(hasErrorText("The email address is already in use by another account."))));
enterText(R.id.signup_email, "a@example.com");
onView(withId(R.id.signup_button)).perform(click());
onView(withId(R.id.signup_button)).perform(scrollTo(), click());
waitFor(() -> onView(withId(R.id.signin_username)).check(matches(isDisplayed())));
enterText(R.id.signin_username, "a");
enterText(R.id.signin_password, "123456");
onView(withId(R.id.signin_button)).perform(click());
waitFor(() -> hasListLength(0));
onView(withId(R.id.signin_button)).perform(scrollTo(), click());
waitFor(()->hasListLength(0));
DocumentReference docRef = db.collection("user").document("a");
docRef.delete().addOnSuccessListener(a -> Objects.requireNonNull(auth.getCurrentUser()).delete().addOnSuccessListener(aVoid -> Log.d("ESP-TEST", "Firebase Auth user deleted successfully"))
.addOnFailureListener(e -> Log.e("ESP-TEST", "Could not delete Firebase Auth user: " + e.getMessage()))).addOnFailureListener(a -> Log.e("ESP-TEST", "Document failed to delete!"));
Expand Down

0 comments on commit 28e5401

Please sign in to comment.