From b61b96c8488baaef38ec06a3f0b7a73f0d60ac7a Mon Sep 17 00:00:00 2001 From: anshooarora Date: Sun, 23 Dec 2018 19:10:11 -0500 Subject: [PATCH 01/10] initial --- ExtentReports/ExtentReports.csproj | 16 +- ExtentReports/Model/Media.cs | 22 +- ExtentReports/Model/ScreenCapture.cs | 16 + ExtentReports/Model/Test.cs | 8 + ExtentReports/Reporter/ExtentHtml2Reporter.cs | 99 ++++ ExtentReports/ViewDefs/MaterialIcon.cs | 2 +- ExtentReports/ViewDefs/TWBSIcon.cs | 42 ++ .../Views/Html/Dashboard/Dashboard.cshtml | 2 +- ExtentReports/Views/Html/Test/Test.cshtml | 1 - ExtentReports/Views/Html2/Author.cshtml | 59 +++ ExtentReports/Views/Html2/Dashboard.cshtml | 456 ++++++++++++++++++ ExtentReports/Views/Html2/Device.cshtml | 59 +++ ExtentReports/Views/Html2/IHtml2Marker.cs | 6 + ExtentReports/Views/Html2/Index.cshtml | 152 ++++++ .../Views/Html2/Partials/Attributes.cshtml | 26 + .../Html2/Partials/AttributesView.cshtml | 58 +++ ExtentReports/Views/Html2/Partials/Log.cshtml | 32 ++ .../Views/Html2/Partials/Navbar.cshtml | 34 ++ .../Views/Html2/Partials/RecurseNodes.cshtml | 32 ++ .../Views/Html2/Partials/Sidenav.cshtml | 55 +++ ExtentReports/Views/Html2/Tag.cshtml | 59 +++ 21 files changed, 1231 insertions(+), 5 deletions(-) create mode 100644 ExtentReports/Reporter/ExtentHtml2Reporter.cs create mode 100644 ExtentReports/ViewDefs/TWBSIcon.cs create mode 100644 ExtentReports/Views/Html2/Author.cshtml create mode 100644 ExtentReports/Views/Html2/Dashboard.cshtml create mode 100644 ExtentReports/Views/Html2/Device.cshtml create mode 100644 ExtentReports/Views/Html2/IHtml2Marker.cs create mode 100644 ExtentReports/Views/Html2/Index.cshtml create mode 100644 ExtentReports/Views/Html2/Partials/Attributes.cshtml create mode 100644 ExtentReports/Views/Html2/Partials/AttributesView.cshtml create mode 100644 ExtentReports/Views/Html2/Partials/Log.cshtml create mode 100644 ExtentReports/Views/Html2/Partials/Navbar.cshtml create mode 100644 ExtentReports/Views/Html2/Partials/RecurseNodes.cshtml create mode 100644 ExtentReports/Views/Html2/Partials/Sidenav.cshtml create mode 100644 ExtentReports/Views/Html2/Tag.cshtml diff --git a/ExtentReports/ExtentReports.csproj b/ExtentReports/ExtentReports.csproj index 8ca1a73..ca9e72f 100644 --- a/ExtentReports/ExtentReports.csproj +++ b/ExtentReports/ExtentReports.csproj @@ -5,7 +5,7 @@ Debug AnyCPU {783324EC-3D15-46A1-B34E-A1F15B97DD59} - Library + Exe AventStack.ExtentReports ExtentReports v4.5 @@ -150,6 +150,7 @@ + @@ -167,8 +168,11 @@ + + + @@ -224,6 +228,16 @@ + + + + + + + + + + diff --git a/ExtentReports/Model/Media.cs b/ExtentReports/Model/Media.cs index afc0e8c..28512b1 100644 --- a/ExtentReports/Model/Media.cs +++ b/ExtentReports/Model/Media.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Threading; using MongoDB.Bson; @@ -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; } } diff --git a/ExtentReports/Model/ScreenCapture.cs b/ExtentReports/Model/ScreenCapture.cs index 7ae3a7b..bbb75d8 100644 --- a/ExtentReports/Model/ScreenCapture.cs +++ b/ExtentReports/Model/ScreenCapture.cs @@ -32,5 +32,21 @@ public string SourceIcon ""; } } + + public string ScreenCapturePath + { + get + { + return !string.IsNullOrEmpty(base.Path) ? base.Path : Base64String; + } + } + + public bool IsBase64 + { + get + { + return !string.IsNullOrEmpty(Base64String); + } + } } } diff --git a/ExtentReports/Model/Test.cs b/ExtentReports/Model/Test.cs index 5c7e44b..009f294 100644 --- a/ExtentReports/Model/Test.cs +++ b/ExtentReports/Model/Test.cs @@ -110,6 +110,14 @@ public bool HasLog } } + public bool HasAttributes + { + get + { + return HasAuthor || HasCategory || HasDevice; + } + } + public GenericStructure CategoryContext { get diff --git a/ExtentReports/Reporter/ExtentHtml2Reporter.cs b/ExtentReports/Reporter/ExtentHtml2Reporter.cs new file mode 100644 index 0000000..3935564 --- /dev/null +++ b/ExtentReports/Reporter/ExtentHtml2Reporter.cs @@ -0,0 +1,99 @@ +using AventStack.ExtentReports.Core; +using AventStack.ExtentReports.Reporter.Configuration; +using AventStack.ExtentReports.Views.Html2; + +using RazorEngine.Templating; + +using System; +using System.IO; + +namespace AventStack.ExtentReports.Reporter +{ + /// + /// The ExtentHtmlReporter creates a rich standalone HTML file. It allows several configuration options + /// via the Configuration() method. + /// + public class ExtentHtml2Reporter : BasicFileReporter + { + public new string ReporterName => "html"; + + private static readonly string TemplateFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Views"); + private static readonly string HtmlTemplateFolderPath = Path.Combine(TemplateFolderPath, "Html2"); + + public ExtentHtml2Reporter(string folderPath) : base(folderPath) + { + Config = new ExtentHtmlReporterConfiguration(this); + Initialize(Config); + } + + public ExtentHtmlReporterConfiguration Config { get; } + + public override void Flush(ReportAggregates reportAggregates) + { + base.Flush(reportAggregates); + + Directory.CreateDirectory(SavePath); + + var source = RazorEngineManager.Instance.Razor.RunCompile("Index", typeof(ExtentHtml2Reporter), this); + File.WriteAllText(SavePath + "index.html", source); + source = RazorEngineManager.Instance.Razor.RunCompile("Dashboard", typeof(ExtentHtml2Reporter), this); + File.WriteAllText(SavePath + "dashboard.html", source); + if (AuthorContext.Context.Count > 0) + { + source = RazorEngineManager.Instance.Razor.RunCompile("Author", typeof(ExtentHtml2Reporter), this); + File.WriteAllText(SavePath + "author.html", source); + } + if (CategoryContext.Context.Count > 0) + { + source = RazorEngineManager.Instance.Razor.RunCompile("Tag", typeof(ExtentHtml2Reporter), this); + File.WriteAllText(SavePath + "tag.html", source); + } + if (DeviceContext.Context.Count > 0) + { + source = RazorEngineManager.Instance.Razor.RunCompile("Device", typeof(ExtentHtml2Reporter), this); + File.WriteAllText(SavePath + "device.html", source); + } + } + + public override void Start() + { + base.Start(); + AddTemplates(); + } + + private void AddTemplates() + { + string[] templates = new string[] + { + "Author", + "Device", + "Index", + "Dashboard", + "Tag", + "Partials.Attributes", + "Partials.AttributesView", + "Partials.Log", + "Partials.Navbar", + "Partials.RecurseNodes", + "Partials.Sidenav" + }; + + foreach (string template in templates) + { + string resourceName = typeof(IHtml2Marker).Namespace + "." + template + ".cshtml"; + using (var resourceStream = typeof(IHtml2Marker).Assembly.GetManifestResourceStream(resourceName)) + { + using (var reader = new StreamReader(resourceStream)) + { + if (resourceStream != null) + { + var arr = template.Split('.'); + var name = arr.Length > 1 ? arr[arr.Length - 1] : arr[0]; + RazorEngineManager.Instance.Razor.AddTemplate(name, reader.ReadToEnd()); + } + } + } + } + } + } +} diff --git a/ExtentReports/ViewDefs/MaterialIcon.cs b/ExtentReports/ViewDefs/MaterialIcon.cs index 532291b..e717c76 100644 --- a/ExtentReports/ViewDefs/MaterialIcon.cs +++ b/ExtentReports/ViewDefs/MaterialIcon.cs @@ -3,7 +3,7 @@ namespace AventStack.ExtentReports.ViewDefs { - public class MaterialIcon + public static class MaterialIcon { private static Dictionary _dic = new Dictionary(); diff --git a/ExtentReports/ViewDefs/TWBSIcon.cs b/ExtentReports/ViewDefs/TWBSIcon.cs new file mode 100644 index 0000000..bea764b --- /dev/null +++ b/ExtentReports/ViewDefs/TWBSIcon.cs @@ -0,0 +1,42 @@ +using System.Collections.Generic; + +namespace AventStack.ExtentReports.ViewDefs +{ + public static class TWBSIcon + { + private static Dictionary _dic = new Dictionary(); + + public static void Override(Status status, string icon) + { + _dic.Add(status, icon); + } + + public static string GetIcon(Status status) + { + if (_dic.ContainsKey(status)) + return _dic[status]; + + switch (status) + { + case Status.Fail: + return "times"; + case Status.Fatal: + return "times"; + case Status.Error: + return "exclamation"; + case Status.Warning: + return"warning"; + case Status.Skip: + return "long-arrow-right"; + case Status.Pass: + return "check"; + case Status.Debug: + return "low_priority"; + case Status.Info: + return "info"; + default: + return "help"; + } + } + } +} diff --git a/ExtentReports/Views/Html/Dashboard/Dashboard.cshtml b/ExtentReports/Views/Html/Dashboard/Dashboard.cshtml index 043280e..ef27b88 100644 --- a/ExtentReports/Views/Html/Dashboard/Dashboard.cshtml +++ b/ExtentReports/Views/Html/Dashboard/Dashboard.cshtml @@ -118,7 +118,7 @@ @context.Skipped @context.Others - @((context.Passed / @context.Count)*100)% + @((context.Passed / context.Count)*100)% } diff --git a/ExtentReports/Views/Html/Test/Test.cshtml b/ExtentReports/Views/Html/Test/Test.cshtml index 1e3960c..e45786e 100644 --- a/ExtentReports/Views/Html/Test/Test.cshtml +++ b/ExtentReports/Views/Html/Test/Test.cshtml @@ -4,7 +4,6 @@ var bdd = false; if (Model.TestList.Count > 0) { - bdd = Model.TestList[0].IsBehaviorDrivenType || (Model.TestList[0].HasChildren && Model.TestList[0].NodeContext.FirstOrDefault().IsBehaviorDrivenType); } } diff --git a/ExtentReports/Views/Html2/Author.cshtml b/ExtentReports/Views/Html2/Author.cshtml new file mode 100644 index 0000000..3b76f8c --- /dev/null +++ b/ExtentReports/Views/Html2/Author.cshtml @@ -0,0 +1,59 @@ +@using RazorEngine +@using RazorEngine.Templating + + + + + + + Extent Framework + + + + + +
+
+ @Include("Navbar") + @Include("Sidenav") +
+
+
+
+ +
+
    + @foreach (var author in Model.AuthorContext.Context) + { + @Include("AttributesView", author) + } +
+
+
+
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/ExtentReports/Views/Html2/Dashboard.cshtml b/ExtentReports/Views/Html2/Dashboard.cshtml new file mode 100644 index 0000000..a6c5e89 --- /dev/null +++ b/ExtentReports/Views/Html2/Dashboard.cshtml @@ -0,0 +1,456 @@ +@using AventStack.ExtentReports + +@{ + var bdd = Model.TestList[0].IsBehaviorDrivenType; + + var boxSize = "col-md-12"; + if (Model.ReportStatusStats.ChildCount > 0) { + boxSize = "col-sm-12 col-md-6"; + } + if (bdd || Model.ReportStatusStats.GrandChildCount > 0) { + boxSize = "col-sm-12 col-md-4"; + } + + var chartWidth="115"; + var chartHeight="90"; + var chartBoxHeight="94px"; + + var parentHeading="Classes"; + var childHeading="Tests"; + var grandChildHeading="Steps"; + var parentLabel="class(es)"; + var childLabel = "test(s)"; + var grandchildLabel="step(s)"; + + if (bdd) { + parentHeading="Features"; + childHeading="Scenarios"; + grandChildHeading="Steps"; + parentLabel="feature(s)"; + childLabel="scenario(s)"; + } else { + if (Model.AnalysisStrategy == AnalysisStrategy.Test) { + parentHeading="Tests"; + childHeading="Steps"; + grandChildHeading=""; + parentLabel="test(s)"; + childLabel=grandchildLabel; + } + } + + var runDuration = DateTime.Now - Model.StartTime; +} + + + + + + + Extent Framework + + + + + +
+
+ + @Include("Sidenav") +
+
+
+
+
+
+
+
@parentHeading
+
+
+
+ +
+
+ +
+
+ @if (Model.ReportStatusStats.ChildCount > 0) + { +
+
+
+
@childHeading
+
+
+
+ +
+
+ +
+
+ } + @if (Model.ReportStatusStats.GrandChildCount > 0) + { +
+
+
+
@grandChildHeading}
+
+
+
+ +
+
+ +
+
+ } +
+
+
+
+
+
+
+

@parentHeading

+

@Model.ReportStatusStats.ParentCount

+ + + @Math.Round(Model.ReportStatusStats.ParentPercentagePass, 2)% + +
+
+ +
+
+
+
+
+ @if (Model.ReportStatusStats.ChildCount > 0) + { +
+
+
+
+
+

@childHeading

+

@Model.ReportStatusStats.ChildCount

+ + + @Math.Round(Model.ReportStatusStats.ChildPercentagePass, 2)% + +
+
+ +
+
+
+
+
+ } +
+
+
+
+
+

Start

+
@Model.StartTime
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+

End

+
@Model.EndTime
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+

Duration

+
@runDuration
+ +
+
+ +
+
+
+
+
+
+ @if (Model.MasterConfig.GetValue("enableTimeline") == "true") + { +
+
+
+
+
Timeline
+
+
+
+ +
+
+
+
+
+ } +
+ @if (Model.AuthorContext.Context.Count > 0) + { +
+
+
+
Author
+
+
+ + + + + + + + + + + + @foreach(var context in Model.AuthorContext.Context) + { + + + + + + + + } + +
NamePassedFailedOthersPassed %
@context.Name@context.Passed@context.Failed@context.Others@(Math.Round(((double)context.Passed/(double)context.Count)*100, 2))%
+
+
+
+ } + @if (Model.CategoryContext.Context.Count > 0) + { +
+
+
+
Tags
+
+
+ + + + + + + + + + + + @foreach(var context in Model.CategoryContext.Context) + { + + + + + + + + } + +
NamePassedFailedOthersPassed %
@context.Name@context.Passed@context.Failed@context.Others@(Math.Round(((double)context.Passed/(double)context.Count)*100, 2))%
+
+
+
+ } + @if (Model.DeviceContext.Context.Count > 0) + { +
+
+
+
Device
+
+
+ + + + + + + + + + + + @foreach(var context in Model.DeviceContext.Context) + { + + + + + + + + } + +
NamePassedFailedOthersPassed %
@context.Name@context.Passed@context.Failed@context.Others@(Math.Round(((double)context.Passed/(double)context.Count)*100, 2))%
+
+
+
+ } + @if (Model.SystemAttributeContext.Count > 0) + { +
+
+
+
Environment
+
+
+ + + + + + + + + @foreach (var attr in Model.SystemAttributeContext.SystemAttributeCollection) + { + + + + + } + +
NameValue
@attr.Name@attr.Value
+
+
+
+ } +
+
+
+
+
+
+ + @if (Model.MasterConfig.GetValue("enableTimeline") == "true") + { + var json = ""; + for (int ix = 0; ix < Model.TestList.Count; ix++) { + json += "\"" + Model.TestList[ix].Name + "\"" + ":" + Model.TestList[ix].RunDuration.TotalSeconds; + if (ix != Model.TestList.Count-1) { + json += ","; + } + } + + } + + + + \ No newline at end of file diff --git a/ExtentReports/Views/Html2/Device.cshtml b/ExtentReports/Views/Html2/Device.cshtml new file mode 100644 index 0000000..05e3ce9 --- /dev/null +++ b/ExtentReports/Views/Html2/Device.cshtml @@ -0,0 +1,59 @@ +@using RazorEngine +@using RazorEngine.Templating + + + + + + + Extent Framework + + + + + +
+
+ @Include("Navbar") + @Include("Sidenav") +
+
+
+
+ +
+
    + @foreach (var device in Model.DeviceContext.Context) + { + @Include("AttributesView", device) + } +
+
+
+
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/ExtentReports/Views/Html2/IHtml2Marker.cs b/ExtentReports/Views/Html2/IHtml2Marker.cs new file mode 100644 index 0000000..d2ddab8 --- /dev/null +++ b/ExtentReports/Views/Html2/IHtml2Marker.cs @@ -0,0 +1,6 @@ +namespace AventStack.ExtentReports.Views.Html2 +{ + internal interface IHtml2Marker + { + } +} diff --git a/ExtentReports/Views/Html2/Index.cshtml b/ExtentReports/Views/Html2/Index.cshtml new file mode 100644 index 0000000..49f1aef --- /dev/null +++ b/ExtentReports/Views/Html2/Index.cshtml @@ -0,0 +1,152 @@ +@using RazorEngine +@using RazorEngine.Templating + + + + + + + Extent Framework + + + + + + +
+
+ @Include("Navbar") + @Include("Sidenav") +
+
+
+
+
+ + +
+
+
    + @foreach (var test in Model.TestList) + { +
  • +
    + @test.Status +
    +
    +
    +

    @test.Name

    +

    @test.RunDuration.ToString("''h'h:'m'm:'s's+'fff'ms'")

    + @test.StartTime.ToString("HH:mm:ss tt") +
    +
    +
  • +
    +
    +
    +
    +

    @test.Name

    + @test.StartTime + @test.EndTime + @test.RunDuration.ToString("''h'h:'m'm:'s's+'fff'ms'") +
    + @if (test.HasAttributes) + { +
    + @Include("Attributes", test) +
    + } +
    + +
    +
    + @if (test.HasLog) + { + @Include("Log", test) + } +
    + @if (test.HasScreenCapture) + { +
    + +
    + } + @if (test.HasChildren) + { + @Include("RecurseNodes", test) + } +
    + } +
+
+
+
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/ExtentReports/Views/Html2/Partials/Attributes.cshtml b/ExtentReports/Views/Html2/Partials/Attributes.cshtml new file mode 100644 index 0000000..eeee68c --- /dev/null +++ b/ExtentReports/Views/Html2/Partials/Attributes.cshtml @@ -0,0 +1,26 @@ +@if (Model.HasAttributes) +{ +
+ @if (Model.HasAuthor) + { + foreach (var author in Model.AuthorContext.All()) + { + @author.Name + } + } + @if (Model.HasCategory) + { + foreach (var category in Model.CategoryContext.All()) + { + @category.Name + } + } + @if (Model.HasDevice) + { + foreach (var device in Model.DeviceContext.All()) + { + @device.Name + } + } +
+} \ No newline at end of file diff --git a/ExtentReports/Views/Html2/Partials/AttributesView.cshtml b/ExtentReports/Views/Html2/Partials/AttributesView.cshtml new file mode 100644 index 0000000..88cf64c --- /dev/null +++ b/ExtentReports/Views/Html2/Partials/AttributesView.cshtml @@ -0,0 +1,58 @@ +
  • +
    +
    +

    @Model.Name

    +

    + @Model.Count tests +

    + + @if (Model.Passed > 0) { @Model.Passed } + @if (Model.Failed > 0) { @Model.Failed } + @if (Model.Skipped > 0) { @Model.Skipped } + @if (Model.Others > 0) { @Model.Others } + +
    +
    +
  • +
    +
    +
    +
    +

    @Model.Name

    + @if (Model.Passed > 0) { @Model.Passed passed } + @if (Model.Failed > 0) { @Model.Failed failed } + @if (Model.Skipped > 0) { @Model.Skipped skipped } + @if (Model.Others > 0) { @Model.Others others } +
    +
    +
    +
    + + + + + + + + + + @foreach (var test in Model.TestCollection) + { + + + + + + } + +
    StatusTimestampTestName
    +
    @test.Status
    +
    @test.StartTime.ToString("HH:mm:ss") + @test.Name + @if (test.Parent != null) + { +
    @test.Parent.Name
    + } +
    +
    +
    \ No newline at end of file diff --git a/ExtentReports/Views/Html2/Partials/Log.cshtml b/ExtentReports/Views/Html2/Partials/Log.cshtml new file mode 100644 index 0000000..a68eb53 --- /dev/null +++ b/ExtentReports/Views/Html2/Partials/Log.cshtml @@ -0,0 +1,32 @@ +@using AventStack.ExtentReports.ViewDefs + + + + + + + + + @foreach (var log in Model.LogContext.All()) + { + + + + + + } + +
    StatusTimestampDetails
    @log.Timestamp.ToString("HH:mm:ss") + @if (log.HasException) + { + + } + else + { + @Raw(log.Details) + } + @if (log.HasScreenCapture) + { + @Raw(log.ScreenCaptureContext.FirstOrDefault().Source) + } +
    diff --git a/ExtentReports/Views/Html2/Partials/Navbar.cshtml b/ExtentReports/Views/Html2/Partials/Navbar.cshtml new file mode 100644 index 0000000..f80c184 --- /dev/null +++ b/ExtentReports/Views/Html2/Partials/Navbar.cshtml @@ -0,0 +1,34 @@ + \ No newline at end of file diff --git a/ExtentReports/Views/Html2/Partials/RecurseNodes.cshtml b/ExtentReports/Views/Html2/Partials/RecurseNodes.cshtml new file mode 100644 index 0000000..1328c46 --- /dev/null +++ b/ExtentReports/Views/Html2/Partials/RecurseNodes.cshtml @@ -0,0 +1,32 @@ +@if (Model.HasChildren) +{ +
    + @foreach (var node in Model.NodeContext.All()) + { +
    + + @if (node.HasLog) + { +
    +
    + @Include("Log", node) +
    +
    + } + @if (node.HasChildren) + { + @Include("RecurseNodes", node) + } +
    + } +
    +} \ No newline at end of file diff --git a/ExtentReports/Views/Html2/Partials/Sidenav.cshtml b/ExtentReports/Views/Html2/Partials/Sidenav.cshtml new file mode 100644 index 0000000..12e0bb2 --- /dev/null +++ b/ExtentReports/Views/Html2/Partials/Sidenav.cshtml @@ -0,0 +1,55 @@ +
    +
    + +
    +
    \ No newline at end of file diff --git a/ExtentReports/Views/Html2/Tag.cshtml b/ExtentReports/Views/Html2/Tag.cshtml new file mode 100644 index 0000000..3e355c1 --- /dev/null +++ b/ExtentReports/Views/Html2/Tag.cshtml @@ -0,0 +1,59 @@ +@using RazorEngine +@using RazorEngine.Templating + + + + + + + Extent Framework + + + + + +
    +
    + @Include("Navbar") + @Include("Sidenav") +
    +
    +
    +
    + +
    +
      + @foreach (var category in Model.CategoryContext.Context) + { + @Include("AttributesView", category) + } +
    +
    +
    +
    +
    +
    +
    +
    +
    + + + + \ No newline at end of file From 08f16684f6ba3f56137f750499821a1fc057443e Mon Sep 17 00:00:00 2001 From: anshooarora Date: Mon, 24 Dec 2018 19:04:21 -0500 Subject: [PATCH 02/10] allow searching for tests/attributes using their names or content --- ExtentReports/Views/Html2/Author.cshtml | 2 +- ExtentReports/Views/Html2/Dashboard.cshtml | 2 +- ExtentReports/Views/Html2/Device.cshtml | 2 +- ExtentReports/Views/Html2/Index.cshtml | 132 +++++++++--------- .../Html2/Partials/AttributesView.cshtml | 82 +++++------ ExtentReports/Views/Html2/Partials/Log.cshtml | 2 +- .../Views/Html2/Partials/Navbar.cshtml | 2 +- ExtentReports/Views/Html2/Tag.cshtml | 2 +- 8 files changed, 117 insertions(+), 109 deletions(-) diff --git a/ExtentReports/Views/Html2/Author.cshtml b/ExtentReports/Views/Html2/Author.cshtml index 3b76f8c..8ba8576 100644 --- a/ExtentReports/Views/Html2/Author.cshtml +++ b/ExtentReports/Views/Html2/Author.cshtml @@ -37,7 +37,7 @@
    -
      +
        @foreach (var author in Model.AuthorContext.Context) { @Include("AttributesView", author) diff --git a/ExtentReports/Views/Html2/Dashboard.cshtml b/ExtentReports/Views/Html2/Dashboard.cshtml index a6c5e89..4a4adae 100644 --- a/ExtentReports/Views/Html2/Dashboard.cshtml +++ b/ExtentReports/Views/Html2/Dashboard.cshtml @@ -135,7 +135,7 @@
        -
        @grandChildHeading}
        +
        @grandChildHeading
        diff --git a/ExtentReports/Views/Html2/Device.cshtml b/ExtentReports/Views/Html2/Device.cshtml index 05e3ce9..d1f73a8 100644 --- a/ExtentReports/Views/Html2/Device.cshtml +++ b/ExtentReports/Views/Html2/Device.cshtml @@ -37,7 +37,7 @@
    -
      +
        @foreach (var device in Model.DeviceContext.Context) { @Include("AttributesView", device) diff --git a/ExtentReports/Views/Html2/Index.cshtml b/ExtentReports/Views/Html2/Index.cshtml index 49f1aef..9daa5df 100644 --- a/ExtentReports/Views/Html2/Index.cshtml +++ b/ExtentReports/Views/Html2/Index.cshtml @@ -56,7 +56,7 @@
    -
      +
        @foreach (var test in Model.TestList) {
      • @@ -70,70 +70,76 @@ @test.StartTime.ToString("HH:mm:ss tt")
    - -
    -
    -
    -
    -

    @test.Name

    - @test.StartTime - @test.EndTime - @test.RunDuration.ToString("''h'h:'m'm:'s's+'fff'ms'") -
    - @if (test.HasAttributes) +
    +
    +
    +
    +

    @test.Name

    + @test.StartTime + @test.EndTime + @test.RunDuration.ToString("''h'h:'m'm:'s's+'fff'ms'") +
    + @if (test.HasAttributes) + { +
    + @Include("Attributes", test) +
    + } + @if (!string.IsNullOrEmpty(test.Description)) + { +
    + @test.Description +
    + } +
    + +
    +
    + @if (test.HasLog) { -
    - @Include("Attributes", test) -
    - } -
    - -
    -
    - @if (test.HasLog) + @Include("Log", test) + } +
    + @if (test.HasScreenCapture) { - @Include("Log", test) - } -
    - @if (test.HasScreenCapture) - { -
    - -
    - } - @if (test.HasChildren) - { - @Include("RecurseNodes", test) - } -
    +
    + +
    + } + @if (test.HasChildren) + { + @Include("RecurseNodes", test) + } +
    + } diff --git a/ExtentReports/Views/Html2/Partials/AttributesView.cshtml b/ExtentReports/Views/Html2/Partials/AttributesView.cshtml index 88cf64c..c139266 100644 --- a/ExtentReports/Views/Html2/Partials/AttributesView.cshtml +++ b/ExtentReports/Views/Html2/Partials/AttributesView.cshtml @@ -13,46 +13,48 @@ - -
    -
    -
    -
    -

    @Model.Name

    - @if (Model.Passed > 0) { @Model.Passed passed } - @if (Model.Failed > 0) { @Model.Failed failed } - @if (Model.Skipped > 0) { @Model.Skipped skipped } - @if (Model.Others > 0) { @Model.Others others } +
    +
    +
    +
    +

    @Model.Name

    + @if (Model.Passed > 0) { @Model.Passed passed } + @if (Model.Failed > 0) { @Model.Failed failed } + @if (Model.Skipped > 0) { @Model.Skipped skipped } + @if (Model.Others > 0) { @Model.Others others } +
    +
    + + + + + + + + + + @foreach (var test in Model.TestCollection) + { + + + + + + } + +
    StatusTimestampTestName
    +
    @test.Status
    +
    @test.StartTime.ToString("HH:mm:ss") + @test.Name + @if (test.Parent != null) + { +
    + @test.Parent.Name +
    + } +
    +
    -
    - - - - - - - - - - @foreach (var test in Model.TestCollection) - { - - - - - - } - -
    StatusTimestampTestName
    -
    @test.Status
    -
    @test.StartTime.ToString("HH:mm:ss") - @test.Name - @if (test.Parent != null) - { -
    @test.Parent.Name
    - } -
    -
    -
    \ No newline at end of file + diff --git a/ExtentReports/Views/Html2/Partials/Log.cshtml b/ExtentReports/Views/Html2/Partials/Log.cshtml index a68eb53..af43f7b 100644 --- a/ExtentReports/Views/Html2/Partials/Log.cshtml +++ b/ExtentReports/Views/Html2/Partials/Log.cshtml @@ -23,7 +23,7 @@ } @if (log.HasScreenCapture) { - @Raw(log.ScreenCaptureContext.FirstOrDefault().Source) + @Raw(log.ScreenCaptureContext.FirstOrDefault().SourceIcon) } diff --git a/ExtentReports/Views/Html2/Partials/Navbar.cshtml b/ExtentReports/Views/Html2/Partials/Navbar.cshtml index f80c184..456f555 100644 --- a/ExtentReports/Views/Html2/Partials/Navbar.cshtml +++ b/ExtentReports/Views/Html2/Partials/Navbar.cshtml @@ -20,7 +20,7 @@
  • - +
  • -
      +
        @foreach (var category in Model.CategoryContext.Context) { @Include("AttributesView", category) From 3f5359ff41000f504f5163975e873f53a2fcb1ed Mon Sep 17 00:00:00 2001 From: anshooarora Date: Mon, 24 Dec 2018 19:36:44 -0500 Subject: [PATCH 03/10] add status, attributes filters --- ExtentReports/Views/Html2/Index.cshtml | 72 +++++++++++++++++++++----- 1 file changed, 58 insertions(+), 14 deletions(-) diff --git a/ExtentReports/Views/Html2/Index.cshtml b/ExtentReports/Views/Html2/Index.cshtml index 9daa5df..c4e8ef5 100644 --- a/ExtentReports/Views/Html2/Index.cshtml +++ b/ExtentReports/Views/Html2/Index.cshtml @@ -1,4 +1,5 @@ -@using RazorEngine +@using AventStack.ExtentReports +@using RazorEngine @using RazorEngine.Templating @@ -34,25 +35,68 @@
      • - - - +
      • + @if (Model.AuthorContext.Context.Count > 0) + {
      • - - - +
      • + } + @if (Model.CategoryContext.Context.Count > 0) + {
      • - - - +
      • + } + @if (Model.DeviceContext.Context.Count > 0) + {
      • - - - +
      • + }
    @@ -74,7 +118,7 @@
    -

    @test.Name

    +

    @test.Name

    @test.StartTime @test.EndTime @test.RunDuration.ToString("''h'h:'m'm:'s's+'fff'ms'") From ba64c7a5f909aa2906e4cdeccc003a2b947109ef Mon Sep 17 00:00:00 2001 From: anshooarora Date: Mon, 24 Dec 2018 21:34:16 -0500 Subject: [PATCH 04/10] add filter logic for status and attributes --- ExtentReports/Core/ExtentObservable.cs | 12 +++++-- ExtentReports/Reporter/BasicFileReporter.cs | 10 +++--- ExtentReports/Views/Html2/Index.cshtml | 37 +++++++++++++++------ 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/ExtentReports/Core/ExtentObservable.cs b/ExtentReports/Core/ExtentObservable.cs index 4009c88..f501a3b 100644 --- a/ExtentReports/Core/ExtentObservable.cs +++ b/ExtentReports/Core/ExtentObservable.cs @@ -206,9 +206,16 @@ private void RefreshStatusList(List 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()) { @@ -350,6 +357,7 @@ private void NotifyReporters() var reportAggregates = new ReportAggregates { TestList = _testList, + StatusList = _statusList, ReportStatusStats = this.ReportStatusStats, AuthorContext = this.AuthorContext, CategoryContext = this.CategoryContext, diff --git a/ExtentReports/Reporter/BasicFileReporter.cs b/ExtentReports/Reporter/BasicFileReporter.cs index 0a82dd5..22a4cb8 100644 --- a/ExtentReports/Reporter/BasicFileReporter.cs +++ b/ExtentReports/Reporter/BasicFileReporter.cs @@ -26,6 +26,8 @@ public abstract class BasicFileReporter : ConfigurableReporter public List TestList { get; protected internal set; } + public List StatusList { get; protected internal set; } + public TestAttributeTestContextProvider AuthorContext { get; protected internal set; } public TestAttributeTestContextProvider CategoryContext { get; protected internal set; } @@ -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; @@ -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); } } } diff --git a/ExtentReports/Views/Html2/Index.cshtml b/ExtentReports/Views/Html2/Index.cshtml index c4e8ef5..ec1c4af 100644 --- a/ExtentReports/Views/Html2/Index.cshtml +++ b/ExtentReports/Views/Html2/Index.cshtml @@ -39,13 +39,15 @@ - @@ -56,7 +58,7 @@ -