Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit c73c066c authored by Mihai BOZ's avatar Mihai BOZ
Browse files

refactor setchangepassword dialog, Changed profiletests to use soft assert

parent 4b8ed8af
No related branches found
No related tags found
No related merge requests found
package ddsl.dcomponents;
import ddsl.DomiSMPPage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
......@@ -35,18 +36,24 @@ public class SetChangePasswordDialog extends DComponent {
PageFactory.initElements(new AjaxElementLocatorFactory(driver, data.getTIMEOUT()), this);
}
public List<WebElement> setNewPassword(String currentPassword, String newPassword) throws Exception {
public void fillChangePassword(String currentPassword, String newPassword) throws Exception {
LOG.info("Set new password");
weToDInput(currentPasswordInput).fill(currentPassword);
weToDInput(newPasswordInput).fill(newPassword, true);
weToDInput(confirmationPasswordInput).fill(newPassword, true);
wait.forElementToBeClickable(setPasswordBtn);
weToDButton(setPasswordBtn).click();
SuccesfullPasswordChangedPopup popup = new SuccesfullPasswordChangedPopup(driver);
popup.closePopup();
}
return fieldsError;
public DomiSMPPage TryClickOnChangePassword() throws Exception {
wait.forElementToBeClickable(setPasswordBtn);
if (weToDButton(setPasswordBtn).isEnabled() && fieldsError.isEmpty()) {
weToDButton(setPasswordBtn).click();
SuccesfullPasswordChangedPopup popup = new SuccesfullPasswordChangedPopup(driver);
popup.closePopup();
return new DomiSMPPage(driver);
} else {
return null;
}
}
public List<String> getFieldErrorMessage() {
......
......@@ -15,7 +15,7 @@ public class UserDataCommonComponent extends DomiSMPPage {
*/
private final static Logger LOG = LoggerFactory.getLogger(UserDataCommonComponent.class);
@FindBy(id = "changePassword_id")
public WebElement setChangePasswordBtn;
private WebElement setChangePasswordBtn;
@FindBy(id = "smpTheme_id")
private WebElement themeSel;
@FindBy(id = "smpLocale_id")
......@@ -52,18 +52,17 @@ public class UserDataCommonComponent extends DomiSMPPage {
}
public String getLastSetValue() {
return lastSetLbl.getText();
return lastSetLbl.getAttribute("value");
}
public String getPasswordExpiresOnValue() {
return passwordExpiresOnLbl.getText();
return passwordExpiresOnLbl.getAttribute("value");
}
public SetChangePasswordDialog getChangePasswordDialog() {
public SetChangePasswordDialog clickOnChangePassword() throws InterruptedException {
setChangePasswordBtn.click();
return new SetChangePasswordDialog(driver);
}
public String fillUserProfileData(String emailValue, String fullNameValue, String selectThemeValue, String localeValue) {
try {
if (!emailValue.isEmpty()) {
......@@ -93,10 +92,4 @@ public class UserDataCommonComponent extends DomiSMPPage {
return null;
}
}
public void ChangePassword(String currentPasssword, String newPassword) throws Exception {
SetChangePasswordDialog dialog = new SetChangePasswordDialog(driver);
dialog.setNewPassword(currentPasssword, newPassword);
}
}
package pages.userSettings;
import ddsl.PageWithGrid;
import ddsl.DomiSMPPage;
import ddsl.dcomponents.commonComponents.UserDataCommonComponent;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ProfilePage extends PageWithGrid {
public class ProfilePage extends DomiSMPPage {
/**
* Page object for the Profile page. This contains the locators of the page and the methods for the behaviour of the page
*/
private final static Logger LOG = LoggerFactory.getLogger(ProfilePage.class);
public UserDataCommonComponent userData;
public UserDataCommonComponent profileData;
public ProfilePage(WebDriver driver) {
super(driver);
userData = new UserDataCommonComponent(driver);
profileData = new UserDataCommonComponent(driver);
LOG.debug("Profile page has loaded");
}
}
\ No newline at end of file
package domiSMPTests.ui;
import ddsl.DomiSMPPage;
import ddsl.dcomponents.SetChangePasswordDialog;
import ddsl.enums.Pages;
import domiSMPTests.SeleniumTest;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;
import pages.LoginPage;
import pages.systemSettings.propertiesPage.PropertiesPage;
import pages.systemSettings.propertiesPage.PropertyPopup;
......@@ -12,24 +16,32 @@ import pages.userSettings.ProfilePage;
import rest.models.UserModel;
import utils.Generator;
import java.util.List;
public class ProfilePgTests extends SeleniumTest {
/**
* This class has the tests against Profile Page
*/
SoftAssert soft = new SoftAssert();
DomiSMPPage homePage;
LoginPage loginPage;
@BeforeMethod(alwaysRun = true)
public void beforeTest() throws Exception {
soft = new SoftAssert();
homePage = new DomiSMPPage(driver);
loginPage = homePage.goToLoginPage();
}
@Test(description = "PROF-01 All logged users are able to view the Profile Page")
public void AllLoggedUsersShouldAbleToSeeProfilePage() throws Exception {
UserModel normalUser = UserModel.generateUserWithUSERrole();
rest.users().createUser(normalUser);
DomiSMPPage homePage = new DomiSMPPage(driver);
LoginPage loginPage = homePage.goToLoginPage();
loginPage.login(normalUser.getUsername(), data.getNewPassword());
//Check if menu is available
Assert.assertTrue(homePage.getSidebar().isMenuAvailable(Pages.USER_SETTINGS_PROFILE));
soft.assertTrue(homePage.getSidebar().isMenuAvailable(Pages.USER_SETTINGS_PROFILE));
//Navigate to page
homePage.getSidebar().navigateTo(Pages.USER_SETTINGS_PROFILE);
......@@ -44,64 +56,56 @@ public class ProfilePgTests extends SeleniumTest {
loginPage.login(adminUser.getUsername(), data.getNewPassword());
//Check if menu is available
Assert.assertTrue(homePage.getSidebar().isMenuAvailable(Pages.USER_SETTINGS_PROFILE));
soft.assertTrue(homePage.getSidebar().isMenuAvailable(Pages.USER_SETTINGS_PROFILE));
//Navigate to page
homePage.getSidebar().navigateTo(Pages.USER_SETTINGS_PROFILE);
//Check if ProfilePage is not available for anonymous users
homePage.logout();
Assert.assertFalse(homePage.getSidebar().isMenuAvailable(Pages.USER_SETTINGS_PROFILE));
soft.assertFalse(homePage.getSidebar().isMenuAvailable(Pages.USER_SETTINGS_PROFILE));
soft.assertAll();
}
@Test(description = "PROF-02 All loggedin users are able to update profile data")
public void AllLoggedUsersShouldAbleToUpdateProfilePage() throws Exception {
UserModel normalUser = UserModel.generateUserWithUSERrole();
rest.users().createUser(normalUser);
DomiSMPPage homePage = new DomiSMPPage(driver);
LoginPage loginPage = homePage.goToLoginPage();
loginPage.login(normalUser.getUsername(), data.getNewPassword());
//Navigate to page
ProfilePage profilePage = homePage.getSidebar().navigateTo(Pages.USER_SETTINGS_PROFILE);
UserModel userNewProfileData = UserModel.generateUserProfileData();
profilePage.userData.fillUserProfileData(userNewProfileData.getEmailAddress(), userNewProfileData.getFullName(), userNewProfileData.getSmpTheme(), userNewProfileData.getSmpLocale());
profilePage.profileData.fillUserProfileData(userNewProfileData.getEmailAddress(), userNewProfileData.getFullName(), userNewProfileData.getSmpTheme(), userNewProfileData.getSmpLocale());
profilePage.refreshPage();
//Verify if data is changed
Assert.assertEquals(profilePage.userData.getEmailAddress(), userNewProfileData.getEmailAddress(), "Email value is different");
Assert.assertEquals(profilePage.userData.getFullName(), userNewProfileData.getFullName(), "Full name value is different");
Assert.assertEquals(profilePage.userData.getSelectedTheme(), userNewProfileData.getSmpTheme(), "Selected theme value is different");
Assert.assertEquals(profilePage.userData.getSelectedLocale(), userNewProfileData.getSmpLocale(), "Locale value is different");
soft.assertEquals(profilePage.profileData.getEmailAddress(), userNewProfileData.getEmailAddress(), "Email value is different");
soft.assertEquals(profilePage.profileData.getFullName(), userNewProfileData.getFullName(), "Full name value is different");
soft.assertEquals(profilePage.profileData.getSelectedTheme(), userNewProfileData.getSmpTheme(), "Selected theme value is different");
soft.assertEquals(profilePage.profileData.getSelectedLocale(), userNewProfileData.getSmpLocale(), "Locale value is different");
homePage.logout();
UserModel adminUser = UserModel.generateUserWithUSERrole();
rest.users().createUser(adminUser);
homePage = new DomiSMPPage(driver);
loginPage = homePage.goToLoginPage();
loginPage.login(adminUser.getUsername(), data.getNewPassword());
//Navigate to page
profilePage = homePage.getSidebar().navigateTo(Pages.USER_SETTINGS_PROFILE);
UserModel adminNewProfileData = UserModel.generateUserProfileData();
profilePage.userData.fillUserProfileData(adminNewProfileData.getEmailAddress(), adminNewProfileData.getFullName(), adminNewProfileData.getSmpTheme(), adminNewProfileData.getSmpLocale());
profilePage.profileData.fillUserProfileData(adminNewProfileData.getEmailAddress(), adminNewProfileData.getFullName(), adminNewProfileData.getSmpTheme(), adminNewProfileData.getSmpLocale());
profilePage.refreshPage();
//Verify if data is changed
Assert.assertEquals(profilePage.userData.getEmailAddress(), adminNewProfileData.getEmailAddress());
Assert.assertEquals(profilePage.userData.getFullName(), adminNewProfileData.getFullName());
Assert.assertEquals(profilePage.userData.getSelectedTheme(), adminNewProfileData.getSmpTheme());
Assert.assertEquals(profilePage.userData.getSelectedLocale(), adminNewProfileData.getSmpLocale());
soft.assertEquals(profilePage.profileData.getEmailAddress(), adminNewProfileData.getEmailAddress());
soft.assertEquals(profilePage.profileData.getFullName(), adminNewProfileData.getFullName());
soft.assertEquals(profilePage.profileData.getSelectedTheme(), adminNewProfileData.getSmpTheme());
soft.assertEquals(profilePage.profileData.getSelectedLocale(), adminNewProfileData.getSmpLocale());
soft.assertAll();
}
......@@ -112,13 +116,9 @@ public class ProfilePgTests extends SeleniumTest {
String new40CharactersPasswordValue = "Edeltest!23456789Edeltest!234567890sssf";
UserModel adminUser = UserModel.generateUserWithADMINrole();
rest.users().createUser(adminUser);
DomiSMPPage homePage = new DomiSMPPage(driver);
LoginPage loginPage = homePage.goToLoginPage();
loginPage.login(adminUser.getUsername(), data.getNewPassword());
PropertiesPage propertiesPage = homePage.getSidebar().navigateTo(Pages.SYSTEM_SETTINGS_PROPERTIES);
propertiesPage.propertySearch(propertyName);
if (!propertiesPage.getPropertyValue(propertyName).equals(newPropertyValue)) {
......@@ -129,36 +129,41 @@ public class ProfilePgTests extends SeleniumTest {
}
ProfilePage profilePage = propertiesPage.getSidebar().navigateTo(Pages.USER_SETTINGS_PROFILE);
profilePage.userData.setChangePasswordBtn.click();
Assert.assertEquals(0, profilePage.userData.getChangePasswordDialog().setNewPassword(data.getNewPassword(), new40CharactersPasswordValue).size(), "Could not change the password of the user");
SetChangePasswordDialog setChangePasswordDialog = profilePage.profileData.clickOnChangePassword();
setChangePasswordDialog.fillChangePassword(data.getNewPassword(), new40CharactersPasswordValue);
List<String> erros = setChangePasswordDialog.getFieldErrorMessage();
DomiSMPPage homepage = setChangePasswordDialog.TryClickOnChangePassword();
soft.assertEquals(erros.size(), 0, "Could not change the password of the user");
soft.assertNotNull(homepage, "Could not change the password of the user");
soft.assertAll();
}
@Ignore
@Test(description = "PROF-04 User should be able to change his password")
public void UserShouldBeAbleToChangeHisPassword() throws Exception {
UserModel adminUser = UserModel.generateUserWithADMINrole();
rest.users().createUser(adminUser);
DomiSMPPage homePage = new DomiSMPPage(driver);
LoginPage loginPage = homePage.goToLoginPage();
loginPage.login(adminUser.getUsername(), data.getNewPassword());
ProfilePage profilePage = loginPage.getSidebar().navigateTo(Pages.USER_SETTINGS_PROFILE);
String oldLastSet = profilePage.userData.getLastSetValue();
String oldPasswordExpiresOn = profilePage.userData.getPasswordExpiresOnValue();
String oldLastSet = profilePage.profileData.getLastSetValue();
String oldPasswordExpiresOn = profilePage.profileData.getPasswordExpiresOnValue();
profilePage.userData.setChangePasswordBtn.click();
//profilePage.profileData.setChangePasswordBtn.click();
String newPass = "Edeltest!23456789Edelt" + Generator.randomAlphaNumeric(4);
SetChangePasswordDialog setChangePasswordDialog = profilePage.profileData.clickOnChangePassword();
setChangePasswordDialog.fillChangePassword(data.getNewPassword(), newPass);
homePage = setChangePasswordDialog.TryClickOnChangePassword();
Assert.assertEquals(profilePage.userData.getChangePasswordDialog().setNewPassword(data.getNewPassword(), newPass).size(), 0, "Could not change the password of the user");
soft.assertNotNull(homePage, "Could not change the password of the user");
homePage.goToLoginPage();
loginPage.login(adminUser.getUsername(), newPass);
profilePage = loginPage.getSidebar().navigateTo(Pages.USER_SETTINGS_PROFILE);
//TODO wait until the lastvalue and old password fields show value as text
// Assert.assertNotSame(profilePage.userData.getLastSetValue(), oldLastSet, "Last set value is not reseted");
// Assert.assertNotSame(profilePage.userData.getPasswordExpiresOnValue(), oldPasswordExpiresOn, "Password expires on value is not reseted");
Assert.assertNotSame(profilePage.profileData.getLastSetValue(), oldLastSet, "Last set value is not reseted");
//TODO: passwordexpiresOn label has a different id after the value is set reason why the test is failing with not element found
Assert.assertNotSame(profilePage.profileData.getPasswordExpiresOnValue(), oldPasswordExpiresOn, "Password expires on value is not reseted");
}
}
......@@ -55,7 +55,5 @@ public class UsersPgTests extends SeleniumTest {
usersPage.getCreateUserBtn().click();
String alertMessage = usersPage.fillNewUserDataAndSave(adminNewUserData);
Assert.assertEquals(alertMessage, "Invalid request [CreateUser]. Error: User with username [" + adminNewUserData.getUsername() + "] already exists!!");
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment