From 831b9711f591819e2f789f3640d6a12cf87c7a9c Mon Sep 17 00:00:00 2001 From: Chris Joosse Date: Fri, 1 Dec 2023 14:13:08 -0800 Subject: [PATCH 1/2] change search scope for 'clear' button to avoid silent no-op --- src/org/labkey/test/components/ui/grids/GridBar.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/org/labkey/test/components/ui/grids/GridBar.java b/src/org/labkey/test/components/ui/grids/GridBar.java index 819149df2b..97d39f846f 100644 --- a/src/org/labkey/test/components/ui/grids/GridBar.java +++ b/src/org/labkey/test/components/ui/grids/GridBar.java @@ -196,12 +196,13 @@ public GridBar clearAllSelections() // Clear button can have text values of 'Clear', 'Clear both' or 'Clear all ' so just look for clear. Locator clearBtn = Locator.xpath("//button[contains(text(), 'Clear')]"); - if(clearBtn.findOptionalElement(this).isPresent()) + if(WebDriverWrapper.waitFor(()-> + clearBtn.findOptionalElement(_queryGrid.getComponentElement()).isPresent(), 5_000)) // give it time to appear, else no-op { - WebElement btn = clearBtn.waitForElement(this, 5_000); + WebElement btn = clearBtn.findElement(_queryGrid.getComponentElement()); btn.click(); - WebDriverWrapper.waitFor(() -> clearBtn.findOptionalElement(this).isEmpty(), + WebDriverWrapper.waitFor(() -> clearBtn.findOptionalElement(_queryGrid.getComponentElement()).isEmpty(), WAIT_FOR_JAVASCRIPT); } From d7792c32afc57ca94b8e8e139d6d7b01c6101f7c Mon Sep 17 00:00:00 2001 From: Chris Joosse Date: Mon, 4 Dec 2023 14:40:06 -0800 Subject: [PATCH 2/2] Refactor grid selections out of GridBar, into grid --- .../test/components/ui/grids/GridBar.java | 45 ----------------- .../test/components/ui/grids/QueryGrid.java | 49 +++++-------------- 2 files changed, 12 insertions(+), 82 deletions(-) diff --git a/src/org/labkey/test/components/ui/grids/GridBar.java b/src/org/labkey/test/components/ui/grids/GridBar.java index 97d39f846f..079ac01db9 100644 --- a/src/org/labkey/test/components/ui/grids/GridBar.java +++ b/src/org/labkey/test/components/ui/grids/GridBar.java @@ -7,7 +7,6 @@ import org.junit.Assert; 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.components.html.BootstrapMenu; @@ -28,7 +27,6 @@ import java.util.List; import java.util.Map; -import static org.labkey.test.BaseWebDriverTest.WAIT_FOR_JAVASCRIPT; import static org.labkey.test.WebDriverWrapper.sleep; /** @@ -166,49 +164,6 @@ public QueryGrid clickPrevious() return _queryGrid; } - /** - * Click the 'Select All' button in the grid bar. - * - * @return This grid bar. - */ - public GridBar selectAllRows() - { - Locator selectBtn = Locator.xpath("//button[contains(text(), 'Select all')]"); // Select all n - Locator selectedText = Locator.xpath("//span[@class='QueryGrid-right-spacing' and normalize-space(contains(text(), 'selected'))]"); // n of n - Locator allSelected = Locator.xpath("//span[contains(text(), 'All ')]"); // All n selected - WebElement btn = selectBtn.waitForElement(_queryGrid, 5_000); - btn.click(); - - WebDriverWrapper.waitFor(() -> allSelected.findOptionalElement(this).isPresent() || - selectBtn.findOptionalElement(this).isEmpty() && - selectedText.findOptionalElement(this).isPresent() , - WAIT_FOR_JAVASCRIPT); - - return this; - } - - /** - * Click the 'Clear All' button in the grid bar. - * @return This grid bar. - */ - public GridBar clearAllSelections() - { - // Clear button can have text values of 'Clear', 'Clear both' or 'Clear all ' so just look for clear. - Locator clearBtn = Locator.xpath("//button[contains(text(), 'Clear')]"); - - if(WebDriverWrapper.waitFor(()-> - clearBtn.findOptionalElement(_queryGrid.getComponentElement()).isPresent(), 5_000)) // give it time to appear, else no-op - { - WebElement btn = clearBtn.findElement(_queryGrid.getComponentElement()); - btn.click(); - - WebDriverWrapper.waitFor(() -> clearBtn.findOptionalElement(_queryGrid.getComponentElement()).isEmpty(), - WAIT_FOR_JAVASCRIPT); - } - - return this; - } - /** * Click a button on the grid bar with the given text. * @param buttonCaption Button caption. diff --git a/src/org/labkey/test/components/ui/grids/QueryGrid.java b/src/org/labkey/test/components/ui/grids/QueryGrid.java index 7b221582f9..c8a025eb03 100644 --- a/src/org/labkey/test/components/ui/grids/QueryGrid.java +++ b/src/org/labkey/test/components/ui/grids/QueryGrid.java @@ -292,26 +292,18 @@ public boolean hasSelectAllButton() */ public QueryGrid selectAllRows() { - if (isGridPanel()) + WebElement selectAllBtn = elementCache().selectAllBtnLoc.findWhenNeeded(elementCache()); + if (selectAllBtn.isDisplayed()) { - WebElement selectAllBtn = elementCache().selectAllBtnLoc.findWhenNeeded(elementCache()); - if (selectAllBtn.isDisplayed()) - { - doAndWaitForUpdate(selectAllBtn::click); - } - else - { - ReactCheckBox selectAll = selectAllBox(); - if (selectAll.isIndeterminate() || !selectAll.isChecked()) - { - doAndWaitForUpdate(() -> selectAllOnPage(true, null)); - } - } + doAndWaitForUpdate(selectAllBtn::click); } else { - doAndWaitForUpdate(() -> - getGridBar().selectAllRows()); + ReactCheckBox selectAll = selectAllBox(); + if (selectAll.isIndeterminate() || !selectAll.isChecked()) + { + doAndWaitForUpdate(() -> selectAllOnPage(true, null)); + } } return this; @@ -334,22 +326,14 @@ public QueryGrid clearAllSelections() { if(hasItemsSelected()) { - if (isGridPanel()) + WebElement clearBtn = elementCache().clearBtnLoc.findWhenNeeded(elementCache()); + if (clearBtn.isDisplayed()) { - WebElement clearBtn = elementCache().clearBtnLoc.findWhenNeeded(elementCache()); - if (clearBtn.isDisplayed()) - { - doAndWaitForUpdate(clearBtn::click); - } - else - { - doAndWaitForUpdate(() -> selectAllOnPage(false)); - } + doAndWaitForUpdate(clearBtn::click); } else { - doAndWaitForUpdate(() -> - getGridBar().clearAllSelections()); + doAndWaitForUpdate(() -> selectAllOnPage(false)); } } @@ -708,15 +692,6 @@ public void closeChart() elementCache().closeButton.click(); } - /** - * possible this is either a GridPanel, or a QueryGridPanel (QGP is to be deprecated). - * use this to test which one so we can fork behavior until QGP is gone - */ - private boolean isGridPanel() - { - return elementCache().selectionStatusContainerLoc.existsIn(elementCache()); - } - @Override protected ElementCache newElementCache() {