Skip to content
This repository was archived by the owner on Jul 17, 2020. It is now read-only.
Closed
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
4 changes: 4 additions & 0 deletions dist/css/extent.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ public ExceptionTestContextImpl() {
}

public void setExceptionContext(ExceptionInfo ei, Test test) {
reset();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A simpler way to fix the overall behavior is to do this:

public class ExceptionTestContextImpl {
    List<ExceptionTestContext> exTestContextList;
    
    public ExceptionTestContextImpl() { 
        exTestContextList = new ArrayList<>();
    }   
    
    public void setExceptionContext(ExceptionInfo ei, Test test) {
        Optional<ExceptionTestContext> exOptionalTestContext = exTestContextList
                .stream()
                .filter(x -> x.getExceptionInfo().getExceptionName().equals(ei.getExceptionName()))
                .findFirst();
        
        if (exOptionalTestContext.isPresent()) {
            List<Test> testList = exOptionalTestContext.get().getTestList();
            
            boolean b = testList
                    .stream()
                    .filter(t -> t.getID() == test.getID())
                    .findFirst()
                    .isPresent();
            
            if (!b)
                exOptionalTestContext.get().setTest(test);
        }
        else {
            ExceptionTestContext exTestContext = new ExceptionTestContext(ei);
            exTestContext.setTest(test);
            
            exTestContextList.add(exTestContext);
        }
    }

    public List<ExceptionTestContext> getExceptionTestContextList() { 
        return exTestContextList; 
    }
}

`Report.java

    private void copyNodeAttributeInfoToAttributeContext(Test node) {
        if (node.hasCategory())
            node.getCategoryContext().getAll().forEach(x -> categoryContext.setAttributeContext((Category) x, node));
        
        if (node.hasAuthor())
            node.getAuthorContext().getAll().forEach(x -> authorContext.setAttributeContext((Author) x, node));
        
        if (node.hasChildren())
            node.getNodeContext().getAll().forEach(this::copyNodeAttributeInfoToAttributeContext);
        
        if (node.hasChildren())
            node.getNodeContext().getAll().forEach(x -> {
                copyNodeAttributeInfoToAttributeContext(x);
                //copyNodeExceptionInfoToExceptionContext(x); <- comment this line
            });
    }


Optional<ExceptionTestContext> exOptionalTestContext = exTestContextList
.stream()
.filter(x -> x.getExceptionInfo().getExceptionName().equals(ei.getExceptionName()))
.findFirst();

if (exOptionalTestContext.isPresent()) {
exOptionalTestContext.get().setTest(test);
}
Expand All @@ -33,12 +31,8 @@ public void setExceptionContext(ExceptionInfo ei, Test test) {
exTestContextList.add(exTestContext);
}
}

private void reset() {
exTestContextList.clear();
}

public List<ExceptionTestContext> getExceptionTestContextList() {
return exTestContextList;
public List<ExceptionTestContext> getExceptionTestContextList() {
return exTestContextList;
}
}
2 changes: 0 additions & 2 deletions src/main/java/com/aventstack/extentreports/ExtentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,6 @@ public synchronized ExtentTest log(Status status, Throwable t, MediaEntityModelP
exInfo.setStackTrace(ExceptionUtil.getStackTrace(t));

getModel().setExceptionInfo(exInfo);
if (getModel().getLevel() > 1)
getModel().getParent().setExceptionInfo(exInfo);

log(status, exInfo.getStackTrace(), provider);

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/aventstack/extentreports/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ synchronized void addNode(Test node) {
}

synchronized void addLog(Test test, Log log) {
collectRunInfo();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove this line of code, consider for very long tests - the user will not have up-to-date information after each log.


reporterCollection.forEach(x -> x.onLogAdded(test, log));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@
</thead>
<tbody>
<#list exception.getTestList() as test>
<tr>
<td>${ test.startTime?datetime?string["${timeStampFormat}"] }</td>
<td class='linked' test-id='${ test.getID() }'>${ test.hierarchicalName }</td>
<td><pre>${ exception.exceptionInfo.getStackTrace() }</pre></td>
</tr>
<#list test.getExceptionInfoList() as testException>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we require a loop here? A test shouldn't have more than 1 exception, correct?

<#if testException.getExceptionName() == exception.exceptionInfo.getExceptionName()>
<tr>
<td>${ test.startTime?datetime?string["${timeStampFormat}"] }</td>
<td class='linked' test-id='${ test.getID() }'>${ test.hierarchicalName }</td>
<td><pre>${ testException.getStackTrace() }</pre></td>
</tr>
</#if>
</#list>
</#list>
</tbody>
</table>
Expand Down