Example #1
0
 private void CascadeAreaOutcome(Step step)
 {
     var areaOutcome = step.Scenario.Feature.Area.Outcome;
     step.Scenario.Feature.Area.Outcome = outcomeAggregator.GetNewParentOutcome(step.Scenario.Feature.Area.Outcome, step.Scenario.Feature.Outcome);
     UpdateOutcome(areaOutcome, step.Scenario.Feature.Area.Outcome,
         step.Scenario.Feature.Area.TestRun.AreaStats);
 }
Example #2
0
 public ScenarioBuilder Given(Step step)
 {
     step.ActionType = ActionType.Given;
     step.Scenario = scenario;
     scenario.Steps.Add(step);
     return this;
 }
Example #3
0
 public ScenarioBuilder And(Step step)
 {
     step.ActionType = ActionType.And;
     step.Scenario = scenario;
     scenario.Steps.Add(step);
     return this;
 }
Example #4
0
 private void CascadeScenarioOutcome(Step step, bool scenarioSkipped)
 {
     var scenarioOutcome = step.Scenario.Outcome;
     step.Scenario.Outcome = outcomeAggregator.GetNewScenarioOutcome(step.Scenario.Outcome, step.Outcome, scenarioSkipped);
     UpdateOutcome(scenarioOutcome, step.Scenario.Outcome,
         step.Scenario.Feature.ScenarioStats,
         step.Scenario.Feature.Area.ScenarioStats,
         step.Scenario.Feature.Area.TestRun.ScenarioStats);
 }
 void ProcessNotImplementedException(StepExecutor stepExecutor, Step step, NotImplementedException ex)
 {
     step.EndTime = DateTime.Now;
     step.Outcome = Outcome.Failed;
     step.Reason = "Not Implemented";
     step.Exception = ex;
     if (scenario.Reason == null)
         scenario.Reason = "Step Not Implemented";
     statsCascader.CascadeStats(step, false);
     throw new StepNotImplementedException(step.Name, ex);
 }
 void ProcessException(StepExecutor stepExecutor, Step step, Exception ex)
 {
     step.EndTime = DateTime.Now;
     step.Outcome = Outcome.Failed;
     step.Reason = ex.Message;
     step.Exception = ex;
     if (scenario.Reason == null)
         scenario.Reason = "Failed Step";
     statsCascader.CascadeStats(step, false);
     throw new StepException(step.Name, ex);
 }
Example #7
0
        void CascadeOutcome(Step step, bool scenarioSkipped)
        {
            UpdateOutcome(Outcome.NotRun, step.Outcome,
				step.Scenario.StepStats,
                step.Scenario.Feature.StepStats,
                step.Scenario.Feature.Area.StepStats,
                step.Scenario.Feature.Area.TestRun.StepStats);
            CascadeScenarioOutcome(step, scenarioSkipped);
			CascadeFeatureOutcome(step);
			CascadeAreaOutcome(step);
            step.Scenario.Feature.Area.TestRun.Outcome = outcomeAggregator.GetNewParentOutcome(step.Scenario.Feature.Area.Outcome, step.Scenario.Feature.Outcome);
        }
Example #8
0
 public void ExecuteStep(Step step)
 {
     try
     {
         PreExecution(step);
         step.Action(step);
         PostExecution(step);
     }
     catch (Exception ex)
     {
         stepExceptionHandler.HandleException(this, step, ex);
     }
 }
Example #9
0
 internal Step CreateStep(xb.Step step, Scenario scenario)
 {
     return(new Step()
     {
         EndTime = step.EndTime,
         Exception = step.Exception == null ? null : step.Exception.Message + "\n" + step.Exception.StackTrace,
         Name = step.Name,
         Outcome = step.Outcome,
         Reason = step.Reason,
         Scenario = scenario,
         StartTime = step.StartTime,
         MultilineParameter = step.Input
     });
 }
 public void HandleException(StepExecutor stepExecutor, Step step, Exception ex)
 {
     if (ex is SkipStepException)
     {
         ProcessSkipException(stepExecutor, step, ex as SkipStepException);
     }
     else if (ex is NotImplementedException)
     {
         ProcessNotImplementedException(stepExecutor, step, ex as NotImplementedException);
     }
     else
     {
         ProcessException(stepExecutor, step, ex);
     }
 }
 private void WriteStep(Step step)
 {
     outputWriter.WriteLine("    " + step.Name);
     if (step.MultilineParameter != null)
     {
         string[] lines = Regex.Split(step.MultilineParameter, "\r\n");
         for(int i =0; i < lines.Length; i++)
         {
             if (i == lines.Length - 1 && lines[i].Length == 0)
                 return;
             else
                 outputWriter.WriteLine((lines[i].Length > 0? "        ": "") + lines[i]);
         }
     }
 }
Example #12
0
        internal static HtmlReportLineItem GetHtmlReportLineItem(this xBDD.Model.Step step)
        {
            var li = new HtmlReportLineItem();

            li.ChildItems    = new List <HtmlReportLineItem>();
            li.ChildStats    = null;
            li.ChildTypeName = null;
            li.EndTime       = step.EndTime;
            li.StartTime     = step.StartTime;
            var action = "";

            switch (step.ActionType)
            {
            case ActionType.Given:
                action = "<strong>Given</strong> ";
                break;

            case ActionType.When:
                action = "<strong>When</strong> ";
                break;

            case ActionType.Then:
                action = "<strong>Then</strong> ";
                break;

            case ActionType.And:
                action = "<strong>And</strong> ";
                break;
            }
            li.Name    = $"{action} {step.Name.HtmlEncode()}";
            li.Outcome = step.Outcome;
            li.Reason  = step.Reason;
            Dictionary <string, Dictionary <string, int> > reasonStats = new Dictionary <string, Dictionary <string, int> >();

            li.ReasonStats       = reasonStats;
            li.TypeName          = "step";
            li.ChildTypeName     = "details";
            li.ChildItems        = new List <HtmlReportLineItem>();
            li.Explanation       = step.Explanation;
            li.ExplanationFormat = step.ExplanationFormat;
            li.Input             = step.Input;
            li.InputFormat       = step.InputFormat;
            li.Output            = step.Output;
            li.OutputFormat      = step.OutputFormat;
            li.Exception         = step.Exception;
            return(li);
        }
Example #13
0
 public async Task ExecuteStepAsync(Step step)
 {
     try
     {
         PreExecution(step);
         if (step.ActionAsync == null && step.Action != null)
         {
             await Task.Run(() => { step.Action(step); });
         }
         else
         {
             await step.ActionAsync(step);
         }
         PostExecution(step);
     }
     catch (Exception ex)
     {
         stepExceptionHandler.HandleException(this, step, ex);
     }
 }
Example #14
0
 private void WriteStep(Step step, StringBuilder sb)
 {
     sb.Append("\t\t\t" + step.FullName);
     if (step.Scenario.Outcome == Outcome.Failed)
     {
         if (step.Outcome != Outcome.Passed)
         {
             sb.Append(" [" + Enum.GetName(typeof(Outcome), step.Outcome));
             if (step.Reason != null && (step.Outcome != Outcome.Failed || step.Reason == "Not Implemented"))
                 sb.Append(" - " + step.Reason);
             sb.AppendLine("]");
         }
         else
             sb.AppendLine();
     }
     else
         sb.AppendLine();
     if (!String.IsNullOrEmpty(step.MultilineParameter))
     {
         WriteMultilineParameter(step.MultilineParameter, sb);
     }
     if (step.Exception != null && !(step.Exception is NotImplementedException) && step.Outcome != Outcome.Skipped)
         WriteException(step.Exception, sb);
 }
Example #15
0
        void WriteStep(Step step, StringBuilder sb, int stepNumber)
        {
            var className = "step " + Enum.GetName(typeof(Outcome), step.Outcome).ToLower();
            switch (step.Outcome)
            {
                case Outcome.NotRun:
                    className = className + " text-info";
                    break;
                case Outcome.Passed:
                    className = className + " text-success";
                    break;
                case Outcome.Failed:
                    className = className + " text-danger";
                    break;
                case Outcome.Skipped:
                    className = className + " text-warning";
                    break;
                default:
                    break;
            }
            WriteTagOpen("li", sb, 8, className, false, "step-" + stepNumber);

            WriteTagOpen("h5", sb, 9, null, true);
            WriteTag("span", sb, 0, "name", step.FullName.HtmlEncode(), true);
            
            if (!String.IsNullOrEmpty(step.Output))
            {
                sb.Append(String.Format("<a class=\"step-output-link\" data-toggle=\"collapse\" href=\"#step-{0}-output\" aria-expanded=\"false\" aria-controls=\"step-{0}-output\">[Output]</a>", stepNumber));
            }
            
            if (step.Scenario.Outcome == Outcome.Failed && step.Outcome != Outcome.Passed)
            {
                WriteTagOpen("span", sb, 0, "status", true);
                sb.Append("[");
                sb.Append(Enum.GetName(typeof(Outcome), step.Outcome));
                if (step.Reason != null && (step.Outcome != Outcome.Failed || step.Reason == "Not Implemented"))
                {
                    sb.Append(" - ");
                    sb.Append(step.Reason.HtmlEncode());
                }
                sb.Append("]");
                WriteTagClose("span", sb, 0);
            }

            WriteTagClose("h5", sb, 0);
            if (!String.IsNullOrEmpty(step.MultilineParameter))
            {
                WriteMultilineParameter(step, sb, stepNumber);
            }
            if (step.Exception != null && !(step.Exception is NotImplementedException) && step.Outcome != Outcome.Skipped)
                WriteException(step.Exception, sb);

            if (!String.IsNullOrEmpty(step.Output))
            {
                WriteOutput(step, sb, stepNumber);
            }
            WriteTagClose("li", sb, 8);
        }
Example #16
0
 void PostExecution(Step step)
 {
     step.EndTime = DateTime.Now;
     step.Outcome = Outcome.Passed;
     statsCascader.CascadeStats(step, false);
 }
Example #17
0
 private void PreExecution(Step step)
 {
     step.StartTime = DateTime.Now;
 }
Example #18
0
 void WriteOutputWithHtmlPreview(Step step, StringBuilder sb, int stepNumber)
 {
     var html = @"                                        <strong><h5>Output</h5></strong>
                                 <ul class=""nav nav-tabs"" role=""tablist"">
                                     <li role=""presentation"" class=""active""><a href=""#output-preview-{0}"" aria-controls=""output-preview-{0}"" role=""tab"" data-toggle=""tab"">Preview</a></li>
                                     <li role=""presentation""><a href=""#output-code-{0}"" aria-controls=""output-code-{0}"" role=""tab"" data-toggle=""tab"">Code</a></li>
                                 </ul>
                                 <div class=""tab-content"">
                                     <div role=""tabpanel"" class=""tab-pane active"" id=""output-preview-{0}"">
                                         <iframe width=""100%"" height=""400px"" id=""iframe{0}""></iframe>
                                         <script type=""text/javascript"">
                                             var iframe{0}doc = document.getElementById('iframe{0}').contentWindow.document;
                                             iframe{0}doc.open();
                                             var html{0} = ""{2}"";
                                             iframe{0}doc.write(html{0});
                                             iframe{0}doc.close();
                                         </script>
                                     </div>
                                     <div role=""tabpanel"" class=""tab-pane"" id=""output-code-{0}"">
                                         <pre class=""mp prettyprint lang-html"">{1}</pre>
                                     </div>
                                 </div>";
     sb.AppendLine(String.Format(html,
         stepNumber, 
         step.Output.HtmlEncode(), 
         step.Output
         .Replace("\r\n", " \\\r\n")
         .Replace(":", "\\:")
         .Replace("/", "\\/")
         .Replace("!", "\\!")
         .Replace("\"", "\\\"")));
 }
Example #19
0
 void WriteOutput(Step step, StringBuilder sb, int stepNumber)
 {
     WriteTagOpen("div", sb, 9, "output collapse", false, "step-" + stepNumber + "-output", null, "aria-expanded=\"false\"");
     if(step.OutputFormat == TextFormat.htmlpreview)
     {
         WriteOutputWithHtmlPreview(step, sb, stepNumber);
     }
     else
     {
         var className = "text";
         if (step.OutputFormat != TextFormat.text)
         {
             className = Enum.GetName(typeof(TextFormat), step.OutputFormat) + " prettyprint";
             if (step.OutputFormat != TextFormat.code)
                 className = className + " lang-" + Enum.GetName(typeof(TextFormat), step.OutputFormat);
         }
         WriteTagOpen("pre", sb, 10, className, true, "output-" + stepNumber);
         sb.Append(step.Output.HtmlEncode());
         WriteTagClose("pre", sb, 0);
     }
     WriteTagClose("div", sb, 0);
 }
Example #20
0
 void WriteMultilineParameter(Step step, StringBuilder sb, int stepNumber)
 {
     if(step.MultilineParameterFormat == TextFormat.htmlpreview)
     {
         WriteMultilineParameterWithHtmlPreview(step, sb, stepNumber);
     }
     else
     {
         var className = "mp";
         if (step.MultilineParameterFormat != TextFormat.text)
         {
             className = className + " prettyprint";
             if (step.MultilineParameterFormat != TextFormat.code)
                 className = className + " lang-" + Enum.GetName(typeof(TextFormat), step.MultilineParameterFormat);
         }
         WriteTagOpen("div", sb, 9, "mp", true);
         WriteTagOpen("pre", sb, 10, className, true);
         sb.Append(step.MultilineParameter.HtmlEncode());
         WriteTagClose("pre", sb, 10);
         WriteTagClose("div", sb, 0);
     }
 }
Example #21
0
		public void CascadeStats(Step step, bool scenarioSkipped)
		{
			CascadeOutcome(step, scenarioSkipped);
			CascadeStartTime(step);
			CascadeEndTime(step);
		}
Example #22
0
        void CascadeStartTime(Step step)
        {
			if(step.Scenario.StartTime.Equals(DateTime.MinValue) || step.Scenario.StartTime > step.StartTime)
            	step.Scenario.StartTime = step.StartTime;
			if(step.Scenario.Feature.StartTime.Equals(DateTime.MinValue) || step.Scenario.Feature.StartTime > step.StartTime)
            	step.Scenario.Feature.StartTime = step.StartTime;
			if(step.Scenario.Feature.Area.StartTime.Equals(DateTime.MinValue) || step.Scenario.Feature.Area.StartTime > step.StartTime)
            	step.Scenario.Feature.Area.StartTime = step.StartTime;
			if(step.Scenario.Feature.Area.TestRun.StartTime.Equals(DateTime.MinValue) || step.Scenario.Feature.Area.TestRun.StartTime > step.StartTime)
            	step.Scenario.Feature.Area.TestRun.StartTime =  step.StartTime;
        }
Example #23
0
        void CascadeEndTime(Step step)
        {
			if(step.Scenario.EndTime > DateTime.MinValue)
            	step.Scenario.EndTime =  step.EndTime;
			if(step.Scenario.Feature.EndTime > DateTime.MinValue)
            	step.Scenario.Feature.EndTime =  step.EndTime;
			if(step.Scenario.Feature.Area.EndTime > DateTime.MinValue)
            	step.Scenario.Feature.Area.EndTime = step.EndTime;
			if(step.Scenario.Feature.Area.TestRun.EndTime > DateTime.MinValue)
            	step.Scenario.Feature.Area.TestRun.EndTime = step.EndTime;
        }