From c09b817dba90348d171f57188a2bf20263c7265f Mon Sep 17 00:00:00 2001 From: Mihai BOZ <Mihai.BOZ@ext.ec.europa.eu> Date: Wed, 30 Aug 2023 18:03:51 +0300 Subject: [PATCH] added PropertiesPageTests. --- .../java/pages/DomainsPage/DomainTab.java | 2 + .../java/pages/propertiesPage/PropGrid.java | 2 +- .../pages/propertiesPage/PropertiesPage.java | 24 +- .../pages/propertiesPage/PropertyPopup.java | 17 +- .../java/domiSMPTests/ui/ProfilePgTests.java | 11 +- .../domiSMPTests/ui/PropertiesPgTests.java | 216 ++++++++++++++++++ 6 files changed, 259 insertions(+), 13 deletions(-) create mode 100644 domiSMP-ui-tests/src/test/java/domiSMPTests/ui/PropertiesPgTests.java diff --git a/domiSMP-ui-tests/src/main/java/pages/DomainsPage/DomainTab.java b/domiSMP-ui-tests/src/main/java/pages/DomainsPage/DomainTab.java index cedb165ad..1253fa58e 100644 --- a/domiSMP-ui-tests/src/main/java/pages/DomainsPage/DomainTab.java +++ b/domiSMP-ui-tests/src/main/java/pages/DomainsPage/DomainTab.java @@ -57,6 +57,8 @@ public class DomainTab extends DComponent { } else { LOG.error("Domain tab changes were not saved"); } + } else { + LOG.error("Save domain button is disabled"); } } diff --git a/domiSMP-ui-tests/src/main/java/pages/propertiesPage/PropGrid.java b/domiSMP-ui-tests/src/main/java/pages/propertiesPage/PropGrid.java index 176ad1c45..2fcbff624 100644 --- a/domiSMP-ui-tests/src/main/java/pages/propertiesPage/PropGrid.java +++ b/domiSMP-ui-tests/src/main/java/pages/propertiesPage/PropGrid.java @@ -14,7 +14,7 @@ public class PropGrid extends BasicGrid { super(driver, container); } - public PropertyPopup selectValue(String propertyValue) { + public PropertyPopup doubleClickValue(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 index ab60bb507..85d561f49 100644 --- a/domiSMP-ui-tests/src/main/java/pages/propertiesPage/PropertiesPage.java +++ b/domiSMP-ui-tests/src/main/java/pages/propertiesPage/PropertiesPage.java @@ -25,6 +25,8 @@ public class PropertiesPage extends DomiSMPPage { private WebElement searchPropertyField; @FindBy(id = "searchbutton_id") private WebElement searchBtn; + @FindBy(css = "smp-search-table [id=\"editButton\"]") + private WebElement editBtn; public PropertiesPage(WebDriver driver) { @@ -42,16 +44,27 @@ public class PropertiesPage extends DomiSMPPage { wait.forElementToBeClickable(searchBtn).click(); } - public void setPropertyValue(String propertyName, String propertyValue) { - PropertyPopup popup = grid().selectValue(propertyName); - popup.editInputField(propertyValue); + public PropertyPopup openEditPropertyPopupup(String propertyName) { + return grid().doubleClickValue(propertyName); + } + + public PropertyPopup clickEdit() { try { - popup.clickOK(); + if (!weToDButton(editBtn).isEnabled()) { + LOG.error("Edit property button is not enabled"); + return null; + } + weToDButton(editBtn).click(); } catch (Exception e) { - LOG.error("Cannot set value for property {1}", propertyName); + LOG.error("Edit property button is not enabled"); + throw new RuntimeException(e); } + return new PropertyPopup(driver); + + } + public String getPropertyValue(String propertyName) { return grid().getPropertyValue(propertyName); @@ -61,6 +74,5 @@ public class PropertiesPage extends DomiSMPPage { 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 index 4e830cab4..0db1c40dd 100644 --- a/domiSMP-ui-tests/src/main/java/pages/propertiesPage/PropertyPopup.java +++ b/domiSMP-ui-tests/src/main/java/pages/propertiesPage/PropertyPopup.java @@ -22,6 +22,9 @@ public class PropertyPopup extends DComponent { WebElement propertyCheckbox; @FindBy(css = "property-details-dialog input") WebElement propertryEditInput; + @FindBy(css = "property-details-dialog .alert-message-error") + WebElement errorMessageLbl; + public PropertyPopup(WebDriver driver) { super(driver); @@ -53,8 +56,11 @@ public class PropertyPopup extends DComponent { LOG.info("click OK"); wait.forElementToBeClickable(popupOkBtn); weToDButton(popupOkBtn).click(); - wait.forElementToBeGone(popupOkBtn); - return new PropertiesPage(driver); + if (!errorMessageLbl.isDisplayed()) { + wait.forElementToBeGone(popupOkBtn); + return new PropertiesPage(driver); + } + return null; } public PropertiesPage clickCancel() { @@ -99,4 +105,11 @@ public class PropertyPopup extends DComponent { propertryEditInput.clear(); propertryEditInput.sendKeys(string); } + + public String getErrorMessage() { + if (!errorMessageLbl.isDisplayed()) { + return null; + } + return errorMessageLbl.getText(); + } } 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 a03493b2c..6a2a64793 100644 --- a/domiSMP-ui-tests/src/test/java/domiSMPTests/ui/ProfilePgTests.java +++ b/domiSMP-ui-tests/src/test/java/domiSMPTests/ui/ProfilePgTests.java @@ -8,6 +8,7 @@ import org.testng.annotations.Test; import pages.LoginPage; import pages.profilePage.ProfilePage; import pages.propertiesPage.PropertiesPage; +import pages.propertiesPage.PropertyPopup; import rest.models.UserModel; import utils.Generator; @@ -106,7 +107,7 @@ public class ProfilePgTests extends SeleniumTest { @Test(description = "PROF-03 Password validation is accord to the smp propeties values") public void PasswordValidationsShouldBeAccordingToPropertiesValue() throws Exception { - String propertyValue = "smp.passwordPolicy.validationRegex"; + String propertyName = "smp.passwordPolicy.validationRegex"; String newPropertyValue = "^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[~`!@#$%^&+=\\-_<>.,?:;*/()|\\[\\]{}'\"\\\\]).{16,40}$"; String new40CharactersPasswordValue = "Edeltest!23456789Edeltest!234567890sssf"; @@ -119,9 +120,11 @@ public class ProfilePgTests extends SeleniumTest { loginPage.login(adminUser.getUsername(), data.getNewPassword()); PropertiesPage propertiesPage = homePage.getSidebar().navigateTo(Pages.SYSTEM_SETTINGS_PROPERTIES); - propertiesPage.propertySearch(propertyValue); - if (!propertiesPage.getPropertyValue(propertyValue).equals(newPropertyValue)) { - propertiesPage.setPropertyValue("smp.passwordPolicy.validationRegex", newPropertyValue); + propertiesPage.propertySearch(propertyName); + if (!propertiesPage.getPropertyValue(propertyName).equals(newPropertyValue)) { + PropertyPopup propertyEditPoup = propertiesPage.openEditPropertyPopupup(propertyName); + propertyEditPoup.editInputField(newPropertyValue); + propertyEditPoup.clickOK(); propertiesPage.save(); } diff --git a/domiSMP-ui-tests/src/test/java/domiSMPTests/ui/PropertiesPgTests.java b/domiSMP-ui-tests/src/test/java/domiSMPTests/ui/PropertiesPgTests.java new file mode 100644 index 000000000..fdb0429bf --- /dev/null +++ b/domiSMP-ui-tests/src/test/java/domiSMPTests/ui/PropertiesPgTests.java @@ -0,0 +1,216 @@ +package domiSMPTests.ui; + +import ddsl.DomiSMPPage; +import ddsl.enums.Pages; +import domiSMPTests.SeleniumTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.testng.asserts.SoftAssert; +import pages.LoginPage; +import pages.propertiesPage.PropertiesPage; +import pages.propertiesPage.PropertyPopup; +import rest.models.UserModel; +import utils.Generator; + +public class PropertiesPgTests extends SeleniumTest { + + DomiSMPPage homePage; + UserModel adminUser; + PropertiesPage propertiesPage; + SoftAssert soft; + + @BeforeClass(alwaysRun = true) + public void beforeClass() { + adminUser = UserModel.generateUserWithADMINrole(); + rest.users().createUser(adminUser); + } + + @BeforeMethod(alwaysRun = true) + public void beforeTest() throws Exception { + soft = new SoftAssert(); + homePage = new DomiSMPPage(driver); + LoginPage loginPage = homePage.goToLoginPage(); + loginPage.login(adminUser.getUsername(), data.getNewPassword()); + propertiesPage = homePage.getSidebar().navigateTo(Pages.SYSTEM_SETTINGS_PROPERTIES); + } + + @Test(description = "PRP-2 - Admin doubleclicks or selects a property and clicks edit button and Edit property dialog is opened") + public void AdminDoubleClicksOrSelectsAPropertyAndClicksEditButtonandEditPropertyDialogIsOpened() throws Exception { + + String property = "bdmsl.integration.url"; + propertiesPage.propertySearch(property); + + //Check if popup opens when double click property + PropertyPopup propertyEditPoup = propertiesPage.openEditPropertyPopupup(property); + propertyEditPoup.clickCancel(); + soft.assertNotNull(propertyEditPoup); + + //Check if popup opens when clicking EDIT button + propertyEditPoup = null; + propertyEditPoup = propertiesPage.clickEdit(); + soft.assertNotNull(propertyEditPoup); + soft.assertAll(); + } + + @Test(description = "PRP-5 Value is validated according to expected format (URL") + public void PropertyValueURLIsValidatedAccordingToExpectedFormat() throws Exception { + + String property = "bdmsl.integration.url"; + String wrongValue1 = Generator.randomAlphaNumeric(6); + String wrongValue2 = wrongValue1 + ".com"; + String wrongValue3 = "www." + wrongValue1 + ".com"; + + propertiesPage.propertySearch(property); + String currentValue = propertiesPage.getPropertyValue(property); + PropertyPopup propertyEditPoup = propertiesPage.openEditPropertyPopupup(property); + + + propertyEditPoup.editInputField(wrongValue1); + propertyEditPoup.clickOK(); + String error = propertyEditPoup.getErrorMessage(); + soft.assertEquals(error, "Configuration error: [Invalid URL address: [" + wrongValue1 + "]. Error:MalformedURLException: no protocol: " + wrongValue1 + "]!"); + + + propertyEditPoup.editInputField(wrongValue2); + propertyEditPoup.clickOK(); + error = propertyEditPoup.getErrorMessage(); + soft.assertEquals(error, "Configuration error: [Invalid URL address: [" + wrongValue2 + "]. Error:MalformedURLException: no protocol: " + wrongValue2 + "]!"); + + propertyEditPoup.editInputField(wrongValue3); + propertyEditPoup.clickOK(); + error = propertyEditPoup.getErrorMessage(); + soft.assertEquals(error, "Configuration error: [Invalid URL address: [" + wrongValue3 + "]. Error:MalformedURLException: no protocol: " + wrongValue3 + "]!"); + + //Check if property value hasn't changed. + propertyEditPoup.clickCancel(); + propertiesPage.refreshPage(); + + propertiesPage.propertySearch(property); + String valueAfterEdit = propertiesPage.getPropertyValue(property); + soft.assertEquals(valueAfterEdit, currentValue); + + soft.assertAll(); + } + + @Test(description = "PRP-5 Value is validated according to expected format (email)") + public void PropertyValueEmailIsValidatedAccordingToExpectedFormat() throws Exception { + + String property = "smp.alert.mail.from"; + String wrongValue1 = Generator.randomAlphaNumeric(6); + String wrongValue2 = wrongValue1 + "@yahoo"; + String wrongValue3 = wrongValue1 + ".com"; + + propertiesPage.propertySearch(property); + String currentValue = propertiesPage.getPropertyValue(property); + PropertyPopup propertyEditPoup = propertiesPage.openEditPropertyPopupup(property); + + + propertyEditPoup.editInputField(wrongValue1); + propertyEditPoup.clickOK(); + String error = propertyEditPoup.getErrorMessage(); + soft.assertEquals(error, "Configuration error: [Invalid email address: [" + wrongValue1 + "].]!"); + + + propertyEditPoup.editInputField(wrongValue2); + propertyEditPoup.clickOK(); + error = propertyEditPoup.getErrorMessage(); + soft.assertEquals(error, "Configuration error: [Invalid email address: [" + wrongValue2 + "].]!"); + + propertyEditPoup.editInputField(wrongValue3); + propertyEditPoup.clickOK(); + error = propertyEditPoup.getErrorMessage(); + soft.assertEquals(error, "Configuration error: [Invalid email address: [" + wrongValue3 + "].]!"); + + //Check if property value hasn't changed. + propertyEditPoup.clickCancel(); + propertiesPage.refreshPage(); + + propertiesPage.propertySearch(property); + String valueAfterEdit = propertiesPage.getPropertyValue(property); + soft.assertEquals(valueAfterEdit, currentValue); + + soft.assertAll(); + } + + @Test(description = "PRP-5 Value is validated according to expected format (cron expression)") + public void PropertyValueCRONexpressionIsValidatedAccordingToExpectedFormat() throws Exception { + + String property = "smp.alert.credentials.cronJobExpression"; + String wrongValue1 = Generator.randomAlphaNumeric(6); + String wrongValue2 = "0 0/1 * * * * *"; + String wrongValue3 = "0 A * * * * "; + + propertiesPage.propertySearch(property); + String currentValue = propertiesPage.getPropertyValue(property); + PropertyPopup propertyEditPoup = propertiesPage.openEditPropertyPopupup(property); + + + propertyEditPoup.editInputField(wrongValue1); + propertyEditPoup.clickOK(); + String error = propertyEditPoup.getErrorMessage(); + soft.assertEquals(error, "Configuration error: [cron expression: [" + wrongValue1 + "]. Error:IllegalArgumentException: Cron expression must consist of 6 fields (found 1 in \"" + wrongValue1 + "\")]!"); + + + propertyEditPoup.editInputField(wrongValue2); + propertyEditPoup.clickOK(); + error = propertyEditPoup.getErrorMessage(); + soft.assertEquals(error, "Configuration error: [cron expression: [" + wrongValue2 + "]. Error:IllegalArgumentException: Cron expression must consist of 6 fields (found 7 in \"" + wrongValue2 + "\")]!"); + + propertyEditPoup.editInputField(wrongValue3); + propertyEditPoup.clickOK(); + error = propertyEditPoup.getErrorMessage(); + soft.assertEquals(error, "Configuration error: [cron expression: [" + wrongValue3 + "]. Error:NumberFormatException: For input string: \"A\"]!"); + + //Check if property value hasn't changed. + propertyEditPoup.clickCancel(); + propertiesPage.refreshPage(); + + propertiesPage.propertySearch(property); + String valueAfterEdit = propertiesPage.getPropertyValue(property); + soft.assertEquals(valueAfterEdit, currentValue); + + soft.assertAll(); + } + + @Test(description = "PRP-5 Value is validated according to expected format (numeric)") + public void PropertyValueNumericIsValidatedAccordingToExpectedFormat() throws Exception { + + String property = "smp.ui.session.idle_timeout.user"; + String wrongValue1 = Generator.randomAlphaNumeric(6); + String wrongValue2 = "333333333333333333333333333333333333333333333333333333"; + String wrongValue3 = "0 A * * * * "; + + propertiesPage.propertySearch(property); + String currentValue = propertiesPage.getPropertyValue(property); + PropertyPopup propertyEditPoup = propertiesPage.openEditPropertyPopupup(property); + + + propertyEditPoup.editInputField(wrongValue1); + propertyEditPoup.clickOK(); + String error = propertyEditPoup.getErrorMessage(); + soft.assertEquals(error, "Configuration error: [Invalid integer: [" + wrongValue1 + "]. Error:NumberFormatException: For input string: \"" + wrongValue1 + "\"]!"); + + + propertyEditPoup.editInputField(wrongValue2); + propertyEditPoup.clickOK(); + error = propertyEditPoup.getErrorMessage(); + soft.assertEquals(error, "Configuration error: [Invalid integer: [" + wrongValue2 + "]. Error:NumberFormatException: For input string: \"" + wrongValue2 + "\"]!"); + + propertyEditPoup.editInputField(wrongValue3); + propertyEditPoup.clickOK(); + error = propertyEditPoup.getErrorMessage(); + soft.assertEquals(error, "Configuration error: [Invalid integer: [" + wrongValue3 + "]. Error:NumberFormatException: For input string: \"" + wrongValue3 + "\"]!"); + + //Check if property value hasn't changed. + propertyEditPoup.clickCancel(); + propertiesPage.refreshPage(); + + propertiesPage.propertySearch(property); + String valueAfterEdit = propertiesPage.getPropertyValue(property); + soft.assertEquals(valueAfterEdit, currentValue); + + soft.assertAll(); + } + +} -- GitLab