diff --git a/src/main/java/com/aventstack/extentreports/ExtentTest.java b/src/main/java/com/aventstack/extentreports/ExtentTest.java index 665d414..b405896 100644 --- a/src/main/java/com/aventstack/extentreports/ExtentTest.java +++ b/src/main/java/com/aventstack/extentreports/ExtentTest.java @@ -2,7 +2,9 @@ import java.io.Serializable; import java.util.Arrays; +import java.util.Date; +import com.aventstack.extentreports.gherkin.model.Feature; import com.aventstack.extentreports.gherkin.model.IGherkinFormatterModel; import com.aventstack.extentreports.markuputils.Markup; import com.aventstack.extentreports.markuputils.MarkupHelper; @@ -53,7 +55,7 @@ public class ExtentTest implements RunResult, Serializable { * An instance of {@link ExtentReports} to which this {@link ExtentTest} * belongs */ - private transient ExtentReports extent; + private final transient ExtentReports extent; /** * Internal model @@ -342,13 +344,9 @@ public ExtentTest generateLog(Status status, Markup markup) { *
* *- * test.log(Status.FAIL, "details", MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build()); + * test.log(buildLog(Status.FAIL, "details"), MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build()); ** - * @param status - * {@link Status} - * @param details - * Details * @param t * A {@link Throwable} exception to be logged, enabling the * Exception view of certain HTML reporters @@ -357,12 +355,8 @@ public ExtentTest generateLog(Status status, Markup markup) { * * @return An {@link ExtentTest} object */ - public ExtentTest log(Status status, String details, Throwable t, Media media) { - Assert.notNull(status, "Status must not be null"); - Log log = Log.builder() - .status(status) - .details(details == null ? "" : details) - .build(); + public ExtentTest log(Log log, Throwable t, Media media) { + Assert.notNull(log.getStatus(), "Status must not be null"); ExceptionInfo exceptionInfo = ExceptionInfoService.createExceptionInfo(t); log.setException(exceptionInfo); if (exceptionInfo != null) @@ -376,6 +370,7 @@ public ExtentTest log(Status status, String details, Throwable t, Media media) { return this; } + /** * Logs an event with {@link Status}, details and a media object: * {@link ScreenCapture} @@ -398,7 +393,11 @@ public ExtentTest log(Status status, String details, Throwable t, Media media) { * @return An {@link ExtentTest} object */ public ExtentTest log(Status status, String details, Media media) { - return log(status, details, null, media); + return log(buildLog(status, details, null), null, media); + } + + public ExtentTest log(Log log){ + return log(log, null, null); } /** @@ -421,7 +420,7 @@ public ExtentTest log(Status status, String details, Media media) { * @return An {@link ExtentTest} object */ public ExtentTest log(Status status, Media media) { - return log(status, null, null, media); + return log(buildLog(status, null, null), null, media); } /** @@ -438,6 +437,20 @@ public ExtentTest log(Status status, String details) { return log(status, details, null); } + /** + * Logs an event with {@link Status} and details + * + * @param status + * {@link Status} + * @param details + * Details + * + * @return An {@link ExtentTest} object + */ +// public ExtentTest log(Status status, String details, Date timestamp) { +// return log(status, details, null); +// } + /** * Logs an event with {@link Status} and custom {@link Markup} such as: * @@ -482,7 +495,7 @@ public ExtentTest log(Status status, Markup markup) { * @return An {@link ExtentTest} object */ public ExtentTest log(Status status, Throwable t, Media media) { - return log(status, null, t, media); + return log(buildLog(status, null, null), t, media); } /** @@ -499,6 +512,25 @@ public ExtentTest log(Status status, Throwable t) { return log(status, t, null); } + /** + * @param status {@link Status} status of the log + * @param details {@link String} details to be added to the log + * @param overrideLogDate if passed, the log will be overridden to this timestamp. Else it will be defaulted to the current time stamp + * @return {@link Log} Log object with the status, details and timestamp set + */ + private Log buildLog(Status status, String details, Date overrideLogDate){ + Assert.notNull(status, "Status must not be null"); + Log log = Log.builder() + .status(status) + .details(details == null ? "" : details) + .build(); + if(overrideLogDate != null){ + log.setTimestamp(overrideLogDate); + } + + return log; + } + /** * Logs an
Status.INFO
event with details and a media object:
* {@link ScreenCapture}
@@ -1095,4 +1127,4 @@ public ExtentTest addScreenCaptureFromBase64String(String base64, String title)
public ExtentTest addScreenCaptureFromBase64String(String base64) {
return addScreenCaptureFromBase64String(base64, null);
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/com/aventstack/extentreports/append/RawEntityConverter.java b/src/main/java/com/aventstack/extentreports/append/RawEntityConverter.java
index 7598b90..359c16c 100644
--- a/src/main/java/com/aventstack/extentreports/append/RawEntityConverter.java
+++ b/src/main/java/com/aventstack/extentreports/append/RawEntityConverter.java
@@ -8,10 +8,7 @@
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.GherkinKeyword;
import com.aventstack.extentreports.MediaEntityBuilder;
-import com.aventstack.extentreports.model.Log;
-import com.aventstack.extentreports.model.Media;
-import com.aventstack.extentreports.model.ScreenCapture;
-import com.aventstack.extentreports.model.Test;
+import com.aventstack.extentreports.model.*;
public class RawEntityConverter {
private final ExtentReports extent;
@@ -53,14 +50,16 @@ else if (log.hasException())
extentTest.log(log.getStatus(), log.getException().getException());
else if (log.hasMedia())
addMedia(log, extentTest, null);
- else
- extentTest.log(log.getStatus(), log.getDetails());
+ else {
+ Log logToAdd = Log.builder().status(log.getStatus()).details(log.getDetails()).timestamp(log.getTimestamp()).build();
+ extentTest.log(logToAdd);
+ }
}
// assign attributes
- test.getAuthorSet().stream().map(x -> x.getName()).forEach(extentTest::assignAuthor);
- test.getCategorySet().stream().map(x -> x.getName()).forEach(extentTest::assignCategory);
- test.getDeviceSet().stream().map(x -> x.getName()).forEach(extentTest::assignDevice);
+ test.getAuthorSet().stream().map(NamedAttribute::getName).forEach(extentTest::assignAuthor);
+ test.getCategorySet().stream().map(NamedAttribute::getName).forEach(extentTest::assignCategory);
+ test.getDeviceSet().stream().map(NamedAttribute::getName).forEach(extentTest::assignDevice);
// handle nodes
for (Test node : test.getChildren()) {
diff --git a/src/test/java/com/aventstack/extentreports/ExtentTestLogTest.java b/src/test/java/com/aventstack/extentreports/ExtentTestLogTest.java
index d08215d..e03e7a3 100644
--- a/src/test/java/com/aventstack/extentreports/ExtentTestLogTest.java
+++ b/src/test/java/com/aventstack/extentreports/ExtentTestLogTest.java
@@ -2,6 +2,7 @@
import java.io.IOException;
+import com.aventstack.extentreports.model.Log;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -22,7 +23,8 @@ private Exception ex() {
@Test(expectedExceptions = IllegalArgumentException.class)
public void logWithStatusNull() {
- test().log(null, null, null, null);
+ Log log = Log.builder().status(null).details("").build();
+ test().log(log, null, null);
}
@Test