From 712f24d1b86bb8078007f9a9d1b4a592a403437b Mon Sep 17 00:00:00 2001 From: Chris Joosse Date: Fri, 19 Jan 2024 10:18:10 -0800 Subject: [PATCH] backport test fixes from develop (#1801) --- .../ui/entities/EntityInsertPanel.java | 36 +++++++++++---- .../components/ui/grids/DetailTableEdit.java | 44 +++++++++++++------ 2 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/org/labkey/test/components/ui/entities/EntityInsertPanel.java b/src/org/labkey/test/components/ui/entities/EntityInsertPanel.java index d21ea09126..ce817d21f5 100644 --- a/src/org/labkey/test/components/ui/entities/EntityInsertPanel.java +++ b/src/org/labkey/test/components/ui/entities/EntityInsertPanel.java @@ -187,11 +187,6 @@ public FileUploadPanel getFileUploadPanel() return panel.fileUploadPanel(); } - private Optional optionalGrid() - { - return new EditableGrid.EditableGridFinder(_driver).findOptional(this); - } - public EntityInsertPanel setMergeData(boolean allowMerge) { var panel = showFileUpload(); @@ -213,7 +208,7 @@ public boolean hasMergeOption() protected FileUploadPanel fileUploadPanel() { - return new FileUploadPanel.FileUploadPanelFinder(_driver).timeout(WAIT_FOR_JAVASCRIPT).waitFor(this); + return elementCache().fileUploadPanel(); } private Optional optionalFileUploadPanel() @@ -233,7 +228,7 @@ public List> getGridData() public boolean isGridVisible() { - var optionalGrid = optionalGrid(); + var optionalGrid = elementCache().optionalGrid(); return optionalGrid.isPresent() && optionalGrid.get().isDisplayed(); } @@ -272,7 +267,7 @@ public EntityBulkUpdateDialog clickBulkUpdate() public boolean hasTabs() { - return Locator.tagWithClassContaining("ul", "list-group").existsIn(this); + return elementCache().hasTabs(); } public boolean isFileUploadVisible() @@ -327,6 +322,11 @@ protected boolean isVisible(Locator locator) public EntityInsertPanel showGrid() { + /* either this is a grid-only insert panel, or there will be a mode-select list-item to + allow the user to select the grid. Await one or the other to be present */ + WebDriverWrapper.waitFor(()-> isGridVisible() || hasTabs(), + "Neither the grid nor its selector appeared within the ready timeout", _readyTimeout); + if (!isGridVisible()) { modeSelectListItem("from Grid") @@ -429,8 +429,28 @@ protected class ElementCache extends Component.ElementCache EditableGrid grid = new EditableGrid.EditableGridFinder(_driver).timeout(WAIT_FOR_JAVASCRIPT).findWhenNeeded(); + private Optional optionalGrid() + { + return new EditableGrid.EditableGridFinder(_driver).findOptional(this); + } + + private Optional optionalFileUploadPanel() + { + return new FileUploadPanel.FileUploadPanelFinder(getDriver()).findOptional(); + } + + protected FileUploadPanel fileUploadPanel() + { + return new FileUploadPanel.FileUploadPanelFinder(_driver).timeout(WAIT_FOR_JAVASCRIPT).waitFor(this); + } + WebElement formatString = Locator.tagWithClass("div","file-form-formats") .refindWhenNeeded(this).withTimeout(WAIT_FOR_JAVASCRIPT); + + public boolean hasTabs() + { + return Locator.tagWithClassContaining("ul", "list-group").existsIn(elementCache()); + } } public static class EntityInsertPanelFinder extends WebDriverComponent.WebDriverComponentFinder diff --git a/src/org/labkey/test/components/ui/grids/DetailTableEdit.java b/src/org/labkey/test/components/ui/grids/DetailTableEdit.java index 05af5b9082..b6c4b5ca70 100644 --- a/src/org/labkey/test/components/ui/grids/DetailTableEdit.java +++ b/src/org/labkey/test/components/ui/grids/DetailTableEdit.java @@ -30,6 +30,7 @@ public class DetailTableEdit extends WebDriverComponent selectVa **/ public DetailTableEdit clearSelectValue(String fieldCaption) { - elementCache().findSelect(fieldCaption).clearSelection(); + return clearSelectValue(fieldCaption, true, true); + } + + /** + * Clear a given select field + * @param fieldCaption The caption/label of the field to clear. + * @param waitForSelection If true, wait for the select to have a selection before clearing it + * @param assertSelection If true, assert if no selection appears (note: does nothing if waitForSelection is not true) + * @return + */ + public DetailTableEdit clearSelectValue(String fieldCaption, boolean waitForSelection, boolean assertSelection) + { + var select = elementCache().findSelect(fieldCaption); + if (waitForSelection) + { + if (assertSelection) { + WebDriverWrapper.waitFor(() -> select.hasSelection(), + String.format("The %s select did not have any selection in time", fieldCaption), _readyTimeout); + } + else { + WebDriverWrapper.waitFor(() -> select.hasSelection(), 1000); + } + } + select.clearSelection(); return this; }