Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewriting UsersCreation.cy.ts according to POM approach #8930

Merged
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e98e99f
removed ClickElementById function from UsersCreation.cy.ts
AnveshNalimela Oct 25, 2024
5479921
Update .env
AnveshNalimela Oct 27, 2024
d47a676
Removed ClickELementById from userCreation.ts
AnveshNalimela Oct 27, 2024
a1ac783
updated .env
AnveshNalimela Oct 27, 2024
b4d9129
Merge branch 'remove-clickElementById/#8929' of https://github.com/An…
AnveshNalimela Oct 27, 2024
2d81b26
Added functions in pageobject/usercreation.ts according to POM approch
AnveshNalimela Oct 27, 2024
086eb6b
Rewrite user creation.cy.ts
AnveshNalimela Oct 28, 2024
daa6deb
Resloving conflicts
AnveshNalimela Nov 1, 2024
5ac2a1c
Finsihed Writing UserCreation.cy.ts
AnveshNalimela Nov 1, 2024
8f98d25
Merge branch 'develop' into remove-clickElementById/#8929
AnveshNalimela Nov 2, 2024
5deaa38
Merge branch 'develop' into remove-clickElementById/#8929
AnveshNalimela Nov 4, 2024
21fb0b2
Merge branch 'develop' into remove-clickElementById/#8929
AnveshNalimela Nov 5, 2024
6e78b30
clear and type functions are defined
AnveshNalimela Nov 5, 2024
012f68e
trying to reslove
AnveshNalimela Nov 7, 2024
b075b33
Merge branch 'ohcnetwork:develop' into remove-clickElementById/#8929
AnveshNalimela Nov 8, 2024
057f1e2
Merge branch 'develop' into remove-clickElementById/#8929
AnveshNalimela Nov 8, 2024
9a0a15e
Merge branch 'remove-clickElementById/#8929' of https://github.com/An…
AnveshNalimela Nov 8, 2024
b7950cd
Merge branch 'develop' into remove-clickElementById/#8929
nihal467 Nov 8, 2024
7aaa96a
Merge branch 'develop' into remove-clickElementById/#8929
AnveshNalimela Nov 9, 2024
d231102
made changes mentioned by coderrabit
AnveshNalimela Nov 10, 2024
b3850f2
Merge branch 'ohcnetwork:develop' into remove-clickElementById/#8929
AnveshNalimela Nov 10, 2024
4cdbdfa
ALtPhoneNumber function crrrected
AnveshNalimela Nov 10, 2024
908926e
Merge branch 'remove-clickElementById/#8929' of github.com:AnveshNali…
AnveshNalimela Nov 10, 2024
289421e
Merge branch 'develop' into remove-clickElementById/#8929
AnveshNalimela Nov 11, 2024
fcceae4
made few changes suggested by coderrabit
AnveshNalimela Nov 11, 2024
926535d
Merge branch 'develop' into remove-clickElementById/#8929
AnveshNalimela Nov 13, 2024
9ab927a
made requested changes
AnveshNalimela Nov 13, 2024
54e9abe
Merge branch 'develop' into remove-clickElementById/#8929
AnveshNalimela Nov 15, 2024
c021f4e
PhoneNumber changes revered
AnveshNalimela Nov 15, 2024
6a56e6f
Merge branch 'develop' into remove-clickElementById/#8929
nihal467 Nov 18, 2024
f70faa3
Merged into develop
AnveshNalimela Nov 26, 2024
54b420f
Merge branch 'remove-clickElementById/#8929' of github.com:AnveshNali…
AnveshNalimela Nov 26, 2024
92fde8b
Made requested changes
AnveshNalimela Nov 26, 2024
8a7b927
Merge branch 'ohcnetwork:develop' into remove-clickElementById/#8929
AnveshNalimela Nov 26, 2024
e735efa
made suggestions from the code rabbit
AnveshNalimela Nov 26, 2024
535e641
Merge branch 'remove-clickElementById/#8929' of github.com:AnveshNali…
AnveshNalimela Nov 26, 2024
b51a349
updated package-lock.json
AnveshNalimela Nov 26, 2024
3593709
Merge branch 'ohcnetwork:develop' into remove-clickElementById/#8929
AnveshNalimela Nov 27, 2024
0c5135f
fix line endings
rithviknishad Nov 28, 2024
ad5da79
coderabbit suggestions
nihal467 Nov 29, 2024
66c8064
number variable modified
nihal467 Nov 29, 2024
cd7c551
removed hard code
nihal467 Nov 29, 2024
360c540
secure the phone number generation
nihal467 Nov 29, 2024
e24c032
add missing # to id
nihal467 Nov 29, 2024
bacfc8a
Merge branch 'develop' into remove-clickElementById/#8929
nihal467 Nov 29, 2024
185e6f3
modified the bed name
nihal467 Nov 29, 2024
5bf8c5d
Merge branch 'remove-clickElementById/#8929' of https://github.com/An…
nihal467 Nov 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 103 additions & 107 deletions cypress/e2e/users_spec/UsersCreation.cy.ts
AnveshNalimela marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import ManageUserPage from "pageobject/Users/ManageUserPage";
import UserProfilePage from "pageobject/Users/UserProfilePage";

import { AssetSearchPage } from "../../pageobject/Asset/AssetSearch";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import LoginPage from "../../pageobject/Login/LoginPage";
Expand All @@ -11,13 +14,15 @@ import {
describe("User Creation", () => {
const userPage = new UserPage();
const loginPage = new LoginPage();
const userProfilePage = new UserProfilePage();
const manageUserPage = new ManageUserPage();
const userCreationPage = new UserCreationPage();
const facilityPage = new FacilityPage();
const assetSearchPage = new AssetSearchPage();
const phone_number = generatePhoneNumber();
const emergency_phone_number = generateEmergencyPhoneNumber();
const fillFacilityName = "Dummy Facility 40";
nihal467 marked this conversation as resolved.
Show resolved Hide resolved
const makeid = (length: number) => {
const makeId = (length: number) => {
let result = "";
const characters = "abcdefghijklmnopqrstuvwxyz0123456789";
const charactersLength = characters.length;
Expand All @@ -26,8 +31,8 @@ describe("User Creation", () => {
}
return result;
};
const username = makeid(8);
const alreadylinkedusersviews = [
const username = makeId(8);
const alreadyLinkedUsersViews = [
"devdoctor",
"devstaff2",
"devdistrictadmin",
Expand All @@ -53,6 +58,27 @@ describe("User Creation", () => {
"This field is required",
"Please enter valid phone number",
];
const userName = "devdistrictadmin";
const firstName = "District Editted";
AnveshNalimela marked this conversation as resolved.
Show resolved Hide resolved
const lastName = "Cypress";
const gender = "Male";
const email = "[email protected]";
const password = "Test@123";
const qualification = "MBBS";
const experience = "2";
const regNo = "123456789";
const newUserFirstName = "cypress test";
const newUserLastName = "staff user";
const state = "Kerala";
const district = "Ernakulam";
const role = "Doctor";
const homeFacility = "Dummy Shifting Center";
const weeklyWorkingHrs = "14";
const dob = "01011998";
const formattedDob = "01/01/1998";
const updateBtn = "Update";
const saveBtn = "Save User";
const newUserDob = "25081999";

before(() => {
loginPage.loginAsDistrictAdmin();
Expand All @@ -66,123 +92,93 @@ describe("User Creation", () => {
});

it("Update the existing user profile and verify its reflection", () => {
userCreationPage.clickElementById("user-profile-name");
userCreationPage.clickElementById("profile-button");
userCreationPage.verifyElementContainsText(
"username-profile-details",
"devdistrictadmin",
);
userCreationPage.clickElementById("edit-cancel-profile-button");
userCreationPage.typeIntoElementByIdPostClear(
"firstName",
"District Editted",
);
userCreationPage.typeIntoElementByIdPostClear("lastName", "Cypress");
userCreationPage.selectDropdownOption("gender", "Male");
userCreationPage.typeIntoElementByIdPostClear("phoneNumber", phone_number);
userCreationPage.typeIntoElementByIdPostClear(
"altPhoneNumber",
emergency_phone_number,
);
userCreationPage.typeIntoElementByIdPostClear("email", "[email protected]");
userCreationPage.typeIntoElementByIdPostClear("weekly_working_hours", "14");
userCreationPage.typeIntoElementByIdPostClearDob(
"date_of_birth",
"01011998",
);
userCreationPage.clickElementById("submit");
userCreationPage.verifyElementContainsText(
"contactno-profile-details",
manageUserPage.navigateToProfile();
cy.verifyContentPresence("#username-profile-details", [userName]);
userProfilePage.clickEditProfileButton();
userCreationPage.clearFirstName();
userCreationPage.typeFirstName(firstName);
userCreationPage.clearLastName();
userCreationPage.typeLastName(lastName);
userProfilePage.selectGender(gender);
userProfilePage.clearPhoneNumber();
userProfilePage.typePhoneNumber(phone_number);
userProfilePage.clearAltPhoneNumber();
userProfilePage.typeAltPhoneNumber(emergency_phone_number);
userProfilePage.clearEmail();
userProfilePage.typeEmail(email);
userProfilePage.clearWorkingHours();
userProfilePage.typeWorkingHours(weeklyWorkingHrs);
userProfilePage.typeDateOfBirth(dob);
cy.intercept("PATCH", "/api/v1/users/*").as("updateUser");
cy.clickSubmitButton(updateBtn);
cy.wait("@updateUser").its("response.statusCode").should("eq", 200);
cy.verifyContentPresence("#contactno-profile-details", [
"+91" + phone_number,
);
userCreationPage.verifyElementContainsText(
"whatsapp-profile-details",
]);
cy.verifyContentPresence("#whatsapp-profile-details", [
"+91" + emergency_phone_number,
);
userCreationPage.verifyElementContainsText(
"firstname-profile-details",
"District Editted",
);
userCreationPage.verifyElementContainsText(
"lastname-profile-details",
"Cypress",
);
userCreationPage.verifyElementContainsText(
"date_of_birth-profile-details",
"01/01/1998",
);
userCreationPage.verifyElementContainsText(
"emailid-profile-details",
"[email protected]",
);
userCreationPage.verifyElementContainsText(
"gender-profile-details",
"Male",
);
userCreationPage.verifyElementContainsText(
"averageworkinghour-profile-details",
"14",
);
]);
cy.verifyContentPresence("#firstname-profile-details", [firstName]);
cy.verifyContentPresence("#lastname-profile-details", [lastName]);
cy.verifyContentPresence("#date_of_birth-profile-details", [formattedDob]);
cy.verifyContentPresence("#emailid-profile-details", [email]);
cy.verifyContentPresence("#gender-profile-details", [gender]);
cy.verifyContentPresence("#averageworkinghour-profile-details", [
weeklyWorkingHrs,
]);
});

it("Update the existing user profile Form Mandatory File Error", () => {
userCreationPage.clickElementById("user-profile-name");
userCreationPage.clickElementById("profile-button");
userCreationPage.clickElementById("edit-cancel-profile-button");
userCreationPage.clearIntoElementById("firstName");
userCreationPage.clearIntoElementById("lastName");
userCreationPage.clearIntoElementById("phoneNumber");
userCreationPage.clearIntoElementById("altPhoneNumber");
userCreationPage.clearIntoElementById("weekly_working_hours");
userCreationPage.clickElementById("submit");
manageUserPage.navigateToProfile();
userProfilePage.clickEditProfileButton();
userCreationPage.clearFirstName();
userCreationPage.clearLastName();
userProfilePage.clearPhoneNumber();
userProfilePage.clearAltPhoneNumber();
userProfilePage.clearWorkingHours();
cy.clickSubmitButton(updateBtn);
userCreationPage.verifyErrorMessages(EXPECTED_PROFILE_ERROR_MESSAGES);
});

it("create new user and verify reflection", () => {
userCreationPage.clickElementById("addUserButton");
userCreationPage.selectFacility("Dummy Shifting Center");
userCreationPage.typeIntoElementById("username", username);
userCreationPage.typeIntoElementById("password", "Test@123");
userCreationPage.selectHomeFacility("Dummy Shifting Center");
userCreationPage.typeIntoElementById("phone_number", phone_number);
userCreationPage.setInputDate("date_of_birth", "25081999");
userCreationPage.selectDropdownOption("user_type", "Doctor");
userCreationPage.typeIntoElementById("c_password", "Test@123");
userCreationPage.typeIntoElementById("qualification", "MBBS");
userCreationPage.typeIntoElementById("doctor_experience_commenced_on", "2");
userCreationPage.typeIntoElementById(
"doctor_medical_council_registration",
"123456789",
);
userCreationPage.typeIntoElementById("first_name", "cypress test");
userCreationPage.typeIntoElementById("last_name", "staff user");
userCreationPage.typeIntoElementById("email", "[email protected]");
userCreationPage.selectDropdownOption("gender", "Male");
userCreationPage.selectDropdownOption("state", "Kerala");
userCreationPage.selectDropdownOption("district", "Ernakulam");
userCreationPage.clickElementById("submit");
userCreationPage.verifyNotification("User added successfully");
userCreationPage.clickAddUserButton();
userCreationPage.selectFacility(homeFacility);
userCreationPage.typeUserName(username);
userCreationPage.typePassword(password);
userCreationPage.typeConfirmPassword(password);
userCreationPage.selectHomeFacility(homeFacility);
userPage.typeInPhoneNumber(phone_number);
userProfilePage.typeDateOfBirth(newUserDob);
userCreationPage.selectUserType(role);
userProfilePage.typeQualification(qualification);
userProfilePage.typeDoctorYoE(experience);
userProfilePage.typeMedicalCouncilRegistration(regNo);
userPage.typeInFirstName(newUserFirstName);
userPage.typeInLastName(newUserLastName);
userProfilePage.typeEmail(email);
userCreationPage.selectGender(gender);
userCreationPage.selectState(state);
userCreationPage.selectDistrict(district);
cy.intercept("POST", "/api/v1/users/add_user/").as("createUser");
cy.clickSubmitButton(saveBtn);
cy.wait("@createUser").its("response.statusCode").should("eq", 201);
cy.verifyNotification("User added successfully");

userPage.typeInSearchInput(username);
userPage.checkUsernameText(username);
userCreationPage.verifyElementContainsText("name", "cypress test");
userCreationPage.verifyElementContainsText("role", "Doctor");
userCreationPage.verifyElementContainsText("district", "Ernakulam");
userCreationPage.verifyElementContainsText(
"home_facility",
"Dummy Shifting Center",
);
userCreationPage.verifyElementContainsText("qualification", "MBBS");
userCreationPage.verifyElementContainsText("doctor-experience", "2");
userCreationPage.verifyElementContainsText(
"medical-council-registration",
"123456789",
);
cy.verifyContentPresence("#name", [newUserFirstName]);
cy.verifyContentPresence("#role", [role]);
cy.verifyContentPresence("#district", [district]);
cy.verifyContentPresence("#home_facility", [homeFacility]);
cy.verifyContentPresence("#qualification", [qualification]);
cy.verifyContentPresence("#doctor-experience", [experience]);
cy.verifyContentPresence("#medical-council-registration", [regNo]);
});

it("create new user form throwing mandatory field error", () => {
userCreationPage.clickElementById("addUserButton");
userCreationPage.clickElementById("submit");
cy.wait(2000);
userCreationPage.clickAddUserButton();
cy.clickSubmitButton(saveBtn);
cy.get(".error-text", { timeout: 10000 }).should("be.visible");
userCreationPage.verifyErrorMessages(EXPECTED_ERROR_MESSAGES);
});

Expand All @@ -194,7 +190,7 @@ describe("User Creation", () => {
facilityPage.visitAlreadyCreatedFacility();
facilityPage.clickManageFacilityDropdown();
facilityPage.clickViewUsersOption();
userPage.verifyMultipleBadgesWithSameId(alreadylinkedusersviews);
userPage.verifyMultipleBadgesWithSameId(alreadyLinkedUsersViews);
});

afterEach(() => {
Expand Down
12 changes: 6 additions & 6 deletions cypress/e2e/users_spec/UsersProfile.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ describe("Manage User Profile", () => {
it("Set Dob, Gender, Email, Phone and Working Hours for a user and verify its reflection in user profile", () => {
userProfilePage.clickEditProfileButton();

userProfilePage.typedate_of_birth(date_of_birth);
userProfilePage.typeDateOfBirth(date_of_birth);
userProfilePage.selectGender(gender);
userProfilePage.typeEmail(email);
userProfilePage.typePhone(phone);
userProfilePage.typeWhatsApp(phone);
userProfilePage.typePhoneNumber(phone);
userProfilePage.typeAltPhoneNumber(phone);
AnveshNalimela marked this conversation as resolved.
Show resolved Hide resolved
userProfilePage.typeWorkingHours(workinghours);
userProfilePage.typeQualification(qualification);
userProfilePage.typeDoctorYoE(doctorYoE);
Expand All @@ -46,11 +46,11 @@ describe("Manage User Profile", () => {

cy.verifyNotification("Details updated successfully");

userProfilePage.assertdate_of_birth("01/01/1999");
userProfilePage.assertDateOfBirth("01/01/1999");
userProfilePage.assertGender(gender);
userProfilePage.assertEmail(email);
userProfilePage.assertPhone(phone);
userProfilePage.assertWhatsApp(phone);
userProfilePage.assertPhoneNumber(phone);
userProfilePage.assertAltPhoneNumber(phone);
userProfilePage.assertWorkingHours(workinghours);
});

Expand Down
75 changes: 29 additions & 46 deletions cypress/pageobject/Users/UserCreation.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,48 @@
// UserCreation.ts
export class UserCreationPage {
clickElementById(elementId: string) {
cy.get("#" + elementId).click();
clickAddUserButton() {
cy.verifyAndClickElement("#addUserButton", "Add New User");
}

typeIntoElementById(elementId: string, value: string) {
cy.get("#" + elementId)
.click()
.type(value);
typeUserName(username: string) {
cy.get("#username").click().type(username);
}

typeIntoElementByIdPostClear(elementId: string, value: string) {
cy.get("#" + elementId)
.click()
.clear()
.click()
.type(value);
typeFirstName(firstName: string) {
cy.get("#firstName").click().type(firstName);
}
typeIntoElementByIdPostClearDob(elementId: string, value: string) {
cy.clickAndTypeDate("#" + elementId, value);
typeLastName(lastName: string) {
cy.get("#lastName").click().type(lastName);
}
clearIntoElementById(elementId: string) {
cy.get("#" + elementId)
.click()
.clear();
typePassword(password: string) {
cy.get("#password").click().type(password);
}

typeIntoInputByName(inputName: string, value: string) {
cy.get("input[name='" + inputName + "']")
.click()
.type(value);
typeConfirmPassword(password: string) {
cy.get("#c_password").click().type(password);
Comment on lines +6 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use cy.typeIntoInput from commands.ts for consistency.

The type methods should use the reusable command for better maintainability.

Apply this pattern to all type methods:

  typeUserName(username: string) {
-   cy.get("#username").click().type(username);
+   cy.typeIntoInput("#username", username);
  }

Committable suggestion skipped: line range outside the PR's diff.

}

selectOptionContainingText(text: string) {
cy.get("[role='option']").contains(text).click();
clearFirstName() {
cy.get("#firstName").click().clear();
}

verifyNotification(message: string) {
cy.verifyNotification(message);
clearLastName() {
cy.get("#lastName").click().clear();
AnveshNalimela marked this conversation as resolved.
Show resolved Hide resolved
}

selectFacility(name: string) {
this.typeIntoInputByName("facilities", name);
this.selectOptionContainingText(name);
cy.get("input[name='facilities'] + button")
.find("#dropdown-toggle")
.click();
selectUserType(role: string) {
cy.clickAndSelectOption("#user_type", role);
}

selectHomeFacility(name: string) {
this.clickElementById("home_facility");
this.selectOptionContainingText(name);
cy.clickAndSelectOption("#home_facility", name);
}

setInputDate(dateElementId: string, dateValue: string) {
cy.clickAndTypeDate("#" + dateElementId, dateValue);
selectGender(gender: string) {
cy.clickAndSelectOption("#gender", gender);
}
selectState(state: string) {
cy.clickAndSelectOption("#state", state);
}
selectDistrict(district: string) {
cy.clickAndSelectOption("#district", district);
Comment on lines +37 to +41
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Based on the search results, I can generate the final response:

Update selectors to match the actual DOM elements

The current selectors #state and #district need to be updated. From the codebase search results, particularly in cypress/pageobject/Users/UserSearch.ts, the correct selectors are:

  • #state input for state selection
  • #district input for district selection

These elements appear to be autocomplete inputs rather than simple dropdowns.

🔗 Analysis chain

Verify state and district element IDs.

The selectors #state and #district might need to be updated to match the actual element IDs in the DOM.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the correct element IDs for state and district dropdowns
echo "Searching for state and district element IDs..."
rg -A 2 'id=["\'](state|district)["\']' src/

Length of output: 332


Script:

#!/bin/bash
# Search for state and district element IDs in all files
rg -A 2 'id=["\'']?(state|district)["\'']?' 

# Search for any React/JSX components that might contain state or district dropdowns
ast-grep --pattern 'Select id="$_" $$$'

# Search for any form fields or components with state or district in their name
rg -i "(state|district).*(select|dropdown|field|input)"

Length of output: 14898

}

selectDropdownOption(dropdownId: string, optionText: string) {
this.clickElementById(dropdownId);
this.selectOptionContainingText(optionText);
selectFacility(name: string) {
cy.typeAndSelectOption("input[name='facilities']", name);
AnveshNalimela marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +44 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use typeAndMultiSelectOption for facility selection.

As suggested in the past reviews, facility selection should use the multi-select option command.

  selectFacility(name: string) {
-   cy.typeAndSelectOption("input[name='facilities']", name);
+   cy.typeAndMultiSelectOption("input[name='facilities']", name);
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
selectFacility(name: string) {
cy.typeAndSelectOption("input[name='facilities']", name);
selectFacility(name: string) {
cy.typeAndMultiSelectOption("input[name='facilities']", name);

}

verifyElementContainsText(elementId: string, expectedText: string) {
AnveshNalimela marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading
Loading