8000 Fixing WebDriver issues when using WaitUtils · iingawal/keycloak@9b43a60 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b43a60

Browse files
authored
Fixing WebDriver issues when using WaitUtils
Closes keycloak#52283 Signed-off-by: Lukas Hanusovsky <lhanusov@redhat.com>
1 parent 0439545 commit 9b43a60

6 files changed

Lines changed: 8 additions & 40 deletions

File tree

‎test-framework/ui/src/main/java/org/keycloak/testframework/ui/page/IdpReviewUserProfilePage.java‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,4 @@ public String getExpectedPageId() {
3030
return "login-idp-review-user-profile";
3131
}
3232

33-
@Override
34-
public void assertCurrent() {
35-
driver.waiting().waitForPage(this);
36-
}
3733
}

‎test-framework/ui/src/main/java/org/keycloak/testframework/ui/page/LoginPage.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void fillPassword(String password) {
5555
}
5656

5757
public void submit() {
58-
driver.waiting().waitForPageReload(() -> submitButton.click());
58+
submitButton.click();
5959
}
6060

6161
public void clickSocial(String alias) {

‎test-framework/ui/src/main/java/org/keycloak/testframework/ui/page/LoginUsernamePage.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public void fillLoginWithUsernameOnly(String username) {
3131
}
3232

3333
public String getUsername() {
34-
return usernameInput.getAttribute("value");
34+
return usernameInput.getDomProperty("value");
3535
}
3636

3737
public String getUsernameAutocomplete() {
38-
return usernameInput.getDomAttribute("autocomplete");
38+
return usernameInput.getDomProperty("autocomplete");
3939
}
4040

4141
public String getUsernameInputError() {
@@ -47,7 +47,7 @@ public String getUsernameInputError() {
4747
}
4848

4949
public void submit() {
50-
driver.waiting().waitForPageReload(() -> submitButton.click());
50+
submitButton.click();
5151
}
5252

5353
@Override

‎test-framework/ui/src/main/java/org/keycloak/testframework/ui/page/PasswordPage.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void fillPassword(String password) {
4141
}
4242

4343
public void submit() {
44-
driver.waiting().waitForPageReload(() -> submitButton.click());
44+
submitButton.click();
4545
}
4646

4747
public String getPassword() {

‎test-framework/ui/src/main/java/org/keycloak/testframework/ui/webdriver/PageUtils.java‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import org.keycloak.testframework.ui.page.AbstractPage;
66

77
import org.openqa.selenium.By;
8-
import org.openqa.selenium.StaleElementReferenceException;
9-
import org.openqa.selenium.WebDriverException;
108
import org.openqa.selenium.support.PageFactory;
119

1210
public class PageUtils {
@@ -29,14 +27,7 @@ public <S extends AbstractPage> S createPage(Class<S> valueType) {
2927
}
3028

3129
public String getCurrentPageId() {
32-
try {
33-
return managed.findElement(By.xpath("//body")).getAttribute("data-page-id");
34-
} catch (WebDriverException e) {
35-
if (e.getMessage() != null && e.getMessage().contains("unhandled inspector error")) {
36-
throw new StaleElementReferenceException("Page is mid-navigation (Chrome CDP inspector error)", e);
37-
}
38-
throw e;
39-
}
30+
return managed.findElement(By.xpath("//body")).getAttribute("data-page-id");
4031
}
4132

4233
public String getTitle() {

‎test-framework/ui/src/main/java/org/keycloak/testframework/ui/webdriver/WaitUtils.java‎

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,23 @@
77
import org.keycloak.testframework.ui.page.AbstractPage;
88

99
import org.junit.jupiter.api.Assertions;
10-
import org.openqa.selenium.By;
1110
import org.openqa.selenium.StaleElementReferenceException;
1211
import org.openqa.selenium.TimeoutException;
1312
import org.openqa.selenium.WebDriver;
14-
import org.openqa.selenium.WebElement;
15-
import org.openqa.selenium.support.ui.ExpectedConditions;
1613
import org.openqa.selenium.support.ui.WebDriverWait;
1714

1815
public class WaitUtils {
1916

20-
private static final Duration DEFAULT_TIMEOUT = Duration.ofSeconds(5);
21-
private static final Duration POLL_INTERVAL = Duration.ofMillis(50);
22-
2317
private final ManagedWebDriver managed;
2418

2519
WaitUtils(ManagedWebDriver managed) {
2620
this.managed = managed;
2721
}
2822

2923
public WaitUtils waitForPage(AbstractPage page) {
30-
return waitForPage(page, DEFAULT_TIMEOUT);
31-
}
32-
33-
public WaitUtils waitForPage(AbstractPage page, Duration timeout) {
3424
String expectedPageId = page.getExpectedPageId();
3525
try {
36-
new WebDriverWait(managed.driver(), timeout, POLL_INTERVAL)
37-
.ignoring(StaleElementReferenceException.class)
38-
.until(d -> expectedPageId.equals(managed.page().getCurrentPageId()));
26+
createDefaultWait().ignoring(StaleElementReferenceException.class).until(d -> expectedPageId.equals(managed.page().getCurrentPageId()));
3927
} catch (TimeoutException e) {
4028
Assertions.fail("Expected page '" + expectedPageId + "' to be loaded, but currently on page '" + managed.page().getCurrentPageId() + "' after timeout");
4129
}
@@ -61,19 +49,12 @@ public WaitUtils waitForTitle(String title) {
6149
return this;
6250
}
6351

64-
public WaitUtils waitForPageReload(Runnable action) {
65-
WebElement body = managed.findElement(By.tagName("body"));
66-
action.run();
67-
createDefaultWait().until(ExpectedConditions.stalenessOf(body));
68-
return this;
69-
}
70-
7152
public <V> V until(Function<WebDriver, V> isTrue) {
7253
return createDefaultWait().until(isTrue);
7354
}
7455

7556
private WebDriverWait createDefaultWait() {
76-
return new WebDriverWait(managed.driver(), DEFAULT_TIMEOUT, POLL_INTERVAL);
57+
return new WebDriverWait(managed.driver(), Duration.ofSeconds(5), Duration.ofMillis(50));
7758
}
7859

7960
}

0 commit comments

Comments
 (0)
0