Skip to content

Commit

Permalink
Fixed Cypress Flaky test in user advance filter (#8519)
Browse files Browse the repository at this point in the history
  • Loading branch information
nihal467 authored Sep 10, 2024
1 parent fc822b5 commit d1bc4c8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 36 deletions.
58 changes: 32 additions & 26 deletions cypress/e2e/users_spec/user_homepage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ import { UserPage } from "../../pageobject/Users/UserSearch";

describe("User Homepage", () => {
const userPage = new UserPage();
const usernameToTest = "devdoctor";
const currentuser = "devdistrictadmin";
const loginPage = new LoginPage();
const phone_number = "9876543219";
const alt_phone_number = "9876543219";
const currentuser = "devdistrictadmin";
const firstName = "Dummy";
const lastName = "Nurse";
const role = "Nurse";
const state = "Kerala";
const district = "Ernakulam";
const phoneNumber = "8878825662";
const altPhoneNumber = "8878825662";
const homeFacility = "Dummy Facility 40";
const nurseUserName = "dummynurse1";
const doctorUserName = "devdoctor";

before(() => {
loginPage.loginAsDisctrictAdmin();
Expand All @@ -22,33 +29,32 @@ describe("User Homepage", () => {

it("User advance filter functionality", () => {
userPage.clickAdvancedFilters();
userPage.typeInFirstName("Dev");
userPage.typeInLastName("Doctor");
userPage.selectRole("Doctor");
userPage.selectState("Kerala");
userPage.selectDistrict("Ernakulam");
userPage.typeInPhoneNumber(phone_number);
userPage.typeInAltPhoneNumber(alt_phone_number);
userPage.selectHomeFacility("Dummy Facility 40");
userPage.typeInFirstName(firstName);
userPage.typeInLastName(lastName);
userPage.selectRole(role);
userPage.selectState(state);
userPage.selectDistrict(district);
userPage.typeInPhoneNumber(phoneNumber);
userPage.typeInAltPhoneNumber(altPhoneNumber);
userPage.selectHomeFacility(homeFacility);
userPage.applyFilter();
userPage.verifyUrlafteradvancefilter();
userPage.checkUsernameText(usernameToTest);
userPage.verifyDataTestIdText("First Name", "First Name: Dev");
userPage.verifyDataTestIdText("Last Name", "Last Name: Doctor");
userPage.checkUsernameText(nurseUserName);
// Verify the badges related to the data
userPage.verifyDataTestIdText("First Name", `First Name: ${firstName}`);
userPage.verifyDataTestIdText("Last Name", `Last Name: ${lastName}`);
userPage.verifyDataTestIdText(
"Phone Number",
"Phone Number: +919876543219",
`Phone Number: +91${phoneNumber}`,
);
userPage.verifyDataTestIdText(
"WhatsApp no.",
"WhatsApp no.: +919876543219",
`WhatsApp no.: +91${altPhoneNumber}`,
);
userPage.verifyDataTestIdText("Role", "Role: Doctor");
userPage.verifyDataTestIdText("Role", `Role: ${role}`);
userPage.verifyDataTestIdText(
"Home Facility",
"Home Facility: Dummy Facility 40",
`Home Facility: ${homeFacility}`,
);
userPage.verifyDataTestIdText("District", "District: Ernakulam");
userPage.clearFilters();
userPage.verifyDataTestIdNotVisible("First Name");
userPage.verifyDataTestIdNotVisible("Last Name");
Expand All @@ -61,14 +67,14 @@ describe("User Homepage", () => {

it("Search by username", () => {
userPage.checkSearchInputVisibility();
userPage.typeInSearchInput(usernameToTest);
userPage.checkUrlForUsername(usernameToTest);
userPage.checkUsernameText(usernameToTest);
userPage.typeInSearchInput(doctorUserName);
userPage.checkUrlForUsername(doctorUserName);
userPage.checkUsernameText(doctorUserName);
userPage.checkUsernameBadgeVisibility(true);
userPage.clearSearchInput();
userPage.checkUsernameBadgeVisibility(false);
userPage.typeInSearchInput(usernameToTest);
userPage.checkUsernameText(usernameToTest);
userPage.typeInSearchInput(doctorUserName);
userPage.checkUsernameText(doctorUserName);
userPage.clickRemoveIcon();
userPage.checkUsernameBadgeVisibility(false);
userPage.checkUsernameText(currentuser);
Expand Down
10 changes: 0 additions & 10 deletions cypress/pageobject/Users/UserSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ export class UserPage {
cy.url().should("include", `username=${username}`);
}

verifyUrlafteradvancefilter() {
cy.url()
.should("include", "first_name=Dev")
.and("include", "last_name=Doctor")
.and("include", "phone_number=%2B919876543219")
.and("include", "alt_phone_number=%2B919876543219")
.and("include", "user_type=Doctor")
.and("include", "district=7");
}

checkUsernameText(username: string) {
cy.get(this.usernameText).should("have.text", username);
}
Expand Down

0 comments on commit d1bc4c8

Please sign in to comment.