Skip to content
Open
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
30 changes: 15 additions & 15 deletions src/org/labkey/test/TestProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.labkey.serverapi.reader.Readers;
import org.labkey.test.util.CachingSupplier;
import org.labkey.test.util.CspLogUtil;
import org.labkey.test.util.TestDataGenerator;
import org.labkey.test.util.TestLogger;
import org.labkey.test.util.Version;
import org.openqa.selenium.Dimension;

Expand All @@ -42,41 +43,41 @@
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public abstract class TestProperties
{
private static final Logger LOG = LogManager.getLogger(TestProperties.class);

static
{
final File propFile = new File(TestFileUtils.getTestRoot(), "test.properties");
final File propFileTemplate = new File(TestFileUtils.getTestRoot(), "test.properties.template");
if (!propFile.exists())
{
TestLogger.log(String.format("'%s' does not exist. Creating default from '%s'", propFile.getName(), propFileTemplate.getName()));
LOG.info("'{}' does not exist. Creating default from '{}'", propFile.getName(), propFileTemplate.getName());
try (Stream<String> propStream = Files.lines(propFileTemplate.toPath()))
{
final Iterator<String> iterator = propStream.filter(line -> !line.startsWith("#!!")).iterator();
Files.write(propFile.toPath(), (Iterable<String>) () -> iterator, StandardOpenOption.CREATE_NEW);
}
catch (IOException e)
{
TestLogger.error(e.getMessage());
LOG.error(e.getMessage(), e);
}
}
try (Reader propReader = Readers.getReader(propFile))
{
TestLogger.log("Loading properties from " + propFile.getName());
LOG.info("Loading properties from {}", propFile.getName());
Properties properties = new Properties();
properties.load(propReader);
properties.putAll(System.getProperties());
System.setProperties(properties);
}
catch (IOException ioe)
{
TestLogger.error("Failed to load " + propFile.getName() + " file. Running with hard-coded defaults");
ioe.printStackTrace(System.err);
LOG.error("Failed to load {} file. Running with hard-coded defaults", propFile.getName(), ioe);
}

final List<String> gradleProperties = List.of("labkeyVersion");
Expand All @@ -85,7 +86,7 @@ public abstract class TestProperties
{
try (Reader propReader = Readers.getReader(serverPropFile))
{
TestLogger.log("Loading properties from " + serverPropFile.getName());
LOG.info("Loading properties from {}", serverPropFile.getName());
Properties properties = new Properties();
properties.load(propReader);
for (String key : gradleProperties)
Expand All @@ -98,8 +99,7 @@ public abstract class TestProperties
}
catch (IOException ioe)
{
TestLogger.error("Failed to load " + serverPropFile.getName() + " file.");
ioe.printStackTrace(System.err);
LOG.error("Failed to load {} file.", serverPropFile.getName(), ioe);
}
}

Expand Down Expand Up @@ -298,9 +298,9 @@ public static boolean isTroubleshootingStacktracesEnabled()
return getBooleanProperty("webtest.troubleshooting.stacktraces", false);
}

public static boolean isDebugLoggingEnabled()
public static String getTestLogLevel()
{
return getBooleanProperty("webtest.logging.debug", false);
return System.getProperty("webtest.log.level");
}

public static boolean isPrimaryUserAppAdmin()
Expand Down Expand Up @@ -432,7 +432,7 @@ public static File getDumpDir()
"Tried system properties failure.output.dir and java.io.tmpdir");
}

TestLogger.log("Using " + dumpDir + " to store test output");
LOG.info("Using {} to store test output", dumpDir);
}
return dumpDir;
}
Expand Down Expand Up @@ -475,7 +475,7 @@ public static int getIntegerProperty(String key, int def)
}
catch (NumberFormatException e)
{
TestLogger.warn("Invalid value for property %s: '%s'".formatted(key, prop), e);
LOG.warn("Invalid value for property {}: '{}'", key, prop, e);
}
}
return def;
Expand All @@ -499,7 +499,7 @@ public static double getDoubleProperty(String key, double def)
}
catch (NumberFormatException e)
{
TestLogger.warn("Invalid value for property %s: '%s'".formatted(key, prop), e);
LOG.warn("Invalid value for property {}: '{}'", key, prop, e);
}
}
return def;
Expand Down
10 changes: 5 additions & 5 deletions src/org/labkey/test/WebDriverWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ protected Pair<WebDriver, DriverService> createNewWebDriver(@NotNull Pair<WebDri
profile.setPreference("extensions.update.enabled", false);
profile.setPreference("dom.max_script_run_time", 0);
profile.setPreference("dom.max_chrome_script_run_time", 0);
//profile.setPreference("dom.reporting.enabled", true); // Enable support for CSP report-to

// Prevent crawler from hanging on '_print=1' pages
profile.setPreference("print.always_print_silent", true);
Expand Down Expand Up @@ -1997,19 +1998,18 @@ private void waitForPageToLoad(WebElement toBeStale, Timer timer)
{
try
{
toBeStale.isEnabled();
new WebDriverWait(getDriver(), timer.timeRemaining())
.withMessage("waiting for browser to navigate")
.until(ExpectedConditions.stalenessOf(toBeStale));
}
catch (StaleElementReferenceException | NoSuchElementException | NullPointerException ignore)
{
// `ExpectedConditions.stalenessOf(toBeStale)` sometimes chokes when coming from a blank page (about:blank)
}
catch (TimeoutException ex)
{
throw new TestTimeoutException(ex); // Triggers thread dump.
}
catch (WebDriverException | NullPointerException ignore)
{
// `ExpectedConditions.stalenessOf(toBeStale)` sometimes chokes when coming from a blank page (about:blank)
}

// WebDriver usually does this automatically, but not always.
new WebDriverWait(getDriver(), timer.timeRemaining())
Expand Down
4 changes: 2 additions & 2 deletions src/org/labkey/test/aspects/MethodLoggingAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void beforeLoggedMethod(JoinPoint joinPoint, LogMethod logMethod)

String argsString = getArgsString(loggedParameters);

if (logMethod.quiet())
if (logMethod.quiet() && !TestLogger.log().isDebugEnabled())
{
TestLogger.suppressLogging(true);
quietMethods.add(method);
Expand Down Expand Up @@ -108,7 +108,7 @@ private void logMethodEnd(JoinPoint joinPoint, LogMethod logMethod, String logPr

String argString = " done";

if (logMethod.quiet())
if (logMethod.quiet() && !TestLogger.log().isDebugEnabled())
{
quietMethods.pop();
argString = quietMethodsArgStrings.pop();
Expand Down
10 changes: 10 additions & 0 deletions src/org/labkey/test/util/TestLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,29 @@
package org.labkey.test.util;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;
import org.apache.logging.log4j.core.config.Configurator;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.TimeUnit;

import static org.labkey.test.TestProperties.getTestLogLevel;

public class TestLogger
{
private static final Logger LOG = LogManager.getLogger(TestLogger.class);
private static final Logger NO_OP = LogManager.getLogger("NoOpLogger");

static
{
if (getTestLogLevel() != null)
Configurator.setLevel(LOG, Level.toLevel(getTestLogLevel()));
}

private static final int indentStep = 2;
private static final int MAX_INDENT = 20;

Expand Down
6 changes: 5 additions & 1 deletion test.properties.template
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ test.credentials.file=
webtest.timeout.multiplier=1.0
## Runs just the cleanup steps of the specified tests/suites
cleanOnly=false
## Set logging level for Selenium tests (default: INFO)
#webtest.log.level=DEBUG
## Set whether DeferredErrorCollector should fail immediately when errors are encountered (default: false)
#webtest.checker.fatal=true


#==============================================================================
Expand Down Expand Up @@ -131,7 +135,7 @@ labkey.contextpath=
#==============================================================================
# Server configuration properties
#
# These define certain Tomcat startup properties. Mostly only used by TeamCity
# These inform tests of certain LabKey startup properties. Mostly only used by TeamCity
#==============================================================================
disableAssertions=false
devMode=true
Expand Down