Skip to content

Commit

Permalink
forward compatibility for core-8340 (#1316)
Browse files Browse the repository at this point in the history
  • Loading branch information
mawinter69 committed Aug 10, 2023
1 parent bf1ceb4 commit 4df8c82
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,14 @@ protected static boolean isStale(WebElement element) {
}
}

protected static boolean isHiddenOrStale(WebElement we) {
try {
return !we.isDisplayed();
} catch (StaleElementReferenceException ser) {
return true;
}
}

/**
* Executes JavaScript.
*/
Expand Down
41 changes: 23 additions & 18 deletions src/main/java/org/jenkinsci/test/acceptance/po/Control.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.openqa.selenium.ElementClickInterceptedException;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

Expand Down Expand Up @@ -118,7 +119,7 @@ public void click() {
WebElement webElement = resolve();
// webElement.submit() despite advertising it does exactly this just blows up :(
webElement.click();
waitFor(webElement).withTimeout(timeout).until(Control::isStale);
waitFor(webElement).withTimeout(timeout).until(Control::isHiddenOrStale);
}


Expand Down Expand Up @@ -185,7 +186,7 @@ public void selectDropdownMenu(Class<?> type) {
waitFor(we).pollingEvery(Duration.ofMillis(100)).withTimeout(Duration.ofSeconds(1)).until(we::isDisplayed);
we.click();
// wait until the menu is hidden
waitFor(we).pollingEvery(Duration.ofMillis(100)).withTimeout(Duration.ofSeconds(1)).until(() -> !we.isDisplayed());
waitFor(we).pollingEvery(Duration.ofMillis(100)).withTimeout(Duration.ofSeconds(10)).until(Control::isHiddenOrStale);
}

public void selectDropdownMenu(String displayName) {
Expand All @@ -206,22 +207,26 @@ public void selectDropdownMenu(String displayName) {
@Override
protected WebElement find(String caption) {
WebElement menuButton = resolve();

// With enough implementations registered the one we are looking for might
// require scrolling in menu to become visible. This dirty hack stretch
// yui menu so that all the items are visible.
executeScript("" +
"YAHOO.util.Dom.batch(" +
" document.querySelector('.yui-menu-body-scrolled')," +
" function (el) {" +
" el.style.height = 'auto';" +
" YAHOO.util.Dom.removeClass(el, 'yui-menu-body-scrolled');" +
" }" +
");"
);
// we can not use `Select` as these are YUI menus and we need to wait for it to be visible
WebElement menu = findElement(menuButton, by.xpath("ancestor::*[contains(@class,'yui-menu-button')]/.."));
return findElement(menu, by.link(caption));
try {
WebElement menu = findElement(menuButton, by.xpath(".."));
return findElement(menu, by.button(caption));
} catch (NoSuchElementException e) {
// With enough implementations registered the one we are looking for might
// require scrolling in menu to become visible. This dirty hack stretch
// yui menu so that all the items are visible.
executeScript("" +
"YAHOO.util.Dom.batch(" +
" document.querySelector('.yui-menu-body-scrolled')," +
" function (el) {" +
" el.style.height = 'auto';" +
" YAHOO.util.Dom.removeClass(el, 'yui-menu-body-scrolled');" +
" }" +
");"
);
// we can not use `Select` as these are YUI menus and we need to wait for it to be visible
WebElement menu = findElement(menuButton, by.xpath("ancestor::*[contains(@class,'yui-menu-button')]/.."));
return findElement(menu, by.link(caption));
}
}
};

Expand Down

0 comments on commit 4df8c82

Please sign in to comment.