Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle MultipleFailureException thrown by tests #2238

Merged
merged 1 commit into from
Jan 22, 2025
Merged
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
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
Loading