diff --git a/domismp-tests/domismp-tests-ui/src/main/java/ddsl/dcomponents/DComponent.java b/domismp-tests/domismp-tests-ui/src/main/java/ddsl/dcomponents/DComponent.java index 1211e6fd633bf6a6a471954cb06359978f779d2a..fae21b8251bd3fc9160d6ce5d3e2876e88e6e08f 100644 --- a/domismp-tests/domismp-tests-ui/src/main/java/ddsl/dcomponents/DComponent.java +++ b/domismp-tests/domismp-tests-ui/src/main/java/ddsl/dcomponents/DComponent.java @@ -1,10 +1,7 @@ package ddsl.dcomponents; import ddsl.dcomponents.mat.MatSelect; -import ddsl.dobjects.DButton; -import ddsl.dobjects.DInput; -import ddsl.dobjects.DSelect; -import ddsl.dobjects.DWait; +import ddsl.dobjects.*; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import utils.TestRunData; @@ -24,6 +21,10 @@ public class DComponent { return new DButton(driver, element); } + protected DCheckbox weToDChecked(WebElement element) { + return new DCheckbox(driver, element); + } + protected DInput weToDInput(WebElement element) { return new DInput(driver, element); } diff --git a/domismp-tests/domismp-tests-ui/src/main/java/ddsl/dcomponents/Grid/GridWithoutPagination.java b/domismp-tests/domismp-tests-ui/src/main/java/ddsl/dcomponents/Grid/GridWithoutPagination.java new file mode 100644 index 0000000000000000000000000000000000000000..6152bbe7ae73a4b9954e3e8ffecbc70bedc75eb1 --- /dev/null +++ b/domismp-tests/domismp-tests-ui/src/main/java/ddsl/dcomponents/Grid/GridWithoutPagination.java @@ -0,0 +1,132 @@ +package ddsl.dcomponents.Grid; + +import ddsl.dcomponents.DComponent; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; +import org.openqa.selenium.support.PageFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.NoSuchElementException; + +public class GridWithoutPagination extends DComponent { + + protected static final By gridHeadersLocator = By.cssSelector("table thead th"); + protected static final By gridRowsLocator = By.cssSelector("table tbody tr"); + private final static Logger LOG = LoggerFactory.getLogger(GridWithoutPagination.class); + private final WebElement parentElement; + + + public GridWithoutPagination(WebDriver driver, WebElement parentElement) { + super(driver); + PageFactory.initElements(driver, this); + this.parentElement = parentElement; + + } + + public List<WebElement> getGridHeaders() { + return parentElement.findElements(gridHeadersLocator); + } + + public List<WebElement> getRows() { + return parentElement.findElements(gridRowsLocator); + } + + public List<WebElement> getCells(WebElement row) { + return row.findElements(By.cssSelector("td")); + } + + public void searchAndDoubleClickElementInColumn(String columnName, String value) { + + wait.forXMillis(100); + List<WebElement> rowHeaders = getGridHeaders(); + int columnIndex = -1; + for (int i = 0; i < rowHeaders.size(); i++) { + if (rowHeaders.get(i).getText().equals(columnName)) { + columnIndex = i; + break; + } + } + if (columnIndex == -1) { + LOG.error("No element found"); + throw new NoSuchElementException("Column not found"); + } + boolean isElementPresent = false; + + + List<WebElement> rows = getRows(); + for (WebElement row : rows) { + List<WebElement> cells = getCells(row); + WebElement currentCell = cells.get(columnIndex); + if (currentCell.getText().equalsIgnoreCase(value)) { + isElementPresent = true; + LOG.debug("Value: " + value + " has been found"); + //Double Click on top right corner of element to prevent clicking on tooltip + Actions act = new Actions(driver); + act.moveToElement(currentCell, currentCell.getSize().getWidth() - 1, 0) + .doubleClick() + .perform(); + + + return; + } + } + LOG.error("Value " + value + " has not been found in the grid"); + } + + public WebElement searchAndGetPrecedentSiblingElementInColumn(String columnName, String value) { + + wait.forXMillis(100); + List<WebElement> rowHeaders = getGridHeaders(); + int columnIndex = -1; + for (int i = 0; i < rowHeaders.size(); i++) { + if (rowHeaders.get(i).getText().equals(columnName)) { + columnIndex = i; + break; + } + } + if (columnIndex == -1) { + return null; + } + List<WebElement> rows = getRows(); + for (WebElement row : rows) { + List<WebElement> cells = getCells(row); + WebElement currentCell = cells.get(columnIndex); + if (currentCell.getText().equals(value)) { + LOG.debug("[{}] found", value); + return currentCell.findElement(By.xpath("preceding-sibling::*")); + } + } + return null; + } + + public WebElement searchAndGetFollowingSiblingElementInColumn(String columnName, String value) { + + wait.forXMillis(100); + List<WebElement> rowHeaders = getGridHeaders(); + int columnIndex = -1; + for (int i = 0; i < rowHeaders.size(); i++) { + if (rowHeaders.get(i).getText().equals(columnName)) { + columnIndex = i; + break; + } + } + if (columnIndex == -1) { + return null; + } + List<WebElement> rows = getRows(); + for (WebElement row : rows) { + List<WebElement> cells = getCells(row); + WebElement currentCell = cells.get(columnIndex); + if (currentCell.getText().equals(value)) { + LOG.debug("[{}] found", value); + return currentCell.findElement(By.xpath("following-sibling::*")); + } + } + return null; + } + +} diff --git a/domismp-tests/domismp-tests-ui/src/main/java/ddsl/dcomponents/commonComponents/domanPropertyEditDialog/DomainPropertyEditDialog.java b/domismp-tests/domismp-tests-ui/src/main/java/ddsl/dcomponents/commonComponents/domanPropertyEditDialog/DomainPropertyEditDialog.java new file mode 100644 index 0000000000000000000000000000000000000000..948d9a38d023f410ce83be15f96271fb1257f05b --- /dev/null +++ b/domismp-tests/domismp-tests-ui/src/main/java/ddsl/dcomponents/commonComponents/domanPropertyEditDialog/DomainPropertyEditDialog.java @@ -0,0 +1,73 @@ +package ddsl.dcomponents.commonComponents.domanPropertyEditDialog; + +import ddsl.dcomponents.DComponent; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.FindBy; +import org.openqa.selenium.support.PageFactory; + +public class DomainPropertyEditDialog extends DComponent { + + @FindBy(css = "#mat-expansion-panel-header-1") + private WebElement propertyNameExpand; + @FindBy(css = "mat-card-content mat-checkbox:nth-of-type(1)") + private WebElement useDefaultValueCheckBox; + @FindBy(css = "mat-card-content mat-form-field div div input") + private WebElement domainValueInput; + @FindBy(css = "mat-card-content mat-checkbox:nth-of-type(2)") + private WebElement domainValueCheckbox; + @FindBy(id = "updatePropertyButton") + private WebElement okBtn; + @FindBy(css = ".mat-mdc-dialog-actions > button:nth-child(2)") + private WebElement cancelBtn; + + public DomainPropertyEditDialog(WebDriver driver) { + super(driver); + PageFactory.initElements(driver, this); + wait.forElementToBeVisible(cancelBtn); + } + + public void setDomainValue(String domainValue) throws Exception { + if (weToDChecked(useDefaultValueCheckBox).isChecked()) { + weToDChecked(useDefaultValueCheckBox).uncheck(); + } + if (weToDInput(domainValueInput).isEnabled()) { + weToDInput(domainValueInput).fill(domainValue); + } + } + + public void setDomainValue(boolean isEnabled) throws Exception { + if (weToDChecked(useDefaultValueCheckBox).isChecked()) { + weToDChecked(useDefaultValueCheckBox).uncheck(); + } + + if (isEnabled) { + if (!weToDChecked(domainValueCheckbox).isChecked()) { + weToDChecked(domainValueCheckbox).check(); + } + } else { + if (weToDChecked(domainValueCheckbox).isChecked()) { + weToDChecked(domainValueCheckbox).uncheck(); + } + } + } + + public void enableSystemValue() throws Exception { + if (!weToDChecked(useDefaultValueCheckBox).isChecked()) { + weToDChecked(useDefaultValueCheckBox).check(); + } + } + + public void disableSystemValue() throws Exception { + if (weToDChecked(useDefaultValueCheckBox).isChecked()) { + weToDChecked(useDefaultValueCheckBox).uncheck(); + } + } + + public void pressOk() { + if (weToDButton(okBtn).isEnabled()) { + weToDButton(okBtn).click(); + } + } + +} diff --git a/domismp-tests/domismp-tests-ui/src/main/java/ddsl/dobjects/DCheckbox.java b/domismp-tests/domismp-tests-ui/src/main/java/ddsl/dobjects/DCheckbox.java new file mode 100644 index 0000000000000000000000000000000000000000..5eb7e86ac3c4e3f6d123101f61d7ad5c6032fb37 --- /dev/null +++ b/domismp-tests/domismp-tests-ui/src/main/java/ddsl/dobjects/DCheckbox.java @@ -0,0 +1,65 @@ +package ddsl.dobjects; + +import org.openqa.selenium.By; +import org.openqa.selenium.ElementNotInteractableException; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +import java.util.List; + +public class DCheckbox extends DObject { + WebElement labelElement; + WebElement input; + + public DCheckbox(WebDriver driver, WebElement element) { + this(driver, element, null); + input = element.findElement(By.cssSelector("input[type='checkbox']")); + } + + public DCheckbox(WebDriver driver, WebElement element, WebElement labelElement) { + super(driver, element); + + this.labelElement = labelElement; + } + + public boolean isChecked() throws Exception { + if (isPresent()) { + if (null != input.getAttribute("checked")) { + return true; + } + List<WebElement> input = element.findElements(By.cssSelector("input[type='checkbox']")); + return !input.isEmpty() && null != input.get(0).getAttribute("checked"); + } + throw new DObjectNotPresentException(); + } + + public void check() throws Exception { + if (isChecked()) return; + if (isEnabled()) { + clickCheckbox(); + wait.forAttributeToContain(element, "class", "checkbox-checked"); + return; + } + throw new Exception("Checkbox is not enabled"); + } + + public void uncheck() throws Exception { + if (!isChecked()) return; + if (isEnabled()) { + clickCheckbox(); + wait.forAttributeToNOTContain(this.element, "class", "checkbox-checked"); + return; + } + throw new Exception("Checkbox is not enabled"); + } + + private void clickCheckbox() { + try { + input.click(); + } catch (ElementNotInteractableException ex) { + // in mat-checkbox the input is actually hidden, and the user has to click on the label to interact with it + if (this.labelElement != null) + this.labelElement.click(); + } + } +} diff --git a/domismp-tests/domismp-tests-ui/src/main/java/ddsl/dobjects/DObjectNotPresentException.java b/domismp-tests/domismp-tests-ui/src/main/java/ddsl/dobjects/DObjectNotPresentException.java new file mode 100644 index 0000000000000000000000000000000000000000..a4fa880193b5a3f42406c3475b0eba5927375c20 --- /dev/null +++ b/domismp-tests/domismp-tests-ui/src/main/java/ddsl/dobjects/DObjectNotPresentException.java @@ -0,0 +1,4 @@ +package ddsl.dobjects; + +public class DObjectNotPresentException extends Exception { +} diff --git a/domismp-tests/domismp-tests-ui/src/main/java/pages/systemSettings/domainsPage/ConfigurationTab/ConfigurationTab.java b/domismp-tests/domismp-tests-ui/src/main/java/pages/systemSettings/domainsPage/ConfigurationTab/ConfigurationTab.java new file mode 100644 index 0000000000000000000000000000000000000000..37a36a9e387ff4483b73ba98193871ef757be3aa --- /dev/null +++ b/domismp-tests/domismp-tests-ui/src/main/java/pages/systemSettings/domainsPage/ConfigurationTab/ConfigurationTab.java @@ -0,0 +1,63 @@ +package pages.systemSettings.domainsPage.ConfigurationTab; + +import ddsl.dcomponents.DComponent; +import ddsl.dcomponents.Grid.GridWithoutPagination; +import ddsl.dcomponents.commonComponents.domanPropertyEditDialog.DomainPropertyEditDialog; +import org.openqa.selenium.By; +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; + +/** + * Page object for the Configuration tab of Domains page. This contains the locators of the page and the methods for the behaviour of the page + */ +public class ConfigurationTab extends DComponent { + private final static Logger LOG = LoggerFactory.getLogger(ConfigurationTab.class); + + @FindBy(css = "[class~=smp-column-data]") + public WebElement rightPanel; + @FindBy(id = "saveButton") + public WebElement saveBtn; + + + public ConfigurationTab(WebDriver driver) { + super(driver); + PageFactory.initElements(new AjaxElementLocatorFactory(driver, data.getWaitTimeShort()), this); + + } + + private GridWithoutPagination getConfigurationGrid() { + return new GridWithoutPagination(driver, rightPanel); + } + + public DomainPropertyEditDialog openProperty(String propertyName) { + getConfigurationGrid().searchAndDoubleClickElementInColumn("Domain property", propertyName); + return new DomainPropertyEditDialog(driver); + } + + public void saveChanges() { + try { + weToDButton(saveBtn).click(); + } catch (Exception e) { + LOG.error("Could not save changes on Configuration tab!"); + } + } + + public Boolean isSystemValueUsed(String propertyName) { + WebElement currentCell = getConfigurationGrid().searchAndGetPrecedentSiblingElementInColumn("Domain property", propertyName); + //check if previous sibling is checked + return currentCell.findElement(By.cssSelector("mat-checkbox")).getAttribute("class").contains("checkbox-checked"); + } + + public String getCurrentPropertyValue(String propertyName) { + WebElement currentCell = getConfigurationGrid().searchAndGetFollowingSiblingElementInColumn("Domain property", propertyName); + //check if previous sibling is checked + return currentCell.getText(); + } + + +} diff --git a/domismp-tests/domismp-tests-ui/src/main/java/pages/systemSettings/domainsPage/DomainsPage.java b/domismp-tests/domismp-tests-ui/src/main/java/pages/systemSettings/domainsPage/DomainsPage.java index 9c95a1c4a9b44a06e332455794dcdb0e79b564f6..4396d1da4dbcb3022083fc1b1740797ce216eb65 100644 --- a/domismp-tests/domismp-tests-ui/src/main/java/pages/systemSettings/domainsPage/DomainsPage.java +++ b/domismp-tests/domismp-tests-ui/src/main/java/pages/systemSettings/domainsPage/DomainsPage.java @@ -7,6 +7,7 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import pages.systemSettings.domainsPage.ConfigurationTab.ConfigurationTab; /** * Page object for the Users page. This contains the locators of the page and the methods for the behaviour of the page @@ -24,11 +25,6 @@ public class DomainsPage extends CommonPageWithTabsAndGrid { return new DButton(driver, addBtn); } - public ResourceTab getResourceTab() { - - return new ResourceTab(driver); - } - public DomainTab getDomainTab() { return new DomainTab(driver); @@ -44,6 +40,11 @@ public class DomainsPage extends CommonPageWithTabsAndGrid { return new MembersTab(driver); } + public ConfigurationTab getConfigurationTab() { + + return new ConfigurationTab(driver); + } + public String getDomainWarningMessage() { return warningLabel.getText(); } diff --git a/domismp-tests/domismp-tests-ui/src/main/java/rest/DomainClient.java b/domismp-tests/domismp-tests-ui/src/main/java/rest/DomainClient.java index 5381669def0680176c8490273202b4ac8559f1af..9ad9941770df29cd2807dd568292a58052987361 100644 --- a/domismp-tests/domismp-tests-ui/src/main/java/rest/DomainClient.java +++ b/domismp-tests/domismp-tests-ui/src/main/java/rest/DomainClient.java @@ -30,6 +30,7 @@ public class DomainClient extends BaseRestClient { public DomainModel createDomain(DomainModel domainModel) { JSONObject domainJson = new JSONObject(domainModel); + startSession(); String createDomainPath = RestServicePaths.getCreateDomainPath(TestRunData.getInstance().getUserId()); ClientResponse response = jsonPUT(resource.path(createDomainPath), domainJson); if (response.getStatus() != 200) { diff --git a/domismp-tests/domismp-tests-ui/src/test/java/domiSMPTests/ui/DomainsPgTests.java b/domismp-tests/domismp-tests-ui/src/test/java/domiSMPTests/ui/DomainsPgTests.java index 782e0272cdd97512f33f4d020667abf9150eb2be..e7dde0bd0c4d018e032c69b7031de2f19099e139 100644 --- a/domismp-tests/domismp-tests-ui/src/test/java/domiSMPTests/ui/DomainsPgTests.java +++ b/domismp-tests/domismp-tests-ui/src/test/java/domiSMPTests/ui/DomainsPgTests.java @@ -1,7 +1,9 @@ package domiSMPTests.ui; import ddsl.DomiSMPPage; +import ddsl.dcomponents.commonComponents.domanPropertyEditDialog.DomainPropertyEditDialog; import ddsl.enums.Pages; +import ddsl.enums.ResourceTypes; import ddsl.enums.ResponseCertificates; import domiSMPTests.SeleniumTest; import org.openqa.selenium.WebElement; @@ -13,7 +15,12 @@ import pages.SmlPage; import pages.administration.editDomainsPage.EditDomainsPage; import pages.systemSettings.domainsPage.DomainsPage; import rest.models.DomainModel; +import rest.models.MemberModel; import rest.models.UserModel; +import utils.TestRunData; + +import java.util.Arrays; +import java.util.List; /** * This class has the tests against Domains Page @@ -173,4 +180,79 @@ public class DomainsPgTests extends SeleniumTest { soft.assertAll(); } + + @Test(description = "DOM-19 - Domain admins are able to change default properties for domains") + public void systemAdminsAreAbleToChangeDefaultPropertiesForDomains() throws Exception { + DomainModel domainModel = DomainModel.generatePublicDomainModelWithSML(); + + MemberModel superMember = new MemberModel(); + superMember.setUsername(TestRunData.getInstance().getAdminUsername()); + superMember.setRoleType("ADMIN"); + + //create domain + domainModel = rest.domains().createDomain(domainModel); + + // rest.domains().addMembersToDomain(domainModel, adminMember); + rest.domains().addMembersToDomain(domainModel, superMember); + + //add resources to domain + List<ResourceTypes> resourcesToBeAdded = Arrays.asList(ResourceTypes.OASIS1, ResourceTypes.OASIS3, ResourceTypes.OASIS2); + domainModel = rest.domains().addResourcesToDomain(domainModel, resourcesToBeAdded); + + domainsPage.refreshPage(); + domainsPage + .getLeftSideGrid().searchAndClickElementInColumn("Domain code", domainModel.getDomainCode()); + domainsPage.goToTab("Configuration"); + + //Check is modifying boolean values + String boolPropertyName = "identifiersBehaviour.scheme.mandatory"; + DomainPropertyEditDialog domainPropertyEditDialog = domainsPage.getConfigurationTab().openProperty(boolPropertyName); + domainPropertyEditDialog.setDomainValue(false); + domainPropertyEditDialog.pressOk(); + domainsPage.getConfigurationTab().saveChanges(); + + //verify changes + soft.assertFalse(domainsPage.getConfigurationTab().isSystemValueUsed(boolPropertyName), "Property is marked as it's using system value"); + soft.assertEquals("false", domainsPage.getConfigurationTab().getCurrentPropertyValue(boolPropertyName)); + + + //Verify disabling system property + String useDomainProperty = "identifiersBehaviour.ParticipantIdentifierScheme.validationRegex"; + domainPropertyEditDialog = domainsPage.getConfigurationTab().openProperty(useDomainProperty); + domainPropertyEditDialog.disableSystemValue(); + domainPropertyEditDialog.pressOk(); + domainsPage.getConfigurationTab().saveChanges(); + //verify changes + soft.assertFalse(domainsPage.getConfigurationTab().isSystemValueUsed(useDomainProperty), "Property is marked as it's using system value"); + + //Verify change to enabling system property + domainPropertyEditDialog = domainsPage.getConfigurationTab().openProperty(useDomainProperty); + domainPropertyEditDialog.enableSystemValue(); + domainPropertyEditDialog.pressOk(); + domainsPage.getConfigurationTab().saveChanges(); + //verify changes + soft.assertTrue(domainsPage.getConfigurationTab().isSystemValueUsed(useDomainProperty)); + + // String property value + String stringProperty = "identifiersBehaviour.caseSensitive.DocumentIdentifierSchemes"; + String defaultPropertyValue = domainsPage.getConfigurationTab().getCurrentPropertyValue(stringProperty); + + domainPropertyEditDialog = domainsPage.getConfigurationTab().openProperty(stringProperty); + domainPropertyEditDialog.setDomainValue("${identifier}${identifier}"); + domainPropertyEditDialog.pressOk(); + domainsPage.getConfigurationTab().saveChanges(); + + soft.assertFalse(domainsPage.getConfigurationTab().isSystemValueUsed(stringProperty), "Property is marked as it's using system value"); + soft.assertTrue(domainsPage.getConfigurationTab().getCurrentPropertyValue(stringProperty).equalsIgnoreCase("${identifier}${identifier}"), "Configuration table is not showing updated value"); + + //Check if the property value is updated with system value after use system value is enabled + domainPropertyEditDialog = domainsPage.getConfigurationTab().openProperty(stringProperty); + domainPropertyEditDialog.enableSystemValue(); + domainPropertyEditDialog.pressOk(); + domainsPage.getConfigurationTab().saveChanges(); + soft.assertTrue(domainsPage.getConfigurationTab().getCurrentPropertyValue(stringProperty).equalsIgnoreCase(defaultPropertyValue), "Configuration table is not showing system value"); + + soft.assertAll(); + } + }