Stabilize test testAccountManagementLinkIdentity by waiting for username to appear

Closes #15054
This commit is contained in:
Alexander Schwartz 2022-10-20 11:17:04 +02:00 committed by Hynek Mlnařík
parent ec73533895
commit 9b80bad391

View file

@ -21,6 +21,7 @@ import org.jboss.arquillian.test.api.ArquillianResource;
import org.junit.Assert; import org.junit.Assert;
import org.keycloak.testsuite.util.DroneUtils; import org.keycloak.testsuite.util.DroneUtils;
import org.keycloak.testsuite.util.OAuthClient; import org.keycloak.testsuite.util.OAuthClient;
import org.keycloak.testsuite.util.WaitUtils;
import org.openqa.selenium.By; import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement; import org.openqa.selenium.WebElement;
@ -46,9 +47,6 @@ public class LoginPage extends LanguageComboboxAwarePage {
@FindBy(id = "input-error") @FindBy(id = "input-error")
private WebElement inputError; private WebElement inputError;
@FindBy(id = "totp")
private WebElement totp;
@FindBy(id = "rememberMe") @FindBy(id = "rememberMe")
private WebElement rememberMe; private WebElement rememberMe;
@ -64,15 +62,9 @@ public class LoginPage extends LanguageComboboxAwarePage {
@FindBy(linkText = "Forgot Password?") @FindBy(linkText = "Forgot Password?")
private WebElement resetPasswordLink; private WebElement resetPasswordLink;
@FindBy(linkText = "Username")
private WebElement recoverUsernameLink;
@FindBy(className = "alert-error") @FindBy(className = "alert-error")
private WebElement loginErrorMessage; private WebElement loginErrorMessage;
@FindBy(className = "alert-warning")
private WebElement loginWarningMessage;
@FindBy(className = "alert-success") @FindBy(className = "alert-success")
private WebElement loginSuccessMessage; private WebElement loginSuccessMessage;
@ -85,7 +77,7 @@ public class LoginPage extends LanguageComboboxAwarePage {
public void login(String username, String password) { public void login(String username, String password) {
usernameInput.clear(); clearUsernameInputAndWaitIfNecessary();
usernameInput.sendKeys(username); usernameInput.sendKeys(username);
passwordInput.clear(); passwordInput.clear();
@ -94,6 +86,17 @@ public class LoginPage extends LanguageComboboxAwarePage {
clickLink(submitButton); clickLink(submitButton);
} }
private void clearUsernameInputAndWaitIfNecessary() {
try {
usernameInput.clear();
} catch (NoSuchElementException ex) {
// we might have clicked on a social login icon and might need to wait for the login to appear.
// avoid waiting by default to avoid the delay.
WaitUtils.waitUntilElement(usernameInput).is().present();
usernameInput.clear();
}
}
public void login(String password) { public void login(String password) {
passwordInput.clear(); passwordInput.clear();
passwordInput.sendKeys(password); passwordInput.sendKeys(password);
@ -102,14 +105,14 @@ public class LoginPage extends LanguageComboboxAwarePage {
} }
public void missingPassword(String username) { public void missingPassword(String username) {
usernameInput.clear(); clearUsernameInputAndWaitIfNecessary();
usernameInput.sendKeys(username); usernameInput.sendKeys(username);
passwordInput.clear(); passwordInput.clear();
clickLink(submitButton); clickLink(submitButton);
} }
public void missingUsername() { public void missingUsername() {
usernameInput.clear(); clearUsernameInputAndWaitIfNecessary();
clickLink(submitButton); clickLink(submitButton);
} }
@ -212,10 +215,6 @@ public class LoginPage extends LanguageComboboxAwarePage {
clickLink(resetPasswordLink); clickLink(resetPasswordLink);
} }
public void recoverUsername() {
clickLink(recoverUsernameLink);
}
public void setRememberMe(boolean enable) { public void setRememberMe(boolean enable) {
boolean current = rememberMe.isSelected(); boolean current = rememberMe.isSelected();
if (current != enable) { if (current != enable) {