Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
UserDataCommonComponent.java 3.76 KiB
Newer Older
package ddsl.dcomponents.commonComponents;
import ddsl.dcomponents.SetChangePasswordDialog;
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;
Mihai BOZ's avatar
Mihai BOZ committed
/**
 * Common component for user data used in Profile and Users page. This contains the locators of the page and the methods for the behaviour of the page
 */
public class UserDataCommonComponent extends DomiSMPPage {
    private final static Logger LOG = LoggerFactory.getLogger(UserDataCommonComponent.class);
    @FindBy(id = "changePassword_id")
    private WebElement setChangePasswordBtn;
    @FindBy(id = "smpTheme_id")
    private WebElement themeSel;
    @FindBy(id = "smpLocale_id")
    private WebElement localeSel;
    @FindBy(id = "saveButton")
    private WebElement saveBtn;
    @FindBy(id = "emailAddress_id")
    private WebElement emailAddressInput;
    @FindBy(id = "fullName_id")
    private WebElement fullNameInput;
    @FindBy(id = "passwordUpdatedOn_id")
    private WebElement lastSetLbl;
    @FindBy(id = "passwordExpireOn_id")
    private WebElement passwordExpiresOnLbl;
    @FindBy(id = "sequentialLoginFailureCount_id")
    private WebElement seqFailedAttempts;
    @FindBy(id = "LastFailedAttempt_id")
    private WebElement lastFailedAttempt;
    @FindBy(id = "suspendedUtil_id")
    private WebElement suspendedUntil;


    public UserDataCommonComponent(WebDriver driver) {
        super(driver);
        PageFactory.initElements(new AjaxElementLocatorFactory(driver, data.getWaitTimeShort()), this);


    }

    public String getSelectedTheme() {
        return weToDSelect(themeSel).getCurrentValue();
    }

    public String getSelectedLocale() {
        return weToDSelect(localeSel).getCurrentValueAttribute("value");
    }

    public String getEmailAddress() {
        return weToDInput(emailAddressInput).getText();
    }

    public String getFullName() {
        return weToDInput(fullNameInput).getText();
    }

    public String getLastSetValue() {
        return lastSetLbl.getAttribute("value");
    }

    public String getPasswordExpiresOnValue() {
        return passwordExpiresOnLbl.getAttribute("value");
    public String getSequenceFailedAttempts() {
        return seqFailedAttempts.getAttribute("value");
    }

    public String getlastFailedAttempt() {
        return lastFailedAttempt.getAttribute("value");
    }

    public String getsuspendedUntil() {
        return suspendedUntil.getAttribute("value");
    }

Mihai BOZ's avatar
Mihai BOZ committed
    public SetChangePasswordDialog clickOnChangePassword(){
        return new SetChangePasswordDialog(driver);
    }
    public String fillUserProfileData(String emailValue, String fullNameValue, String selectThemeValue, String localeValue) {
        try {
            if (!emailValue.isEmpty()) {
                weToDInput(emailAddressInput).fill(emailValue);
            }
            if (!emailValue.isEmpty()) {
                weToDInput(fullNameInput).fill(fullNameValue);
            }
            weToDSelect(themeSel).selectByVisibleText(selectThemeValue);
            wait.forXMillis(data.getWaitTimeoutShortMilliseconds());
            weToDSelect(localeSel).selectByVisibleText(localeValue);

        } catch (Exception e) {
            LOG.error("Cannot change User Profile Data ", e);
        }

        if (saveBtn.isEnabled()) {
            saveBtn.click();
        } else {
            LOG.debug("Save button is " + saveBtn.isEnabled());
            return getAlertArea().getAlertMessage();
            return null;