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
  • 604a1e67249622056d6dfc4848fb25a6ff298571
  • development default
  • 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
  • feature/EDELIVERY-15382-rest-api-jwt-authentication-for-dynamic-discovery-client
  • 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
  • release/5.1.x
  • feature/EDELIVERY-12746-external-secret-sharing-services-as-vaults
  • EDELIVERY-15229-upgrade-libraries-and-plugins
  • 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

PageComponent.java

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    PageComponent.java 5.49 KiB
    package pages.components.baseComponents;
    
    
    import org.apache.log4j.Logger;
    import org.openqa.selenium.*;
    import org.openqa.selenium.support.ui.ExpectedCondition;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;
    import utils.PROPERTIES;
    
    
    public class PageComponent {
    
    	protected WebDriver driver;
    	protected WebDriverWait wait;
    	protected Logger log = Logger.getLogger(this.getClass());
    
    
    	public PageComponent(WebDriver driver) {
    		this.driver = driver;
    		this.wait = new WebDriverWait(this.driver, PROPERTIES.TIMEOUT);
    	}
    
    
    	public WebElement waitForElementToBeClickable(WebElement element) {
    		return wait.until(ExpectedConditions.elementToBeClickable(element));
    	}
    
    	public WebElement waitForElementToBeVisible(WebElement element) {
    		return wait.until(ExpectedConditions.visibilityOf(element));
    	}
    
    	public WebElement waitForElementToBeVisible(By elementSelector) {
    		return wait.until(ExpectedConditions.visibilityOfElementLocated(elementSelector));
    	}
    
    	public void waitForElementToBeEnabled(WebElement element) {
    		int maxTimeout = PROPERTIES.SHORT_UI_TIMEOUT * 1000;
    		int waitedSoFar = 0;
    		while ((null != element.getAttribute("disabled")) && (waitedSoFar < maxTimeout)) {
    			waitedSoFar += 300;
    			waitForXMillis(300);
    		}
    	}
    
    	public void waitForElementToBeDisabled(WebElement element) {
    		int maxTimeout = PROPERTIES.SHORT_UI_TIMEOUT * 1000;
    		int waitedSoFar = 0;
    		while ((null == element.getAttribute("disabled")) && (waitedSoFar < maxTimeout)) {
    			waitedSoFar += 300;
    			waitForXMillis(300);
    		}
    	}
    
    
    	public void waitForElementToBeGone(WebElement element) {
    		WebDriverWait myWait = new WebDriverWait(driver, PROPERTIES.SHORT_UI_TIMEOUT);
    
    		try {
    			myWait.until(ExpectedConditions.visibilityOf(element));
    		} catch (Exception e) {
    			return;
    		}
    
    		int waitTime = PROPERTIES.SHORT_UI_TIMEOUT * 1000;
    		while (waitTime > 0) {
    			boolean displayed = true;
    
    			try {
    				displayed = element.isDisplayed();
    			} catch (Exception e) {
    				return;
    			}
    
    			if (!displayed) {
    				return;
    			}
    			waitForXMillis(500);
    			waitTime = waitTime - 500;
    		}
    	}
    
    	public void waitForNumberOfWindowsToBe(int noOfWindows) {
    		try {
    			wait.until(numberOfWindowsToBe(noOfWindows));
    		} catch (Exception e) {
    		}
    	}
    
    	public void clearAndFillInput(WebElement element, String toFill) {
    		waitForElementToBeVisible(element).clear();
    		log.info("cleared input");
    		waitForElementToBeEnabled(element);
    		element.sendKeys(toFill);
    		log.info("filled in text " + toFill);
    	}
    
    	public void clickVoidSpace() {
    		log.info("clicking void");
    		try {
    			waitForXMillis(500);
    			((JavascriptExecutor) driver).executeScript("document.querySelector('[class*=\"overlay-backdrop\"]').click()");
    			waitForXMillis(500);
    		} catch (Exception e) {
    		}
    		waitForXMillis(500);
    	}
    
    	private ExpectedCondition<Boolean> numberOfWindowsToBe(final int numberOfWindows) {
    		return new ExpectedCondition<Boolean>() {
    			@Override
    			public Boolean apply(WebDriver driver) {
    				driver.getWindowHandles();
    				return driver.getWindowHandles().size() == numberOfWindows;
    			}
    		};
    	}
    
    	public void waitForXMillis(Integer millis) {
    		try {
    			Thread.sleep(millis);
    		} catch (InterruptedException e) {
    			log.error("EXCEPTION: ", e);
    		}
    	}
    
    	public void waitForAttributeNotEmpty(WebElement element, String attributeName) {
    		wait.until(ExpectedConditions.attributeToBeNotEmpty(element, attributeName));
    	}
    
    	public void waitForElementToHaveText(WebElement element, String title) {
    		wait.until(ExpectedConditions.textToBePresentInElement(element, title));
    	}
    
    	public void waitForElementToBe(WebElement element) {
    
    		wait.until(new ExpectedCondition<Boolean>() {
    			@Override
    			public Boolean apply(WebDriver driver) {
    				return element.getLocation() != null;
    			}
    		});
    
    	}
    
    	public void waitForAttributeToContain(WebElement element, String attributeName, String value) {
    		wait.until(ExpectedConditions.attributeContains(element, attributeName, value));
    	}
    
    	public void waitForElementToHaveText(WebElement element) {
    		wait.until(new ExpectedCondition<Boolean>() {
    			@Override
    			public Boolean apply(WebDriver driver) {
    				return !element.getText().trim().isEmpty();
    			}
    		});
    	}
    
    	public void waitForElementToContainText(WebElement element, String text) {
    		wait.until(ExpectedConditions.textToBePresentInElement(element, text));
    	}
    
    	public boolean isVisible(WebElement element){
    		log.info("checking if element is visible");
    
    		try {
    			waitForElementToBe(element);
    			return element.isDisplayed();
    		} catch (Exception e) {		}
    		return false;
    	}
    
    	public boolean isEnabled(WebElement element){
    		log.info("checking if element is enabled");
    		try {
    			waitForElementToBeEnabled(element);
    		} catch (Exception e) {
    			return false;
    		}
    		return element.isEnabled();
    	}
    
    	public boolean isDisabled(WebElement element){
    		log.info("checking if element is disabled");
    		try {
    			waitForElementToBeDisabled(element);
    		} catch (Exception e) {
    			return false;
    		}
    		return true;
    	}
    
    
    	protected By loadingBar = By.className("mat-ripple-element");
    
    	public void waitForRowsToLoad() {
    		log.info("waiting for rows to load");
    		try {
    			waitForElementToBeVisible(loadingBar);
    
    			int bars = 1;
    			int waits = 0;
    			while (bars > 0 && waits < 30) {
    				Object tmp = ((JavascriptExecutor) driver).executeScript("return document.querySelectorAll('.mat-ripple-element').length;");
    				bars = Integer.valueOf(tmp.toString());
    				waits++;
    				waitForXMillis(500);
    			}
    			log.debug("waited for rows to load for ms = 500*" + waits);
    		} catch (Exception e) {	}
    		waitForXMillis(500);
    	}
    
    
    
    }