Skip to content
Merged
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
2 changes: 1 addition & 1 deletion ExtentReports.Tests/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected void Setup()
{
string dir = TestContext.CurrentContext.TestDirectory + "\\";
var fileName = this.GetType().ToString() + ".html";
ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(dir + fileName);
ExtentV3HtmlReporter htmlReporter = new ExtentV3HtmlReporter(dir + fileName);

_extent = new ExtentReports();
_extent.AttachReporter(htmlReporter);
Expand Down
2 changes: 1 addition & 1 deletion ExtentReports.Tests/Core/BuildsReportWithoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BuildsReportWithoutTests
public void BuildReportWithoutTests()
{
var fileName = TestContext.CurrentContext.Test.Name + ".html";
var reporter = new ExtentHtmlReporter(fileName);
var reporter = new ExtentV3HtmlReporter(fileName);
var extent = new ExtentReports();
extent.AttachReporter(reporter);
extent.Flush();
Expand Down
2 changes: 1 addition & 1 deletion ExtentReports.Tests/Service/ExtentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ExtentService

static ExtentService()
{
var htmlReporter = new ExtentHtmlReporter(TestContext.CurrentContext.TestDirectory + "\\Extent.html");
var htmlReporter = new ExtentV3HtmlReporter(TestContext.CurrentContext.TestDirectory + "\\Extent.html");
htmlReporter.Config.DocumentTitle = "Extent/NUnit Samples";
htmlReporter.Config.ReportName = "Extent/NUnit Samples";
htmlReporter.Config.Theme = Theme.Standard;
Expand Down
12 changes: 10 additions & 2 deletions ExtentReports/Core/ExtentObservable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,16 @@ private void RefreshStatusList(List<Test> testList)
return;
}

_statusMap.Clear();
var distinctStatusList = testList.Select(x => x.Status).Distinct();
distinctStatusList.ToList().ForEach(x => _statusMap.Add(x, false));

foreach (var s in distinctStatusList)
{
if (!_statusMap.ContainsKey(s))
{
_statusMap.Add(s, false);
}
}

// recursively, do the same for child tests
foreach (var test in testList.ToList())
{
Expand Down Expand Up @@ -350,6 +357,7 @@ private void NotifyReporters()
var reportAggregates = new ReportAggregates
{
TestList = _testList,
StatusList = _statusList,
ReportStatusStats = this.ReportStatusStats,
AuthorContext = this.AuthorContext,
CategoryContext = this.CategoryContext,
Expand Down
39 changes: 28 additions & 11 deletions ExtentReports/ExtentReports.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
<Compile Include="Reporter\Configuration\RichViewReporterConfiguration.cs" />
<Compile Include="Reporter\Configuration\Theme.cs" />
<Compile Include="Reporter\ExtentHtmlReporter.cs" />
<Compile Include="Reporter\ExtentV3HtmlReporter.cs" />
<Compile Include="Reporter\ExtentLoggerReporter.cs" />
<Compile Include="Reporter\TemplateEngine\RazorEngineManager.cs" />
<Compile Include="Reporter\TemplateInfo.cs" />
Expand All @@ -167,9 +168,12 @@
<Compile Include="Utils\ExceptionUtil.cs" />
<Compile Include="Utils\ListUtil.cs" />
<Compile Include="Utils\ResourceUtils.cs" />
<Compile Include="ViewDefs\TWBSIcon.cs" />
<Compile Include="ViewDefs\MaterialIcon.cs" />
<Compile Include="Views\Commons\ICommonsMarker.cs" />
<Compile Include="Views\Html\IHtmlMarker.cs" />
<Compile Include="Views\Html\IHtml2Marker.cs" />
<EmbeddedResource Include="Views\Html\Partials\Attributes.cshtml" />
<Compile Include="Views\V3Html\IV3HtmlMarker.cs" />
<Compile Include="Views\Logger\ILoggerMarker.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -189,26 +193,26 @@
<EmbeddedResource Include="Views\Commons\CommonsInjectCss.cshtml" />
<EmbeddedResource Include="Views\Commons\CommonsInjectJs.cshtml" />
<EmbeddedResource Include="Views\Commons\CommonsTag.cshtml" />
<EmbeddedResource Include="Views\Html\Author\Author.cshtml" />
<EmbeddedResource Include="Views\Html\Category\Category.cshtml" />
<EmbeddedResource Include="Views\Html\Dashboard\Dashboard.cshtml" />
<EmbeddedResource Include="Views\Html\Exception\Exception.cshtml">
<EmbeddedResource Include="Views\V3Html\Author\V3Author.cshtml" />
<EmbeddedResource Include="Views\V3Html\Category\V3Category.cshtml" />
<EmbeddedResource Include="Views\V3Html\Dashboard\V3Dashboard.cshtml" />
<EmbeddedResource Include="Views\V3Html\Exception\V3Exception.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Views\Html\TestRunner\Logs.cshtml" />
<EmbeddedResource Include="Views\Html\Test\Charts.cshtml">
<EmbeddedResource Include="Views\V3Html\TestRunner\V3Logs.cshtml" />
<EmbeddedResource Include="Views\V3Html\Test\V3Charts.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Views\Html\Test\Test.cshtml">
<EmbeddedResource Include="Views\V3Html\Test\V3Test.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Views\Html\Head.cshtml">
<EmbeddedResource Include="Views\V3Html\V3Head.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Views\Html\Index.cshtml" />
<EmbeddedResource Include="Views\Html\Nav.cshtml">
<EmbeddedResource Include="Views\V3Html\V3Index.cshtml" />
<EmbeddedResource Include="Views\V3Html\V3Nav.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<EmbeddedResource Include="Views\Logger\LoggerDashboard.cshtml">
Expand All @@ -224,6 +228,19 @@
<EmbeddedResource Include="Views\Commons\CommonsAttributes.cshtml" />
<EmbeddedResource Include="Views\Commons\CommonsMedia.cshtml" />
<EmbeddedResource Include="Views\Commons\CommonsRow.cshtml" />
<EmbeddedResource Include="Views\Html\Tag.cshtml" />
<EmbeddedResource Include="Views\Html\Dashboard.cshtml" />
<EmbeddedResource Include="Views\Html\Index.cshtml" />
<EmbeddedResource Include="Views\Html\Partials\Sidenav.cshtml" />
<EmbeddedResource Include="Views\Html\Partials\Log.cshtml" />
<EmbeddedResource Include="Views\Html\Partials\RecurseNodes.cshtml" />
<EmbeddedResource Include="Views\Html\Partials\AttributesView.cshtml" />
<EmbeddedResource Include="Views\Html\Partials\Navbar.cshtml" />
<EmbeddedResource Include="Views\Html\Author.cshtml" />
<EmbeddedResource Include="Views\Html\Device.cshtml" />
<EmbeddedResource Include="Views\Html\Exception.cshtml" />
<EmbeddedResource Include="Views\Html\Partials\Head.cshtml" />
<EmbeddedResource Include="Views\Html\Partials\Scripts.cshtml" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\Languages.txt" />
Expand Down
22 changes: 21 additions & 1 deletion ExtentReports/Model/Media.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Threading;

using MongoDB.Bson;
Expand All @@ -12,13 +13,32 @@ public class Media
public ObjectId ReportObjectId { get; set; }
public ObjectId TestObjectId { get; set; }
public ObjectId LogObjectId { get; set; }
public long FileSize { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Path { get; set; }
public string Title { get; set; }
public string Base64String { get; set; }
public int Sequence { get; private set; } = Interlocked.Increment(ref _seq);

public string Path
{
get
{
return _path;
}
set
{
_path = value;

Name = !string.IsNullOrEmpty(Name) ? Name : System.IO.Path.GetFileName(value);
if (File.Exists(value))
{
FileSize = new FileInfo(value).Length;
}
}
}

private static int _seq;
private string _path;
}
}
16 changes: 16 additions & 0 deletions ExtentReports/Model/ScreenCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,21 @@ public string SourceIcon
"</a>";
}
}

public string ScreenCapturePath
{
get
{
return !string.IsNullOrEmpty(base.Path) ? base.Path : Base64String;
}
}

public bool IsBase64
{
get
{
return !string.IsNullOrEmpty(Base64String);
}
}
}
}
8 changes: 8 additions & 0 deletions ExtentReports/Model/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ public bool HasLog
}
}

public bool HasAttributes
{
get
{
return HasAuthor || HasCategory || HasDevice;
}
}

public GenericStructure<TestAttribute> CategoryContext
{
get
Expand Down
10 changes: 4 additions & 6 deletions ExtentReports/Reporter/BasicFileReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public abstract class BasicFileReporter : ConfigurableReporter

public List<Test> TestList { get; protected internal set; }

public List<Status> StatusList { get; protected internal set; }

public TestAttributeTestContextProvider<Author> AuthorContext { get; protected internal set; }

public TestAttributeTestContextProvider<Category> CategoryContext { get; protected internal set; }
Expand Down Expand Up @@ -62,6 +64,7 @@ protected void Initialize(BasicFileConfiguration userConfig)
public override void Flush(ReportAggregates reportAggregates)
{
TestList = reportAggregates.TestList;
StatusList = reportAggregates.StatusList;
ReportStatusStats = reportAggregates.ReportStatusStats;
AuthorContext = reportAggregates.AuthorContext;
CategoryContext = reportAggregates.CategoryContext;
Expand Down Expand Up @@ -144,12 +147,7 @@ public override void Stop()

public bool ContainsStatus(Status status)
{
return true;
}

public bool ContainsStatus(string status)
{
return true;
return StatusList.Contains(status);
}
}
}
55 changes: 42 additions & 13 deletions ExtentReports/Reporter/ExtentHtmlReporter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using AventStack.ExtentReports.Core;
using AventStack.ExtentReports.Views.Html;
using AventStack.ExtentReports.Reporter.Configuration;
using AventStack.ExtentReports.Views.Html;

using RazorEngine.Templating;

Expand All @@ -20,7 +20,7 @@ public class ExtentHtmlReporter : BasicFileReporter
private static readonly string TemplateFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Views");
private static readonly string HtmlTemplateFolderPath = Path.Combine(TemplateFolderPath, "Html");

public ExtentHtmlReporter(string filePath) : base(filePath)
public ExtentHtmlReporter(string folderPath) : base(folderPath)
{
Config = new ExtentHtmlReporterConfiguration(this);
Initialize(Config);
Expand All @@ -31,8 +31,33 @@ public ExtentHtmlReporter(string filePath) : base(filePath)
public override void Flush(ReportAggregates reportAggregates)
{
base.Flush(reportAggregates);

Directory.CreateDirectory(SavePath);

var source = RazorEngineManager.Instance.Razor.RunCompile("Index", typeof(ExtentHtmlReporter), this);
File.WriteAllText(SavePath, source);
File.WriteAllText(SavePath + "index.html", source);
source = RazorEngineManager.Instance.Razor.RunCompile("Dashboard", typeof(ExtentHtmlReporter), this);
File.WriteAllText(SavePath + "dashboard.html", source);
if (AuthorContext.Context.Count > 0)
{
source = RazorEngineManager.Instance.Razor.RunCompile("Author", typeof(ExtentHtmlReporter), this);
File.WriteAllText(SavePath + "author.html", source);
}
if (CategoryContext.Context.Count > 0)
{
source = RazorEngineManager.Instance.Razor.RunCompile("Tag", typeof(ExtentHtmlReporter), this);
File.WriteAllText(SavePath + "tag.html", source);
}
if (DeviceContext.Context.Count > 0)
{
source = RazorEngineManager.Instance.Razor.RunCompile("Device", typeof(ExtentHtmlReporter), this);
File.WriteAllText(SavePath + "device.html", source);
}
if (ExceptionInfoContext.Context.Count > 0)
{
source = RazorEngineManager.Instance.Razor.RunCompile("Exception", typeof(ExtentHtmlReporter), this);
File.WriteAllText(SavePath + "exception.html", source);
}
}

public override void Start()
Expand All @@ -45,18 +70,22 @@ private void AddTemplates()
{
string[] templates = new string[]
{
"Author",
"Dashboard",
"Device",
"Exception",
"Index",
"Head",
"Nav",
"Test.Test",
"Test.Charts",
"Author.Author",
"Category.Category",
"Dashboard.Dashboard",
"Exception.Exception",
"TestRunner.Logs"
"Tag",
"Partials.Attributes",
"Partials.AttributesView",
"Partials.Head",
"Partials.Log",
"Partials.Navbar",
"Partials.RecurseNodes",
"Partials.Scripts",
"Partials.Sidenav"
};

foreach (string template in templates)
{
string resourceName = typeof(IHtmlMarker).Namespace + "." + template + ".cshtml";
Expand Down
Loading