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
34 changes: 34 additions & 0 deletions ExtentReports.Tests/Reporter/SparkReporterConcurrentTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Linq;
using System.Threading.Tasks;
using AventStack.ExtentReports.Model;
using AventStack.ExtentReports.Reporter;
using NUnit.Framework;
using NUnit.Framework.Internal;

namespace AventStack.ExtentReports.Tests.Reporter
{
public class SparkReporterConcurrentTest
{
private ExtentReports _extent;

[SetUp]
public void Setup()
{
_extent = new ExtentReports();
_extent.AttachReporter(new ExtentSparkReporter("SparkReporterConcurrentTest.html"));
}

[Test]
public void ParallelCreateTestsAndFlush()
{
var rng = Enumerable.Range(0, 100);
Parallel.ForEach(rng, new ParallelOptions { MaxDegreeOfParallelism = 4 }, x => {
_extent.CreateTest("Test").Info("");
if (x % 5 == 0)
{
_extent.Flush();
}
});
}
}
}
18 changes: 16 additions & 2 deletions ExtentReports.Tests/Reporter/SparkReporterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,26 @@ public void SparkXMLConfig()
[Test]
public void SparkJSONConfig()
{
var xmlConfigPath = Path.Combine(@"../../../../", @"config/spark-config.json");
var jsonConfigPath = Path.Combine(@"../../../../", @"config/spark-config.json");
var spark = new ExtentSparkReporter("Spark.html");
spark.LoadJSONConfig(xmlConfigPath);
spark.LoadJSONConfig(jsonConfigPath);
Assert.AreEqual(spark.Config.Theme, Theme.Standard);
Assert.AreEqual(spark.Config.DocumentTitle, "Extent Framework");
Assert.AreEqual(spark.Config.Protocol, Protocol.HTTPS);
}

[Test]
public void SparkReporterTimestamp()
{
var extent = new ExtentReports();
var spark = new ExtentSparkReporter("Index.html");
extent.AttachReporter(spark);
var jsonConfigPath = Path.Combine(@"../../../../", @"config/spark-config.json");
spark.LoadJSONConfig(jsonConfigPath);

extent.CreateTest("SparkReporterTimestamp")
.Pass("Passed");
extent.Flush();
}
}
}
2 changes: 1 addition & 1 deletion ExtentReports/ExtentReports.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<PackOnBuild>true</PackOnBuild>
<RootNamespace>AventStack.ExtentReports</RootNamespace>
<PackageVersion>5.0.3-beta</PackageVersion>
<PackageVersion>5.0.3-beta2</PackageVersion>
<Authors>anshooarora</Authors>
<Copyright>AventStack</Copyright>
<PackageLicenseUrl>https://github.com/extent-framework/extentreports-csharp/blob/master/LICENSE</PackageLicenseUrl>
Expand Down
15 changes: 15 additions & 0 deletions ExtentReports/Reporter/Config/ExtentSparkReporterConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ public class ExtentSparkReporterConfig : InteractiveReporterConfig
{
private const string OfflinePackage = "extent";
private const string Package = "AventStack.ExtentReports.Views.Spark.Offline";
private const string DefaultTimeStampFormat = "MMM dd, yyyy HH:mm:ss";
private bool _offline = false;
private string _timestampFormat = DefaultTimeStampFormat;

internal ExtentSparkReporter Reporter { get; set; }

Expand All @@ -32,6 +34,19 @@ public bool OfflineMode
}
}

[XmlElement("timeStampFormat")]
public string TimeStampFormat
{
get
{
return string.IsNullOrEmpty(_timestampFormat) ? DefaultTimeStampFormat : _timestampFormat;
}
set
{
_timestampFormat = value;
}
}

public ExtentSparkReporterConfig() { }

[JsonConstructor]
Expand Down
16 changes: 16 additions & 0 deletions ExtentReports/Reporter/Model/SparkReporterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using AventStack.ExtentReports.Model;

namespace AventStack.ExtentReports.Reporter.Model
{
public class SparkReporterTest
{
public SparkReporterTest(ExtentSparkReporter reporter, Test test)
{
Reporter = reporter;
Test = test;
}

public ExtentSparkReporter Reporter;
public Test Test;
}
}
4 changes: 2 additions & 2 deletions ExtentReports/Views/Spark/Partials/Log.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@using RazorEngine.Templating

@{
var logs = new List<Log>(Model.Logs);
var logs = Model.Test.Logs;
}

<table class="table table-sm">
Expand All @@ -16,7 +16,7 @@
var status = log.Status.ToString().ToLower();
<tr class="event-row">
<td><span class="badge log @status-bg">@log.Status</span></td>
<td>@log.Timestamp.ToShortTimeString()</td>
<td>@log.Timestamp.ToString(Model.Reporter.Config.TimeStampFormat)</td>
<td>
@if (log.HasException)
{
Expand Down
12 changes: 7 additions & 5 deletions ExtentReports/Views/Spark/Partials/RecurseNodes.cshtml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
@using AventStack.ExtentReports
@using AventStack.ExtentReports.Model
@using AventStack.ExtentReports.Reporter.Model
@using System
@using RazorEngine
@using RazorEngine.Templating

@if (Model.HasChildren)
@if (Model.Test.HasChildren)
{
var children = new List<Test>(Model.Children);
var children = Model.Test.Children;

<div class="accordion">
@foreach (var child in children)
Expand Down Expand Up @@ -48,7 +49,7 @@
<div class="detail-body mt-4">
@if (child.HasGeneratedLog)
{
var genLog = new List<Log>(child.GeneratedLog);
var genLog = child.GeneratedLog;
@foreach (var l in genLog)
{
<div>
Expand All @@ -57,7 +58,7 @@
</div>
}
}
@if (child.HasLog) { @Include("Log", child) }
@if (child.HasLog) { @Include("Log", new SparkReporterTest(Model.Reporter, child)) }
</div>
}
@foreach (var m in child.Media)
Expand All @@ -69,7 +70,8 @@
}
@if (child.HasChildren)
{
@Include("RecurseNodes", child)
var reporterTest = new SparkReporterTest(Model.Reporter, child);
@Include("RecurseNodes", reporterTest)
}
</div>
}
Expand Down
12 changes: 6 additions & 6 deletions ExtentReports/Views/Spark/Partials/SparkBDD.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
@using RazorEngine
@using RazorEngine.Templating

@if (Model.HasChildren)
@if (Model.Test.HasChildren)
{
var children = new List<Test>(Model.Children);
@Include("SparkMediaTest", Model)
var children = Model.Test.Children;
@Include("SparkMediaTest", Model.Test)
<div class="accordion mt-4">
@foreach (var node in children)
{
Expand All @@ -26,7 +26,7 @@
if (node.BddType.Name == "ScenarioOutline")
{
var css = node.Status == Status.Pass ? "collapse" : "";
var scenarios = new List<Test>(node.Children);
var scenarios = node.Children;
<div class="scenario_outline @css">
@foreach (var child in scenarios)
{
Expand All @@ -43,7 +43,7 @@
</div>
@{
css = child.Status == Status.Pass ? "collapse" : "";
var steps = new List<Test>(child.Children);
var steps = child.Children;
}
@foreach (var step in steps)
{
Expand All @@ -60,7 +60,7 @@
else
{
var css = node.Status == Status.Pass ? "collapse" : "";
var steps = new List<Test>(node.Children);
var steps = node.Children;
<div class="@css">
<div class="card-body">
@Include("SparkMediaTest", node)
Expand Down
12 changes: 6 additions & 6 deletions ExtentReports/Views/Spark/Partials/SparkStandard.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
@using RazorEngine
@using RazorEngine.Templating

@foreach (var m in Model.Media)
@foreach (var m in Model.Test.Media)
{
@Include("SparkMedia", m)
}

@if (Model.HasAnyLog)
@if (Model.Test.HasAnyLog)
{
<div class="detail-body mt-4">
@if (Model.HasGeneratedLog)
@if (Model.Test.HasGeneratedLog)
{
var genLog = new List<Log>(Model.GeneratedLog);
var genLog = new List<Log>(Model.Test.GeneratedLog);
@foreach (var l in genLog)
{
<div>
Expand All @@ -23,10 +23,10 @@
</div>
}
}
@if (Model.HasLog) { @Include("Log", Model) }
@if (Model.Test.HasLog) { @Include("Log", Model) }
</div>
}
@if (Model.HasChildren)
@if (Model.Test.HasChildren)
{
<div class="mt-4">@Include("RecurseNodes", Model)</div>
}
8 changes: 5 additions & 3 deletions ExtentReports/Views/Spark/Partials/SparkTestSPA.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@using AventStack.ExtentReports
@using AventStack.ExtentReports.Model
@using AventStack.ExtentReports.Reporter.Model
@using System
@using RazorEngine
@using RazorEngine.Templating
Expand Down Expand Up @@ -60,6 +61,7 @@
<ul class="test-list-item">
@foreach (var test in testList)
{
var reporterTest = new SparkReporterTest(Model, test);
var timeTaken = Math.Round(test.TimeTaken, 2);
var status = test.Status.ToString().ToLower();
var authors = ""; var tags = ""; var devices = "";
Expand All @@ -82,8 +84,8 @@
<div class="p-v-10">
<div class="info">
<h5 class="test-status text-@status">@test.Name</h5>
<span class='badge badge-success'>@test.StartTime</span>
<span class='badge badge-danger'>@test.EndTime</span>
<span class='badge badge-success'>@test.StartTime.ToString(Model.Config.TimeStampFormat)</span>
<span class='badge badge-danger'>@test.EndTime.ToString(Model.Config.TimeStampFormat)</span>
<span class='badge badge-default'>@timeTaken ms</span>
&middot; <span class='uri-anchor badge badge-default'>#test-id=@test.Id</span>
<span title='Skip to the next failed step' class='badge badge-danger pointer float-right ne ml-1'><i class="fa fa-fast-forward"></i></span>
Expand All @@ -94,7 +96,7 @@
@if (!string.IsNullOrEmpty(test.Description)) { <div class="m-t-10 m-l-5">@test.Description</div> }
</div>
</div>
@if (isbdd) { @Include("SparkBDD", test) } else { @Include("SparkStandard", test) }
@if (isbdd) { @Include("SparkBDD", reporterTest) } else { @Include("SparkStandard", reporterTest) }
</div>
</li>
}
Expand Down
2 changes: 1 addition & 1 deletion ExtentReports/Views/Spark/Partials/StepDetails.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@if (Model.HasLog)
{
var logs = new List<Log>(Model.Logs);
var logs = Model.Logs;
foreach (var log in logs)
{
<div>
Expand Down
2 changes: 1 addition & 1 deletion config/spark-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"thumbnailForBase64": false,
"documentTitle": "Extent Framework",
"reportName": "ExtentReports",
"timeStampFormat": "MMM dd, yyyy HH:mm:ss a",
"timeStampFormat": "MMM dd, yyyy HH:mm:ss",
"js": "",
"css": ""
}