htmlseleniumnunitextentreports

How to stop ExtentReports from converting HTML references in your Selenium logs to actual HTML?


I am using ExtentReports 4 for .Net with HTML V3 reporter. My issue is that when a test fails, I output the failure message to the ExtentReport and if that failure message contains a HTML tag, it converts this to actual HTML on the report!! This messes up the page.

eg.

OpenQA.Selenium.ElementClickInterceptedException : element click intercepted: Element <button type="button" class="btn btn-sm btn-default" data-bind="click: AddDashlet" data-toggle="modal" data-target="#dashboardSelector">...</button> is not clickable at point (584, 124). Other element would receive the click: <a href="#" data-bind="click: Toggle">...</a>

The above message generates an actual button!

The documentation just says the following:

Simply insert custom HTML in the logs by using an HTML tag:

test.Log(Status.Info, "Usage: <b>BOLD TEXT</b>");

The error message is being output using Nunit's Testcontext. It's probably that I could strip the < and > characters from it but is there any way to stop this happening at all please? Thanks


Solution

  • Problem is since you pass the exception message which has HTML tags ,ExtentReports thinks you are trying to pass some HTML code.

    Though below is not a good solution, it can be a kind of workaround for your problem. Just replace the "<" and ">" tags in your exception message as replace and then pass to the test.log() method.

    //Use <small> or <p> tags based on your convenient but you have to keep your exception message inside some HTML tag as I have done below.
    String exceptionMessage = "Your exception message which has <a> tag"
    
    test.Log(Status.Info, "<small>"+exceptionMessage.Replace("<","&#60").Replace(">","&#62")+"</small>");