Skip to content

Commit

Permalink
Added /reportTitle parameter so users can change the default trx titl…
Browse files Browse the repository at this point in the history
…e. Added StdErr parsing. Fixed a few visual bugs in the report template. Added functionality to change the panel color based ont he test outcome.
  • Loading branch information
SlaviDimitrov committed Dec 12, 2016
1 parent 1557e08 commit d426e47
Show file tree
Hide file tree
Showing 6 changed files with 317 additions and 199 deletions.
57 changes: 37 additions & 20 deletions TRX_Merger/Program.cs
Expand Up @@ -14,17 +14,17 @@ public class Program
{
public static int Main(string[] args)
{


if(args.Length == 0

if (args.Length == 0
|| args.Contains("/h")
|| args.Contains("/help"))
{
DispalyHelp();
return 1;
}

if(args.Where(a => a.StartsWith("/trx")).FirstOrDefault() == null)
if (args.Where(a => a.StartsWith("/trx")).FirstOrDefault() == null)
{
Console.WriteLine("/trx parameter is required");
return 1;
Expand All @@ -36,15 +36,15 @@ public static int Main(string[] args)
{
Console.WriteLine("No trx files found!");
return 1;
}
}

if(trxFiles.Count == 1)
if (trxFiles.Count == 1)
{
if (trxFiles[0].StartsWith("Error: "))
{
Console.WriteLine(trxFiles[0]);
return 1;
}
}

if (args.Where(a => a.StartsWith("/report")).FirstOrDefault() == null)
{
Expand All @@ -66,9 +66,10 @@ public static int Main(string[] args)
}

string screenshotLocation = ResolveScreenshotLocation(args.Where(a => a.StartsWith("/screenshots")).FirstOrDefault());
string reportTitle = ResolveReportTitle(args.Where(a => a.StartsWith("/reportTitle")).FirstOrDefault());
try
{
TrxReportGenerator.GenerateReport(trxFiles[0], reportOutput, screenshotLocation);
TrxReportGenerator.GenerateReport(trxFiles[0], reportOutput, screenshotLocation, reportTitle);
}
catch (Exception ex)
{
Expand All @@ -77,7 +78,7 @@ public static int Main(string[] args)

Console.WriteLine("Error: " + ex.Message);
return 1;
}
}
}
else
{
Expand All @@ -86,17 +87,17 @@ public static int Main(string[] args)
Console.WriteLine("/output parameter is required, when there are multiple trx files in /trx argument");
return 1;
}

string outputParam = ResolveOutputFileName(args.Where(a => a.StartsWith("/output")).FirstOrDefault());
if (outputParam.StartsWith("Error: "))
{
Console.WriteLine(outputParam);
return 1;
}

if (trxFiles.Contains(outputParam))
if (trxFiles.Contains(outputParam))
trxFiles.Remove(outputParam);

try
{
var combinedTestRun = TestRunMerger.MergeTRXsAndSave(trxFiles, outputParam);
Expand All @@ -112,8 +113,9 @@ public static int Main(string[] args)
}

string screenshotLocation = ResolveScreenshotLocation(args.Where(a => a.StartsWith("/screenshots")).FirstOrDefault());
string reportTitle = ResolveReportTitle(args.Where(a => a.StartsWith("/reportTitle", StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault());

TrxReportGenerator.GenerateReport(combinedTestRun, reportOutput, screenshotLocation);
TrxReportGenerator.GenerateReport(combinedTestRun, reportOutput, screenshotLocation, reportTitle);
}
catch (Exception ex)
{
Expand All @@ -122,7 +124,7 @@ public static int Main(string[] args)

Console.WriteLine("Error: " + ex.Message);
return 1;
}
}
}

return 0;
Expand Down Expand Up @@ -166,14 +168,14 @@ private static void DispalyHelp()
}

private static string ResolveOutputFileName(string outputParam)
{
{
var splitOutput = outputParam.Split(new char[] { ':' });

if (splitOutput.Length == 1
|| !outputParam.EndsWith(".trx"))
return "Error: /output parameter is in the incorrect format. Expected /output:<file name | directory and file name>. Execute /help for more information";

return outputParam.Substring(8, outputParam.Length - 8);
return outputParam.Substring(8, outputParam.Length - 8);
}

private static string ResolveReportLocation(string reportParam)
Expand Down Expand Up @@ -207,25 +209,40 @@ private static string ResolveScreenshotLocation(string screenshots)
return screenshotsLocation;
}

private static string ResolveReportTitle(string reportTitle)
{
if (string.IsNullOrEmpty(reportTitle))
return null;

var splitScreenshots = reportTitle.Split(new char[] { ':' });

if (splitScreenshots.Length == 1)
return "Error: /reportTitle parameter is in the correct format. Expected /reportTitle:<title>. Execute /help for more information";

var screenshotsLocation = reportTitle.Substring("/reportTitle".Length + 1);

return screenshotsLocation;
}

private static List<string> ResolveTrxFilePaths(string trxParams, bool recursive)
{
List<string> paths = new List<string>();

var splitTrx = trxParams.Split(new char[] { ':' });

var searchOpts = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;

if (splitTrx.Length == 1)
return Directory.GetFiles(Directory.GetCurrentDirectory(), "*.trx", searchOpts).ToList();

var args = trxParams.Substring(5,trxParams.Length - 5).Split(new char[] { ',' }).ToList();
var args = trxParams.Substring(5, trxParams.Length - 5).Split(new char[] { ',' }).ToList();

foreach (var a in args)
{
bool isTrxFile = File.Exists(a) && a.EndsWith(".trx");
bool isDir = Directory.Exists(a);
if(!isTrxFile && !isDir)

if (!isTrxFile && !isDir)
return new List<string>
{
string.Format("Error: {0} is not a trx file or directory", a)
Expand All @@ -236,7 +253,7 @@ private static List<string> ResolveTrxFilePaths(string trxParams, bool recursive

if (isDir)
paths.AddRange(Directory.GetFiles(a, "*.trx", searchOpts).ToList());

}

return paths;
Expand Down
17 changes: 10 additions & 7 deletions TRX_Merger/ReportGenerator/TrxReportGenerator.cs
Expand Up @@ -14,21 +14,24 @@ namespace TRX_Merger.ReportGenerator
{
public static class TrxReportGenerator
{
public static void GenerateReport(string trxFilePath, string outputFile, string screenshotLocation)
public static void GenerateReport(string trxFilePath, string outputFile, string screenshotLocation, string reportTitle)
{
var testRun = TRXSerializationUtils.DeserializeTRX(trxFilePath);

GenerateReport(testRun, outputFile, screenshotLocation);
GenerateReport(testRun, outputFile, screenshotLocation, reportTitle);
}

public static void GenerateReport(TestRun run, string outputFile, string screenshotLocation)
public static void GenerateReport(TestRun run, string outputFile, string screenshotLocation, string reportTitle)
{
if (!string.IsNullOrEmpty(reportTitle))
run.Name = reportTitle;

Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
string template = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ReportGenerator/trx_report_template.html"));

string result = Engine.Razor.RunCompile(
template,
"rawTemplate",
template,
"rawTemplate",
null,
new TestRunReport(run));

Expand All @@ -39,8 +42,8 @@ public static void GenerateReport(TestRun run, string outputFile, string screens
Console.WriteLine("Deleting: " + outputFile);
File.Delete(outputFile);
}
File.WriteAllText(outputFile, result);

File.WriteAllText(outputFile, result);
}
}
}

0 comments on commit d426e47

Please sign in to comment.