Skip to content

Commit f6a6793

Browse files
authored
Version 4 default reporter (#5)
* initial * allow searching for tests/attributes using their names or content * add status, attributes filters * add filter logic for status and attributes * adds ExceptionView * config:documentTitle * config:css * refactor reporter names, prepend legacy report with v3 * modularize head, scripts * Update ExtentReports.csproj
1 parent 317082a commit f6a6793

39 files changed

+1451
-118
lines changed

ExtentReports.Tests/Base.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected void Setup()
1717
{
1818
string dir = TestContext.CurrentContext.TestDirectory + "\\";
1919
var fileName = this.GetType().ToString() + ".html";
20-
ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(dir + fileName);
20+
ExtentV3HtmlReporter htmlReporter = new ExtentV3HtmlReporter(dir + fileName);
2121

2222
_extent = new ExtentReports();
2323
_extent.AttachReporter(htmlReporter);

ExtentReports.Tests/Core/BuildsReportWithoutTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class BuildsReportWithoutTests
1313
public void BuildReportWithoutTests()
1414
{
1515
var fileName = TestContext.CurrentContext.Test.Name + ".html";
16-
var reporter = new ExtentHtmlReporter(fileName);
16+
var reporter = new ExtentV3HtmlReporter(fileName);
1717
var extent = new ExtentReports();
1818
extent.AttachReporter(reporter);
1919
extent.Flush();

ExtentReports.Tests/Service/ExtentService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class ExtentService
1515

1616
static ExtentService()
1717
{
18-
var htmlReporter = new ExtentHtmlReporter(TestContext.CurrentContext.TestDirectory + "\\Extent.html");
18+
var htmlReporter = new ExtentV3HtmlReporter(TestContext.CurrentContext.TestDirectory + "\\Extent.html");
1919
htmlReporter.Config.DocumentTitle = "Extent/NUnit Samples";
2020
htmlReporter.Config.ReportName = "Extent/NUnit Samples";
2121
htmlReporter.Config.Theme = Theme.Standard;

ExtentReports/Core/ExtentObservable.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,16 @@ private void RefreshStatusList(List<Test> testList)
206206
return;
207207
}
208208

209-
_statusMap.Clear();
210209
var distinctStatusList = testList.Select(x => x.Status).Distinct();
211-
distinctStatusList.ToList().ForEach(x => _statusMap.Add(x, false));
210+
211+
foreach (var s in distinctStatusList)
212+
{
213+
if (!_statusMap.ContainsKey(s))
214+
{
215+
_statusMap.Add(s, false);
216+
}
217+
}
218+
212219
// recursively, do the same for child tests
213220
foreach (var test in testList.ToList())
214221
{
@@ -350,6 +357,7 @@ private void NotifyReporters()
350357
var reportAggregates = new ReportAggregates
351358
{
352359
TestList = _testList,
360+
StatusList = _statusList,
353361
ReportStatusStats = this.ReportStatusStats,
354362
AuthorContext = this.AuthorContext,
355363
CategoryContext = this.CategoryContext,

ExtentReports/ExtentReports.csproj

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
<Compile Include="Reporter\Configuration\RichViewReporterConfiguration.cs" />
152152
<Compile Include="Reporter\Configuration\Theme.cs" />
153153
<Compile Include="Reporter\ExtentHtmlReporter.cs" />
154+
<Compile Include="Reporter\ExtentV3HtmlReporter.cs" />
154155
<Compile Include="Reporter\ExtentLoggerReporter.cs" />
155156
<Compile Include="Reporter\TemplateEngine\RazorEngineManager.cs" />
156157
<Compile Include="Reporter\TemplateInfo.cs" />
@@ -167,9 +168,12 @@
167168
<Compile Include="Utils\ExceptionUtil.cs" />
168169
<Compile Include="Utils\ListUtil.cs" />
169170
<Compile Include="Utils\ResourceUtils.cs" />
171+
<Compile Include="ViewDefs\TWBSIcon.cs" />
170172
<Compile Include="ViewDefs\MaterialIcon.cs" />
171173
<Compile Include="Views\Commons\ICommonsMarker.cs" />
172-
<Compile Include="Views\Html\IHtmlMarker.cs" />
174+
<Compile Include="Views\Html\IHtml2Marker.cs" />
175+
<EmbeddedResource Include="Views\Html\Partials\Attributes.cshtml" />
176+
<Compile Include="Views\V3Html\IV3HtmlMarker.cs" />
173177
<Compile Include="Views\Logger\ILoggerMarker.cs" />
174178
</ItemGroup>
175179
<ItemGroup>
@@ -189,26 +193,26 @@
189193
<EmbeddedResource Include="Views\Commons\CommonsInjectCss.cshtml" />
190194
<EmbeddedResource Include="Views\Commons\CommonsInjectJs.cshtml" />
191195
<EmbeddedResource Include="Views\Commons\CommonsTag.cshtml" />
192-
<EmbeddedResource Include="Views\Html\Author\Author.cshtml" />
193-
<EmbeddedResource Include="Views\Html\Category\Category.cshtml" />
194-
<EmbeddedResource Include="Views\Html\Dashboard\Dashboard.cshtml" />
195-
<EmbeddedResource Include="Views\Html\Exception\Exception.cshtml">
196+
<EmbeddedResource Include="Views\V3Html\Author\V3Author.cshtml" />
197+
<EmbeddedResource Include="Views\V3Html\Category\V3Category.cshtml" />
198+
<EmbeddedResource Include="Views\V3Html\Dashboard\V3Dashboard.cshtml" />
199+
<EmbeddedResource Include="Views\V3Html\Exception\V3Exception.cshtml">
196200
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
197201
</EmbeddedResource>
198-
<EmbeddedResource Include="Views\Html\TestRunner\Logs.cshtml" />
199-
<EmbeddedResource Include="Views\Html\Test\Charts.cshtml">
202+
<EmbeddedResource Include="Views\V3Html\TestRunner\V3Logs.cshtml" />
203+
<EmbeddedResource Include="Views\V3Html\Test\V3Charts.cshtml">
200204
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
201205
</EmbeddedResource>
202-
<EmbeddedResource Include="Views\Html\Test\Test.cshtml">
206+
<EmbeddedResource Include="Views\V3Html\Test\V3Test.cshtml">
203207
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
204208
<SubType>Designer</SubType>
205209
</EmbeddedResource>
206-
<EmbeddedResource Include="Views\Html\Head.cshtml">
210+
<EmbeddedResource Include="Views\V3Html\V3Head.cshtml">
207211
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
208212
<SubType>Designer</SubType>
209213
</EmbeddedResource>
210-
<EmbeddedResource Include="Views\Html\Index.cshtml" />
211-
<EmbeddedResource Include="Views\Html\Nav.cshtml">
214+
<EmbeddedResource Include="Views\V3Html\V3Index.cshtml" />
215+
<EmbeddedResource Include="Views\V3Html\V3Nav.cshtml">
212216
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
213217
</EmbeddedResource>
214218
<EmbeddedResource Include="Views\Logger\LoggerDashboard.cshtml">
@@ -224,6 +228,19 @@
224228
<EmbeddedResource Include="Views\Commons\CommonsAttributes.cshtml" />
225229
<EmbeddedResource Include="Views\Commons\CommonsMedia.cshtml" />
226230
<EmbeddedResource Include="Views\Commons\CommonsRow.cshtml" />
231+
<EmbeddedResource Include="Views\Html\Tag.cshtml" />
232+
<EmbeddedResource Include="Views\Html\Dashboard.cshtml" />
233+
<EmbeddedResource Include="Views\Html\Index.cshtml" />
234+
<EmbeddedResource Include="Views\Html\Partials\Sidenav.cshtml" />
235+
<EmbeddedResource Include="Views\Html\Partials\Log.cshtml" />
236+
<EmbeddedResource Include="Views\Html\Partials\RecurseNodes.cshtml" />
237+
<EmbeddedResource Include="Views\Html\Partials\AttributesView.cshtml" />
238+
<EmbeddedResource Include="Views\Html\Partials\Navbar.cshtml" />
239+
<EmbeddedResource Include="Views\Html\Author.cshtml" />
240+
<EmbeddedResource Include="Views\Html\Device.cshtml" />
241+
<EmbeddedResource Include="Views\Html\Exception.cshtml" />
242+
<EmbeddedResource Include="Views\Html\Partials\Head.cshtml" />
243+
<EmbeddedResource Include="Views\Html\Partials\Scripts.cshtml" />
227244
</ItemGroup>
228245
<ItemGroup>
229246
<None Include="Resources\Languages.txt" />

ExtentReports/Model/Media.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Threading;
34

45
using MongoDB.Bson;
@@ -12,13 +13,32 @@ public class Media
1213
public ObjectId ReportObjectId { get; set; }
1314
public ObjectId TestObjectId { get; set; }
1415
public ObjectId LogObjectId { get; set; }
16+
public long FileSize { get; set; }
1517
public string Name { get; set; }
1618
public string Description { get; set; }
17-
public string Path { get; set; }
1819
public string Title { get; set; }
1920
public string Base64String { get; set; }
2021
public int Sequence { get; private set; } = Interlocked.Increment(ref _seq);
2122

23+
public string Path
24+
{
25+
get
26+
{
27+
return _path;
28+
}
29+
set
30+
{
31+
_path = value;
32+
33+
Name = !string.IsNullOrEmpty(Name) ? Name : System.IO.Path.GetFileName(value);
34+
if (File.Exists(value))
35+
{
36+
FileSize = new FileInfo(value).Length;
37+
}
38+
}
39+
}
40+
2241
private static int _seq;
42+
private string _path;
2343
}
2444
}

ExtentReports/Model/ScreenCapture.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,21 @@ public string SourceIcon
3232
"</a>";
3333
}
3434
}
35+
36+
public string ScreenCapturePath
37+
{
38+
get
39+
{
40+
return !string.IsNullOrEmpty(base.Path) ? base.Path : Base64String;
41+
}
42+
}
43+
44+
public bool IsBase64
45+
{
46+
get
47+
{
48+
return !string.IsNullOrEmpty(Base64String);
49+
}
50+
}
3551
}
3652
}

ExtentReports/Model/Test.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ public bool HasLog
110110
}
111111
}
112112

113+
public bool HasAttributes
114+
{
115+
get
116+
{
117+
return HasAuthor || HasCategory || HasDevice;
118+
}
119+
}
120+
113121
public GenericStructure<TestAttribute> CategoryContext
114122
{
115123
get

ExtentReports/Reporter/BasicFileReporter.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public abstract class BasicFileReporter : ConfigurableReporter
2626

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

29+
public List<Status> StatusList { get; protected internal set; }
30+
2931
public TestAttributeTestContextProvider<Author> AuthorContext { get; protected internal set; }
3032

3133
public TestAttributeTestContextProvider<Category> CategoryContext { get; protected internal set; }
@@ -62,6 +64,7 @@ protected void Initialize(BasicFileConfiguration userConfig)
6264
public override void Flush(ReportAggregates reportAggregates)
6365
{
6466
TestList = reportAggregates.TestList;
67+
StatusList = reportAggregates.StatusList;
6568
ReportStatusStats = reportAggregates.ReportStatusStats;
6669
AuthorContext = reportAggregates.AuthorContext;
6770
CategoryContext = reportAggregates.CategoryContext;
@@ -144,12 +147,7 @@ public override void Stop()
144147

145148
public bool ContainsStatus(Status status)
146149
{
147-
return true;
148-
}
149-
150-
public bool ContainsStatus(string status)
151-
{
152-
return true;
150+
return StatusList.Contains(status);
153151
}
154152
}
155153
}

ExtentReports/Reporter/ExtentHtmlReporter.cs

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using AventStack.ExtentReports.Core;
2-
using AventStack.ExtentReports.Views.Html;
32
using AventStack.ExtentReports.Reporter.Configuration;
3+
using AventStack.ExtentReports.Views.Html;
44

55
using RazorEngine.Templating;
66

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

23-
public ExtentHtmlReporter(string filePath) : base(filePath)
23+
public ExtentHtmlReporter(string folderPath) : base(folderPath)
2424
{
2525
Config = new ExtentHtmlReporterConfiguration(this);
2626
Initialize(Config);
@@ -31,8 +31,33 @@ public ExtentHtmlReporter(string filePath) : base(filePath)
3131
public override void Flush(ReportAggregates reportAggregates)
3232
{
3333
base.Flush(reportAggregates);
34+
35+
Directory.CreateDirectory(SavePath);
36+
3437
var source = RazorEngineManager.Instance.Razor.RunCompile("Index", typeof(ExtentHtmlReporter), this);
35-
File.WriteAllText(SavePath, source);
38+
File.WriteAllText(SavePath + "index.html", source);
39+
source = RazorEngineManager.Instance.Razor.RunCompile("Dashboard", typeof(ExtentHtmlReporter), this);
40+
File.WriteAllText(SavePath + "dashboard.html", source);
41+
if (AuthorContext.Context.Count > 0)
42+
{
43+
source = RazorEngineManager.Instance.Razor.RunCompile("Author", typeof(ExtentHtmlReporter), this);
44+
File.WriteAllText(SavePath + "author.html", source);
45+
}
46+
if (CategoryContext.Context.Count > 0)
47+
{
48+
source = RazorEngineManager.Instance.Razor.RunCompile("Tag", typeof(ExtentHtmlReporter), this);
49+
File.WriteAllText(SavePath + "tag.html", source);
50+
}
51+
if (DeviceContext.Context.Count > 0)
52+
{
53+
source = RazorEngineManager.Instance.Razor.RunCompile("Device", typeof(ExtentHtmlReporter), this);
54+
File.WriteAllText(SavePath + "device.html", source);
55+
}
56+
if (ExceptionInfoContext.Context.Count > 0)
57+
{
58+
source = RazorEngineManager.Instance.Razor.RunCompile("Exception", typeof(ExtentHtmlReporter), this);
59+
File.WriteAllText(SavePath + "exception.html", source);
60+
}
3661
}
3762

3863
public override void Start()
@@ -45,18 +70,22 @@ private void AddTemplates()
4570
{
4671
string[] templates = new string[]
4772
{
73+
"Author",
74+
"Dashboard",
75+
"Device",
76+
"Exception",
4877
"Index",
49-
"Head",
50-
"Nav",
51-
"Test.Test",
52-
"Test.Charts",
53-
"Author.Author",
54-
"Category.Category",
55-
"Dashboard.Dashboard",
56-
"Exception.Exception",
57-
"TestRunner.Logs"
78+
"Tag",
79+
"Partials.Attributes",
80+
"Partials.AttributesView",
81+
"Partials.Head",
82+
"Partials.Log",
83+
"Partials.Navbar",
84+
"Partials.RecurseNodes",
85+
"Partials.Scripts",
86+
"Partials.Sidenav"
5887
};
59-
88+
6089
foreach (string template in templates)
6190
{
6291
string resourceName = typeof(IHtmlMarker).Namespace + "." + template + ".cshtml";

0 commit comments

Comments
 (0)