326 lines
13 KiB
TypeScript
326 lines
13 KiB
TypeScript
|
import { test, expect, Page } from '@playwright/test'
|
||
|
import { BasicUserInfoSectionPage } from '../src/page-objects/AD_BasicUserInfoSectionInPage'
|
||
|
import { LeftMenuAdminPage } from '../src/page-objects/AD_LeftMenuAdminPage'
|
||
|
import { ViewUsersPage } from '../src/page-objects/AD_ViewUsersPage'
|
||
|
import { AddMembershipPage } from '../src/page-objects/AD_AddMembershipPage'
|
||
|
import { UserPersonalInformationPage } from '../src/page-objects/AD_UserPersonalInformationPage'
|
||
|
import { MembershipSectionPage } from '../src/page-objects/AD_MembershipSectionPage'
|
||
|
import { testingUsers, users } from '../src/data_stores/usersDataInitialization'
|
||
|
import { createUsersRandomList } from '../src/utils'
|
||
|
import { URL_IDHUB } from '../src/constants/env_constants'
|
||
|
import { checkIfTheInformationIsValid, clickAddUserOnLeftMenu, clickViewUsersOnLeftMenu, gotoBasicInfoPageOfTheUser, loginAsAdmin } from '../src/steps'
|
||
|
|
||
|
/**
|
||
|
* Testing Administrator's interface - USERS section functionality
|
||
|
*/
|
||
|
|
||
|
test.describe('USER Section Tests', () => {
|
||
|
|
||
|
test.beforeEach(async ({ page }) => { //executed at the beginning of each test
|
||
|
const leftMenu = new LeftMenuAdminPage(page);
|
||
|
await loginAsAdmin(page, URL_IDHUB);
|
||
|
(await leftMenu.getUsersLink()).click()
|
||
|
})
|
||
|
/**
|
||
|
* UPDATE the basic data for default testing users user1..user5
|
||
|
*/
|
||
|
|
||
|
test('USERS -> Modify personal data for testing users (user<#>.example.org) with meaningful basic data', async ({ page }) => {
|
||
|
// Initialize pages
|
||
|
const basicInfoPage = new BasicUserInfoSectionPage(page);
|
||
|
const userPersonalInformationPage = new UserPersonalInformationPage(page);
|
||
|
|
||
|
for (let user of testingUsers) {
|
||
|
console.log("Modifying user: ", user)
|
||
|
await gotoBasicInfoPageOfTheUser(page, user);
|
||
|
await userPersonalInformationPage.selectModifyUser();
|
||
|
await basicInfoPage.updateUserBasicInfo(user.firstName, user.lastName, user.email, false);
|
||
|
console.log("Updated basic data for user: ", user.email)
|
||
|
}
|
||
|
|
||
|
});
|
||
|
|
||
|
/**
|
||
|
* Add membership data for default testing users user1..user5
|
||
|
*/
|
||
|
|
||
|
test('USERS -> Modify membership data for testing users (user<#>.example.org)', async ({ page }) => {
|
||
|
// Initialize pages
|
||
|
const userPersonalInformationPage = new UserPersonalInformationPage(page);
|
||
|
const membershipSectionPage = new MembershipSectionPage(page);
|
||
|
const addMembershipPage = new AddMembershipPage(page);
|
||
|
|
||
|
for (let user of testingUsers) {
|
||
|
console.log("Modifying membership for user: ", user)
|
||
|
// Update the membership
|
||
|
await gotoBasicInfoPageOfTheUser(page, user);
|
||
|
await userPersonalInformationPage.selectModifyUser();
|
||
|
await membershipSectionPage.selectAddMembershipButton();
|
||
|
|
||
|
await addMembershipPage.addNewUserMembership('2', '2022-01-12', '2026-01-12')
|
||
|
console.log("Create a new membership for user: ", user.email)
|
||
|
|
||
|
// Validate the updated user data
|
||
|
await gotoBasicInfoPageOfTheUser(page, user);
|
||
|
expect(await membershipSectionPage.membershipExist(page, '2')).toBeTruthy()
|
||
|
}
|
||
|
|
||
|
});
|
||
|
|
||
|
/**
|
||
|
* Assign user5 as Idhub administrator
|
||
|
*/
|
||
|
test('USERS -> Modify personal data -> Assign user5 as Idhub administrator ', async ({ page }) => {
|
||
|
// Initialize pages
|
||
|
const basicInfoPage = new BasicUserInfoSectionPage(page);
|
||
|
const userPersonalInformationPage = new UserPersonalInformationPage(page);
|
||
|
|
||
|
console.log("Modifying user: ", testingUsers[4]);
|
||
|
let user = testingUsers[4];
|
||
|
await gotoBasicInfoPageOfTheUser(page, user);
|
||
|
await userPersonalInformationPage.selectModifyUser();
|
||
|
await basicInfoPage.updateUserBasicInfo(user.firstName, user.lastName, user.email, true);
|
||
|
console.log("Updated basic data for user: ", user.email)
|
||
|
|
||
|
});
|
||
|
|
||
|
/**
|
||
|
* Create a list of random users
|
||
|
* ADD the USER (basic info) to the idhub
|
||
|
* Validate infomation after addition
|
||
|
*/
|
||
|
|
||
|
test.skip('USERS -> Add user: Add random users with basic data', async ({ page }) => {
|
||
|
|
||
|
const randomUsers = createUsersRandomList(6)
|
||
|
for (let user of randomUsers) {
|
||
|
console.log(user)
|
||
|
}
|
||
|
|
||
|
// Initialize pages
|
||
|
const basicInfoPage = new BasicUserInfoSectionPage(page);
|
||
|
const membershipPage = new AddMembershipPage(page);
|
||
|
|
||
|
// Navigate to the Add User page
|
||
|
const { addUserLink } = await clickAddUserOnLeftMenu(page);
|
||
|
|
||
|
// Add the list of users
|
||
|
for (let user of randomUsers) {
|
||
|
await basicInfoPage.addUserBasicInfo(user.firstName, user.lastName, user.email, false);
|
||
|
expect(await membershipPage.alertUserCreationMessageIsValid()).toBeTruthy();
|
||
|
await membershipPage.addUserMembership(user.membershipType, user.startDate, user.endDate);
|
||
|
await addUserLink.click();
|
||
|
}
|
||
|
|
||
|
// Check if the users are visible in 'View users' panel
|
||
|
const viewUsersPage = new ViewUsersPage(page);
|
||
|
const { viewUsersLink } = await clickViewUsersOnLeftMenu(page);
|
||
|
for (let user of randomUsers) {
|
||
|
expect(await viewUsersPage.userExists(user.email)).toBeTruthy();
|
||
|
await viewUsersLink.click();
|
||
|
}
|
||
|
|
||
|
});
|
||
|
|
||
|
/**
|
||
|
* ADD a user (basic information) and validate it after addition
|
||
|
* UPDATE their basic information and validate it after modification
|
||
|
* DELETE the USER added before
|
||
|
*/
|
||
|
test('USERS -> Update basic user information for a user', async ({ page }) => {
|
||
|
|
||
|
// Initialize pages
|
||
|
const basicInfoPage = new BasicUserInfoSectionPage(page);
|
||
|
const userPersonalInformationPage = new UserPersonalInformationPage(page);
|
||
|
const membershipPage = new AddMembershipPage(page);
|
||
|
|
||
|
// Define user data
|
||
|
let user = {
|
||
|
firstName: 'James',
|
||
|
lastName: 'Swift',
|
||
|
email: 'james.swift@example.org',
|
||
|
membershipType: '1',
|
||
|
startDate: '2023-01-01',
|
||
|
endDate: '2024-01-01'
|
||
|
};
|
||
|
|
||
|
// Generate updated user data
|
||
|
const fn = user.firstName.concat(' Junior');
|
||
|
const ln = user.lastName.concat(' Anderson');
|
||
|
const em = fn.toLowerCase().replace(/\s/g, '') + '.' + ln.toLowerCase().replace(/\s/g, '') + '@example.org';
|
||
|
|
||
|
let updateData = {
|
||
|
firstName: fn,
|
||
|
lastName: ln,
|
||
|
email: em,
|
||
|
membershipType: user.membershipType,
|
||
|
startDate: user.startDate,
|
||
|
endDate: user.endDate
|
||
|
};
|
||
|
|
||
|
// Navigate to the Add User page
|
||
|
const { addUserLink } = await clickAddUserOnLeftMenu(page);
|
||
|
|
||
|
// Create a new user
|
||
|
await basicInfoPage.addUserBasicInfo(user.firstName, user.lastName, user.email, false);
|
||
|
expect(await membershipPage.alertUserCreationMessageIsValid()).toBeTruthy();
|
||
|
await membershipPage.addUserMembership(user.membershipType, user.startDate, user.endDate);
|
||
|
await addUserLink.click();
|
||
|
console.log("Created user: ", user.email)
|
||
|
|
||
|
// Validate the newly created user
|
||
|
await gotoBasicInfoPageOfTheUser(page, user);
|
||
|
await checkIfTheInformationIsValid(page, user);
|
||
|
|
||
|
// Update the user data
|
||
|
await gotoBasicInfoPageOfTheUser(page, user);
|
||
|
await userPersonalInformationPage.selectModifyUser();
|
||
|
await basicInfoPage.updateUserBasicInfo(updateData.firstName, updateData.lastName, updateData.email, false);
|
||
|
|
||
|
console.log("Updated basic data for user: ", user.email)
|
||
|
|
||
|
// Validate the updated user data
|
||
|
await gotoBasicInfoPageOfTheUser(page, updateData);
|
||
|
await checkIfTheInformationIsValid(page, updateData);
|
||
|
|
||
|
//Delete the user
|
||
|
await gotoBasicInfoPageOfTheUser(page, updateData);
|
||
|
await userPersonalInformationPage.deleteUser(page);
|
||
|
console.log("Deleted user: ", user.email)
|
||
|
|
||
|
|
||
|
});
|
||
|
|
||
|
/**
|
||
|
* ADD a user (basic info) and membership
|
||
|
* UPDATE the MEMBERSHIP information and validate after modification
|
||
|
* ADD a second MEMBERSHIP and validate
|
||
|
* DELETE the first added MEMBERSHIP and validate
|
||
|
* Delete the user
|
||
|
*/
|
||
|
test('USERS -> Add, modify, delete a membershipType', async ({ page }) => {
|
||
|
// Initialize pages
|
||
|
const basicInfoPage = new BasicUserInfoSectionPage(page);
|
||
|
const userPersonalInformationPage = new UserPersonalInformationPage(page);
|
||
|
const addMembershipPage = new AddMembershipPage(page);
|
||
|
const membershipSectionPage = new MembershipSectionPage(page);
|
||
|
|
||
|
// Navigate to the Add User page
|
||
|
const { addUserLink } = await clickAddUserOnLeftMenu(page);
|
||
|
|
||
|
// Define user data
|
||
|
let user = {
|
||
|
firstName: 'Caroline',
|
||
|
lastName: 'Harari',
|
||
|
email: 'caroline.harari' + '@example.org',
|
||
|
membershipType: '1',
|
||
|
startDate: '2023-01-01',
|
||
|
endDate: '2024-01-01'
|
||
|
};
|
||
|
|
||
|
|
||
|
let updateData = {
|
||
|
firstName: user.firstName,
|
||
|
lastName: user.lastName,
|
||
|
email: user.email,
|
||
|
membershipType: '2',
|
||
|
startDate: '2024-01-04',
|
||
|
endDate: '2025-04-04'
|
||
|
};
|
||
|
|
||
|
// Create a new user
|
||
|
await basicInfoPage.addUserBasicInfo(user.firstName, user.lastName, user.email, false);
|
||
|
expect(await addMembershipPage.alertUserCreationMessageIsValid()).toBeTruthy();
|
||
|
await addMembershipPage.addUserMembership(user.membershipType, user.startDate, user.endDate);
|
||
|
await addUserLink.click();
|
||
|
console.log("Created user: ", user.email)
|
||
|
|
||
|
// Validate the newly created user
|
||
|
await gotoBasicInfoPageOfTheUser(page, user);
|
||
|
await checkIfTheInformationIsValid(page, user);
|
||
|
|
||
|
// Update the membership
|
||
|
await gotoBasicInfoPageOfTheUser(page, user);
|
||
|
await userPersonalInformationPage.selectModifyUser();
|
||
|
await membershipSectionPage.gotoModifyMembershipPage(page, user.membershipType);
|
||
|
await addMembershipPage.updateExistingUserMembership(page, user.membershipType, updateData.membershipType, updateData.startDate, updateData.endDate)
|
||
|
|
||
|
console.log("Updated membership for user: ", user.email)
|
||
|
|
||
|
// Validate the updated user data
|
||
|
await gotoBasicInfoPageOfTheUser(page, updateData);
|
||
|
await checkIfTheInformationIsValid(page, updateData);
|
||
|
|
||
|
//Add a second membership
|
||
|
await gotoBasicInfoPageOfTheUser(page, user);
|
||
|
await userPersonalInformationPage.selectModifyUser();
|
||
|
await membershipSectionPage.selectAddMembershipButton();
|
||
|
await addMembershipPage.addNewUserMembership('3', '2022-01-12', '2025-01-12');
|
||
|
console.log("Updated with second membership for user: ", user.email);
|
||
|
|
||
|
// Validate the updated user data
|
||
|
await gotoBasicInfoPageOfTheUser(page, updateData);
|
||
|
expect(await membershipSectionPage.membershipExist(page, '3')).toBeTruthy()
|
||
|
|
||
|
//Delete the first membership
|
||
|
await gotoBasicInfoPageOfTheUser(page, user);
|
||
|
await userPersonalInformationPage.selectModifyUser();
|
||
|
await membershipSectionPage.gotoDeleteSpecificMembership(page, updateData.membershipType)
|
||
|
console.log("Deleted membership for user: ", user.email)
|
||
|
|
||
|
// Validate the updated user data
|
||
|
await gotoBasicInfoPageOfTheUser(page, updateData);
|
||
|
expect(await membershipSectionPage.membershipExist(page, updateData.membershipType)).toBeFalsy()
|
||
|
|
||
|
//Delete the user
|
||
|
await gotoBasicInfoPageOfTheUser(page, updateData);
|
||
|
await userPersonalInformationPage.deleteUser(page);
|
||
|
console.log("Deleted user: ", user.email)
|
||
|
});
|
||
|
/**
|
||
|
* Create a pre-defined group of users
|
||
|
* Add the users (basic information) to the idhub
|
||
|
* Validate the users information after addition
|
||
|
*/
|
||
|
test('USERS -> Add, Modify and delete users: Add a group of users, with basic info and membership, then delete', async ({ page }) => {
|
||
|
// Initialize pages
|
||
|
const basicInfoPage = new BasicUserInfoSectionPage(page);
|
||
|
const membershipPage = new AddMembershipPage(page);
|
||
|
const userPersonalInformationPage = new UserPersonalInformationPage(page);
|
||
|
for (let user of users) {
|
||
|
console.log(user)
|
||
|
}
|
||
|
// Navigate to the Add User page
|
||
|
const { addUserLink } = await clickAddUserOnLeftMenu(page);
|
||
|
|
||
|
// Add the list of users
|
||
|
for (let user of users) {
|
||
|
await basicInfoPage.addUserBasicInfo(user.firstName, user.lastName, user.email, false);
|
||
|
expect(await membershipPage.alertUserCreationMessageIsValid()).toBeTruthy();
|
||
|
await membershipPage.addUserMembership(user.membershipType, user.startDate, user.endDate);
|
||
|
await addUserLink.click();
|
||
|
}
|
||
|
|
||
|
// Check if the users are visible in 'View users'
|
||
|
const viewUsersPage = new ViewUsersPage(page);
|
||
|
const { viewUsersLink } = await clickViewUsersOnLeftMenu(page);
|
||
|
for (let user of users) {
|
||
|
expect(await viewUsersPage.userExists(user.email)).toBeTruthy();
|
||
|
await viewUsersLink.click();
|
||
|
}
|
||
|
|
||
|
// Delete all the users in the list
|
||
|
await clickViewUsersOnLeftMenu(page);
|
||
|
for (let user of users) {
|
||
|
await gotoBasicInfoPageOfTheUser(page, user);
|
||
|
await userPersonalInformationPage.deleteUser(page);
|
||
|
|
||
|
}
|
||
|
await clickViewUsersOnLeftMenu(page);
|
||
|
for (let user of users) {
|
||
|
expect(await viewUsersPage.userExists(user.email)).toBeFalsy();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
})
|