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

Fixing same time stamp in combined reports #321

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
64 changes: 48 additions & 16 deletions src/main/java/com/aventstack/extentreports/ExtentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,7 +55,7 @@
* An instance of {@link ExtentReports} to which this {@link ExtentTest}
* belongs
*/
private transient ExtentReports extent;
private final transient ExtentReports extent;

/**
* Internal model
Expand Down Expand Up @@ -342,13 +344,9 @@
* </p>
*
* <pre>
* test.log(Status.FAIL, "details", MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
* test.log(buildLog(Status.FAIL, "details"), MediaEntityBuilder.createScreenCaptureFromPath("screen.png").build());
* </pre>
*
* @param status
* {@link Status}
* @param details
* Details
* @param t
* A {@link Throwable} exception to be logged, enabling the
* Exception view of certain HTML reporters
Expand All @@ -357,12 +355,8 @@
*
* @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)
Expand All @@ -376,6 +370,7 @@
return this;
}


/**
* Logs an event with {@link Status}, details and a media object:
* {@link ScreenCapture}
Expand All @@ -398,7 +393,11 @@
* @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);
}

/**
Expand All @@ -421,7 +420,7 @@
* @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);
}

/**
Expand All @@ -438,6 +437,20 @@
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:
*
Expand Down Expand Up @@ -482,7 +495,7 @@
* @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);
}

/**
Expand All @@ -499,6 +512,25 @@
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);

Check warning on line 528 in src/main/java/com/aventstack/extentreports/ExtentTest.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/aventstack/extentreports/ExtentTest.java#L528

Added line #L528 was not covered by tests
}

return log;
}

/**
* Logs an <code>Status.INFO</code> event with details and a media object:
* {@link ScreenCapture}
Expand Down Expand Up @@ -1095,4 +1127,4 @@
public ExtentTest addScreenCaptureFromBase64String(String base64) {
return addScreenCaptureFromBase64String(base64, null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;

import com.aventstack.extentreports.model.Log;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand All @@ -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
Expand Down