Extent Reportinh | Selenium Webdriver Tutorial with c# |Selenium C# training
20% Mid August Discount Avail now

Selenium C# Training Forum

Extent Reportinh

R
Rezaul Post on 26/04/2019

Hi,

I am using ExtentReports version=3.1.3. A file is created such as AutomationReport.html. But when I clik this file it couldnot parse the html. I did some research and found that it is happeing becuase 

Extent reports don't render //cdn.rawgit.com/anshooarora/extentreports/a7fadea2f449184064e06465391f689653dea590/cdn/extent.css

as this is blocked by company  network

The author host this resources on

  1. extentreports: http://extentreports.com   (http://extentreports.com/resx/dist/js/extent.js)
  2. jsDelivr: http://www.jsdelivr.com/

The author suggested to configure this resources and  I tried to add this in extent-config.xml but it did not work.

<!-- cdn to extent reports -->
<cdn>extentreports</cdn>

 

I found authors post (for java) : https://github.com/anshooarora/extentreports-java/commit/5e6b803173eedf915a49fcb81c21b18cbb6fbc44  

This is a very common issue and many people are having this issue. Can you please help?

Thanks,

Rezaul

 

G

Instructor

gunjan Reply on 28/04/2019

Can you please share the complete code that you are implementing

R
Rezaul Reply on 30/04/2019

public class ExtentManager
{
private static ExtentHtmlReporter htmlReporter;

private static ExtentReports extent;

private ExtentManager()
{
}

protected static string Env { get; private set; }

public static ExtentReports GetInstance()
{
string reportPath = string.Empty;
string dir = string.Empty;
string extentConfigPath = string.Empty;
string extentConfigFile = string.Empty;
if (extent == null)
{
var secName = ConfigurationManager.GetSection("extentreport") as NameValueCollection;
if (secName != null)
{
dir = AppDomain.CurrentDomain.BaseDirectory.Replace("\\bin\\Debug", string.Empty); // C:\\Data\\Auto\\
reportPath ="Reports";
reportPath = dir + reportPath; // C:\\Data\\Auto\\Reports
extentConfigFile = "ExtentReport\\extent-config.xml";
extentConfigFile = dir + extentConfigFile; // C:\\Data\\Auto\\ExtentReport\\extent-config.xml

string reportPrefix = "\\" + "AutomationReport_";
string reportFile = reportPrefix + DateTime.Now.ToString().Replace("/", "_").Replace(":", "_").Replace(" ", "_").Replace("-", "_") + ".html"; // \\AutomationReport_4_25_2019_12_36_39_PM
htmlReporter = new ExtentHtmlReporter(reportPath + reportFile); C:\\Data\\Auto\\Reports\\AutomationReport_4_25_2019_12_36_39_PM
extent = new ExtentReports();
extent.AttachReporter(htmlReporter);
extent.AddSystemInfo("OS", "Windows");
Env = "qua";
extent.AddSystemInfo("Environment", Env);
extent.AddSystemInfo("UserName", Environment.UserName);
htmlReporter.LoadConfig(extentConfigFile);
}

return extent;
}
}

 

 

public class ExtentTestManager
{
[ThreadStatic]
private static ExtentTest parentTest;

[ThreadStatic]
private static ExtentTest childTest;

[MethodImpl(MethodImplOptions.Synchronized)]
public static ExtentTest CreateParentTest(string testName, string description = null)
{
parentTest = ExtentManager.GetInstance().CreateTest(testName, description);
return parentTest;
}

[MethodImpl(MethodImplOptions.Synchronized)]
public static ExtentTest CreateTest(string testName, string description = null)
{
childTest = parentTest.CreateNode(testName, description);
return childTest;
}

[MethodImpl(MethodImplOptions.Synchronized)]
public static ExtentTest GetTest()
{
return childTest;
}
}

 

public class BaseFixture
{
[OneTimeSetUp]
public void OneTimeSetup()
{
ExtentTest test = ExtentTestManager.CreateParentTest(GetType().Name);
}

[SetUp]
public void BeforeTest()
{
ExtentTest test = ExtentTestManager.CreateTest(TestContext.CurrentContext.Test.Name);
}

[TearDown]
public void AfterTest()
{
var status = TestContext.CurrentContext.Result.Outcome.Status;
var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.StackTrace)
? string.Empty
: string.Format("<pre>{0}</pre>", TestContext.CurrentContext.Result.StackTrace);
Status logstatus;

switch (status)
{
case TestStatus.Failed:
logstatus = Status.Fail;
break;
case TestStatus.Inconclusive:
logstatus = Status.Warning;
break;
case TestStatus.Skipped:
logstatus = Status.Skip;
break;
default:
logstatus = Status.Pass;
break;
}

ExtentTest test1 = ExtentTestManager.GetTest();
ExtentTestManager.GetTest().Log(logstatus, "Test ended with " + logstatus + stacktrace);
ExtentManager.GetInstance().Flush();
}

[OneTimeTearDown]
protected void OneTimeTearDown()
{
ExtentManager.GetInstance().Flush();
}
}

 

public class TestBase : BaseFixture
{
private string url;

protected string Env { get; private set; }

protected string DefaultUsername { get; private set; }

protected string DefaultPassword { get; private set; }

protected Session CurrentSession { get; private set; }

[SetUp]
public void SetUp()
{
TestRunData.SessionStorageFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "lastSession.txt");

if (!File.Exists(TestRunData.SessionStorageFile))
{
File.Create(TestRunData.SessionStorageFile).Close();
}

Env = Environment.GetEnvironmentVariable("env");
if (string.IsNullOrEmpty(Env))
{
Env = "default";
}

Dictionary<string, string> envDetails = Config.GetEnvironmentDetails(Env);
url = envDetails["url"];
DefaultUsername = envDetails["username"];
DefaultPassword = envDetails["password"];
StartSession();
CleanupOldSessions();
OpenLoginPage();
}

...........
............
}
}

 

[TestFixture]
[Category("Test1")]
public class MyTest : Setup.TestBase
{
[Test]
public void Method1()
{
Assert.AreEqual("hello", "hello");
ExtentTestManager.GetTest().Log(Status.Info, "Test passed");
}

[Test]
public void Method2()
{
Assert.AreEqual("hello", "hello1");
ExtentTestManager.GetTest().Log(Status.Info, "Test Failed");
}
}

 

 

Output: 

 html file created: C:\\Data\\Auto\\Reports\\AutomationReport_4_25_2019_12_36_39_PM

but it cannot render render //cdn.rawgit.com/anshooarora/extentreports/a7fadea2f449184064e06465391f689653dea590/cdn/extent.css

 

 

 

G

Instructor

gunjan Reply on 30/04/2019

Please share the zip of the code.

R
Rezaul Reply on 10/05/2019

I could not zip the file beacuse of secuirty isue from my company. But I worked with the secuirt team to add the domain (https://rawgit.com/) to their allowed list. it works fine now

 

Thanks