Skip to content

Commit 264bb36

Browse files
authored
Fix intermittent failure in SNDTest and cleanup some helpers (#1020)
1 parent d8a73e6 commit 264bb36

4 files changed

Lines changed: 103 additions & 89 deletions

File tree

snd/test/src/org/labkey/test/components/snd/CategoryEditRow.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public WebDriver getDriver()
5757
public CategoryEditRow setDescription(String value)
5858
{
5959
elementCache().descriptionInput.set(value);
60-
getWrapper().waitFor(()-> elementCache().descriptionInput.get() == value, 2000);
60+
WebDriverWrapper.waitFor(()-> value.equals(elementCache().descriptionInput.get()), 2000);
6161
return this;
6262
}
6363

@@ -80,7 +80,7 @@ public boolean getIsActive()
8080
public void delete()
8181
{
8282
getWrapper().fireEvent(elementCache().deleteLI, WebDriverWrapper.SeleniumEvent.mouseover);
83-
getWrapper().waitFor(()-> elementCache().deleteLI.isEnabled() && elementCache().deleteLI.isSelected(), 2000);
83+
WebDriverWrapper.waitFor(()-> elementCache().deleteLI.isEnabled() && elementCache().deleteLI.isSelected(), 2000);
8484
elementCache().deleteLI.click();
8585
}
8686

@@ -90,7 +90,7 @@ protected ElementCache newElementCache()
9090
return new ElementCache();
9191
}
9292

93-
protected class ElementCache extends Component.ElementCache
93+
protected class ElementCache extends Component<?>.ElementCache
9494
{
9595
Input descriptionInput = Input(Locators.descriptionEdit(), getDriver()).timeout(4000).findWhenNeeded(this);
9696
Checkbox activeCheckBox = Checkbox.Checkbox(

snd/test/src/org/labkey/test/components/snd/SuperPackageRow.java

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,38 +61,41 @@ public boolean isSelected()
6161
public SuperPackageRow select() // note: this 'selection' behavior is expressed among assigned packages, not among available packages
6262
{
6363
if (!isSelected())
64-
newElementCache().desc.click();
65-
getWrapper().waitFor(()-> isSelected(),
64+
elementCache().desc.click();
65+
WebDriverWrapper.waitFor(this::isSelected,
6666
"row item never became selected",2000);
6767
return this;
6868
}
6969

7070
public String getLabel()
7171
{
72-
return newElementCache().desc.getText();
72+
return elementCache().desc.getText();
7373
}
7474

7575
public SuperPackageRow clickMenuItem(String menuText)
7676
{
77-
getWrapper().fireEvent(newElementCache().menuToggle, WebDriverWrapper.SeleniumEvent.mouseover);
78-
newElementCache().menuToggle.click();
79-
// wait for the menu to expand
80-
getWrapper().waitFor(()-> newElementCache().menuToggle.getAttribute("class").contains("open"), 1000);
81-
Locator menuItem = Locator.tagWithAttribute("li", "role", "presentation")
82-
.child(Locator.tagWithAttribute("a", "role", "menuitem")
83-
.containing(menuText));
84-
WebElement itemToClick = menuItem.waitForElement(getComponentElement(), 2000);
85-
getWrapper().fireEvent(newElementCache().menuToggle, WebDriverWrapper.SeleniumEvent.mouseover);
86-
getWrapper().waitFor(()-> itemToClick.isEnabled(), 2000);
87-
itemToClick.click();
88-
// wait for the menu to collapse (or disappear, if 'remove' was the action')
89-
getWrapper().waitFor(()-> {
90-
try
91-
{
92-
return newElementCache().menuToggle.getAttribute("aria-expanded").equals("false");
93-
}catch (StaleElementReferenceException sere){return true;}
94-
}, 1000);
95-
return this;
77+
getWrapper().mouseOver(this.getComponentElement());
78+
elementCache().menuToggle.click();
79+
// wait for the menu to expand
80+
WebDriverWrapper.waitFor(() -> elementCache().menuToggle.getAttribute("aria-expanded").equals("true"), () -> "Menu didn't open: " + getLabel(), 1000);
81+
Locator menuItem = Locator.tagWithAttribute("li", "role", "presentation")
82+
.child(Locator.tagWithAttribute("a", "role", "menuitem")
83+
.containing(menuText));
84+
WebElement itemToClick = menuItem.waitForElement(getComponentElement(), 2000);
85+
WebDriverWrapper.waitFor(itemToClick::isEnabled, () -> "Menu item not enabled: " + menuText, 2000);
86+
itemToClick.click();
87+
// wait for the menu to collapse (or disappear, if 'remove' was the action')
88+
WebDriverWrapper.waitFor(() -> {
89+
try
90+
{
91+
return elementCache().menuToggle.getAttribute("aria-expanded").equals("false");
92+
}
93+
catch (StaleElementReferenceException sere)
94+
{
95+
return true;
96+
}
97+
}, "Menu didn't close", 1000);
98+
return this;
9699
}
97100

98101
@Override
@@ -101,7 +104,7 @@ protected ElementCache newElementCache()
101104
return new ElementCache();
102105
}
103106

104-
protected class ElementCache extends Component.ElementCache
107+
protected class ElementCache extends Component<?>.ElementCache
105108
{
106109
public WebElement menuToggle = Locator.tagWithClassContaining("div", "btn-group") // sometimes dropdown, dropup
107110
.child(Locator.id("superpackage-actions"))

snd/test/src/org/labkey/test/pages/snd/EditCategoriesPage.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
import org.labkey.test.Locator;
1919
import org.labkey.test.WebDriverWrapper;
2020
import org.labkey.test.WebTestHelper;
21+
import org.labkey.test.components.bootstrap.ModalDialog;
2122
import org.labkey.test.components.snd.CategoryEditRow;
2223
import org.labkey.test.pages.LabKeyPage;
2324
import org.openqa.selenium.WebDriver;
2425
import org.openqa.selenium.WebElement;
26+
import org.openqa.selenium.support.ui.ExpectedConditions;
2527

2628
import java.util.List;
2729

@@ -73,18 +75,32 @@ public List<CategoryEditRow> getAllCategories()
7375

7476
public EditCategoriesPage clickSave()
7577
{
76-
waitFor(()-> elementCache().saveButton.getAttribute("disabled")==null,
77-
"'Save' button is disabled", 2000);
78-
elementCache().saveButton.click();
79-
sleep(1000); // todo: wait for save button to detatch/unmount before re-mounting into next page view
78+
return clickSave(false);
79+
}
80+
81+
public EditCategoriesPage clickSaveAndConfirmDelete()
82+
{
83+
return clickSave(true);
84+
}
85+
86+
public EditCategoriesPage clickSave(boolean confirmDelete)
87+
{
88+
shortWait().until(ExpectedConditions.elementToBeClickable(elementCache().saveButton)).click();
89+
if (confirmDelete)
90+
{
91+
new ModalDialog.ModalDialogFinder(getDriver())
92+
.withBodyTextContaining("Are you sure you want to delete row").find()
93+
.dismiss("Submit Changes");
94+
}
95+
shortWait().until(ExpectedConditions.stalenessOf(elementCache().saveButton));
96+
clearCache();
8097
return new EditCategoriesPage(getDriver());
8198
}
8299

83100
public PackageListPage clickCancel()
84101
{
85-
waitFor(()-> elementCache().cancelButton.getAttribute("disabled")==null,
86-
"'Cancel' button is disabled", 2000);
87-
elementCache().cancelButton.click();
102+
shortWait().until(ExpectedConditions.elementToBeClickable(elementCache().cancelButton)).click();
103+
shortWait().until(ExpectedConditions.stalenessOf(elementCache().cancelButton));
88104
return new PackageListPage(getDriver());
89105
}
90106

@@ -98,7 +114,7 @@ protected class ElementCache extends LabKeyPage.ElementCache
98114
{
99115
// TODO: Add other elements that are on the page
100116
WebElement addCategoriesBtn = Locator.tag("div").containing("Add Category")
101-
.withChild(Locator.tagWithClass("i", "fa fa-plus-circle"))
117+
.withChild(Locator.tagWithClass("i", "fa-plus-circle"))
102118
.findWhenNeeded(getDriver()).withTimeout(4000);
103119
WebElement cancelButton = Locator.button("Cancel").findWhenNeeded(getDriver()).withTimeout(4000);
104120
WebElement saveButton = Locator.button("Save").findWhenNeeded(getDriver()).withTimeout(4000);

0 commit comments

Comments
 (0)