8000 Fix flaky VerifyProfileTest#testCustomValidationLastName by ahus1 · Pull Request #55173 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading 8000
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@ public WaitUtils waitForPage(AbstractPage page) {
}

public WaitUtils waitForOAuthCallback() {
waitForOAuthCallback(webdriver1 -> webdriver1.getCurrentUrl().contains(OAuth2Constants.CODE + "=") || webdriver1.getCurrentUrl().contains(OAuth2Constants.ERROR + "="));
waitForOAuthCallback(webdriver1 -> {
// match whole parameter names, as the login page URL contains "session_code="
String url = webdriver1.getCurrentUrl();
return hasUrlParameter(url, OAuth2Constants.CODE) || hasUrlParameter(url, OAuth2Constants.ERROR);
});
return this;
}

private static boolean hasUrlParameter(String url, String name) {
return url.contains("?" + name + "=") || url.contains("&" + name + "=") || url.contains("#" + name + "=");
}

public WaitUtils waitForOAuthCallback(Function<? super WebDriver, Boolean> oAuthResponseIsPresent) {
try {
createDefaultWait().until(oAuthResponseIsPresent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@

import org.junit.jupiter.api.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
Expand All @@ -96,6 +97,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand Down Expand Up @@ -442,9 +444,20 @@ public void testCustomValidationLastName() {

verifyProfilePage.assertCurrent();
//submit with error
// the initial page already shows a last name error, so wait for the submitted form to be replaced
WebElement submittedForm = driver.findElement(By.tagName("form"));
verifyProfilePage.update("First", "L");
driver.waiting().until(d -> {
try {
submittedForm.isEnabled();
return false;
} catch (StaleElementReferenceException e) {
return true;
}
});

verifyProfilePage.assertCurrent();
assertNotNull(verifyProfilePage.getInputErrors().getLastNameError());
Comment thread
ahus1 marked this conversation as resolved.
Resolved
//submit OK
verifyProfilePage.update("First", "Last");
managedRealm.cleanup().add(RealmResource::logoutAll);
Expand Down
Loading
0