From 9356524d41574b4761c730da0b1c7100176260d1 Mon Sep 17 00:00:00 2001 From: madrine Date: Mon, 22 Jul 2024 17:17:32 +0300 Subject: [PATCH] Tests for adding and removing family members and fixed naming convention --- .../activity/anc/HomePageActivityTest.java | 35 +-- .../anc/activity/anc/LoginActivityTest.java | 32 +-- .../anc/activity/anc/ProfilePageTests.java | 73 ++--- .../anc/RegisterFamilyMemberPageTests.java | 59 ++-- .../activity/anc/RemoveFamilyMemberTest.java | 269 ++++++++++++++++++ .../anc/activity/utils/Configs.java | 9 + .../anc/activity/utils/Utils.java | 25 ++ 7 files changed, 385 insertions(+), 117 deletions(-) create mode 100644 reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/RemoveFamilyMemberTest.java diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/HomePageActivityTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/HomePageActivityTest.java index 24a36756f..a2580897a 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/HomePageActivityTest.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/HomePageActivityTest.java @@ -1,25 +1,18 @@ package org.smartregister.anc.activity.anc; -import static androidx.test.espresso.Espresso.closeSoftKeyboard; + import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.action.ViewActions.scrollTo; import static androidx.test.espresso.action.ViewActions.typeText; import static androidx.test.espresso.assertion.ViewAssertions.matches; -import static androidx.test.espresso.matcher.RootMatchers.withDecorView; -import static androidx.test.espresso.matcher.ViewMatchers.hasDescendant; -import static androidx.test.espresso.matcher.ViewMatchers.isClickable; + import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription; import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withSubstring; -import static androidx.test.espresso.matcher.ViewMatchers.withText; - -//import static org.smartregister.anc.activity.utils.Utils.withRecyclerViewId; +import static androidx.test.espresso.matcher.ViewMatchers.withText; import static org.hamcrest.CoreMatchers.allOf; -import static org.hamcrest.CoreMatchers.is; - import androidx.test.espresso.action.ViewActions; import androidx.test.espresso.contrib.RecyclerViewActions; import androidx.test.ext.junit.rules.ActivityScenarioRule; @@ -48,18 +41,18 @@ public class HomePageActivityTest { private Utils utils = new Utils(); @Test - public void A_setUp() throws InterruptedException { + public void asetUp() throws InterruptedException { utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword); } @Test - public void B_SearchBarPresent() { + public void bSearchBarPresent() { onView(withId(R.id.search_bar_layout)).check(matches(isDisplayed())); } @Test - public void C_SearchPatientByName() throws InterruptedException { + public void cSearchPatientByName() throws InterruptedException { onView(withId(R.id.edt_search)).perform(typeText(Configs.TestDataConfigs.clientName), ViewActions.closeSoftKeyboard()); onView(withId(R.id.patient_name)).check(matches(isDisplayed())); @@ -68,7 +61,7 @@ public void C_SearchPatientByName() throws InterruptedException { } @Test - public void C_SearchPatientByID() throws InterruptedException { + public void dSearchPatientByID() throws InterruptedException { onView(withId(R.id.edt_search)).perform(typeText(Configs.TestDataConfigs.clientID), ViewActions.closeSoftKeyboard()); onView(withId(R.id.patient_name)).check(matches(isDisplayed())); @@ -77,7 +70,7 @@ public void C_SearchPatientByID() throws InterruptedException { } @Test - public void D_AdvancedSearch() throws InterruptedException { + public void eAdvancedSearch() throws InterruptedException { onView(withId(R.id.action_search)).perform(click()); onView(withId(R.id.qrCodeButton)).check(matches(isDisplayed())); Thread.sleep(1000); @@ -87,7 +80,7 @@ public void D_AdvancedSearch() throws InterruptedException { } @Test - public void E_OpenLibrary() throws InterruptedException { + public void fOpenLibrary() throws InterruptedException { onView(withId(R.id.action_library)).perform(click()); onView(withId(R.id.library_toolbar_title)).check(matches(isDisplayed())); Thread.sleep(1000); @@ -96,20 +89,20 @@ public void E_OpenLibrary() throws InterruptedException { } @Test - public void userCanAccessANCRegistrationForm() throws InterruptedException { + public void guserCanAccessANCRegistrationForm() throws InterruptedException { onView(withContentDescription("Register")).perform(click()); Thread.sleep(1500); onView(withId(R.id.scan_button)).check(matches(isDisplayed())); } @Test - public void userCanAccessProfile() throws InterruptedException { + public void huserCanAccessProfile() throws InterruptedException { onView(withContentDescription("Me")).perform(click()); Thread.sleep(1500); onView(withId(R.id.locationImageView)).check(matches(isDisplayed())); } @Test - public void userCanClickOnAPatient() throws InterruptedException { + public void iuserCanClickOnAPatient() throws InterruptedException { onView(allOf(withId(R.id.recycler_view), isDisplayed())) .perform(RecyclerViewActions.actionOnItemAtPosition(0, click())); Thread.sleep(2000); @@ -117,7 +110,7 @@ public void userCanClickOnAPatient() throws InterruptedException { } @Test - public void userCanClickOnNextButtonOnRegister() throws InterruptedException { + public void juserCanClickOnNextButtonOnRegister() throws InterruptedException { Thread.sleep(2000); onView(allOf(withId(R.id.recycler_view), isDisplayed())) .perform(RecyclerViewActions.scrollToPosition(20)); @@ -126,7 +119,7 @@ public void userCanClickOnNextButtonOnRegister() throws InterruptedException { onView(withId(R.id.btn_previous_page)).check(matches(isDisplayed())); } @Test - public void userCanClickOnThePreviousBtnOnRegister() throws InterruptedException { + public void kuserCanClickOnThePreviousBtnOnRegister() throws InterruptedException { Thread.sleep(2000); onView(allOf(withId(R.id.recycler_view), isDisplayed())) .perform(RecyclerViewActions.scrollToPosition(20)); diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/LoginActivityTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/LoginActivityTest.java index 2e2f89854..3b6f3e7f0 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/LoginActivityTest.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/LoginActivityTest.java @@ -4,40 +4,30 @@ import static androidx.test.espresso.Espresso.onView; import static androidx.test.espresso.action.ViewActions.click; import static androidx.test.espresso.action.ViewActions.closeSoftKeyboard; -import static androidx.test.espresso.action.ViewActions.replaceText; -import static androidx.test.espresso.action.ViewActions.scrollTo; + import static androidx.test.espresso.action.ViewActions.typeText; import static androidx.test.espresso.assertion.ViewAssertions.matches; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription; + import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withParent; + import static androidx.test.espresso.matcher.ViewMatchers.withText; import org.smartregister.anc.activity.LoginActivity; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewParent; - -import androidx.test.espresso.ViewInteraction; -import androidx.test.espresso.action.TypeTextAction; import androidx.test.ext.junit.rules.ActivityScenarioRule; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; -import org.hamcrest.Description; -import org.hamcrest.Matcher; -import org.hamcrest.TypeSafeMatcher; + import org.junit.FixMethodOrder; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.MethodSorters; import org.smartregister.anc.R; -import org.smartregister.anc.activity.utils.Constants; -import org.smartregister.anc.activity.utils.Utils; + @LargeTest @FixMethodOrder(MethodSorters.NAME_ASCENDING) @@ -51,7 +41,7 @@ public class LoginActivityTest { @Test - public void E_testShowPassword(){ + public void eTestShowPassword(){ onView(withId(R.id.login_password_edit_text)).perform(typeText(correctPassword),closeSoftKeyboard()); onView(withId(R.id.login_show_password_checkbox)).perform(click(),closeSoftKeyboard()); onView(withId(R.id.login_password_edit_text)).check(matches(withText(correctPassword))); @@ -59,7 +49,7 @@ public void E_testShowPassword(){ } @Test - public void F_testSuccessfulLogin() throws InterruptedException { + public void fTestSuccessfulLogin() throws InterruptedException { onView(withId(R.id.login_user_name_edit_text)).perform(typeText("demo"), closeSoftKeyboard()); onView(withId(R.id.login_password_edit_text)).perform(typeText(correctPassword), closeSoftKeyboard()); onView(withId(R.id.login_login_btn)).perform(click()); @@ -70,7 +60,7 @@ public void F_testSuccessfulLogin() throws InterruptedException { } @Test - public void C_testIncorrectUsername() throws InterruptedException { + public void cTestIncorrectUsername() throws InterruptedException { onView(withId(R.id.login_user_name_edit_text)).perform(typeText("Beba"),closeSoftKeyboard()); onView(withId(R.id.login_password_edit_text)).perform(typeText(correctPassword),closeSoftKeyboard()); onView(withId(R.id.login_login_btn)).perform(click()); @@ -83,7 +73,7 @@ public void C_testIncorrectUsername() throws InterruptedException { @Test - public void D_testIncorrectPassword() throws InterruptedException { + public void dTestIncorrectPassword() throws InterruptedException { onView(withId(R.id.login_user_name_edit_text)).perform(typeText("demo"),closeSoftKeyboard()); onView(withId(R.id.login_password_edit_text)).perform(typeText("mani"),closeSoftKeyboard()); onView(withId(R.id.login_login_btn)).perform(click()); @@ -94,7 +84,7 @@ public void D_testIncorrectPassword() throws InterruptedException { } @Test - public void A_testEmptyUsername() throws InterruptedException { + public void aTestEmptyUsername() throws InterruptedException { onView(withId(R.id.login_user_name_edit_text)).perform(typeText(" "),closeSoftKeyboard()); onView(withId(R.id.login_password_edit_text)).perform(typeText(correctPassword),closeSoftKeyboard()); onView(withId(R.id.login_login_btn)).perform(click()); @@ -105,7 +95,7 @@ public void A_testEmptyUsername() throws InterruptedException { } @Test - public void B_testEmptyPassword() throws InterruptedException { + public void bTestEmptyPassword() throws InterruptedException { onView(withId(R.id.login_user_name_edit_text)).perform(typeText("Beba"),closeSoftKeyboard()); onView(withId(R.id.login_password_edit_text)).perform(typeText(" "),closeSoftKeyboard()); onView(withId(R.id.login_login_btn)).perform(click()); diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ProfilePageTests.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ProfilePageTests.java index 82d5d2d22..5dffa0e22 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ProfilePageTests.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ProfilePageTests.java @@ -1,33 +1,33 @@ package org.smartregister.anc.activity.anc; -import static androidx.test.espresso.Espresso.onData; + import static androidx.test.espresso.Espresso.onView; 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.ViewMatchers.hasDescendant; -import static androidx.test.espresso.matcher.ViewMatchers.isClickable; -import static androidx.test.espresso.matcher.ViewMatchers.isCompletelyDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA; + import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription; -import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility; + import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withTagValue; + +import static androidx.test.espresso.matcher.ViewMatchers.withSubstring; import static androidx.test.espresso.matcher.ViewMatchers.withText; -//import androidx.test.espresso.contrib.RecyclerViewActions; import static org.hamcrest.CoreMatchers.allOf; -import static org.hamcrest.CoreMatchers.is; -import androidx.test.espresso.action.ScrollToAction; +import android.app.Activity; + import androidx.test.espresso.contrib.RecyclerViewActions; -import androidx.test.espresso.matcher.ViewMatchers; + import androidx.test.ext.junit.rules.ActivityScenarioRule; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; +import com.vijay.jsonwizard.activities.JsonFormActivity; + import org.junit.FixMethodOrder; import org.junit.Rule; import org.junit.Test; @@ -50,22 +50,23 @@ public class ProfilePageTests { Utils utils = new Utils(); @Test - public void A_SetUp() throws InterruptedException { + public void aSetUp() throws InterruptedException { utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword); } @Test - public void B_UserLocationIsDisplayed() { + public void bUserLocationIsDisplayed() throws InterruptedException { onView(withContentDescription("Me")).perform(click()); onView(withId(R.id.facility_selection)).perform(click()); onView(withId(R.id.locations_lv)).check(matches(isDisplayed())); onView(withId(R.id.locations_lv)).perform(click()); + Thread.sleep(1000); } @Test - public void C_ChangeLanguageToBahasa() throws InterruptedException { + public void cChangeLanguageToBahasa() throws InterruptedException { onView(withContentDescription("Me")).perform(click()); onView(withId(R.id.language_switcher_text)).perform(click()); onView(withText("Bahasa (Indonesia)")).perform(click()); @@ -76,7 +77,7 @@ public void C_ChangeLanguageToBahasa() throws InterruptedException { @Test - public void E_ChangeLanguageToFrench() throws InterruptedException { + public void eChangeLanguageToFrench() throws InterruptedException { onView(withContentDescription("Me")).perform(click()); onView(withId(R.id.language_switcher_text)).perform(click()); onView(withText("French")).perform(click()); @@ -86,7 +87,7 @@ public void E_ChangeLanguageToFrench() throws InterruptedException { } @Test - public void F_ChangeLanguageToPortuguese() throws InterruptedException { + public void fChangeLanguageToPortuguese() throws InterruptedException { onView(withContentDescription("Moi")).perform(click()); onView(withId(R.id.language_switcher_text)).perform(click()); onView(withText("Portuguese (Brazil)")).perform(click()); @@ -96,7 +97,7 @@ public void F_ChangeLanguageToPortuguese() throws InterruptedException { } @Test - public void G_ChangeLanguageToEnglish() throws InterruptedException { + public void gChangeLanguageToEnglish() throws InterruptedException { onView(withContentDescription("Eu")).perform(click()); onView(withId(R.id.language_switcher_text)).perform(click()); onView(withText("English")).perform(click()); @@ -105,7 +106,7 @@ public void G_ChangeLanguageToEnglish() throws InterruptedException { Thread.sleep(1000); } @Test - public void H_LoadPopulationXstics() throws InterruptedException { + public void hLoadPopulationXstics() throws InterruptedException { onView(withContentDescription("Me")).perform(click()); onView(withId(R.id.pop_characteristics_text)).perform(click()); onView(withId(R.id.characteristics_toolbar_title)).check(matches(isDisplayed())); @@ -114,7 +115,7 @@ public void H_LoadPopulationXstics() throws InterruptedException { } @Test - public void I_PopulationXsticScrollDown() { + public void iPopulationXsticScrollDown() { onView(withContentDescription("Me")).perform(click()); onView(withId(R.id.pop_characteristics_text)).perform(click()); onView(withId(R.id.population_characteristics)).perform(RecyclerViewActions.scrollTo(hasDescendant(withText("Syphilis prevalence 5% or higher")))).check(matches(isDisplayed())); @@ -122,34 +123,36 @@ public void I_PopulationXsticScrollDown() { } - //how to add banner tests 'infor tip') + @Test - public void J_LoadSiteXstics() { + public void jLoadSiteXstics() { onView(withContentDescription("Me")).perform(click()); onView(withId(R.id.site_characteristics_text)).perform(click()); onView(withId(R.id.characteristics_toolbar_title)).check(matches(isDisplayed())); } - @Test - public void K_EditSiteXstics() throws InterruptedException { - onView(withContentDescription("Me")).perform(click()); - onView(withId(R.id.site_characteristics_text)).perform(click()); - onView(withId(R.id.characteristics_toolbar_edit)).perform(click()); - Thread.sleep(1500); - onView(allOf(withText("Yes"), - isDisplayed())).perform(click()); - onView(withId(R.id.action_save)).perform(click()); - onView(withId(R.id.opensrp_logo_image_view)).check(matches(isDisplayed())); - - } - //Device to device sync tests skipped because module is not implemented +// @Test +// public void kEditSiteXstics() throws Throwable { +// onView(withContentDescription("Me")).perform(click()); +// onView(withId(R.id.site_characteristics_text)).perform(click()); +// onView(withId(R.id.characteristics_toolbar_edit)).perform(click()); +// Thread.sleep(1500); +// Activity activity = utils.getCurrentActivity(); +// onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:site_ultrasound"))).perform(click()); +// //fix the ambiguous error +// // onView(withSubstring("Yes")).perform(click()); +// onView(withId(R.id.action_save)).perform(click()); +// onView(withId(R.id.opensrp_logo_image_view)).check(matches(isDisplayed())); + + // } + // Device to device sync tests skipped because module is not implemented @Test - public void L_LogOut() throws InterruptedException { + public void lLogOut() throws InterruptedException { onView(withContentDescription("Me")).perform(click()); onView(withId(R.id.logout_text)).perform(click()); Thread.sleep(1500); diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/RegisterFamilyMemberPageTests.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/RegisterFamilyMemberPageTests.java index 22e288416..dc2011c41 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/RegisterFamilyMemberPageTests.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/RegisterFamilyMemberPageTests.java @@ -6,36 +6,29 @@ import static androidx.test.espresso.action.ViewActions.typeText; import static androidx.test.espresso.assertion.ViewAssertions.matches; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; -import static androidx.test.espresso.matcher.ViewMatchers.withClassName; -import static androidx.test.espresso.matcher.ViewMatchers.withContentDescription; -import static androidx.test.espresso.matcher.ViewMatchers.withHint; + import static androidx.test.espresso.matcher.ViewMatchers.withId; -import static androidx.test.espresso.matcher.ViewMatchers.withParent; import static androidx.test.espresso.matcher.ViewMatchers.withSubstring; import static androidx.test.espresso.matcher.ViewMatchers.withText; -import static org.hamcrest.CoreMatchers.allOf; -import static org.hamcrest.Matchers.is; + import android.app.Activity; -import androidx.test.espresso.contrib.RecyclerViewActions; import androidx.test.ext.junit.rules.ActivityScenarioRule; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; import com.vijay.jsonwizard.activities.JsonFormActivity; -import org.json.JSONObject; import org.junit.FixMethodOrder; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; import org.junit.runners.MethodSorters; -import org.smartregister.Context; import org.smartregister.anc.R; import org.smartregister.anc.activity.LoginActivity; +import org.smartregister.anc.activity.utils.Configs; import org.smartregister.anc.activity.utils.Constants; import org.smartregister.anc.activity.utils.Utils; @LargeTest @@ -49,38 +42,27 @@ public class RegisterFamilyMemberPageTests { public ActivityScenarioRule mActivityScenario = new ActivityScenarioRule<>(LoginActivity.class); Utils utils = new Utils(); - //JsonFormActivity jsonFormActivity = new JsonFormActivity(); - @Test - public void a_SetUp() throws InterruptedException { - utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword); - } + +@Test +public void aSetUp() throws InterruptedException { + utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword); +} @Test - public void b_AddAFamilyMember() throws Throwable { - onView(withId(R.id.action_register)).perform(click()); - //get Activity - Activity activity = utils.getCurrentActivity(); - onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:first_name"))).perform(typeText("espresso"), closeSoftKeyboard()); - onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:last_name"))).perform(typeText("Tester "), closeSoftKeyboard()); - onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:dob_unknown"))).perform(click()); - onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:age_entered"))).perform(typeText("28"), closeSoftKeyboard()); - onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:home_address"))).perform(typeText("28th street Ng"), closeSoftKeyboard()); - onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:phone_number"))).perform(typeText("+254701000000"), closeSoftKeyboard()); - onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:reminders"))).perform(click()); - onView(withSubstring("Yes")).perform(click()); - onView(withId(R.id.action_save)).perform(click()); + public void bAddAFamilyMember() throws Throwable { + utils.addAFamilyMember(); Thread.sleep(3000); - onView(withText("espresso Tester")).check(matches(isDisplayed())); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).check(matches(isDisplayed())); } //Always run below test after the test above @Test - public void c_RemoveFamilyMemberAdded() throws Throwable { + public void cRemoveFamilyMemberAdded() throws Throwable { - onView(withText("Espresso Tester")).perform(click()); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); Thread.sleep(2000); onView(withId(R.id.overflow_menu_item)).perform(click()); onView(withText("Close ANC Record")).perform(click()); @@ -94,15 +76,15 @@ public void c_RemoveFamilyMemberAdded() throws Throwable { } @Test - public void d_AddMemberWithMissingMandatoryFields() throws Throwable { + public void dAddMemberWithMissingMandatoryFields() throws Throwable { onView(withId(R.id.action_register)).perform(click()); Activity activity = utils.getCurrentActivity(); - onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:first_name"))).perform(typeText("espresso"), closeSoftKeyboard()); - onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:last_name"))).perform(typeText("Tester "), closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:first_name"))).perform(typeText(Configs.TestDataConfigs.firstName), closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:last_name"))).perform(typeText(Configs.TestDataConfigs.lastName), closeSoftKeyboard()); onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:dob_unknown"))).perform(click()); - onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:age_entered"))).perform(typeText("28"), closeSoftKeyboard()); - onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:home_address"))).perform(typeText("28th street Ng"), closeSoftKeyboard()); - onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:phone_number"))).perform(typeText("+254701000000"), closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:age_entered"))).perform(typeText(Configs.TestDataConfigs.clientAge),closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:home_address"))).perform(typeText(Configs.TestDataConfigs.clientAddress), closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:phone_number"))).perform(typeText(Configs.TestDataConfigs.phoneNumber), closeSoftKeyboard()); onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:reminders"))).perform(click()); onView(withId(R.id.action_save)).perform(click()); onView(withSubstring("Found 1 error(s) in the form. Please correct them to submit.")).check(matches(isDisplayed())); @@ -114,9 +96,6 @@ public void d_AddMemberWithMissingMandatoryFields() throws Throwable { - // JSONObject jsonObject = jsonFormActivity.getmJSONObject(); -// jsonObject.getString("first_name"); - diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/RemoveFamilyMemberTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/RemoveFamilyMemberTest.java new file mode 100644 index 000000000..2b9cab0b8 --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/RemoveFamilyMemberTest.java @@ -0,0 +1,269 @@ +package org.smartregister.anc.activity.anc; + +import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.click; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withSubstring; +import static androidx.test.espresso.matcher.ViewMatchers.withText; + +import android.app.Activity; + +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; + +import com.vijay.jsonwizard.activities.JsonFormActivity; + +import org.junit.FixMethodOrder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.smartregister.anc.R; +import org.smartregister.anc.activity.LoginActivity; +import org.smartregister.anc.activity.utils.Configs; +import org.smartregister.anc.activity.utils.Constants; +import org.smartregister.anc.activity.utils.Utils; + +@LargeTest +@RunWith(AndroidJUnit4.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) + +public class RemoveFamilyMemberTest { + @Rule + public ActivityScenarioRule mActivityScenario = new ActivityScenarioRule<>(LoginActivity.class); + + Utils utils = new Utils(); + + + @Test + + public void aSetUp() throws InterruptedException { + utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword); + } + + @Test + public void bRemoveByMovedAway() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(1000); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(2000); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Moved away")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + } + @Test + public void cRemoveByDeath() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1000); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(500); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Woman died")).perform(click()); + Thread.sleep(1000); + onView(withId(utils.getViewId((JsonFormActivity) activity, "step1:death_date"))).perform(click()); + onView(withId(R.id.ok_button)).perform(click()); + onView(withSubstring("Cause of death")).perform(click()); + onView(withSubstring("Eclampsia")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + } + @Test + public void dRemoveByOther() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(2000); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Other")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + } + @Test + public void eRemoveByMiscarriage() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(500); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Miscarriage")).perform(click()); + + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:miscarriage_abortion_date"))).perform(click()); + + onView(withId(R.id.ok_button)).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + } + + + @Test + public void fRemoveByStillBirth() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(500); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Stillbirth")).perform(click()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:delivery_date"))).perform(click()); + onView(withId(R.id.ok_button)).perform(click()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:delivery_place"))).perform(click()); + onView(withSubstring("Health facility")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + // Thread.sleep(1000); + + + } + + @Test + public void gRemoveByAbortion() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(1500); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(500); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Abortion")).perform(click()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:miscarriage_abortion_date"))).perform(click()); + onView(withId(R.id.ok_button)).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + } + +// @Test +// public void hRemoveByOther() throws Throwable { +// utils.addAFamilyMember(); +// onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); +// Thread.sleep(500); +// onView(withId(R.id.overflow_menu_item)).perform(click()); +// onView(withText("Close ANC Record")).perform(click()); +// Thread.sleep(500); +// Activity activity = utils.getCurrentActivity(); +// onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); +// onView(withSubstring("Other")).perform(click()); +// onView(withId(R.id.action_save)).perform(click()); +// +// +// +// } + + @Test + public void iRemoveByLiveBirth() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(1500); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(500); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + Thread.sleep(500); + onView(withSubstring("Live birth")).perform(click()); + Thread.sleep(500); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:delivery_date"))).perform(click()); + onView(withId(R.id.ok_button)).perform(click()); + Thread.sleep(500); + onView(withSubstring("Place of delivery")).perform(click()); + onView(withSubstring("Health facility")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + } + @Test + public void jRemoveByFalsePregnancy() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(1500); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(500); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("False pregnancy")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + + } + + @Test + public void kRemoveByLostToFollowUp() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(1500); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(500); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Lost to follow-up")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + + } + + @Test + public void lRemoveByWrongEntry() throws Throwable { + utils.addAFamilyMember(); + Thread.sleep(1500); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).perform(click()); + Thread.sleep(1500); + onView(withId(R.id.overflow_menu_item)).perform(click()); + onView(withText("Close ANC Record")).perform(click()); + Thread.sleep(500); + Activity activity = utils.getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:anc_close_reason"))).perform(click()); + onView(withSubstring("Wrong entry")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(1000); + + + + } + + + + + + +} diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Configs.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Configs.java index c8db85bde..75d9ff82c 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Configs.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Configs.java @@ -5,6 +5,15 @@ public class Configs { public static class TestDataConfigs{ public static final String clientName = "Lauren Hill"; public static final String clientID = "7138845"; + public static final String firstName = "Test"; + public static final String lastName = "Client"; + public static final String clientAge = "29"; + public static final String clientAddress = "28th strt Nrb"; + public static final String phoneNumber = "+254700100200"; + public static final String firstAndLastName = "Test Client"; + + + } } diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Utils.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Utils.java index 199aeb02f..697a4e907 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Utils.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Utils.java @@ -4,7 +4,12 @@ import static androidx.test.espresso.action.ViewActions.click; 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.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withInputType; +import static androidx.test.espresso.matcher.ViewMatchers.withSubstring; +import static androidx.test.espresso.matcher.ViewMatchers.withText; import static androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; @@ -50,6 +55,26 @@ public static int getViewId(JsonFormActivity jsonFormActivity, String key) } + public void addAFamilyMember() throws Throwable { + onView(withId(R.id.action_register)).perform(click()); + //get Activity + Activity activity = getCurrentActivity(); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:first_name"))).perform(typeText(Configs.TestDataConfigs.firstName), closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:last_name"))).perform(typeText(Configs.TestDataConfigs.lastName), closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:dob_unknown"))).perform(click()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:age_entered"))).perform(typeText(Configs.TestDataConfigs.clientAge),closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:home_address"))).perform(typeText(Configs.TestDataConfigs.clientAddress), closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:phone_number"))).perform(typeText(Configs.TestDataConfigs.phoneNumber), closeSoftKeyboard()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:reminders"))).perform(click()); + onView(withSubstring("Yes")).perform(click()); + onView(withId(R.id.action_save)).perform(click()); + Thread.sleep(3000); + onView(withText(Configs.TestDataConfigs.firstAndLastName)).check(matches(isDisplayed())); + + } + + +