public static void WriteWarning(string message)
{
message = "<div class=\"infoMessage\">" + message + "</div>";
Console.WriteLine(message);
}
<div class="infoMessage">ji...@no.com has been typed into the element./div>
.infoMessage
{
width: 600px;
color: Green;
font-weight: bold;
}
<div class="infoMessage">jill@no.com has been typed into the element.</div>
@functions
{
/* XXX MY CUSTOMISED FUNCTION XXX */
string compose_message(string message)
{
message = "<div class=\"infoMessage\">" + message + "</div>";
return message;
}
}
Stephen - Thanks for taking the time to look at this. Not sure how the closing div tag was missing but it should have been displayed. I have tried a few different ways and no luck. I changed my LogFunctions.cs from public static void to a public static string and returned the message and my report then had nothing appearing in it. i got tired of looking at the html tags in the report so I am now just returning the text but below is how it was setup.
public static void WriteInfo(string message)
{ message = "<div class=\"infoMessage\">" + message + "</div>";
Console.WriteLine(message); }
Non-working html
Working html
I take it the quotation mark before the first "<div" isn't actually supposed to be there?
The working HTML is essentially the same as taking the <pre> tags out altogether (as there is no text affected by the tag).
LogFunctions.WriteInfo("Confirm Password " + confirmPass + " entered into website.");
using System;
namespace TestFramework
{
public static class LogFunctions
{
public static void WriteWarning(string message)
{
message = "<div class=\"warningMessage\">" + message + "</div>";
Console.WriteLine(message);
}
public static void WriteError(string message)
{
message = "<div class=\"errorMessage\">" + message + "</div>";
Console.WriteLine(message);
}
public static void WriteInfo(string message)
{
message = "<div class=\"infoMessage\">" + message + "</div>";
Console.WriteLine(message);
}
}
}
.errorMessage
{
width: 600px;
color: Red;
font-weight: bold;
}
.infoMessage
{
width: 600px;
color: Green;
font-weight: bold;
}
.warnMessage
{
width: 600px;
color: Yellow;
font-weight: bold;
}
I take it you want something like this:
<div class="errorMessage">Error: Function not declared at customs</div>
<br>
<pre class="log">done: CalculatorSteps.GivenIHaveEnteredIntoTheCalculator(50) (0.0s)</pre>
<!-- [@traceEvent.Type: @relatedNode.Type - @relatedNode.Title] -->
@{
String source = traceEvent.TechMessages.TrimEnd(); //Get the console message without HTML formatting
String formattedText = ""; //This will contain the error/info/warning message if present
String message = source; //This is the message passed to the console
String tag = "</div>"; //This is the closing tag we are looking for that designates the end of the error/info/warning
int a = source.LastIndexOf(tag); //Find the position of the tag in the source string (-1 means not present)
if (a > -1) //If the formatting tag is present...
{
formattedText = source.Substring(0, a + tag.Length ); //Strip out the substring until the end of the </div> tag
message = source.Substring(formattedText.Length + 1, source.Length - formattedText.Length-1); //and remove the extra data from the message
}
}
<pre class="log">@Raw(FormatTechMessages(traceEvent.TechMessages.TrimEnd()))</pre>
@Raw(formattedText)
<br />
<pre class="log">@Raw(message)</pre>
System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string.Parameter name: startIndex at System.String.Substring(Int32 startIndex, Int32 length) at CompiledRazorTemplates.Dynamic.RazorEngine_79e72a39cb2c45a9a38e485ef30b13ca.Execute() at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader) at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag) at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag) at RazorEngine.Templating.DynamicWrapperService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag) at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass1.<RunCompile>b__0(TextWriter writer) at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter) at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, ITemplateKey key, Type modelType, Object model, DynamicViewBag viewBag) at TechTalk.SpecRun.Framework.Reporting.RazorRenderer.RenderReport(TestRunResult testRunResult, Report report) at TechTalk.SpecRun.Framework.Reporting.ReportingEngine.GenerateReport(TestRunResult testRunResult, String outputFileName, Report report) at TechTalk.SpecRun.Framework.Reporting.ExecutionReporter.ReportResult(TestRunResult result) at TechTalk.SpecRun.Framework.ExecutionEngine.ExecuteTestSuite(TestProfile testProfile, TestRunExecutionConfiguration executionConfiguration, IExecutionContainerBuilder containerBuilder) at TechTalk.SpecRun.VisualStudio.TestAdapter.SpecRunTestExecutor.<>c__DisplayClass9_0.<ExecuteTestSuite>b__1() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() at System.String.Substring(Int32 startIndex, Int32 length) at CompiledRazorTemplates.Dynamic.RazorEngine_79e72a39cb2c45a9a38e485ef30b13ca.Execute() at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader) at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag) at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag) at RazorEngine.Templating.DynamicWrapperService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag) at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass1.<RunCompile>b__0(TextWriter writer) at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter) at RazorEngine.Templating.RazorEngineServiceExtensions.RunCompile(IRazorEngineService service, ITemplateKey key, Type modelType, Object model, DynamicViewBag viewBag) at TechTalk.SpecRun.Framework.Reporting.RazorRenderer.RenderReport(TestRunResult testRunResult, Report report) at TechTalk.SpecRun.Framework.Reporting.ReportingEngine.GenerateReport(TestRunResult testRunResult, String outputFileName, Report report) at TechTalk.SpecRun.Framework.Reporting.ExecutionReporter.ReportResult(TestRunResult result) at TechTalk.SpecRun.Framework.ExecutionEngine.ExecuteTestSuite(TestProfile testProfile, TestRunExecutionConfiguration executionConfiguration, IExecutionContainerBuilder containerBuilder) at TechTalk.SpecRun.VisualStudio.TestAdapter.SpecRunTestExecutor.<>c__DisplayClass9_0.<ExecuteTestSuite>b__1() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()Log file: file:///D:\Proj\TestResults\Tests_Default_2016-11-10T134909.logAn exception occurred while invoking executor 'executor://specrun/executorV1.0.0.0': Object reference not set to an instance of an object.========== Run test finished: 1 run (0:00:48.485) ==========
message = source.Substring(formattedText.Length + 1, source.Length - formattedText.Length-1);