diff --git a/src/org/labkey/test/WebDriverWrapper.java b/src/org/labkey/test/WebDriverWrapper.java index fe0077f074..83bd5dd672 100644 --- a/src/org/labkey/test/WebDriverWrapper.java +++ b/src/org/labkey/test/WebDriverWrapper.java @@ -75,6 +75,7 @@ import org.openqa.selenium.Keys; import org.openqa.selenium.NoAlertPresentException; import org.openqa.selenium.NoSuchElementException; +import org.openqa.selenium.NoSuchWindowException; import org.openqa.selenium.ScriptTimeoutException; import org.openqa.selenium.SearchContext; import org.openqa.selenium.StaleElementReferenceException; @@ -2132,6 +2133,29 @@ public long doAndMaybeWaitForPageToLoad(int msWait, Supplier action) return loadTimer.elapsed().toMillis(); } + public long doAndWaitForWindow(Runnable action, String windowName) + { + return doAndMaybeWaitForPageToLoad(10_000, () -> { + String initialWindow = getDriver().getWindowHandle(); + boolean targetWindowExists; + try + { + getDriver().switchTo().window(windowName); + getDriver().switchTo().window(initialWindow); + targetWindowExists = true; + } + catch (NoSuchWindowException e) + { + targetWindowExists = false; + } + + action.run(); + + getDriver().switchTo().window(windowName); + return targetWindowExists; + }); + } + public long doAndAcceptUnloadAlert(Runnable func, String partialAlertText) { return doAndWaitForPageToLoad(() -> diff --git a/src/org/labkey/test/pages/admin/ConfigureSystemMaintenancePage.java b/src/org/labkey/test/pages/admin/ConfigureSystemMaintenancePage.java index 15961fa834..abf65023eb 100644 --- a/src/org/labkey/test/pages/admin/ConfigureSystemMaintenancePage.java +++ b/src/org/labkey/test/pages/admin/ConfigureSystemMaintenancePage.java @@ -26,9 +26,8 @@ public static ConfigureSystemMaintenancePage beginAt(WebDriverWrapper webDriverW */ public PipelineStatusDetailsPage runMaintenanceTask(String description) { - click(Locator.tagWithAttribute("input", "type", "checkbox") - .followingSibling("a").withText(description)); - getDriver().switchTo().window("systemMaintenance"); + doAndWaitForWindow(() -> click(Locator.tagWithAttribute("input", "type", "checkbox") + .followingSibling("a").withText(description)), "systemMaintenance"); PipelineStatusDetailsPage pipelineStatusDetailsPage = new PipelineStatusDetailsPage(getDriver()); pipelineStatusDetailsPage.waitForComplete();