Skip to content

Commit 17b993e

Browse files
committed
Merge remote-tracking branch 'origin/develop' into fb_moreDomainNameFuzzing
2 parents 7aa58af + 9b0dbab commit 17b993e

17 files changed

+300
-301
lines changed

src/org/labkey/test/WebDriverWrapper.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import org.openqa.selenium.Keys;
7777
import org.openqa.selenium.NoAlertPresentException;
7878
import org.openqa.selenium.NoSuchElementException;
79+
import org.openqa.selenium.NoSuchWindowException;
7980
import org.openqa.selenium.ScriptTimeoutException;
8081
import org.openqa.selenium.SearchContext;
8182
import org.openqa.selenium.StaleElementReferenceException;
@@ -1637,14 +1638,12 @@ public boolean isTextPresent(String... texts)
16371638
if (htmlSource == null || !htmlSource.contains(text))
16381639
present.setFalse();
16391640

1640-
return present.getValue();
1641+
return present.get();
16411642
};
16421643
TextSearcher searcher = new TextSearcher(this);
1643-
searcher.setSearchTransformer(TextSearcher.TextTransformers.IDENTITY);
1644-
searcher.setSourceTransformer(TextSearcher.TextTransformers.IDENTITY);
16451644
searcher.searchForTexts(handler, Arrays.asList(texts));
16461645

1647-
return present.getValue();
1646+
return present.get();
16481647
}
16491648

16501649
public List<String> getTextOrder(TextSearcher searcher, String... texts)
@@ -1735,12 +1734,12 @@ public boolean isAnyTextPresent(String... texts)
17351734
if (htmlSource.contains(text))
17361735
found.setTrue();
17371736

1738-
return !found.getValue(); // stop searching if any value is found
1737+
return !found.get(); // stop searching if any value is found
17391738
};
17401739
TextSearcher searcher = new TextSearcher(this);
17411740
searcher.searchForTexts(handler, Arrays.asList(texts));
17421741

1743-
return found.getValue();
1742+
return found.get();
17441743
}
17451744

17461745
/**
@@ -2140,6 +2139,29 @@ public long doAndMaybeWaitForPageToLoad(int msWait, Supplier<Boolean> action)
21402139
return loadTimer.elapsed().toMillis();
21412140
}
21422141

2142+
public long doAndWaitForWindow(Runnable action, String windowName)
2143+
{
2144+
return doAndMaybeWaitForPageToLoad(10_000, () -> {
2145+
String initialWindow = getDriver().getWindowHandle();
2146+
boolean targetWindowExists;
2147+
try
2148+
{
2149+
getDriver().switchTo().window(windowName);
2150+
getDriver().switchTo().window(initialWindow);
2151+
targetWindowExists = true;
2152+
}
2153+
catch (NoSuchWindowException e)
2154+
{
2155+
targetWindowExists = false;
2156+
}
2157+
2158+
action.run();
2159+
2160+
getDriver().switchTo().window(windowName);
2161+
return targetWindowExists;
2162+
});
2163+
}
2164+
21432165
public long doAndAcceptUnloadAlert(Runnable func, String partialAlertText)
21442166
{
21452167
return doAndWaitForPageToLoad(() ->

src/org/labkey/test/components/ui/Pager.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,41 @@ public int getCurrentPage() // only works on GridPanel
6363

6464
public Pager selectPageSize(String pageSize) // only works on GridPanel
6565
{
66-
int currentPageSize = getPageSize();
67-
if(currentPageSize != Integer.parseInt(pageSize))
68-
{
69-
_pagedComponent.doAndWaitForUpdate(() -> elementCache().jumpToDropdown.clickSubMenu(false, pageSize));
70-
}
66+
pageSize(pageSize);
7167
return this;
7268
}
7369

7470
public int getPageSize() // only works on GridPanel
7571
{
76-
// Changing the jumpToDropdown button from the deprecated DropdownButtonGroup class to a MultiMenu type has changed
77-
// the way that various text from the control is gathered. Getting the current page size now requires that the dropdown
72+
return pageSize(null);
73+
}
74+
75+
/**
76+
* Sets the page size if required (pageSize is specified and doesn't match the current page size)
77+
* @return returns the initial page size
78+
*/
79+
private int pageSize(String pageSize) // only works on GridPanel
80+
{
81+
// Getting the current page size requires that the dropdown
7882
// be expanded and the selected page size found in the list.
7983
elementCache().jumpToDropdown.expand();
8084

8185
// Find the selected li element in the page size list
8286
WebElement activeLi = Locator.byClass("active").findElement(elementCache().jumpToDropdown);
8387

84-
int size = Integer.parseInt(activeLi.getText());
85-
elementCache().jumpToDropdown.collapse();
88+
int initialSize = Integer.parseInt(activeLi.getText());
89+
90+
if (pageSize != null && initialSize != Integer.parseInt(pageSize))
91+
{
92+
_pagedComponent.doAndWaitForUpdate(() -> elementCache().jumpToDropdown.clickSubMenu(false, pageSize));
93+
}
94+
else
95+
{
96+
// Tooltip sometimes blocks button. Click active option to dismiss menu.
97+
activeLi.click();
98+
}
8699

87-
return size;
100+
return initialSize;
88101
}
89102

90103
/**

src/org/labkey/test/components/ui/grids/EditableGrid.java

Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.labkey.test.components.ui.grids.FieldReferenceManager.FieldReference;
2020
import org.labkey.test.params.FieldDefinition;
2121
import org.labkey.test.params.FieldKey;
22+
import org.labkey.test.util.CachingSupplier;
2223
import org.labkey.test.util.selenium.ScrollUtils;
2324
import org.labkey.test.util.selenium.WebElementUtils;
2425
import org.openqa.selenium.By;
@@ -176,55 +177,29 @@ public boolean canRemoveColumn(CharSequence columnIdentifier)
176177

177178
private boolean hasSelectColumn()
178179
{
179-
return elementCache().selectColumn.isDisplayed();
180+
return elementCache().hasSelectColumn.get();
180181
}
181182

182183
public EditableGrid selectRow(int index, boolean checked)
183184
{
184-
if (hasSelectColumn())
185-
{
186-
WebElement checkBox = Locator.css("td > input[type=checkbox]").findElement(getRow(index));
187-
getWrapper().setCheckbox(checkBox, checked);
188-
}
189-
else
190-
{
191-
throw new NoSuchElementException("There is no select checkbox for row " + index);
192-
}
185+
elementCache().getCheckbox(index).set(checked);
193186
return this;
194187
}
195188

196189
public boolean isRowSelected(int index)
197190
{
198-
if (hasSelectColumn())
199-
{
200-
WebElement checkBox = Locator.css("td > input[type=checkbox]").findElement(getRow(index));
201-
return checkBox.isSelected();
202-
}
203-
else
204-
{
205-
throw new NoSuchElementException("There is no select checkbox for row " + index);
206-
}
191+
return elementCache().getCheckbox(index).isSelected();
207192
}
208193

209194
public EditableGrid selectAll(boolean checked)
210195
{
211-
if (hasSelectColumn())
212-
{
213-
getWrapper().setCheckbox(elementCache().selectColumn, checked);
214-
}
215-
else
216-
{
217-
throw new NoSuchElementException("There is no select checkbox for all rows.");
218-
}
196+
elementCache().selectAllCheckbox.set(checked);
219197
return this;
220198
}
221199

222200
public boolean areAllRowsSelected()
223201
{
224-
if (hasSelectColumn())
225-
return new Checkbox(elementCache().selectColumn).isSelected();
226-
else
227-
throw new NoSuchElementException("There is no select checkbox for all rows.");
202+
return elementCache().selectAllCheckbox.isSelected();
228203
}
229204

230205
/**
@@ -237,26 +212,22 @@ public boolean areAllRowsSelected()
237212
public EditableGrid shiftSelectRange(int start, int end)
238213
{
239214
if (!hasSelectColumn())
240-
throw new NoSuchElementException("there is no select checkbox for all rows");
215+
throw new NoSuchElementException("there is no selection column for grid");
241216

242217
var checkBoxes = Locator.tag("tr").child("td")
243218
.child(Locator.tagWithAttribute("input", "type", "checkbox"))
244219
.findElements(elementCache().table);
245-
getWrapper().scrollIntoView(checkBoxes.get(0), true); // bring as much of the grid into view as possible
220+
getWrapper().scrollIntoView(checkBoxes.get(start)); // Make sure the header isn't in the way
221+
checkBoxes.get(start).click();
222+
getWrapper().scrollIntoView(checkBoxes.get(end)); // Actions.click() doesn't scroll
246223
new Actions(getDriver())
247-
.click(checkBoxes.get(start))
248224
.keyDown(Keys.SHIFT)
249225
.click(checkBoxes.get(end))
250226
.keyUp(Keys.SHIFT)
251227
.perform();
252228
return this;
253229
}
254230

255-
private List<WebElement> getRows()
256-
{
257-
return Locators.rows.findElements(elementCache().table);
258-
}
259-
260231
/**
261232
* @param columnIdentifiers fieldKeys, names, or labels of columns
262233
* @return grid data for the specified columns, keyed by column label
@@ -316,7 +287,7 @@ private <T> List<Map<T, String>> getGridData(Function<FieldReferenceManager.Fiel
316287
}
317288
}
318289

319-
for (WebElement row : getRows())
290+
for (WebElement row : elementCache().getRows())
320291
{
321292
List<WebElement> cells = row.findElements(By.tagName("td"));
322293
Map<T, String> rowMap = new LinkedHashMap<>(includedColHeaders.size());
@@ -362,7 +333,7 @@ public List<String> getColumnData(CharSequence columnIdentifier)
362333

363334
private WebElement getRow(int index)
364335
{
365-
return getRows().get(index);
336+
return elementCache().getRows().get(index);
366337
}
367338

368339
/**
@@ -412,7 +383,7 @@ public boolean isCellReadOnly(int row, CharSequence columnIdentifier)
412383

413384
public int getRowCount()
414385
{
415-
return getRows().size();
386+
return elementCache().getRows().size();
416387
}
417388

418389
/**
@@ -682,6 +653,7 @@ public WebElement activateCellUsingDoubleClick(int row, CharSequence columnIdent
682653
// Account for the cell already being active.
683654
if(!textArea.isDisplayed())
684655
{
656+
getWrapper().scrollIntoView(gridCell);
685657
getWrapper().doubleClick(gridCell);
686658
waitFor(textArea::isDisplayed,
687659
String.format("Table cell for row %d and column '%s' was not activated.", row, columnIdentifier), 1_000);
@@ -1111,7 +1083,7 @@ private boolean areAllInSelection()
11111083
List<String> columns = getColumnLabels();
11121084
int selectIndexOffset = hasSelectColumn() ? 1 : 0;
11131085
WebElement indexCell = getCell(0, columns.get(1 + selectIndexOffset));
1114-
WebElement endCell = getCell(getRows().size()-1, columns.get(columns.size()-1));
1086+
WebElement endCell = getCell(elementCache().getRows().size()-1, columns.get(columns.size()-1));
11151087
return (isInSelection(indexCell) && isInSelection(endCell));
11161088
}
11171089

@@ -1244,7 +1216,13 @@ protected class ElementCache extends Component<?>.ElementCache
12441216
final WebElement deleteRowsBtn = Locator.byClass("bulk-remove-button").findWhenNeeded(topControls);
12451217
final ExportMenu exportMenu = ExportMenu.finder(getDriver()).findWhenNeeded(topControls);
12461218
final WebElement table = Locator.byClass("table-cellular").findWhenNeeded(this);
1247-
private final WebElement selectColumn = Locator.xpath("//th/input[@type='checkbox']").findWhenNeeded(table);
1219+
private final Checkbox selectAllCheckbox = new Checkbox(Locator.xpath("//th/input[@type='checkbox']").findWhenNeeded(table));
1220+
private final CachingSupplier<Boolean> hasSelectColumn = new CachingSupplier<>(selectAllCheckbox::isDisplayed);
1221+
1222+
Checkbox getCheckbox(int rowIndex)
1223+
{
1224+
return new Checkbox(Locator.css("td > input[type=checkbox]").findElement(getRow(rowIndex)));
1225+
}
12481226

12491227
protected WebElement getColumnHeaderCell(CharSequence columnIdentifier)
12501228
{
@@ -1317,6 +1295,11 @@ public ReactDateTimePicker datePicker()
13171295
final WebElement addRowsPanel = Locator.byClass("editable-grid__controls").findWhenNeeded(this);
13181296
final Input addCountInput = Input.Input(Locator.name("addCount"), getDriver()).findWhenNeeded(addRowsPanel);
13191297
final WebElement addRowsButton = Locator.byClass("btn-primary").findWhenNeeded(addRowsPanel);
1298+
1299+
List<WebElement> getRows()
1300+
{
1301+
return Locators.rows.findElements(table);
1302+
}
13201303
}
13211304

13221305
protected abstract static class Locators

src/org/labkey/test/pages/ConfigureReportsAndScriptsPage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.labkey.test.util.LogMethod;
2828
import org.labkey.test.util.LoggedParam;
2929
import org.labkey.test.util.TestLogger;
30+
import org.openqa.selenium.WebDriver;
3031
import org.openqa.selenium.WebElement;
3132

3233
import java.io.File;
@@ -45,7 +46,7 @@ public class ConfigureReportsAndScriptsPage extends LabKeyPage
4546
private static final String DEFAULT_ENGINE = "Mozilla Rhino";
4647
private static final String EDIT_WINDOW_TITLE = "Edit Engine Configuration";
4748

48-
public ConfigureReportsAndScriptsPage(WebDriverWrapper test)
49+
public ConfigureReportsAndScriptsPage(WebDriver test)
4950
{
5051
super(test);
5152
waitForEnginesGrid();
@@ -54,7 +55,7 @@ public ConfigureReportsAndScriptsPage(WebDriverWrapper test)
5455
public static ConfigureReportsAndScriptsPage beginAt(WebDriverWrapper driver)
5556
{
5657
driver.beginAt(WebTestHelper.buildURL("core", "configureReportsAndScripts"));
57-
return new ConfigureReportsAndScriptsPage(driver);
58+
return new ConfigureReportsAndScriptsPage(driver.getDriver());
5859
}
5960

6061
public void waitForEnginesGrid()

src/org/labkey/test/pages/admin/ConfigureSystemMaintenancePage.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ public static ConfigureSystemMaintenancePage beginAt(WebDriverWrapper webDriverW
2626
*/
2727
public PipelineStatusDetailsPage runMaintenanceTask(String description)
2828
{
29-
click(Locator.tagWithAttribute("input", "type", "checkbox")
30-
.followingSibling("a").withText(description));
31-
getDriver().switchTo().window("systemMaintenance");
29+
doAndWaitForWindow(() -> click(Locator.tagWithAttribute("input", "type", "checkbox")
30+
.followingSibling("a").withText(description)), "systemMaintenance");
3231

3332
PipelineStatusDetailsPage pipelineStatusDetailsPage = new PipelineStatusDetailsPage(getDriver());
3433
pipelineStatusDetailsPage.waitForComplete();

0 commit comments

Comments
 (0)