Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/org/labkey/test/WebDriverWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -2118,25 +2119,29 @@ public long doAndMaybeWaitForPageToLoad(int msWait, Supplier<Boolean> action)

public long doAndWaitForWindow(Runnable action, String windowName)
{
String initialWindow = getDriver().getWindowHandle();
AtomicBoolean targetWindowExists = new AtomicBoolean(false);
try
{
getDriver().switchTo().window(windowName);
targetWindowExists.set(true);
}
catch (NoSuchWindowException e)
{
targetWindowExists.set(false);
}

// Call doAndMaybeWaitForPageToLoad with target window in focus (if present)
// Then it will correctly detect the page load in that window
return doAndMaybeWaitForPageToLoad(10_000, () -> {
String initialWindow = getDriver().getWindowHandle();
boolean targetWindowExists;
try
{
getDriver().switchTo().window(windowName);
if (targetWindowExists.get())
getDriver().switchTo().window(initialWindow);
targetWindowExists = true;
}
catch (NoSuchWindowException e)
{
targetWindowExists = false;
}

action.run();

new WebDriverWait(getDriver(), Duration.ofSeconds(5)).until(windowIsPresent(windowName));

return targetWindowExists;
return targetWindowExists.get();
});
}

Expand Down
72 changes: 39 additions & 33 deletions src/org/labkey/test/util/TestDataGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -428,46 +429,51 @@ private Map<String, Object> generateRow()
private Supplier<Object> getDefaultDataSupplier(PropertyDescriptor propertyDescriptor)
{
Map<String, Object> allProperties = Objects.requireNonNullElse(propertyDescriptor.getAllProperties(), Collections.emptyMap());
String columnType = (String) allProperties.get("conceptURI");
if (columnType == null) columnType = propertyDescriptor.getRangeURI();
Function<String, String> getType = s -> s == null ? "" : s.substring(s.indexOf('#') + 1).toLowerCase().trim();
String conceptUriName = getType.apply((String) allProperties.get("conceptURI"));
String rangeUriName = getType.apply(propertyDescriptor.getRangeURI());

switch (columnType.substring(columnType.indexOf('#') + 1).toLowerCase())
switch (conceptUriName)
{
case "string":
return () -> randomString(20, _excludedChars, _alphaNumericStr ? ALPHANUMERIC_STRING : CHARSET_STRING);
case "int":
return () -> randomInt(0, 20);
case "float":
return () -> randomFloat(0, 20);
case "double":
return () -> randomDouble(0, 20);
case "boolean":
return this::randomBoolean;
case "date":
case "datetime":
return () -> randomDateString(DateUtils.addWeeks(new Date(), -39), new Date());
case "time":
return () ->
randomInt(0, 23) + ":" + // hour
StringUtils.leftPad(String.valueOf(randomInt(0, 59)), 2, "0") + ":" + // minute
StringUtils.leftPad(String.valueOf(randomInt(0, 59)), 2, "0") + "." + // second
StringUtils.leftPad(String.valueOf(randomInt(0, 999)), 3, "0"); // millisecond
case "textchoice":
List<String> textChoices = ((FieldDefinition) propertyDescriptor)
.getValidators().stream()
.map(v -> {
if (v instanceof FieldDefinition.TextChoiceValidator tcv && !tcv.getValues().isEmpty())
return tcv.getValues();
else
return null;
})
.filter(Objects::nonNull)
.findFirst()
.orElseThrow(() -> new IllegalStateException("No choices defined for textChoice field : " + propertyDescriptor.getName()));
.getValidators().stream()
.map(v -> {
if (v instanceof FieldDefinition.TextChoiceValidator tcv && !tcv.getValues().isEmpty())
return tcv.getValues();
else
return null;
})
.filter(Objects::nonNull)
.findFirst()
.orElseThrow(() -> new IllegalStateException("No choices defined for textChoice field : " + propertyDescriptor.getName()));

return () -> randomChoice(textChoices);
default:
throw new IllegalArgumentException("ColumnType " + columnType + " isn't implemented yet");
switch (rangeUriName)
{
case "string":
return () -> randomString(20, _excludedChars, _alphaNumericStr ? ALPHANUMERIC_STRING : CHARSET_STRING);
case "int":
return () -> randomInt(0, 20);
case "float":
return () -> randomFloat(0, 20);
case "double":
return () -> randomDouble(0, 20);
case "boolean":
return this::randomBoolean;
case "date":
case "datetime":
return () -> randomDateString(DateUtils.addWeeks(new Date(), -39), new Date());
case "time":
return () ->
randomInt(0, 23) + ":" + // hour
StringUtils.leftPad(String.valueOf(randomInt(0, 59)), 2, "0") + ":" + // minute
StringUtils.leftPad(String.valueOf(randomInt(0, 59)), 2, "0") + "." + // second
StringUtils.leftPad(String.valueOf(randomInt(0, 999)), 3, "0"); // millisecond
default:
throw new IllegalArgumentException("ColumnType " + conceptUriName + " isn't implemented yet");
}
}
}

Expand Down