Skip to content

Commit

Permalink
Tests for adding and removing family members and fixed naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
madrine authored and madrine committed Jul 22, 2024
1 parent cb1a2e2 commit 9356524
Show file tree
Hide file tree
Showing 7 changed files with 385 additions and 117 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()));
Expand All @@ -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()));
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -96,28 +89,28 @@ 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);
onView(withId(R.id.btn_profile_registration_info)).check(matches(isDisplayed()));
}

@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));
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -51,15 +41,15 @@ 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)));

}

@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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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()));
Expand All @@ -114,42 +115,44 @@ 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()));


}

//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);
Expand Down
Loading

0 comments on commit 9356524

Please sign in to comment.