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 ea8ca511 authored by Mihai BOZ's avatar Mihai BOZ
Browse files

added tests for Domain page configuration tab

parent c6ef578e
No related branches found
No related tags found
No related merge requests found
Pipeline #216487 failed
Showing
with 431 additions and 9 deletions
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);
}
......
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;
}
}
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();
}
}
}
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();
}
}
}
package ddsl.dobjects;
public class DObjectNotPresentException extends Exception {
}
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();
}
}
......@@ -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();
}
......
......@@ -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) {
......
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();
}
}
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