Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Select Git revision
  • 2792595d0299cd5c84b7b806825a3d5a210e9619
  • development default
  • feature/EDELIVERY-13760-translate-server-side-error-messages
  • release/5.1.x
  • feature/EDELIVERY-15382-rest-api-jwt-authentication-for-dynamic-discovery-client
  • bugfix/EDELIVERY-14172-domismp-accepts-requests-with-wrong-domain-header-value
  • EDELIVERY-15372-upgrade-libraries-and-plugins-and-update-httpclient-to-httpclient5
  • EDELIVERY-15377-migrate-to-angular-20
  • bugfix/EDELIVERY-14196-select-domain-select-resource-dropdown-should-be-order-alphabetically
  • feature/EDELIVERY-12753-sml-integration-migration-to-different-smp
  • feature/EDELIVERY-13757-extend-session-dialog-should-have-an-active-counter
  • EDELIVERY-15144-sql-update
  • bugfix/EDELIVERY-14326-ui-edit-resource-filters
  • feature/EDELIVERY-15144-domismp-system-notification-generalize-time-expiration-alerts
  • bugfix/EDELIVERY-15102-alert-is-not-appearing-when-adding-duplicated-certificate
  • bugfix/EDELIVERY-15203-small-left-grid-shows-no-data-found-for-1-2-seconds-before-loading-the-data
  • EDELIVERY-15219-search-filter-with-understore-char-does-not-work
  • bugfix/EDELIVERY-15226-certificates-error-when-trying-to-delete-certificates
  • bugfix/EDELIVERY-15224-error-when-trying-to-update-info-from-profile-page
  • bugfix/EDELIVERY-15225-emails-are-not-sent-in-domismp
  • feature/EDELIVERY-12746-external-secret-sharing-services-as-vaults
  • 5.1.1
  • 5.1
  • 5.1-TEST
  • 5.1-RC1
  • 5.0.1
  • 5.0
  • 5.0-RC1
  • 4.2
  • 4.2-RC1
  • 4.1.2
  • 4.1.1
  • 4.1.0
  • 4.1.0-RC1
  • 4.0.0
  • 4.0.0-RC1
  • 3.0.2
  • 3.0.1
  • 3.0.0
39 results

ResourcePageGrid.java

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ResourcePageGrid.java 6.31 KiB
    package pages.search;
    
    import ddsl.dcomponents.DComponent;
    import ddsl.dcomponents.Grid.GridPagination;
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.support.PageFactory;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import java.util.List;
    import java.util.NoSuchElementException;
    
    
    public class ResourcePageGrid extends DComponent {
        protected static final By gridHeadersLocator = By.cssSelector("datatable-header div.datatable-row-center datatable-header-cell");
        protected static final By gridRowsLocator = By.cssSelector("datatable-body-row > div.datatable-row-center.datatable-row-group");
        private final static Logger LOG = LoggerFactory.getLogger(ResourcePageGrid.class);
        private final WebElement parentElement;
    
        public ResourcePageGrid(WebDriver driver, WebElement parentElement) {
            super(driver);
            PageFactory.initElements(driver, this);
            this.parentElement = parentElement;
        }
    
        public GridPagination getGridPagination() {
            return new GridPagination(driver, 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("datatable-body-cell"));
        }
    
        public void searchAndClickElementInColumn(String columnName, String value) {
    
            wait.forXMillis(100);
            int numOfPages;
            try {
                numOfPages = getGridPagination().getTotalPageNumber();
            } catch (Exception e) {
                LOG.debug("No pagination found");
                numOfPages = 1;
            }
            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;
            for (int pageNr = 0; pageNr < numOfPages + 1; pageNr++) {
    
                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 on page [{}]", value, pageNr);
                        isElementPresent = true;
                        currentCell.click();
                    }
                }
                if (isElementPresent) {
                    return;
                }
                if (numOfPages > 1) {
                    getGridPagination().goToNextPage();
                }
            }
            if (!isElementPresent) {
                throw new NoSuchElementException("Value [" + value + "] was not found in the grid");
    
            }
    
        }
    
        public void openSubresource(String resourceColumn, String resourceValue, String columnNameSubresouce, String valueSubresource) {
    
            wait.forXMillis(100);
            int numOfPages;
            try {
                numOfPages = getGridPagination().getTotalPageNumber();
            } catch (Exception e) {
                LOG.debug("No pagination found");
                numOfPages = 1;
            }
            List<WebElement> rowHeaders = getGridHeaders();
            int columnIndex = -1;
            for (int i = 0; i < rowHeaders.size(); i++) {
                if (rowHeaders.get(i).getText().equals(resourceColumn)) {
                    columnIndex = i;
                    break;
                }
            }
            if (columnIndex == -1) {
                LOG.error("No element found");
                throw new NoSuchElementException("Column not found");
            }
            boolean isElementPresent = false;
            for (int pageNr = 0; pageNr < numOfPages + 1; pageNr++) {
    
                List<WebElement> rows = getRows();
                for (WebElement row : rows) {
                    List<WebElement> cells = getCells(row);
                    WebElement currentCell = cells.get(columnIndex);
                    if (currentCell.getText().equals(resourceValue)) {
                        LOG.debug("[{}] found on page [{}]", resourceValue, pageNr);
                        isElementPresent = true;
                        currentCell.click();
                        openURLSubresouce(row, columnNameSubresouce, valueSubresource);
                    }
                }
                if (isElementPresent) {
                    return;
                }
                if (numOfPages > 1) {
                    getGridPagination().goToNextPage();
                }
            }
            if (!isElementPresent) {
                throw new NoSuchElementException("Value [" + resourceValue + "] was not found in the grid");
    
            }
    
        }
    
        private void openURLSubresouce(WebElement resourceRow, String columnName, String value) {
            WebElement parentRowElement = resourceRow.findElement(By.xpath("../following-sibling::*[1]"));
            List<WebElement> rowHeaders = parentRowElement.findElements(gridHeadersLocator);
            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 = parentRowElement.findElements(gridRowsLocator);
            for (WebElement row : rows) {
                List<WebElement> cells = getCells(row);
                WebElement currentCell = cells.get(columnIndex);
                if (currentCell.getText().equals(value)) {
                    LOG.debug("[{}] found on page", value);
                    isElementPresent = true;
                    WebElement urlCell = cells.get(2);
                    urlCell.findElement(By.cssSelector("a")).click();
                }
            }
            if (isElementPresent) {
                return;
            }
    
            if (!isElementPresent) {
                throw new NoSuchElementException("Value [" + value + "] was not found in the grid");
    
            }
    
        }
    }