Skip to content

Commit b35d721

Browse files
committed
points to the parent directory if user provides a filepath
1 parent f6a6793 commit b35d721

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

ExtentReports/Reporter/BasicFileReporter.cs

+15-11
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
using System;
88
using System.Collections.Generic;
99
using System.Configuration;
10+
using System.IO;
1011

1112
namespace AventStack.ExtentReports.Reporter
1213
{
1314
public abstract class BasicFileReporter : ConfigurableReporter
1415
{
1516
public override string ReporterName { get; }
1617

17-
public string SavePath { get; protected internal set; }
18+
protected string SavePath { get; set; }
19+
protected string FolderSavePath { get; set; }
1820

1921
public override AnalysisStrategy AnalysisStrategy { get; set; }
2022

@@ -45,6 +47,8 @@ public abstract class BasicFileReporter : ConfigurableReporter
4547
protected BasicFileReporter(string filePath)
4648
{
4749
SavePath = filePath;
50+
FolderSavePath = Path.GetDirectoryName(filePath);
51+
FolderSavePath = string.IsNullOrEmpty(FolderSavePath) ? "./" : FolderSavePath;
4852
}
4953

5054
protected void Initialize(BasicFileConfiguration userConfig)
@@ -92,47 +96,47 @@ private void LoadUserConfig()
9296

9397
public override void OnAuthorAssigned(Test test, Author author)
9498
{
95-
99+
96100
}
97101

98102
public override void OnCategoryAssigned(Test test, Category category)
99103
{
100-
104+
101105
}
102106

103107
public override void OnDeviceAssigned(Test test, Device device)
104108
{
105-
109+
106110
}
107111

108112
public override void OnLogAdded(Test test, Log log)
109113
{
110-
114+
111115
}
112116

113117
public override void OnNodeStarted(Test node)
114118
{
115-
119+
116120
}
117121

118122
public override void OnScreenCaptureAdded(Test test, ScreenCapture screenCapture)
119123
{
120-
124+
121125
}
122126

123127
public override void OnScreenCaptureAdded(Log log, ScreenCapture screenCapture)
124128
{
125-
129+
126130
}
127131

128132
public override void OnTestRemoved(Test test)
129133
{
130-
134+
131135
}
132136

133137
public override void OnTestStarted(Test test)
134138
{
135-
139+
136140
}
137141

138142
public override void Start()
@@ -142,7 +146,7 @@ public override void Start()
142146

143147
public override void Stop()
144148
{
145-
149+
146150
}
147151

148152
public bool ContainsStatus(Status status)

ExtentReports/Reporter/ExtentHtmlReporter.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,34 @@ public override void Flush(ReportAggregates reportAggregates)
3232
{
3333
base.Flush(reportAggregates);
3434

35-
Directory.CreateDirectory(SavePath);
35+
Directory.CreateDirectory(FolderSavePath);
3636

3737
var source = RazorEngineManager.Instance.Razor.RunCompile("Index", typeof(ExtentHtmlReporter), this);
38-
File.WriteAllText(SavePath + "index.html", source);
38+
File.WriteAllText(FolderSavePath + "index.html", source);
3939
source = RazorEngineManager.Instance.Razor.RunCompile("Dashboard", typeof(ExtentHtmlReporter), this);
40-
File.WriteAllText(SavePath + "dashboard.html", source);
40+
File.WriteAllText(FolderSavePath + "dashboard.html", source);
4141
if (AuthorContext.Context.Count > 0)
4242
{
4343
source = RazorEngineManager.Instance.Razor.RunCompile("Author", typeof(ExtentHtmlReporter), this);
44-
File.WriteAllText(SavePath + "author.html", source);
44+
File.WriteAllText(FolderSavePath + "author.html", source);
4545
}
4646
if (CategoryContext.Context.Count > 0)
4747
{
4848
source = RazorEngineManager.Instance.Razor.RunCompile("Tag", typeof(ExtentHtmlReporter), this);
49-
File.WriteAllText(SavePath + "tag.html", source);
49+
File.WriteAllText(FolderSavePath + "tag.html", source);
5050
}
5151
if (DeviceContext.Context.Count > 0)
5252
{
5353
source = RazorEngineManager.Instance.Razor.RunCompile("Device", typeof(ExtentHtmlReporter), this);
54-
File.WriteAllText(SavePath + "device.html", source);
54+
File.WriteAllText(FolderSavePath + "device.html", source);
5555
}
5656
if (ExceptionInfoContext.Context.Count > 0)
5757
{
5858
source = RazorEngineManager.Instance.Razor.RunCompile("Exception", typeof(ExtentHtmlReporter), this);
59-
File.WriteAllText(SavePath + "exception.html", source);
59+
File.WriteAllText(FolderSavePath + "exception.html", source);
6060
}
6161
}
62-
62+
6363
public override void Start()
6464
{
6565
base.Start();
@@ -85,7 +85,7 @@ private void AddTemplates()
8585
"Partials.Scripts",
8686
"Partials.Sidenav"
8787
};
88-
88+
8989
foreach (string template in templates)
9090
{
9191
string resourceName = typeof(IHtmlMarker).Namespace + "." + template + ".cshtml";

0 commit comments

Comments
 (0)