From ec18d77ec24f6898b06e3adad6f6df9d754edf29 Mon Sep 17 00:00:00 2001 From: Scott Babcock Date: Wed, 16 Mar 2022 16:44:00 +0000 Subject: [PATCH] Add setting for retry exception logging (#57) --- gradle.properties | 2 +- .../automation/testng/RetryManager.java | 22 +++++++---- .../automation/testng/TestNGConfig.java | 38 +++++++++++++++++-- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/gradle.properties b/gradle.properties index c645b01..d0b78fc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ profile=java8 -version=3.0.7-SNAPSHOT +version=3.0.8-SNAPSHOT org.gradle.java.installations.auto-detect=false org.gradle.java.installations.auto-download=false org.gradle.java.installations.fromEnv=JDK7_HOME,JDK8_HOME,JDK11_HOME diff --git a/src/main/java/com/nordstrom/automation/testng/RetryManager.java b/src/main/java/com/nordstrom/automation/testng/RetryManager.java index 668fef2..2953a7f 100644 --- a/src/main/java/com/nordstrom/automation/testng/RetryManager.java +++ b/src/main/java/com/nordstrom/automation/testng/RetryManager.java @@ -110,13 +110,8 @@ public boolean retry(final ITestResult result) { doRetry = isRetriable(result); if (doRetry) { - if (logger.isDebugEnabled()) { - logger.debug("### RETRY ### [{}/{}] {}", - invocation.suiteName, invocation.testName, invocation, result.getThrowable()); - } else { - logger.warn("### RETRY ### [{}/{}] {}", - invocation.suiteName, invocation.testName, invocation); - } + logger.warn("### RETRY ### [{}/{}] {}", invocation.suiteName, invocation.testName, invocation, + getThrowableToLog(result)); } } @@ -139,4 +134,17 @@ protected boolean isRetriable(final ITestResult result) { } return false; } + + /** + * Get the {@link Throwable} to log with the retry notification. + * + * @param result result of test method that's being retried + * @return if exception logging is indicated, the exception that caused the test to fail; otherwise {@code null} + */ + private Throwable getThrowableToLog(ITestResult result) { + if (logger.isDebugEnabled() || config.getBoolean(TestNGSettings.RETRY_MORE_INFO.key())) { + return result.getThrowable(); + } + return null; + } } diff --git a/src/main/java/com/nordstrom/automation/testng/TestNGConfig.java b/src/main/java/com/nordstrom/automation/testng/TestNGConfig.java index 6ab446d..f2e325d 100644 --- a/src/main/java/com/nordstrom/automation/testng/TestNGConfig.java +++ b/src/main/java/com/nordstrom/automation/testng/TestNGConfig.java @@ -32,12 +32,42 @@ public class TestNGConfig extends SettingsCore { * the {@code testng.properties} file and System property declarations. */ public enum TestNGSettings implements SettingsCore.SettingsAPI { - /** name: testng.timeout.test
default: {@code null} */ + /** + * This setting specifies the global default + * + * method timeout in milliseconds. + *

+ * name: testng.timeout.test
+ * default: {@code null} + */ TEST_TIMEOUT("testng.timeout.test", null), - /** name: testng.retry.analyzer
default: com.nordstrom.automation.testng.RetryManager */ + + /** + * This setting specifies the fully-qualified class name of the default TestNG + * + * retry analyzer. + *

+ * name: testng.retry.analyzer
+ * default: {@link com.nordstrom.automation.testng.RetryManager} + */ RETRY_ANALYZER("testng.retry.analyzer", "com.nordstrom.automation.testng.RetryManager"), - /** name: testng.max.retry
default: 0 */ - MAX_RETRY("testng.max.retry", "0"); + + /** + * This setting specifies the maximum number of times a failed method will be retried. + *

+ * name: testng.max.retry
+ * default: 0 + */ + MAX_RETRY("testng.max.retry", "0"), + + /** + * This setting specifies whether the exception that caused a test to fail will be logged in the notification + * that the test is being retried. + *

+ * name: retry.more.info
+ * default: {@code false} + */ + RETRY_MORE_INFO("retry.more.info", "false"); private String propertyName; private String defaultValue;