From decc29331af0b6129342bf9bac22622215162531 Mon Sep 17 00:00:00 2001 From: madrine Date: Wed, 12 Jun 2024 17:46:48 +0300 Subject: [PATCH 1/9] Espresso dependencies and Login tests --- opensrp-anc/build.gradle | 4 + reference-app/build.gradle | 36 +++-- .../anc/activity/LoginActivityTest.java | 124 ++++++++++++++++++ 3 files changed, 152 insertions(+), 12 deletions(-) create mode 100644 reference-app/src/androidTest/java/org/smartregister/anc/activity/LoginActivityTest.java diff --git a/opensrp-anc/build.gradle b/opensrp-anc/build.gradle index 88bcf7a00..63b24480c 100644 --- a/opensrp-anc/build.gradle +++ b/opensrp-anc/build.gradle @@ -1,3 +1,6 @@ + + + buildscript { repositories { mavenCentral() @@ -229,6 +232,7 @@ dependencies { implementation group: 'org.apache.commons', name: 'commons-text', version: '1.9' implementation 'junit:junit:4.12' implementation 'androidx.test:core:1.4.0' + testImplementation project(':opensrp-anc') annotationProcessor 'com.jakewharton:butterknife:10.2.3' implementation 'net.zetetic:android-database-sqlcipher:4.4.0@aar' implementation 'commons-validator:commons-validator:1.7' diff --git a/reference-app/build.gradle b/reference-app/build.gradle index 1165dd516..26d23ea50 100644 --- a/reference-app/build.gradle +++ b/reference-app/build.gradle @@ -39,18 +39,18 @@ android { * This allows you to run the app in the release variant. make sure to add this configs to the * local.properties files when you need to use them * */ - signingConfigs { - release { - //Store your local.properties file in the project root folder - v1SigningEnabled true - v2SigningEnabled true - keyAlias System.getenv("KEYSTORE_ALIAS") ?: project.KEYSTORE_ALIAS - keyPassword System.getenv("KEY_PASSWORD") ?: project.KEY_PASSWORD - storePassword System.getenv("KEYSTORE_PASSWORD") ?: project.KEYSTORE_PASSWORD - //Save your keystore file as ~/opensrp-release-upload-key.jks (in your home directory) - storeFile file(System.getProperty("user.home") + "/anckey.keystore.jks") - } - } + signingConfigs { + release { + //Store your local.properties file in the project root folder + v1SigningEnabled true + v2SigningEnabled true + keyAlias System.getenv("KEYSTORE_ALIAS") ?: project.KEYSTORE_ALIAS + keyPassword System.getenv("KEY_PASSWORD") ?: project.KEY_PASSWORD + storePassword System.getenv("KEYSTORE_PASSWORD") ?: project.KEYSTORE_PASSWORD + //Save your keystore file as ~/opensrp-release-upload-key.jks (in your home directory) + storeFile file(System.getProperty("user.home") + "/anckey.keystore.jks") + } + } useLibrary 'org.apache.http.legacy' compileSdkVersion androidCompileSdkVersion buildToolsVersion androidBuildToolsVersion @@ -224,6 +224,18 @@ tasks.withType(Test) { } dependencies { + + // AndroidX Test libraries + androidTestImplementation 'androidx.test:runner:1.5.2' + androidTestImplementation 'androidx.test:rules:1.5.0' + + // AndroidX Core testing libraries + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' + androidTestImplementation project(':reference-app') + debugImplementation "androidx.test:monitor:1.6.0" + androidTestImplementation 'androidx.test:core:1.4.0' + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' def powerMockVersion = '2.0.7' implementation project(":opensrp-anc") diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/LoginActivityTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/LoginActivityTest.java new file mode 100644 index 000000000..c0d447745 --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/LoginActivityTest.java @@ -0,0 +1,124 @@ +package org.smartregister.anc.activity; + + +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 static org.hamcrest.Matchers.allOf; +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; + +@LargeTest +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@RunWith(AndroidJUnit4.class) +public class LoginActivityTest { + + @Rule + public ActivityScenarioRule mActivityScenario = new ActivityScenarioRule<>(LoginActivity.class); + public String correctPassword = "Amani123"; + + + + + @Test + public void E_testShowPassword(){ + 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))); + + } + + @Test + public void F_testSuccessfulLogin() 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()); + Thread.sleep(30000); + onView(withId(R.id.edt_search)).check(matches(isDisplayed())); + + } + + @Test + public void C_testIncorrectUsername() 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()); + Thread.sleep(20000); + onView(withText("Please check the credentials")).check(matches(isDisplayed())); + + + + } + + + @Test + public void D_testIncorrectPassword() 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()); + Thread.sleep(20000); + onView(withText("Please check the credentials")).check(matches(isDisplayed())); + + + } + + @Test + public void A_testEmptyUsername() 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()); + Thread.sleep(20000); + onView(withText("Please check the credentials")).check(matches(isDisplayed())); + + + } + + @Test + public void B_testEmptyPassword() 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()); + Thread.sleep(20000); + onView(withText("Please check the credentials")).check(matches(isDisplayed())); + + + } + + + + + + + + +} From 1f7c1d332621ff014a72266d6d0c0b819d3e2dd9 Mon Sep 17 00:00:00 2001 From: madrine Date: Wed, 12 Jun 2024 17:54:47 +0300 Subject: [PATCH 2/9] adding more tests --- .../java/org/smartregister/anc/activity/LoginActivityTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/LoginActivityTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/LoginActivityTest.java index c0d447745..97cecd0b3 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/LoginActivityTest.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/LoginActivityTest.java @@ -64,6 +64,7 @@ public void F_testSuccessfulLogin() throws InterruptedException { onView(withId(R.id.login_password_edit_text)).perform(typeText(correctPassword), closeSoftKeyboard()); onView(withId(R.id.login_login_btn)).perform(click()); Thread.sleep(30000); + //fix error caused by the id edt_search onView(withId(R.id.edt_search)).check(matches(isDisplayed())); } From 34eb083787c9aaf1ceb8cbfb4e8312043a66d331 Mon Sep 17 00:00:00 2001 From: Karina Brian Date: Fri, 21 Jun 2024 17:44:15 +0300 Subject: [PATCH 3/9] Added homepage test and utils package. --- .../activity/anc/HomePageActivityTest.java | 47 +++++++++++++++++++ .../activity/{ => anc}/LoginActivityTest.java | 5 +- .../anc/activity/utils/Constants.java | 8 ++++ .../anc/activity/utils/Utils.java | 22 +++++++++ 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/HomePageActivityTest.java rename reference-app/src/androidTest/java/org/smartregister/anc/activity/{ => anc}/LoginActivityTest.java (96%) create mode 100644 reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Constants.java create mode 100644 reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Utils.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 new file mode 100644 index 000000000..98f1aae70 --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/HomePageActivityTest.java @@ -0,0 +1,47 @@ +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.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 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.Constants; +import org.smartregister.anc.activity.utils.Utils; + +@LargeTest +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@RunWith(AndroidJUnit4.class) + +public class HomePageActivityTest { + @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_searchBarPresent() { + onView(withId(R.id.search_bar_layout)).check(matches(isDisplayed())); + + } +} + diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/LoginActivityTest.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/LoginActivityTest.java similarity index 96% rename from reference-app/src/androidTest/java/org/smartregister/anc/activity/LoginActivityTest.java rename to reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/LoginActivityTest.java index 97cecd0b3..ed0ca7df1 100644 --- a/reference-app/src/androidTest/java/org/smartregister/anc/activity/LoginActivityTest.java +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/LoginActivityTest.java @@ -1,4 +1,4 @@ -package org.smartregister.anc.activity; +package org.smartregister.anc.activity.anc; import static androidx.test.espresso.Espresso.onView; @@ -37,6 +37,8 @@ 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) @@ -49,7 +51,6 @@ public class LoginActivityTest { - @Test public void E_testShowPassword(){ onView(withId(R.id.login_password_edit_text)).perform(typeText(correctPassword),closeSoftKeyboard()); diff --git a/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Constants.java b/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Constants.java new file mode 100644 index 000000000..fca0b5037 --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Constants.java @@ -0,0 +1,8 @@ +package org.smartregister.anc.activity.utils; +public class Constants { + public static class ancConstants { + public static final String ancUsername = "demo"; + public static final String ancPassword = "Amani123"; + + } +} 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 new file mode 100644 index 000000000..7a3199c04 --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Utils.java @@ -0,0 +1,22 @@ +package org.smartregister.anc.activity.utils; + +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.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 org.smartregister.anc.R; + +public class Utils { + + + public void logIn(String username, String password) throws InterruptedException { + onView(withId(R.id.login_user_name_edit_text)).perform(typeText(username), closeSoftKeyboard()); + onView(withId(R.id.login_password_edit_text)).perform(typeText(password), closeSoftKeyboard()); + onView(withId(R.id.login_login_btn)).perform(click()); + Thread.sleep(30000); + } +} From b78809c77b5468f9931888c6082dea800cda808f Mon Sep 17 00:00:00 2001 From: madrine Date: Tue, 25 Jun 2024 13:32:56 +0300 Subject: [PATCH 4/9] added Configs class and homepage Tests --- .../activity/anc/HomePageActivityTest.java | 44 ++++++++++++++++++- .../anc/activity/utils/Configs.java | 10 +++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Configs.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 98f1aae70..dcaafc060 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 @@ -5,8 +5,10 @@ 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.ViewMatchers.isClickable; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.withId; +import static androidx.test.espresso.matcher.ViewMatchers.withSubstring; import androidx.test.espresso.action.ViewActions; import androidx.test.ext.junit.rules.ActivityScenarioRule; @@ -20,6 +22,7 @@ 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; @@ -39,9 +42,48 @@ public void A_setUp() throws InterruptedException { } @Test - public void B_searchBarPresent() { + public void B_SearchBarPresent() { onView(withId(R.id.search_bar_layout)).check(matches(isDisplayed())); + } + @Test + public void C_SearchPatientByName() throws InterruptedException { + + onView(withId(R.id.edt_search)).perform(typeText(Configs.TestDataConfigs.clientName), ViewActions.closeSoftKeyboard()); + onView(withId(R.id.patient_name)).check(matches(isDisplayed())); + Thread.sleep(1000); + onView(withId(R.id.btn_search_cancel)).perform(click()); + } + @Test + public void C_SearchPatientByID() throws InterruptedException { + + onView(withId(R.id.edt_search)).perform(typeText(Configs.TestDataConfigs.clientID), ViewActions.closeSoftKeyboard()); + onView(withId(R.id.patient_name)).check(matches(isDisplayed())); + Thread.sleep(1000); + onView(withId(R.id.btn_search_cancel)).perform(click()); + } + + @Test + public void D_AdvancedSearch() throws InterruptedException { + onView(withId(R.id.action_search)).perform(click()); + Thread.sleep(2000); +// onView(withId(R.id.anc_id)).check(matches(isDisplayed())); +// Thread.sleep(2000); + onView(withId(R.id.action_clients)).perform(click()); + + + } + + @Test + public void E_OpenLibrary() throws InterruptedException { + onView(withId(R.id.action_library)).perform(click()); + Thread.sleep(2000); + // onView(withId(R.id.library_item_layout)).atPosition(1).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.library_toolbar_title)).check(matches(isDisplayed())); + onView(withId(R.id.action_clients)).perform(click()); + + } } 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 new file mode 100644 index 000000000..c8db85bde --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/utils/Configs.java @@ -0,0 +1,10 @@ +package org.smartregister.anc.activity.utils; +public class Configs { + + + public static class TestDataConfigs{ + public static final String clientName = "Lauren Hill"; + public static final String clientID = "7138845"; + + } +} From fd62e1ec68c9c16dd608d73d3d5c15a1e6b0d087 Mon Sep 17 00:00:00 2001 From: Karina Brian Date: Wed, 26 Jun 2024 17:43:54 +0300 Subject: [PATCH 5/9] added tests to access anc registration form and user profile --- .../activity/anc/HomePageActivityTest.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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 dcaafc060..4512d83ed 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 @@ -7,6 +7,7 @@ import static androidx.test.espresso.assertion.ViewAssertions.matches; 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; @@ -46,6 +47,7 @@ public void B_SearchBarPresent() { onView(withId(R.id.search_bar_layout)).check(matches(isDisplayed())); } + @Test public void C_SearchPatientByName() throws InterruptedException { @@ -53,15 +55,16 @@ public void C_SearchPatientByName() throws InterruptedException { onView(withId(R.id.patient_name)).check(matches(isDisplayed())); Thread.sleep(1000); onView(withId(R.id.btn_search_cancel)).perform(click()); - } - @Test + } + + @Test public void C_SearchPatientByID() throws InterruptedException { onView(withId(R.id.edt_search)).perform(typeText(Configs.TestDataConfigs.clientID), ViewActions.closeSoftKeyboard()); onView(withId(R.id.patient_name)).check(matches(isDisplayed())); Thread.sleep(1000); onView(withId(R.id.btn_search_cancel)).perform(click()); - } + } @Test public void D_AdvancedSearch() throws InterruptedException { @@ -78,12 +81,25 @@ public void D_AdvancedSearch() throws InterruptedException { public void E_OpenLibrary() throws InterruptedException { onView(withId(R.id.action_library)).perform(click()); Thread.sleep(2000); - // onView(withId(R.id.library_item_layout)).atPosition(1).perform(click()); + // onView(withId(R.id.library_item_layout)).atPosition(1).perform(click()); Thread.sleep(2000); onView(withId(R.id.library_toolbar_title)).check(matches(isDisplayed())); onView(withId(R.id.action_clients)).perform(click()); } + @Test + public void userCanAccessANCRegistrationForm() 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 { + onView(withContentDescription("Me")).perform(click()); + Thread.sleep(1500); + onView(withId(R.id.locationImageView)).check(matches(isDisplayed())); + } } + From 11a3a8cb74159a7e17ed182990bcf31878f2c8d5 Mon Sep 17 00:00:00 2001 From: madrine Date: Thu, 27 Jun 2024 12:51:43 +0300 Subject: [PATCH 6/9] advanced search tests --- .../anc/activity/anc/HomePageActivityTest.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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 4512d83ed..f741ef6fe 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 @@ -69,9 +69,8 @@ public void C_SearchPatientByID() throws InterruptedException { @Test public void D_AdvancedSearch() throws InterruptedException { onView(withId(R.id.action_search)).perform(click()); - Thread.sleep(2000); -// onView(withId(R.id.anc_id)).check(matches(isDisplayed())); -// Thread.sleep(2000); + onView(withId(R.id.qrCodeButton)).check(matches(isDisplayed())); + Thread.sleep(1000); onView(withId(R.id.action_clients)).perform(click()); @@ -80,10 +79,8 @@ public void D_AdvancedSearch() throws InterruptedException { @Test public void E_OpenLibrary() throws InterruptedException { onView(withId(R.id.action_library)).perform(click()); - Thread.sleep(2000); - // onView(withId(R.id.library_item_layout)).atPosition(1).perform(click()); - Thread.sleep(2000); onView(withId(R.id.library_toolbar_title)).check(matches(isDisplayed())); + Thread.sleep(1000); onView(withId(R.id.action_clients)).perform(click()); From 73ef2ee06c4c1eed9971e8faec43068401a8fcdd Mon Sep 17 00:00:00 2001 From: Karina Brian Date: Thu, 4 Jul 2024 17:12:39 +0300 Subject: [PATCH 7/9] Added more tests to the Homepage Module --- reference-app/build.gradle | 2 +- .../activity/anc/HomePageActivityTest.java | 40 +++++++++++++++++++ .../anc/activity/anc/LoginActivityTest.java | 1 - .../anc/activity/utils/Utils.java | 22 ++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/reference-app/build.gradle b/reference-app/build.gradle index 26d23ea50..2e2ad5326 100644 --- a/reference-app/build.gradle +++ b/reference-app/build.gradle @@ -232,10 +232,10 @@ dependencies { // AndroidX Core testing libraries androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' + androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.3.0' androidTestImplementation project(':reference-app') debugImplementation "androidx.test:monitor:1.6.0" androidTestImplementation 'androidx.test:core:1.4.0' - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' def powerMockVersion = '2.0.7' implementation project(":opensrp-anc") 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 f741ef6fe..24a36756f 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 @@ -3,15 +3,25 @@ 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 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; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.LargeTest; @@ -97,6 +107,36 @@ public void userCanAccessProfile() throws InterruptedException { Thread.sleep(1500); onView(withId(R.id.locationImageView)).check(matches(isDisplayed())); } + + @Test + public void userCanClickOnAPatient() throws InterruptedException { + onView(allOf(withId(R.id.recycler_view), isDisplayed())) + .perform(RecyclerViewActions.actionOnItemAtPosition(0, click())); + Thread.sleep(2000); + onView(withId(R.id.btn_profile_registration_info)).check(matches(isDisplayed())); + } + + @Test + public void userCanClickOnNextButtonOnRegister() throws InterruptedException { + Thread.sleep(2000); + onView(allOf(withId(R.id.recycler_view), isDisplayed())) + .perform(RecyclerViewActions.scrollToPosition(20)); + Thread.sleep(2000); + onView(withId(R.id.btn_next_page)).perform(click()); + onView(withId(R.id.btn_previous_page)).check(matches(isDisplayed())); + } + @Test + public void userCanClickOnThePreviousBtnOnRegister() throws InterruptedException { + Thread.sleep(2000); + onView(allOf(withId(R.id.recycler_view), isDisplayed())) + .perform(RecyclerViewActions.scrollToPosition(20)); + Thread.sleep(2000); + onView(withId(R.id.btn_next_page)).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.btn_previous_page)).perform(scrollTo()).perform(click()); + Thread.sleep(2000); + onView(withText("Page 1 of 9")).perform(scrollTo()).check(matches(isDisplayed())); + } } 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 ed0ca7df1..2e2f89854 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 @@ -13,7 +13,6 @@ 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 static org.hamcrest.Matchers.allOf; import org.smartregister.anc.activity.LoginActivity; 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 7a3199c04..e898a6fd1 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 @@ -6,8 +6,15 @@ 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.isRoot; import static androidx.test.espresso.matcher.ViewMatchers.withId; +import android.view.View; +import android.view.ViewGroup; + +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.hamcrest.TypeSafeMatcher; import org.smartregister.anc.R; public class Utils { @@ -19,4 +26,19 @@ public void logIn(String username, String password) throws InterruptedException onView(withId(R.id.login_login_btn)).perform(click()); Thread.sleep(30000); } + +// public static Matcher withRecyclerViewId(final int recyclerViewId) { +// return new TypeSafeMatcher() { +// @Override +// public void describeTo(Description description) { +// description.appendText("RecyclerView with ID: " + recyclerViewId); +// } +// @Override +// public boolean matchesSafely(View view) { +// return view.getId() == recyclerViewId; +// } +// }; +// } + } + From 574b350886e13422a0107a6ff5deb0038004bb0d Mon Sep 17 00:00:00 2001 From: madrine Date: Thu, 4 Jul 2024 17:22:14 +0300 Subject: [PATCH 8/9] Added profile page tests --- .../anc/activity/anc/ProfilePageTests.java | 164 ++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ProfilePageTests.java 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 new file mode 100644 index 000000000..82d5d2d22 --- /dev/null +++ b/reference-app/src/androidTest/java/org/smartregister/anc/activity/anc/ProfilePageTests.java @@ -0,0 +1,164 @@ +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.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 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 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.Constants; +import org.smartregister.anc.activity.utils.Utils; + +@LargeTest +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@RunWith(AndroidJUnit4.class) + +public class ProfilePageTests { + +@Rule + public ActivityScenarioRule mActivityScenario = new ActivityScenarioRule<>(LoginActivity.class); + +Utils utils = new Utils(); + + @Test + public void A_SetUp() throws InterruptedException { + utils.logIn(Constants.ancConstants.ancUsername, Constants.ancConstants.ancPassword); + } + + @Test + public void B_UserLocationIsDisplayed() { + 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()); + } + + + + @Test + public void C_ChangeLanguageToBahasa() throws InterruptedException { + onView(withContentDescription("Me")).perform(click()); + onView(withId(R.id.language_switcher_text)).perform(click()); + onView(withText("Bahasa (Indonesia)")).perform(click()); + Thread.sleep(3000); + onView(withId(R.id.opensrp_logo_image_view)).check(matches(isDisplayed())); + Thread.sleep(1000); + } + + + @Test + public void E_ChangeLanguageToFrench() throws InterruptedException { + onView(withContentDescription("Me")).perform(click()); + onView(withId(R.id.language_switcher_text)).perform(click()); + onView(withText("French")).perform(click()); + Thread.sleep(3000); + onView(withId(R.id.opensrp_logo_image_view)).check(matches(isDisplayed())); + Thread.sleep(1000); + } + + @Test + public void F_ChangeLanguageToPortuguese() throws InterruptedException { + onView(withContentDescription("Moi")).perform(click()); + onView(withId(R.id.language_switcher_text)).perform(click()); + onView(withText("Portuguese (Brazil)")).perform(click()); + Thread.sleep(3000); + onView(withId(R.id.opensrp_logo_image_view)).check(matches(isDisplayed())); + Thread.sleep(1000); + } + + @Test + public void G_ChangeLanguageToEnglish() throws InterruptedException { + onView(withContentDescription("Eu")).perform(click()); + onView(withId(R.id.language_switcher_text)).perform(click()); + onView(withText("English")).perform(click()); + Thread.sleep(2000); + onView(withId(R.id.opensrp_logo_image_view)).check(matches(isDisplayed())); + Thread.sleep(1000); + } + @Test + public void H_LoadPopulationXstics() 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())); + Thread.sleep(1500); + + } + + @Test + public void I_PopulationXsticScrollDown() { + 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())); + + + } + + //how to add banner tests 'infor tip') + + + + @Test + public void J_LoadSiteXstics() { + 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 L_LogOut() throws InterruptedException { + 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())); + + } + + + + + +} From 24f26a16d9dbba16aa1b4e88c2abc5f55e949604 Mon Sep 17 00:00:00 2001 From: Naima-Bashir Date: Tue, 16 Jul 2024 17:31:03 +0300 Subject: [PATCH 9/9] 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"; } }