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

Skip to content
Snippets Groups Projects
SetChangePasswordDialog.java 2.23 KiB
Newer Older
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;
import pages.userSettings.SuccesfullPasswordChangedPopup;
Mihai BOZ's avatar
Mihai BOZ committed
/**
 * Page object for the Set/change password dialog. This contains the locators of the page and the methods for the behaviour of the page
 */
public class SetChangePasswordDialog extends DComponent {
    private final static Logger LOG = LoggerFactory.getLogger(SetChangePasswordDialog.class);
    @FindBy(css = ".smp-field-error")
    List<WebElement> fieldsError;
    @FindBy(id = "cp_id")
    private WebElement currentPasswordInput;
    @FindBy(id = "np_id")
    private WebElement newPasswordInput;
    @FindBy(id = "cnp_id")
    private WebElement confirmationPasswordInput;
    private WebElement setPasswordBtn;


    public SetChangePasswordDialog(WebDriver driver) {
        super(driver);
        PageFactory.initElements(new AjaxElementLocatorFactory(driver, data.getWaitTimeShort()), this);
    public void fillChangePassword(String currentPassword, String newPassword) throws Exception {

        LOG.info("Set new password");
        weToDInput(currentPasswordInput).fill(currentPassword);
Mihai BOZ's avatar
Mihai BOZ committed
        weToDInput(newPasswordInput).fill(newPassword, true);
        weToDInput(confirmationPasswordInput).fill(newPassword, true);
Mihai BOZ's avatar
Mihai BOZ committed
    public DomiSMPPage TryClickOnChangePassword(){
Mihai BOZ's avatar
Mihai BOZ committed
        //wait.forElementToBeClickable(setPasswordBtn);
        if (weToDButton(setPasswordBtn).isEnabled()) {
            weToDButton(setPasswordBtn).click();
            return new DomiSMPPage(driver);
        } else {
            return null;
        }
    }

    public List<String> getFieldErrorMessage() {
        ArrayList<String> fieldErrors = new ArrayList<>();
        if (!fieldsError.isEmpty()) {
            fieldsError.forEach(error -> {
                fieldErrors.add(error.getText());
            });
        }
        return fieldErrors;
    }
}