diff --git a/domiSMP-ui-tests/src/main/java/ddsl/dcomponents/ConfirmationDialog.java b/domiSMP-ui-tests/src/main/java/ddsl/dcomponents/ConfirmationDialog.java new file mode 100644 index 0000000000000000000000000000000000000000..7104941694dfc4e8b597b79ec0bf46b921e824dd --- /dev/null +++ b/domiSMP-ui-tests/src/main/java/ddsl/dcomponents/ConfirmationDialog.java @@ -0,0 +1,38 @@ +package ddsl.dcomponents; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ConfirmationDialog extends DComponent { + private final static Logger LOG = LoggerFactory.getLogger(ConfirmationDialog.class); + + @FindBy(id = "yesbuttondialog_id") + private WebElement yesBtn; + @SuppressWarnings("SpellCheckingInspection") + @FindBy(id = "nobuttondialog_id") + private WebElement noBtn; + + public ConfirmationDialog(WebDriver driver) { + super(driver); + PageFactory.initElements(new AjaxElementLocatorFactory(driver, data.getTIMEOUT()), this); + } + + public void confirm() { + LOG.info("dialog .. confirm"); + wait.forElementToBeClickable(yesBtn); + yesBtn.click(); + wait.forElementToBeClickable(yesBtn); + } + + public void cancel() { + LOG.info("dialog .. cancel"); + wait.forElementToBeClickable(noBtn); + noBtn.click(); + wait.forElementToBeGone(noBtn); + } +} diff --git a/domiSMP-ui-tests/src/main/java/ddsl/dcomponents/Grid/BasicGrid.java b/domiSMP-ui-tests/src/main/java/ddsl/dcomponents/Grid/BasicGrid.java new file mode 100644 index 0000000000000000000000000000000000000000..9bde25e34d2c0a7b86fa15191393aa61539358f4 --- /dev/null +++ b/domiSMP-ui-tests/src/main/java/ddsl/dcomponents/Grid/BasicGrid.java @@ -0,0 +1,88 @@ +package ddsl.dcomponents.Grid; + +import ddsl.dcomponents.DComponent; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.pagefactory.DefaultElementLocatorFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +public class BasicGrid extends DComponent { + private final static Logger LOG = LoggerFactory.getLogger(BasicGrid.class); + + @FindBy(css = "datatable-header div.datatable-row-center datatable-header-cell") + protected List<WebElement> gridHeaders; + @FindBy(css = "datatable-body-row > div.datatable-row-center.datatable-row-group") + protected List<WebElement> gridRows; + protected ArrayList<String> headerTxt = new ArrayList<String>(); + + + public BasicGrid(WebDriver driver, WebElement container) { + super(driver); + + LOG.info("Loading basic grid"); + wait.forXMillis(500); + PageFactory.initElements(new DefaultElementLocatorFactory(container), this); + + for (int i = 0; i < gridHeaders.size(); i++) { + headerTxt.add(gridHeaders.get(i).getText().trim()); + } + + } + + public void selectRow(int rowNumber) { + LOG.info("selecting row with number ... " + rowNumber); + wait.forXMillis(500); + if (rowNumber >= gridRows.size()) { + return; + } + gridRows.get(rowNumber).click(); + wait.forXMillis(500); + } + + public void doubleClickRow(String propertyName) { + gridRows.forEach(row -> { + if (row.getText().startsWith(propertyName)) { + Actions action = new Actions(driver); + action.doubleClick(row).perform(); + } + } + + ); + wait.forXMillis(500); + } + + public void doubleClickRow(int rowNumber) { + + LOG.info("double clicking row ... " + rowNumber); + wait.forXMillis(500); + if (rowNumber >= gridRows.size()) { + return; + } + Actions action = new Actions(driver); + action.doubleClick(gridRows.get(rowNumber)).perform(); + } + + public int getColumnsNo() { + LOG.info("getting number of columns"); + return gridHeaders.size(); + } + + public int getRowsNo() { + return gridRows.size(); + } + + public void scrollRow(int index) { + JavascriptExecutor js = (JavascriptExecutor) driver; + js.executeScript("arguments[0].scrollIntoView();", gridRows.get(index)); + wait.forXMillis(500); + } + +} diff --git a/domiSMP-ui-tests/src/main/java/ddsl/dcomponents/SetChangePasswordDialog.java b/domiSMP-ui-tests/src/main/java/ddsl/dcomponents/SetChangePasswordDialog.java new file mode 100644 index 0000000000000000000000000000000000000000..aa53f075aac593edc1f1a7e4b1dcf30c3f935598 --- /dev/null +++ b/domiSMP-ui-tests/src/main/java/ddsl/dcomponents/SetChangePasswordDialog.java @@ -0,0 +1,64 @@ +package ddsl.dcomponents; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +public class SetChangePasswordDialog extends DComponent { + private final static Logger LOG = LoggerFactory.getLogger(SetChangePasswordDialog.class); + @FindBy(css = ".smp-field-error") + List<WebElement> fieldsError; + @FindBy(id = "cp_id") + private WebElement currentPasswordInput; + @SuppressWarnings("SpellCheckingInspection") + @FindBy(id = "np_id") + private WebElement newPasswordInput; + @FindBy(id = "cnp_id") + private WebElement confirmationPasswordInput; + @FindBy(id = "cnp_id") + private WebElement setPasswordBtn; + @FindBy(id = "cnp_id") + private WebElement closeBtn; + + + public SetChangePasswordDialog(WebDriver driver) { + super(driver); + PageFactory.initElements(new AjaxElementLocatorFactory(driver, data.getTIMEOUT()), this); + } + + public boolean trySetPassword(String currentPassword, String newPassword) throws Exception { + + LOG.info("Set new password"); + weToDInput(currentPasswordInput).fill(currentPassword); + weToDInput(newPasswordInput).fill(newPassword); + weToDInput(confirmationPasswordInput).fill(newPassword); + Integer hasError; + if (weToDButton(setPasswordBtn).isEnabled() && fieldsError.size() < 1) { + weToDButton(setPasswordBtn).click(); + return true; + } + { + getFieldErrorMessage().forEach(LOG::error); + return false; + } + + } + + public List<String> getFieldErrorMessage() { + ArrayList<String> fieldErrors = new ArrayList<>(); + if (fieldsError.size() > 0) { + fieldsError.forEach(error -> { + fieldErrors.add(error.getText()); + }); + } + return fieldErrors; + } +} + diff --git a/domiSMP-ui-tests/src/main/java/ddsl/dcomponents/SideNavigationComponent.java b/domiSMP-ui-tests/src/main/java/ddsl/dcomponents/SideNavigationComponent.java index d35c7e7b66bc2ff5f861add7806e3f940963a355..4fde72f9f468785813c8023707cb688e4f6f4df3 100644 --- a/domiSMP-ui-tests/src/main/java/ddsl/dcomponents/SideNavigationComponent.java +++ b/domiSMP-ui-tests/src/main/java/ddsl/dcomponents/SideNavigationComponent.java @@ -11,6 +11,7 @@ import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import pages.ProfilePage; +import pages.PropertiesPage.PropertiesPage; import java.util.Objects; @@ -125,9 +126,11 @@ public class SideNavigationComponent extends DomiSMPPage { // case SYSTEM_SETTINGS_EXTENSIONS: // expandSection(systemSettingsExpand); // return new DLink(driver, extensionsLnk); - // case SYSTEM_SETTINGS_PROPERTIES: - // expandSection(systemSettingsExpand); - // return new DLink(driver, propertiesLnk); + if (page == Pages.SYSTEM_SETTINGS_PROPERTIES) { + openSubmenu(systemSettingsExpand, propertiesLnk); + return new PropertiesPage(driver); + } + // case SYSTEM_SETTINGS_ALERS: // expandSection(systemSettingsExpand); // return new DLink(driver, alersLnk); diff --git a/domiSMP-ui-tests/src/main/java/pages/ProfilePage.java b/domiSMP-ui-tests/src/main/java/pages/ProfilePage.java index af7aa8f30a89d9be7184fe91508f03f92d409aa4..8727d4a453308c23045c05fade5e70164ceb4238 100644 --- a/domiSMP-ui-tests/src/main/java/pages/ProfilePage.java +++ b/domiSMP-ui-tests/src/main/java/pages/ProfilePage.java @@ -1,6 +1,7 @@ package pages; import ddsl.dcomponents.DomiSMPPage; +import ddsl.dcomponents.SetChangePasswordDialog; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; @@ -26,6 +27,8 @@ public class ProfilePage extends DomiSMPPage { private WebElement emailAddressInput; @FindBy(id = "fullName_id") private WebElement fullNameInput; + @FindBy(id = "changePassword_id") + private WebElement setChangePasswordBtn; public ProfilePage(WebDriver driver) { super(driver); @@ -66,6 +69,11 @@ public class ProfilePage extends DomiSMPPage { } + public Boolean tryChangePassword(String currentPasssword, String newPassword) throws Exception { + weToDButton(setChangePasswordBtn).click(); + SetChangePasswordDialog dialog = new SetChangePasswordDialog(driver); + return dialog.trySetPassword(currentPasssword, newPassword); + } public String getSelectedTheme() { return weToDSelect(themeSel).getCurrentValue(); diff --git a/domiSMP-ui-tests/src/main/java/pages/PropertiesPage/PropGrid.java b/domiSMP-ui-tests/src/main/java/pages/PropertiesPage/PropGrid.java new file mode 100644 index 0000000000000000000000000000000000000000..cff28c6c78ee7d1116e60c7df72241ff05669dd7 --- /dev/null +++ b/domiSMP-ui-tests/src/main/java/pages/PropertiesPage/PropGrid.java @@ -0,0 +1,20 @@ +package pages.PropertiesPage; + +import ddsl.dcomponents.Grid.BasicGrid; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +public class PropGrid extends BasicGrid { + + public PropGrid(WebDriver driver, WebElement container) { + super(driver, container); + } + + public PropertyPopup selectValue(String propertyValue) { + this.doubleClickRow(propertyValue); + return new PropertyPopup(driver); + } + + ; + +} diff --git a/domiSMP-ui-tests/src/main/java/pages/PropertiesPage/PropertiesPage.java b/domiSMP-ui-tests/src/main/java/pages/PropertiesPage/PropertiesPage.java new file mode 100644 index 0000000000000000000000000000000000000000..323d9cae99582d6352439f47e0fd2376cdd45fd3 --- /dev/null +++ b/domiSMP-ui-tests/src/main/java/pages/PropertiesPage/PropertiesPage.java @@ -0,0 +1,62 @@ +package pages.PropertiesPage; + +import ddsl.dcomponents.ConfirmationDialog; +import ddsl.dcomponents.DomiSMPPage; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; +import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PropertiesPage extends DomiSMPPage { + private final static Logger LOG = LoggerFactory.getLogger(PropertiesPage.class); + + @FindBy(id = "searchTable") + private WebElement propertyTableContainer; + @FindBy(id = "cancelButton") + private WebElement cancelBtn; + @FindBy(id = "saveButton") + private WebElement saveBtn; + @FindBy(id = "editButton") + private WebElement editBtn; + @FindBy(id = "searchProperty") + private WebElement searchPropertyField; + @FindBy(id = "searchbutton_id") + private WebElement searchBtn; + + + public PropertiesPage(WebDriver driver) { + super(driver); + PageFactory.initElements(new AjaxElementLocatorFactory(driver, data.getTIMEOUT()), this); + } + + public PropGrid grid() { + return new PropGrid(driver, propertyTableContainer); + } + + public void propertySearch(String propertyname) { + LOG.info("Search for property"); + wait.forElementToBeVisible(searchPropertyField).sendKeys(propertyname); + wait.forElementToBeClickable(searchBtn).click(); + } + + public void setPropertyValue(String propertyName, String propertyValue) { + PropertyPopup popup = grid().selectValue(propertyName); + popup.editInputField(propertyValue); + try { + popup.clickOK(); + } catch (Exception e) { + LOG.error("Cannot set value for property {1}", propertyName); + } + + } + + public void save() throws Exception { + weToDButton(saveBtn).click(); + ConfirmationDialog confirmationDialog = new ConfirmationDialog(driver); + confirmationDialog.confirm(); + + } +} diff --git a/domiSMP-ui-tests/src/main/java/pages/PropertiesPage/PropertyPopup.java b/domiSMP-ui-tests/src/main/java/pages/PropertiesPage/PropertyPopup.java new file mode 100644 index 0000000000000000000000000000000000000000..a754aca2c28b1c52dc4352322ecf2194de2a1a10 --- /dev/null +++ b/domiSMP-ui-tests/src/main/java/pages/PropertiesPage/PropertyPopup.java @@ -0,0 +1,99 @@ +package pages.PropertiesPage; + +import ddsl.dcomponents.DComponent; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PropertyPopup extends DComponent { + private final static Logger LOG = LoggerFactory.getLogger(PropertiesPage.class); + @FindBy(id = "updatePropertyButton") + WebElement popupOkBtn; + @FindBy(css = "mat-dialog-actions button:nth-of-type(2)") + WebElement popupCancelBtn; + @FindBy(css = "span.mat-checkbox-inner-container input") + WebElement propertyCheckbox; + @FindBy(css = "property-details-dialog input") + WebElement propertryEditInput; + + public PropertyPopup(WebDriver driver) { + super(driver); + PageFactory.initElements(driver, this); + + } + + public boolean isOKButtonActive() { + try { + return weToDButton(popupOkBtn).isEnabled(); + + } catch (Exception e) { + LOG.error("Element is not visible", e); + return false; + } + } + + public boolean isCancelButtonActive() { + try { + return weToDButton(popupCancelBtn).isEnabled(); + + } catch (Exception e) { + LOG.error("Element is not visible", e); + return false; + } + } + + public PropertiesPage clickOK() throws Exception { + LOG.info("click OK"); + wait.forElementToBeClickable(popupOkBtn); + weToDButton(popupOkBtn).click(); + wait.forElementToBeGone(popupOkBtn); + return new PropertiesPage(driver); + } + + public PropertiesPage clickCancel() { + LOG.info("click cancel"); + wait.forElementToBeClickable(popupCancelBtn); + popupCancelBtn.click(); + wait.forElementToBeGone(popupCancelBtn); + return new PropertiesPage(driver); + } + + public PropertiesPage enableCheckboxOfProperty() { + Boolean bool = propertyCheckbox.isSelected(); + + if (bool == false) { + propertyCheckbox.click(); + popupOkBtn.click(); + } else { + popupCancelBtn.click(); + } + return new PropertiesPage(driver); + } + + public PropertiesPage disableCheckboxOfProperty() { + Boolean bool = propertyCheckbox.isSelected(); + if (bool == true) { + JavascriptExecutor executor = (JavascriptExecutor) driver; + executor.executeScript("arguments[0].click();", propertyCheckbox); + try { + Thread.sleep(1000); + } catch (Exception e) { + e.printStackTrace(); + } + popupOkBtn.click(); + } else { + popupCancelBtn.click(); + } + return new PropertiesPage(driver); + + } + + public void editInputField(String string) { + propertryEditInput.clear(); + propertryEditInput.sendKeys(string); + } +} diff --git a/domiSMP-ui-tests/src/test/java/domiSMPTests/ui/ProfilePgTests.java b/domiSMP-ui-tests/src/test/java/domiSMPTests/ui/ProfilePgTests.java index 05bf203afccef57ac08f5361e75669151e11a829..5981e87a9b6155d3bbc1564ae3ae216ab26d19a0 100644 --- a/domiSMP-ui-tests/src/test/java/domiSMPTests/ui/ProfilePgTests.java +++ b/domiSMP-ui-tests/src/test/java/domiSMPTests/ui/ProfilePgTests.java @@ -7,6 +7,7 @@ import org.testng.Assert; import org.testng.annotations.Test; import pages.LoginPage; import pages.ProfilePage; +import pages.PropertiesPage.PropertiesPage; import rest.models.UserModel; @@ -16,7 +17,7 @@ public class ProfilePgTests extends SeleniumTest { * This class has the tests against Profile Page */ @Test(description = "PROF-01") - public void AllLoggedUsersAreAbleToSeeProfilePage() throws Exception { + public void AllLoggedUsersShouldAbleToSeeProfilePage() throws Exception { UserModel normalUser = UserModel.createUserWithUSERrole(); rest.users().createUser(normalUser); @@ -52,7 +53,7 @@ public class ProfilePgTests extends SeleniumTest { } @Test(description = "PROF-02") - public void AllLoggedUsersAreAbleToUpdateProfilePage() throws Exception { + public void AllLoggedUsersShouldAbleToUpdateProfilePage() throws Exception { UserModel normalUser = UserModel.createUserWithUSERrole(); rest.users().createUser(normalUser); @@ -101,4 +102,24 @@ public class ProfilePgTests extends SeleniumTest { } + + @Test(description = "PROF-03") + public void PasswordValidationsShouldBeAccordingToPropertiesValue() throws Exception { + UserModel adminUser = UserModel.createUserWithADMINrole(); + + rest.users().createUser(adminUser); + + DomiSMPPage homePage = new DomiSMPPage(driver); + LoginPage loginPage = homePage.goToLoginPage(); + loginPage.login(adminUser.getUsername(), data.getNewPassword()); + + PropertiesPage propertiesPage = (PropertiesPage) homePage.getSidebar().navigateTo(Pages.SYSTEM_SETTINGS_PROPERTIES); + propertiesPage.propertySearch("smp.passwordPolicy.validationRegex"); + propertiesPage.setPropertyValue("smp.passwordPolicy.validationRegex", "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[~`!@#$%^&+=\\-_<>.,?:;*/()|\\[\\]{}'\"\\\\]).{16,35}$"); + propertiesPage.save(); + + ProfilePage profilePage = (ProfilePage) propertiesPage.getSidebar().navigateTo(Pages.USER_SETTINGS_PROFILE); + Boolean isPasswordChanged = profilePage.tryChangePassword(data.getNewPassword(), "Edeltest!23456789Edeltest!234567890"); + Assert.assertTrue(isPasswordChanged); + } }