From 24f26a16d9dbba16aa1b4e88c2abc5f55e949604 Mon Sep 17 00:00:00 2001 From: Naima-Bashir Date: Tue, 16 Jul 2024 17:31:03 +0300 Subject: [PATCH 1/7] Tests for Contact Visit 1 --- .../activity/anc/ContactsActivityTest.java | 55 +++++++++++++++++++ .../anc/activity/utils/Configs.java | 4 +- 2 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java new file mode 100644 index 000000000..7405ba252 --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java @@ -0,0 +1,55 @@ +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.ViewMatchers.isDisplayed; +import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withText; + +import androidx.test.espresso.action.ViewActions; +import androidx.test.ext.junit.rules.ActivityScenarioRule; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; +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 +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@RunWith(AndroidJUnit4.class) +public class ContactsActivityTest { + + @Rule + public ActivityScenarioRule mActivityScenario = new ActivityScenarioRule<>(LoginActivity.class); + + private Utils utils = new Utils(); + + @Test + public void A_setUp() throws InterruptedException { + utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword); + } + + @Test + public void B_StartContactVisit() throws InterruptedException { + + Thread.sleep(2000); + + onView(withId(R.id.edt_search)).perform(typeText(Configs.TestDataConfigs.clientName), ViewActions.closeSoftKeyboard()); + onView(withId(R.id.patient_name)).check(matches(isDisplayed())); + + onView(withId(R.id.due_button_wrapper)).perform(click()); + Thread.sleep(2000); + + } +} 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..1a8538c16 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 @@ -3,8 +3,8 @@ public class Configs { public static class TestDataConfigs{ - public static final String clientName = "Lauren Hill"; - public static final String clientID = "7138845"; + public static final String clientName = "Beth Kasin"; + public static final String clientID = "7187941"; } } From b7680274665f0e7cf41e0f5d9c2e9a608dffe81f Mon Sep 17 00:00:00 2001 From: Naima-Bashir Date: Tue, 16 Jul 2024 19:19:05 +0300 Subject: [PATCH 2/7] Tests for the Form Updates Pop up --- .../anc/activity/anc/ContactsActivityTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java index 7405ba252..a820b9371 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java @@ -10,6 +10,7 @@ import static androidx.test.espresso.matcher.ViewMatchers.withId; import static androidx.test.espresso.matcher.ViewMatchers.withText; +import androidx.test.espresso.NoMatchingViewException; import androidx.test.espresso.action.ViewActions; import androidx.test.ext.junit.rules.ActivityScenarioRule; import androidx.test.ext.junit.runners.AndroidJUnit4; @@ -51,5 +52,14 @@ public void B_StartContactVisit() throws InterruptedException { onView(withId(R.id.due_button_wrapper)).perform(click()); Thread.sleep(2000); + try { + onView(withText("Form Update")).check(matches(isDisplayed())); + onView(withText("OK")).perform(click()); + Thread.sleep(2000); + } catch (NoMatchingViewException e) { + } + onView(withId(R.id.contact_title)).check(matches(isDisplayed())); } + } + From 9ebe27743cb4794a3f6456f9483d3d18cef99050 Mon Sep 17 00:00:00 2001 From: Naima-Bashir Date: Thu, 18 Jul 2024 10:54:36 +0300 Subject: [PATCH 3/7] More tests on the Quick Check Page --- .../activity/anc/ContactsActivityTest.java | 13 +++++++++- .../anc/activity/utils/Utils.java | 26 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java index a820b9371..760bf5026 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java @@ -7,14 +7,20 @@ 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.withText; +import android.app.Activity; + import androidx.test.espresso.NoMatchingViewException; import androidx.test.espresso.action.ViewActions; 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; @@ -42,7 +48,7 @@ public void A_setUp() throws InterruptedException { } @Test - public void B_StartContactVisit() throws InterruptedException { + public void B_StartContactVisit() throws Throwable { Thread.sleep(2000); @@ -59,6 +65,11 @@ public void B_StartContactVisit() throws InterruptedException { } catch (NoMatchingViewException e) { } onView(withId(R.id.contact_title)).check(matches(isDisplayed())); + onView(withContentDescription("First contact")); + Activity activity = utils.getCurrentActivity(); +// onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:first_contact"))).perform(click()); + Thread.sleep(2000); + } } 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 e898a6fd1..035db0feb 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 @@ -8,10 +8,19 @@ import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.isRoot; import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread; +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; +import android.app.Activity; import android.view.View; import android.view.ViewGroup; +import androidx.test.espresso.core.internal.deps.guava.collect.Iterables; +import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry; +import androidx.test.runner.lifecycle.Stage; + +import com.vijay.jsonwizard.activities.JsonFormActivity; + import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; @@ -27,6 +36,23 @@ public void logIn(String username, String password) throws InterruptedException Thread.sleep(30000); } + public Activity getCurrentActivity() throws Throwable { + getInstrumentation().waitForIdleSync(); + final Activity[] activity = new Activity[1]; + runOnUiThread(() -> { + java.util.Collection activities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED); + activity[0] = (Activity) Iterables.getOnlyElement(activities); + }); + return activity[0]; + } + + public static int getViewId(JsonFormActivity jsonFormActivity, String key) + { + return jsonFormActivity.getFormDataView(key).getId(); + + } + + // public static Matcher withRecyclerViewId(final int recyclerViewId) { // return new TypeSafeMatcher() { // @Override From 874e208aafa40732f5faf0ba24436d1ac52b4fb9 Mon Sep 17 00:00:00 2001 From: Naima-Bashir Date: Thu, 18 Jul 2024 13:36:57 +0300 Subject: [PATCH 4/7] Quick Check Tests --- .../anc/activity/anc/ContactsActivityTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java index 760bf5026..90555cfea 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java @@ -9,6 +9,7 @@ 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 android.app.Activity; @@ -50,7 +51,7 @@ public void A_setUp() throws InterruptedException { @Test public void B_StartContactVisit() throws Throwable { - Thread.sleep(2000); +// Thread.sleep(2000); onView(withId(R.id.edt_search)).perform(typeText(Configs.TestDataConfigs.clientName), ViewActions.closeSoftKeyboard()); onView(withId(R.id.patient_name)).check(matches(isDisplayed())); @@ -67,7 +68,10 @@ public void B_StartContactVisit() throws Throwable { onView(withId(R.id.contact_title)).check(matches(isDisplayed())); onView(withContentDescription("First contact")); Activity activity = utils.getCurrentActivity(); -// onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:first_contact"))).perform(click()); + onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:contact_reason"))).perform(click()); + onView(withSubstring("First contact")).perform(click());; + Thread.sleep(4000); + onView(withSubstring("None")).perform(click()); Thread.sleep(2000); } From 97f7708cfd8b0275e55a3c0a46a537c682a4f51d Mon Sep 17 00:00:00 2001 From: Naima-Bashir Date: Thu, 18 Jul 2024 15:10:02 +0300 Subject: [PATCH 5/7] Final tests on the Quick Check Page --- .../anc/activity/anc/ContactsActivityTest.java | 6 +++--- .../java/org/smartregister/anc/activity/utils/Configs.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java index 90555cfea..64d8aa69a 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java @@ -69,12 +69,12 @@ public void B_StartContactVisit() throws Throwable { onView(withContentDescription("First contact")); Activity activity = utils.getCurrentActivity(); onView(withId(Utils.getViewId((JsonFormActivity) activity, "step1:contact_reason"))).perform(click()); - onView(withSubstring("First contact")).perform(click());; + onView(withSubstring("First contact")).perform(click()); Thread.sleep(4000); onView(withSubstring("None")).perform(click()); Thread.sleep(2000); - + onView(withSubstring("PROCEED TO NORMAL CONTACT")).perform(click());; + Thread.sleep(2000); } - } 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 1a8538c16..6416e9211 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 @@ -3,8 +3,8 @@ public class Configs { public static class TestDataConfigs{ - public static final String clientName = "Beth Kasin"; - public static final String clientID = "7187941"; + public static final String clientName = "Natsya Masha"; + public static final String clientID = "7180953"; } } From 5181ce7280382a1a6a245d8a0df89c075c33f4e6 Mon Sep 17 00:00:00 2001 From: Naima-Bashir Date: Fri, 19 Jul 2024 09:50:33 +0300 Subject: [PATCH 6/7] Quality changes to the Contact Visit Tests --- .../anc/activity/anc/ContactsActivityTest.java | 8 ++++---- .../org/smartregister/anc/activity/utils/Configs.java | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java index 64d8aa69a..cb18a809c 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java @@ -44,14 +44,13 @@ public class ContactsActivityTest { private Utils utils = new Utils(); @Test - public void A_setUp() throws InterruptedException { + public void setUp() throws InterruptedException { utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword); + onView(withId(R.id.search_bar_layout)).check(matches(isDisplayed())); } @Test - public void B_StartContactVisit() throws Throwable { - -// Thread.sleep(2000); + public void startContactVisit() throws Throwable { onView(withId(R.id.edt_search)).perform(typeText(Configs.TestDataConfigs.clientName), ViewActions.closeSoftKeyboard()); onView(withId(R.id.patient_name)).check(matches(isDisplayed())); @@ -75,6 +74,7 @@ public void B_StartContactVisit() throws Throwable { Thread.sleep(2000); onView(withSubstring("PROCEED TO NORMAL CONTACT")).perform(click());; Thread.sleep(2000); + } } 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 6416e9211..62f56fff5 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 @@ -3,8 +3,8 @@ public class Configs { public static class TestDataConfigs{ - public static final String clientName = "Natsya Masha"; - public static final String clientID = "7180953"; + public static final String clientName = "Las Mas"; + public static final String clientID = "7226962"; } } From 86d4e05ce3f932c67cd35d4389f686940c793d50 Mon Sep 17 00:00:00 2001 From: Naima-Bashir Date: Fri, 26 Jul 2024 14:06:01 +0300 Subject: [PATCH 7/7] Added tear down method to clean up after tests --- .../anc/activity/anc/ContactsActivityTest.java | 9 +++++++++ .../org/smartregister/anc/activity/utils/Configs.java | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java index cb18a809c..2499eaf5f 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ContactsActivityTest.java @@ -22,6 +22,7 @@ import com.vijay.jsonwizard.activities.JsonFormActivity; +import org.junit.AfterClass; import org.junit.FixMethodOrder; import org.junit.Rule; import org.junit.Test; @@ -76,5 +77,13 @@ public void startContactVisit() throws Throwable { Thread.sleep(2000); } + @AfterClass + public static void tearDown() throws InterruptedException { + // Perform logout + onView(withContentDescription("Me")).perform(click()); + onView(withId(R.id.logout_text)).perform(click()); + Thread.sleep(1500); + onView(withId(R.id.login_login_btn)).check(matches(isDisplayed())); + } } 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 62f56fff5..12e2474e2 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 @@ -3,8 +3,8 @@ public class Configs { public static class TestDataConfigs{ - public static final String clientName = "Las Mas"; - public static final String clientID = "7226962"; + public static final String clientName = "Jaco El"; + public static final String clientID = "7233943"; } }