diff --git a/src/org/labkey/test/TestProperties.java b/src/org/labkey/test/TestProperties.java index 572df3c078..31e2f23a49 100644 --- a/src/org/labkey/test/TestProperties.java +++ b/src/org/labkey/test/TestProperties.java @@ -205,7 +205,9 @@ public static boolean isDiagnosticsExportEnabled() public static boolean isRunWebDriverHeadless() { - return getBooleanProperty("webtest.webdriver.headless", false); + // Firefox 153 dies opening its first window on the Windows agents, which run as LocalSystem without a desktop + boolean defaultValue = isTestRunningOnTeamCity() && SystemUtils.IS_OS_WINDOWS; + return getBooleanProperty("webtest.webdriver.headless", defaultValue); } public static boolean isDumpBrowserConsole() diff --git a/src/org/labkey/test/WebDriverWrapper.java b/src/org/labkey/test/WebDriverWrapper.java index 1effae6b41..5477a8c6bc 100644 --- a/src/org/labkey/test/WebDriverWrapper.java +++ b/src/org/labkey/test/WebDriverWrapper.java @@ -331,6 +331,11 @@ protected Pair createNewWebDriver(@NotNull Pair createNewWebDriver(@NotNull Pair getFormElement(input).isEmpty(), 500)) + if (isExt4FormField(input)) { - TestLogger.warn("Failed to clear input: " + input); + // clear() blurs the field, which lets an Ext4 form refill it (e.g. with a default) before the text is typed + // Typing in the same sendKeys call as the chord sends it with the modifier still held + input.sendKeys(Keys.chord(WebDriverUtils.MODIFIER_KEY, "a")); + input.sendKeys(text); + } + else + { + input.clear(); + if (!waitFor(()-> getFormElement(input).isEmpty(), 500)) + { + TestLogger.warn("Failed to clear input: " + input); + } + input.sendKeys(text); } - input.sendKeys(text); if (!waitFor(()-> getFormElement(input).equals(text), 500)) { TestLogger.warn("Failed to set input: " + input); @@ -3555,6 +3577,15 @@ else if (text.length() < 1000 && !text.contains("\n") && !text.contains("\t")) } } + private static final Pattern EXT4_FORM_TEXT_CLASS = Pattern.compile("\\bx4-form-text\\b"); + + // Typing over an Ext3 field (e.g. the data region filter dialog) leaves it empty, so this is Ext4 only + private boolean isExt4FormField(WebElement input) + { + String elementClass = input.getDomAttribute("class"); + return elementClass != null && EXT4_FORM_TEXT_CLASS.matcher(elementClass).find(); + } + public void actionClick(WebElement el) { new Actions(getDriver()).moveToElement(el).click().perform(); @@ -3617,19 +3648,37 @@ public void clearClipboardContent() protected void setClipboardContent(String text, boolean isHtml) { - Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); - Transferable sel; - - if (isHtml) + if (useBrowserClipboard()) { - sel = new HtmlFragmentSelection(text); + if (isHtml) + { + executeScript(""" + return navigator.clipboard.write([new ClipboardItem({ + 'text/html': new Blob([arguments[0]], {type: 'text/html'}), + 'text/plain': new Blob([arguments[0]], {type: 'text/plain'}) + })]);""", text); + } + else + { + executeScript("return navigator.clipboard.writeText(arguments[0]);", text); + } } else { - sel = new StringSelection(text); - } + Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); + Transferable sel; + + if (isHtml) + { + sel = new HtmlFragmentSelection(text); + } + else + { + sel = new StringSelection(text); + } - c.setContents(sel, null); + c.setContents(sel, null); + } } protected void setClipboardContent(String text) @@ -3639,6 +3688,11 @@ protected void setClipboardContent(String text) public String getClipboardContent() throws IOException, UnsupportedFlavorException { + if (useBrowserClipboard()) + { + return (String) executeScript("return navigator.clipboard.readText();"); + } + Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); if (t != null) diff --git a/src/org/labkey/test/components/ChartTypeDialog.java b/src/org/labkey/test/components/ChartTypeDialog.java index d0e91e37c7..36701694da 100644 --- a/src/org/labkey/test/components/ChartTypeDialog.java +++ b/src/org/labkey/test/components/ChartTypeDialog.java @@ -20,7 +20,6 @@ import org.labkey.test.pages.TimeChartWizard; import org.labkey.test.selenium.LazyWebElement; import org.labkey.test.util.Ext4Helper; -import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; @@ -334,12 +333,14 @@ private ChartTypeDialog setValue(WebElement target, String columnName, String co WebElement column = elementCache().getColumn(columnName, columnGridCls); getWrapper().scrollIntoView(column); column.click(); - getWrapper(); + WebDriverWrapper.waitFor(target::isDisplayed, "Target element is not displayed", 5000); + Locator.XPathLocator selectionText = Locator.xpath("../div[contains(@class, 'field-area')]//div[contains(@class, 'field-selection-text')]"); + List previousSelection = selectionText.findElements(target); + // Firefox 153 sometimes drops the click on the field area, so retry until the selection re-renders WebDriverWrapper.waitFor(() -> { - return target.isDisplayed(); - }, "Target element is not displayed", 5000); - getWrapper().actionClick(target); // The drop text may be obscured, just need to click the location - getWrapper().waitForFormElementToNotEqual(target.findElement(By.xpath("//div[contains(@class, 'field-selection-text')]")), columnName); + getWrapper().actionClick(target); // The drop text may be obscured, just need to click the location + return WebDriverWrapper.waitFor(() -> selectionText.findElements(target).stream().anyMatch(el -> !previousSelection.contains(el)), 1000); + }, "Column '" + columnName + "' was not applied to the field area", WAIT_FOR_JAVASCRIPT); return this; } diff --git a/src/org/labkey/test/components/ColorPickerInput.java b/src/org/labkey/test/components/ColorPickerInput.java index c57412efeb..fda81226a4 100644 --- a/src/org/labkey/test/components/ColorPickerInput.java +++ b/src/org/labkey/test/components/ColorPickerInput.java @@ -17,13 +17,11 @@ import org.labkey.test.Locator; import org.labkey.test.components.html.Input; -import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.Color; -import java.util.List; - -public class ColorPickerInput extends WebDriverComponent.ElementCache> +public class ColorPickerInput extends WebDriverComponent { private final WebDriver _driver; final WebElement _componentElement; @@ -47,20 +45,31 @@ protected WebDriver getDriver() public void setHexValue(String hexValue) { - List inputs = Locator.tag("input").findElements(this); - if (inputs.isEmpty()) - throw new NoSuchElementException("Input tag not found in color picker"); - WebElement hexInput = inputs.getFirst(); - new Input(hexInput, getDriver()).setWithPaste(hexValue); + setColor(Color.fromString(hexValue)); + } + + public void setColor(Color color) + { + elementCache().hexInput.setWithPaste(color.asHex()); + getWrapper().quickWait().until(_ -> getSelectedColor().equals(color)); + } + + public Color getSelectedColor() + { + return Color.fromString(elementCache().selectedColorDiv.getCssValue("background-color")); + } + + @Override + protected ElementCache newElementCache() + { + return new ElementCache(); } - public String getHexValue() + protected class ElementCache extends Component.ElementCache { - List inputs = Locator.tag("input").findElements(this); - if (inputs.isEmpty()) - throw new NoSuchElementException("Input tag not found in color picker"); - WebElement hexInput = inputs.getFirst(); - return new Input(hexInput, getDriver()).getValue(); + final WebElement inputFooter = Locator.byClass("flexbox-fix").findWhenNeeded(this); + final WebElement selectedColorDiv = Locator.tag("div").findWhenNeeded(inputFooter); + final Input hexInput = Input.Input(Locator.tag("input").withLabel("hex"), getDriver()).findWhenNeeded(inputFooter); } public static class ColorPickerInputFinder extends WebDriverComponentFinder diff --git a/src/org/labkey/test/components/bootstrap/ModalDialog.java b/src/org/labkey/test/components/bootstrap/ModalDialog.java index abb940a100..a45cad7a60 100644 --- a/src/org/labkey/test/components/bootstrap/ModalDialog.java +++ b/src/org/labkey/test/components/bootstrap/ModalDialog.java @@ -128,7 +128,11 @@ public void dismiss(String buttonText) /* for synchronous operations that take time, the caller can specify how long to wait */ public void dismiss(String buttonText, Integer waitSeconds) { - Locators.dismissButton(buttonText).findElement(getComponentElement()).click(); + // Dialogs may render their buttons after loading their content + WebElement button = Locators.dismissButton(buttonText).findWhenNeeded(getComponentElement()); + new WebDriverWait(getDriver(), Duration.ofMillis(WAIT_FOR_JAVASCRIPT)) + .until(ExpectedConditions.elementToBeClickable(button)); + button.click(); waitForClose(waitSeconds); } @@ -180,7 +184,7 @@ static public Locator.XPathLocator dismissButton(String text) public static class ModalDialogFinder extends WebDriverComponent.WebDriverComponentFinder { - private Locator _locator; + private Locator.XPathLocator _locator; public ModalDialogFinder(WebDriver driver) { @@ -206,6 +210,13 @@ public ModalDialogFinder withBodyTextContaining(String text) return this; } + /** Skip a placeholder dialog that only shows a spinner until a loaded dialog replaces it. */ + public ModalDialogFinder withoutLoadingSpinner() + { + _locator = _locator.withoutPredicate(BootstrapLocators.loadingSpinner); + return this; + } + @Override protected ModalDialog construct(WebElement el, WebDriver driver) { diff --git a/src/org/labkey/test/components/domain/BaseDomainDesigner.java b/src/org/labkey/test/components/domain/BaseDomainDesigner.java index 1ed53cb344..a7212263f2 100644 --- a/src/org/labkey/test/components/domain/BaseDomainDesigner.java +++ b/src/org/labkey/test/components/domain/BaseDomainDesigner.java @@ -17,9 +17,11 @@ import org.labkey.test.BootstrapLocators; import org.labkey.test.Locator; +import org.labkey.test.WebDriverWrapper; import org.labkey.test.components.Component; import org.labkey.test.components.WebDriverComponent; import org.labkey.test.util.selenium.ScrollUtils; +import org.openqa.selenium.StaleElementReferenceException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; @@ -89,8 +91,27 @@ public Object clickSave() public List clickSaveExpectingErrors() { + List previousErrors = getErrors(); elementCache().saveButton.click(); - return getWrapper().getTexts(BootstrapLocators.errorBanner.waitForElements(getWrapper().shortWait())).stream() + // The error banner is updated in place rather than re-rendered, so wait for its text to change + return WebDriverWrapper.waitFor(() -> { + try + { + List errors = getErrors(); + return !errors.isEmpty() && !errors.equals(previousErrors) ? errors : null; + } + catch (StaleElementReferenceException ignore) + { + return null; + } + }, + () -> "Save didn't produce new errors. Previous errors: " + previousErrors + ". ", + WebDriverWrapper.WAIT_FOR_JAVASCRIPT); + } + + private List getErrors() + { + return getWrapper().getTexts(BootstrapLocators.errorBanner.findElements(getDriver())).stream() .map(String::trim) .collect(Collectors.toList()); } diff --git a/src/org/labkey/test/components/html/SiteNavBar.java b/src/org/labkey/test/components/html/SiteNavBar.java index 70a8391d7f..1062d5f0ac 100644 --- a/src/org/labkey/test/components/html/SiteNavBar.java +++ b/src/org/labkey/test/components/html/SiteNavBar.java @@ -15,6 +15,7 @@ */ package org.labkey.test.components.html; +import org.apache.commons.lang3.StringUtils; import org.labkey.test.Locator; import org.labkey.test.WebDriverWrapper; import org.labkey.test.components.Component; @@ -29,6 +30,7 @@ import org.labkey.test.pages.search.SearchResultsPage; import org.labkey.test.pages.user.ShowUsersPage; import org.labkey.test.util.AbstractUserHelper; +import org.labkey.test.util.LabKeyExpectedConditions; import org.labkey.test.util.LogMethod; import org.labkey.test.util.LoggedParam; import org.openqa.selenium.NoSuchElementException; @@ -172,8 +174,8 @@ public SearchResultsPage search(String searchTerm) public boolean isSearchBarExpanded() { - String searchBarContainerClass = elementCache().searchContainer.getAttribute("class"); - return searchBarContainerClass.contains("active"); + String searchBarContainerClass = StringUtils.trimToEmpty(elementCache().searchContainer.getAttribute("class")); + return searchBarContainerClass.contains("active") && elementCache().searchInput.isEnabled(); } /* toggles the search form open and returns the search input element */ @@ -183,6 +185,7 @@ public WebElement expandSearchBar() { elementCache().searchToggle.click(); WebDriverWrapper.waitFor(this::isSearchBarExpanded, "Search bar didn't expand", WebDriverWrapper.WAIT_FOR_JAVASCRIPT); + getWrapper().shortWait().until(LabKeyExpectedConditions.animationIsDone(elementCache().searchInput)); } return elementCache().searchInput; } diff --git a/src/org/labkey/test/components/react/QueryChartDialog.java b/src/org/labkey/test/components/react/QueryChartDialog.java index bf603f6b2f..da075a3f13 100644 --- a/src/org/labkey/test/components/react/QueryChartDialog.java +++ b/src/org/labkey/test/components/react/QueryChartDialog.java @@ -334,12 +334,21 @@ public List getYAxisSelectionOptions() private void doAndWaitForPreview(Runnable action) { + waitForPreviewToLoad(); WebElement svg = isPreviewPresent() ? elementCache().svg() : null; action.run(); // preview might not appear after action, but it will definitely go stale. if (svg != null) getWrapper().shortWait().until(ExpectedConditions.stalenessOf(svg)); + waitForPreviewToLoad(); + } + + // Each config change re-queries the preview data, and every response redraws the preview + private void waitForPreviewToLoad() + { + WebDriverWrapper.waitFor(() -> !elementCache().previewLoadingLoc.existsIn(elementCache().previewContainer()), + "The chart preview did not finish loading.", WebDriverWrapper.WAIT_FOR_JAVASCRIPT); } public QueryChartDialog selectYAxisAggregateMethod(String option) @@ -808,6 +817,7 @@ public String grayTextPreviewInstruction() } private final Locator previewBodyLoc = Locator.tagWithClass("div", "chart-builder-preview-body"); + private final Locator previewLoadingLoc = Locator.tagWithClass("div", "chart-loading-mask"); private final Locator svgLoc = Locator.tagWithClass("div", "svg-chart__chart").childTag("svg"); private final Locator svgErrorLoc = Locator.tagWithClass("div", "svg-chart__chart").childTag("div"); diff --git a/src/org/labkey/test/components/react/ReactSelect.java b/src/org/labkey/test/components/react/ReactSelect.java index ee6ac437a6..0be4bed230 100644 --- a/src/org/labkey/test/components/react/ReactSelect.java +++ b/src/org/labkey/test/components/react/ReactSelect.java @@ -18,6 +18,8 @@ import org.jetbrains.annotations.NotNull; import org.labkey.test.Locator; import org.labkey.test.util.TestLogger; +import org.labkey.test.util.selenium.ScrollUtils; +import org.labkey.test.util.selenium.ScrollUtils.Alignment; import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.StaleElementReferenceException; import org.openqa.selenium.WebDriver; @@ -99,7 +101,7 @@ protected void clickOption(String option) try { optionEl = elementCache().findOption(option); - getWrapper().scrollIntoView(optionEl); + scrollOptionIntoView(optionEl); } catch (NoSuchElementException nse) { @@ -135,7 +137,7 @@ protected void clickOption(String option) for (int i = 0; i < 5 && !optionEl.isDisplayed(); i++) { sleep(500); - getWrapper().scrollIntoView(optionEl); + scrollOptionIntoView(optionEl); TestLogger.debug("scroll optionEl into view, attempt " + i); } @@ -147,6 +149,12 @@ protected void clickOption(String option) new FluentWait<>(getWrapper().getDriver()).withTimeout(Duration.ofSeconds(1)).until(ExpectedConditions.stalenessOf(optionEl)); } + // Aligning a tall option to the end of a short menu can scroll its center out of the list, leaving it unclickable + private void scrollOptionIntoView(WebElement optionEl) + { + ScrollUtils.scrollIntoView(optionEl, Alignment.nearest, Alignment.nearest); + } + @Override protected ElementCache newElementCache() { diff --git a/src/org/labkey/test/components/ui/DeleteConfirmationDialog.java b/src/org/labkey/test/components/ui/DeleteConfirmationDialog.java index 2e045a6cba..72c90b12a8 100644 --- a/src/org/labkey/test/components/ui/DeleteConfirmationDialog.java +++ b/src/org/labkey/test/components/ui/DeleteConfirmationDialog.java @@ -71,7 +71,8 @@ public DeleteConfirmationDialog(@NotNull WebDriverWrapper sourcePage, UpdatingCo protected DeleteConfirmationDialog(String partialTitle, @NotNull WebDriverWrapper sourcePage, Function confirmationSynchronizationFunction) { - this(new ModalDialog.ModalDialogFinder(sourcePage.getDriver()).withTitleIgnoreCase(partialTitle), confirmationSynchronizationFunction); + this(new ModalDialog.ModalDialogFinder(sourcePage.getDriver()).withTitleIgnoreCase(partialTitle).withoutLoadingSpinner(), + confirmationSynchronizationFunction); } protected DeleteConfirmationDialog(ModalDialogFinder finder, Function confirmationSynchronizationFunction) @@ -86,7 +87,7 @@ protected void waitForReady() WebDriverWrapper.waitFor(()-> elementCache().body.isDisplayed() && !elementCache().title.getText().isEmpty() && !BootstrapLocators.loadingSpinner.existsIn(this), - "The delete confirmation dialog did not become ready.", 1_000); + "The delete confirmation dialog did not become ready.", WebDriverWrapper.WAIT_FOR_JAVASCRIPT); } public DeleteConfirmationDialog setSkipAuditEventCheck(boolean skipAuditEventCheck) diff --git a/src/org/labkey/test/components/ui/Pager.java b/src/org/labkey/test/components/ui/Pager.java index 1a90ef34c9..5173674a93 100644 --- a/src/org/labkey/test/components/ui/Pager.java +++ b/src/org/labkey/test/components/ui/Pager.java @@ -58,6 +58,7 @@ public Pager jumpToPage(String jumpTo) // only works on GridPanel { _pagedComponent.doAndWaitForUpdate(()-> elementCache().jumpToDropdown.clickSubMenu(false, jumpTo)); + dismissCurrentPageTooltip(); return this; } @@ -86,6 +87,7 @@ public boolean isLastPageAvailable() finally { menu.collapse(); + dismissCurrentPageTooltip(); } } @@ -115,6 +117,7 @@ public boolean isCountAllRowsAvailable() finally { menu.collapse(); + dismissCurrentPageTooltip(); } } @@ -124,6 +127,7 @@ public Pager countAllRows() // Wait for the exact total to render: the summary shows "... of N" (no capped "+"). The total is briefly hidden // behind a spinner while counting, so require the " of " to be back before checking that the "+" is gone. elementCache().jumpToDropdown.clickSubMenu(false, COUNT_ALL_ROWS_OPTION); + dismissCurrentPageTooltip(); WebDriverWrapper.waitFor(() -> summary().contains(" of ") && !summary().contains("+"), "Exact count did not load", 30_000); @@ -169,10 +173,18 @@ private int pageSize(String pageSize) // only works on GridPanel { elementCache().jumpToDropdown.collapse(); } + dismissCurrentPageTooltip(); return initialSize; } + // The 'Current Page' tooltip can linger on Firefox after Selenium interacts with the pager, covering neighboring controls + private void dismissCurrentPageTooltip() + { + getWrapper().mouseOverWithoutScrolling(elementCache().currentPageButton); + getWrapper().mouseOut(); + } + /** * Helper to see if the paging menu is visible. * Basically this is to check issue 45451. diff --git a/src/org/labkey/test/components/ui/domainproperties/EntityTypeDesigner.java b/src/org/labkey/test/components/ui/domainproperties/EntityTypeDesigner.java index 9a691a6445..68bbf00703 100644 --- a/src/org/labkey/test/components/ui/domainproperties/EntityTypeDesigner.java +++ b/src/org/labkey/test/components/ui/domainproperties/EntityTypeDesigner.java @@ -148,8 +148,12 @@ public T setNameExpression(String nameExpression) public String getNameExpressionPreview() { - getWrapper().mouseOver(elementCache().helpTarget("Naming ")); - waitFor(()->elementCache().popover.isDisplayed(), "No tooltip was shown for the Name Expression.", 1_000); + // A hover can miss if a banner shifts the layout while it lands + waitFor(() -> { + getWrapper().mouseOut(); + getWrapper().mouseOver(elementCache().helpTarget("Naming ")); + return waitFor(() -> elementCache().popover.isDisplayed(), 1_000); + }, "No tooltip was shown for the Naming Pattern.", 5_000); return elementCache().popover.getText(); } diff --git a/src/org/labkey/test/components/ui/grids/DetailDataPanel.java b/src/org/labkey/test/components/ui/grids/DetailDataPanel.java index 80626cf14b..2211ad3361 100644 --- a/src/org/labkey/test/components/ui/grids/DetailDataPanel.java +++ b/src/org/labkey/test/components/ui/grids/DetailDataPanel.java @@ -240,8 +240,12 @@ protected Locator locator() if (_asTooltip) return _baseLocatorAsTooltip; else if (_title != null) + { + // Exact match, so "Details" can't find a "Source Details" or "Parent Details" panel that renders first + String title = Locator.xq(_title); return _baseLocator.withChild(Locator.byClass("panel-heading") - .withText().containing(_title)); + .withPredicate("descendant-or-self::*[normalize-space()=" + title + "] or text()[normalize-space()=" + title + "]")); + } else return _baseLocator; } diff --git a/src/org/labkey/test/components/ui/grids/ManageViewsDialog.java b/src/org/labkey/test/components/ui/grids/ManageViewsDialog.java index df3b654286..8299a19b11 100644 --- a/src/org/labkey/test/components/ui/grids/ManageViewsDialog.java +++ b/src/org/labkey/test/components/ui/grids/ManageViewsDialog.java @@ -35,6 +35,7 @@ */ public class ManageViewsDialog extends ModalDialog { + private String _pendingDeleteView; public ManageViewsDialog(WebDriver driver) { @@ -124,6 +125,7 @@ public ManageViewsDialog deleteView(String viewName) Assert.assertTrue(String.format("View named '%s' cannot be deleted.", viewName), canViewBeDeleted(viewName)); Locator.tagWithClass("i", "fa-trash-o").findElement(elementCache().viewRow(viewName)).click(); + _pendingDeleteView = viewName; return this; } @@ -162,6 +164,13 @@ public ManageViewsDialog confirmDelete() WebElement deleteYesButton = elementCache().deleteYesButton; deleteYesButton.click(); getWrapper().quickWait().until(ExpectedConditions.stalenessOf(deleteYesButton)); + if (_pendingDeleteView != null) + { + // The confirmation closes before the view list reloads, and that reload discards any newer confirmation + Locator deletedRow = elementCache().viewRowLoc(_pendingDeleteView); + getWrapper().shortWait().until(wd -> deletedRow.findElements(this).isEmpty()); + _pendingDeleteView = null; + } return this; } @@ -175,6 +184,7 @@ public ManageViewsDialog cancelDelete() WebElement deleteNoButton = elementCache().deleteNoButton; deleteNoButton.click(); getWrapper().quickWait().until(ExpectedConditions.stalenessOf(deleteNoButton)); + _pendingDeleteView = null; return this; } @@ -191,6 +201,9 @@ public ManageViewsDialog revertDefaultView() if(tag.isDisplayed()) { elementCache().revertDefault.click(); + // Closing the dialog before the revert saves reloads the grid with the old default + WebDriverWrapper.waitFor(() -> !Locator.tagWithText("button", "Revert").withClass("clickable-text").existsIn(this), + "Default view was not reverted.", WebDriverWrapper.WAIT_FOR_JAVASCRIPT); } return this; } @@ -224,6 +237,8 @@ public boolean canDefaultBeReverted() public ManageViewsDialog makeViewDefault(String viewName) { Locator.tagWithText("button", "Make default").findElement(elementCache().viewRow(viewName)).click(); + // The saved default is enabled for revert once the view list reloads + var _ = WebDriverWrapper.waitFor(() -> Locator.tagWithText("button", "Revert").withClass("clickable-text").existsIn(this), WebDriverWrapper.WAIT_FOR_JAVASCRIPT); return this; } @@ -250,7 +265,12 @@ protected List viewRows() protected WebElement viewRow(String viewName) { - return Locator.tagWithText("div", viewName).parent("div").withClass("row").findElement(this); + return viewRowLoc(viewName).findElement(this); + } + + protected Locator viewRowLoc(String viewName) + { + return Locator.tagWithText("div", viewName).parent("div").withClass("row"); } protected final WebElement viewNameInput = Locator.tagWithName("input", "gridViewName") diff --git a/src/org/labkey/test/components/ui/grids/TabbedGridPanel.java b/src/org/labkey/test/components/ui/grids/TabbedGridPanel.java index 0526e63cd6..e1de715977 100644 --- a/src/org/labkey/test/components/ui/grids/TabbedGridPanel.java +++ b/src/org/labkey/test/components/ui/grids/TabbedGridPanel.java @@ -20,6 +20,7 @@ import org.labkey.test.components.Component; import org.labkey.test.components.WebDriverComponent; import org.labkey.test.components.react.MultiMenu; +import org.openqa.selenium.NoSuchElementException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.ui.ExpectedConditions; @@ -137,7 +138,17 @@ public QueryGrid selectGrid(String tabText) var tab = elementCache().navTab(tabText); getWrapper().shortWait().until(ExpectedConditions.elementToBeClickable(tab)); tab.click(); - WebDriverWrapper.waitFor(()-> isSelected(tabText), "tab did not become selected in time", 2000); + WebDriverWrapper.waitFor(() -> { + try + { + return isSelected(tabText); + } + catch (NoSuchElementException countReloading) + { + // The tab's row count disappears while the selected grid reloads + return false; + } + }, "tab did not become selected in time", WebDriverWrapper.WAIT_FOR_JAVASCRIPT); getWrapper().shortWait().until(ExpectedConditions.stalenessOf(grid.getComponentElement())); grid = getSelectedGrid(); } diff --git a/src/org/labkey/test/pages/admin/CreateSubFolderPage.java b/src/org/labkey/test/pages/admin/CreateSubFolderPage.java index c505fa6d3f..3d9964aad4 100644 --- a/src/org/labkey/test/pages/admin/CreateSubFolderPage.java +++ b/src/org/labkey/test/pages/admin/CreateSubFolderPage.java @@ -18,9 +18,12 @@ import org.labkey.test.Locator; import org.labkey.test.components.html.Checkbox; import org.labkey.test.pages.LabKeyPage; +import org.labkey.test.util.LabKeyExpectedConditions; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import static org.labkey.test.components.ext4.Checkbox.Ext4Checkbox; + public class CreateSubFolderPage extends LabKeyPage { public CreateSubFolderPage(WebDriver test) @@ -70,7 +73,10 @@ public CreateSubFolderPage createFromTemplateFolder(String templateFolder) _ext4Helper.selectComboBoxItem(Locator.xpath("//div") .withClass("labkey-wizard-header") .withText("Choose Template Folder:").append("/following-sibling::table[contains(@id, 'combobox')]"), templateFolder); - _ext4Helper.checkCheckbox("Include Subfolders"); + Checkbox includeSubfolders = Ext4Checkbox().withLabel("Include Subfolders").waitFor(getDriver()); + // The template options animate in after a template is chosen + shortWait().until(LabKeyExpectedConditions.animationIsDone(includeSubfolders.getComponentElement())); + includeSubfolders.check(); return this; } diff --git a/src/org/labkey/test/pages/core/login/AuthDialogBase.java b/src/org/labkey/test/pages/core/login/AuthDialogBase.java index 3becb894c6..a7076f126f 100644 --- a/src/org/labkey/test/pages/core/login/AuthDialogBase.java +++ b/src/org/labkey/test/pages/core/login/AuthDialogBase.java @@ -16,11 +16,13 @@ package org.labkey.test.pages.core.login; import org.labkey.test.Locator; +import org.labkey.test.WebDriverWrapper; import org.labkey.test.components.bootstrap.ModalDialog; import org.labkey.test.components.html.Input; import org.labkey.test.components.react.ToggleButton; import org.labkey.test.params.login.AuthenticationProvider; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; public abstract class AuthDialogBase> extends ModalDialog { @@ -80,6 +82,10 @@ public T clickApplyExpectingError() { String buttonText = _row == null ? "Finish" : "Apply"; Locators.dismissButton(buttonText).waitForElement(this, 2000).click(); + // Required-field errors show immediately; server validation errors arrive after the save request + WebDriverWrapper.waitFor(() -> Locator.tagWithClassContaining("div", "modal__tiny-error").existsIn(this) || + !Locator.byClass("modal__error-message").findOptionalElement(this).map(WebElement::getText).orElse("").isBlank(), + "No error was shown after applying the configuration.", WebDriverWrapper.WAIT_FOR_JAVASCRIPT); return getThis(); } diff --git a/src/org/labkey/test/tests/DataViewsTest.java b/src/org/labkey/test/tests/DataViewsTest.java index 398ad235de..cf962720fc 100644 --- a/src/org/labkey/test/tests/DataViewsTest.java +++ b/src/org/labkey/test/tests/DataViewsTest.java @@ -476,12 +476,15 @@ public void sortDataViewsTest() waitFor(alphabeticalRadio::isChecked, "Radio button 'Alphabetical' did not become checked after clicking.", 2000); clickButton("Save", 0); _ext4Helper.waitForMaskToDisappear(); - assertTextPresentInThisOrder(CATEGORIES[0], "Abbreviated Demographics", "Alt ID mapping", "APX-1: Abbreviated Physical Exam", + String[] expectedTopCategoryOrder = {CATEGORIES[0], "Abbreviated Demographics", "Alt ID mapping", "APX-1: Abbreviated Physical Exam", "Crosstab: MouseId Counts", "DEM-1: Demographics", "FPX-1: Final Complete Physical Exam", "PRE-1: Pre-Existing Conditions", "R Report: Dataset Column Names", "RCP-1: Reactogenicity-Resolution", "Scatter: Systolic vs Diastolic", "SCL-1: Specimen Collection", "Time Chart: Body Temp + Pulse For Group 2", "Types", - "VAC-1: Post-enrollment Vaccination", "verifyAssay"); + "VAC-1: Post-enrollment Vaccination", "verifyAssay"}; + // The grid reloads asynchronously after the save mask is removed + if (!waitFor(() -> isPresentInThisOrder(expectedTopCategoryOrder) == null, WAIT_FOR_JAVASCRIPT)) + assertTextPresentInThisOrder(expectedTopCategoryOrder); // check if bottom category sorts Alphabetical assertTextPresentInThisOrder(CATEGORIES[4], "ENR-1: Enrollment", "EPX-1: Enrollment Abbreviated Physical Exam", diff --git a/src/org/labkey/test/tests/SampleTypeTest.java b/src/org/labkey/test/tests/SampleTypeTest.java index 759ffe0724..68807763fb 100644 --- a/src/org/labkey/test/tests/SampleTypeTest.java +++ b/src/org/labkey/test/tests/SampleTypeTest.java @@ -325,14 +325,7 @@ public void testOverlappingAliases() containsString("You have 2 field errors.")); checker().screenShotIfNewError("duplicateImportAlias"); - log("Aliases differing only by case are still duplicates."); - createPage = new CreateSampleTypePage(this.getDriver()); - fieldsPanel.getField(fieldTwo).setImportAliases(sharedAlias.toUpperCase()); - checker().verifyThat("Expected an error when two fields share an import alias differing only by case", - String.join("\n", createPage.clickSaveExpectingErrors()), - containsString("You have 2 field errors.")); - checker().screenShotIfNewError("duplicateImportAliasIgnoringCase"); - + // Interleave the scenarios so consecutive saves don't produce identical errors log("Verify there can be no import aliases that collide with field names (case-insensitive)."); createPage = new CreateSampleTypePage(this.getDriver()); fieldsPanel.getField(fieldTwo).setImportAliases(""); @@ -342,8 +335,18 @@ public void testOverlappingAliases() containsString("Import alias '" + fieldTwo + "' on field '" + fieldOne + "' conflicts with a field name.")); checker().screenShotIfNewError("importAliasConflictsWithFieldName"); + log("Aliases differing only by case are still duplicates."); + createPage = new CreateSampleTypePage(this.getDriver()); + fieldsPanel.getField(fieldOne).setImportAliases(sharedAlias); + fieldsPanel.getField(fieldTwo).setImportAliases(sharedAlias.toUpperCase()); + checker().verifyThat("Expected an error when two fields share an import alias differing only by case", + String.join("\n", createPage.clickSaveExpectingErrors()), + containsString("You have 2 field errors.")); + checker().screenShotIfNewError("duplicateImportAliasIgnoringCase"); + log("An alias that matches a field name except for case is still a conflict."); createPage = new CreateSampleTypePage(this.getDriver()); + fieldsPanel.getField(fieldTwo).setImportAliases(""); fieldsPanel.getField(fieldOne).setImportAliases(fieldTwo.toLowerCase()); checker().verifyThat("Expected an error when an import alias matches another field's name except for case", String.join("\n", createPage.clickSaveExpectingErrors()), diff --git a/src/org/labkey/test/util/AuditLogHelper.java b/src/org/labkey/test/util/AuditLogHelper.java index 40195c98fe..cace51875a 100644 --- a/src/org/labkey/test/util/AuditLogHelper.java +++ b/src/org/labkey/test/util/AuditLogHelper.java @@ -463,6 +463,20 @@ public Integer getLastEventId(String containerPath, AuditEvent auditEventName) } } + /** + * Perform an action and wait for it to record a new transaction audit event. + * @return RowId of the new transaction audit event + */ + public Integer doAndWaitForTransaction(Runnable action, String containerPath) + { + int prevTransactionId = Objects.requireNonNullElse(getLastTransactionId(containerPath), -1); + action.run(); + return waitFor(() -> { + Integer transactionId = getLastTransactionId(containerPath); + return transactionId != null && transactionId > prevTransactionId ? transactionId : null; + }, "No new transaction audit event was recorded", WAIT_FOR_JAVASCRIPT); + } + public Integer doAndWaitForTransaction(Runnable action, String containerPath, AuditEvent auditEventName) { int prevTransactionId;