Skip to content

Commit db8d3a7

Browse files
committed
Make refinding a bit less fragile
1 parent 7e6dcb5 commit db8d3a7

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/org/labkey/test/util/DataRegion.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.Collections;
3838
import java.util.List;
3939
import java.util.Map;
40+
import java.util.Objects;
4041
import java.util.TreeMap;
4142
import java.util.regex.Pattern;
4243

@@ -190,7 +191,7 @@ protected String getTableId()
190191
{
191192
if (_tableId == null)
192193
{
193-
String id = _el.getAttribute("id");
194+
String id = Objects.requireNonNull(_el.getAttribute("id"), "Table has no ID");
194195
if (id.endsWith("-form"))
195196
_tableId = id.replace("-form", "");
196197
else
@@ -334,7 +335,7 @@ public static Locator.XPathLocator form(String regionName)
334335
}
335336
}
336337

337-
public class ElementCache extends Component.ElementCache
338+
public class ElementCache extends Component<DataRegion.ElementCache>.ElementCache
338339
{
339340
protected ElementCache()
340341
{
@@ -418,7 +419,7 @@ protected BootstrapMenu getHeaderMenu(String text)
418419

419420
private abstract class BaseDataRegionApi
420421
{
421-
final String regionJS = "LABKEY.DataRegions['" + getDataRegionName().replaceAll("'", "\\\\'") + "']";
422+
final CachingSupplier<String> regionJS = new CachingSupplier<>(() -> "LABKEY.DataRegions['" + getDataRegionName().replaceAll("'", "\\\\'") + "']");
422423

423424
public void executeScript(String methodWithArgs, Object... args)
424425
{
@@ -427,7 +428,7 @@ public void executeScript(String methodWithArgs, Object... args)
427428

428429
public <T> T executeScript(String methodWithArgs, Class<T> expectedResultType, Object... args)
429430
{
430-
return getWrapper().executeScript((expectedResultType != null ? "return " : "") + regionJS + "." + methodWithArgs, expectedResultType, args);
431+
return getWrapper().executeScript((expectedResultType != null ? "return " : "") + regionJS.get() + "." + methodWithArgs, expectedResultType, args);
431432
}
432433

433434
public void callMethod(String apiMethodName, Object... args)
@@ -465,7 +466,7 @@ public <T> T executeScript(String methodWithArgs, Class<T> expectedResultType, O
465466
{
466467
MutableObject<T> result = new MutableObject<>();
467468
doAndWaitForUpdate(() -> result.setValue(super.executeScript(methodWithArgs, expectedResultType, args)));
468-
return result.getValue();
469+
return result.get();
469470
}
470471
}
471472
}

0 commit comments

Comments
 (0)