Skip to content

Commit

Permalink
Handle MultipleFailureException thrown by tests
Browse files Browse the repository at this point in the history
  • Loading branch information
labkey-tchad committed Jan 21, 2025
1 parent b71490f commit 15c4641
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/org/labkey/test/BaseWebDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.junit.rules.TestRule;
import org.junit.rules.Timeout;
import org.junit.runner.Description;
import org.junit.runners.model.MultipleFailureException;
import org.junit.runners.model.Statement;
import org.junit.runners.model.TestTimedOutException;
import org.labkey.junit.rules.TestWatcher;
Expand Down Expand Up @@ -928,7 +929,17 @@ private void handleFailure(Throwable error, @LoggedParam String testName)
_testFailed = true;
_anyTestFailed = true;

error.printStackTrace();
if (error instanceof MultipleFailureException mfe)
{
// Only "handle" primary test failure. Just log failures thrown during @After or @AfterClass methods.
error = mfe.getFailures().get(0);
for (int i = 1; i < mfe.getFailures().size(); i++)
{
TestLogger.error("Secondary error after test:", mfe.getFailures().get(i));
}
}

TestLogger.error("Primary test failure:", error);

if (Thread.interrupted() || wasCausedBy(error, Arrays.asList(TestTimedOutException.class, InterruptedException.class)))
{
Expand Down Expand Up @@ -1042,24 +1053,16 @@ private void handleFailure(Throwable error, @LoggedParam String testName)

try
{
boolean inIFrame = Locator.css(":root").findElement(getDriver()).getSize().getHeight() > 0;
if (inIFrame)
try
{
// TODO: Need a better way to detect when we are in an iFrame. Above method is not reliable
//if (isFirefox()) // As of 2.45, Chromedriver screenshots are not restricted to currently focused iFrame
//{
// getArtifactCollector().dumpPageSnapshot(testName + "-iframe", null, false); // Snapshot of iFrame
//}
try
{
// Switch to default content just in case we're in an iFrame
getDriver().switchTo().defaultContent();
}
catch (UnhandledAlertException alert)
{
TestLogger.warn("Alert was triggered by iframe: " + WebDriverUtils.getUnhandledAlertText(alert, getDriver()));
}
// Switch to default content just in case we're in an iFrame
getDriver().switchTo().defaultContent();
}
catch (UnhandledAlertException alert)
{
TestLogger.warn("Alert was triggered by iframe: " + WebDriverUtils.getUnhandledAlertText(alert, getDriver()));
}

// Don't take screenshots if error was deferred and any screenshots were taken
if (!(error instanceof DeferredErrorCollector.DeferredAssertionError))
{
Expand Down

0 comments on commit 15c4641

Please sign in to comment.