Exemplo n.º 1
0
 public async Task Execute()
 {
     await Task.Run(async() =>
     {
         try
         {
             StartTime = DateTime.Now;
             await Runnable.Run();
             Status = Status.Passed;
         }
         catch (NotImplementedException e)
         {
             Status    = Status.NotImplemented;
             Exception = e;
             throw;
         }
         catch (Exception e)
         {
             Status    = Status.Failed;
             Exception = e;
             throw;
         }
         finally
         {
             EndTime   = DateTime.Now;
             TimeTaken = EndTime - StartTime;
             Output    = TestOutputData.Instance.ToString();
             TestOutputData.ClearCurrentTaskData();
         }
     });
 }
Exemplo n.º 2
0
        private void WriteTestInformation(Scenario scenario)
        {
            WriteStoryAndScenario(scenario);

            WriteCustomTestInformation(scenario);

            TestOutputData.ClearCurrentTaskData();
        }
Exemplo n.º 3
0
        internal async Task Execute()
        {
            SetStepText();

            await Task.Run(async() =>
            {
                try
                {
                    StartTime = DateTime.Now;

                    if (ShouldSkip())
                    {
                        StepText = $"[Skipped] {StepText}";
                        Status   = Status.Skipped;
                        return;
                    }

                    await Runnable.Run();
                    Status = Status.Passed;
                }
                catch (NotImplementedException e)
                {
                    Status    = Status.NotImplemented;
                    Exception = new ExceptionWrapper(e);
                    throw;
                }
                catch (Exception e) when(BDTestSettings.CustomExceptionSettings.SuccessExceptionTypes.Contains(e.GetType()))
                {
                    Status = Status.Passed;
                    throw;
                }
                catch (Exception e) when(BDTestSettings.CustomExceptionSettings.InconclusiveExceptionTypes.Contains(e.GetType()))
                {
                    Status = Status.Inconclusive;
                    throw;
                }
                catch (Exception e)
                {
                    Status    = Status.Failed;
                    Exception = new ExceptionWrapper(e);
                    throw;
                }
                finally
                {
                    EndTime   = DateTime.Now;
                    TimeTaken = EndTime - StartTime;
                    Output    = TestOutputData.Instance.ToString().Trim();
                    TestOutputData.ClearCurrentTaskData();
                }
            });
        }
Exemplo n.º 4
0
        internal async Task Execute()
        {
            SetStepText();

            CheckIfAlreadyExecuted();

            await Task.Run(async() =>
            {
                try
                {
                    StartTime = DateTime.Now;
                    await Runnable.Run();
                    Status = Status.Passed;
                }
                catch (NotImplementedException e)
                {
                    Status    = Status.NotImplemented;
                    Exception = e;
                    throw;
                }
                catch (Exception e)
                {
                    if (BDTestSettings.SuccessExceptionTypes.Contains(e.GetType()))
                    {
                        Status = Status.Passed;
                    }
                    else
                    {
                        Status    = Status.Failed;
                        Exception = e;
                        throw;
                    }
                }
                finally
                {
                    EndTime   = DateTime.Now;
                    TimeTaken = EndTime - StartTime;
                    Output    = TestOutputData.Instance.ToString();
                    TestOutputData.ClearCurrentTaskData();
                }
            });
        }
Exemplo n.º 5
0
 public void Custom(string html)
 {
     TestOutputData.WriteCustomHtmlForReport(TestId, html);
 }
Exemplo n.º 6
0
 public async Task WriteTearDownOutput(string text)
 {
     await TestOutputData.WriteTearDownOutput(TestId, text);
 }
Exemplo n.º 7
0
        public async Task ExecuteAsync(Scenario scenario)
        {
            await _scenarioRetryManager.CheckIfAlreadyExecuted(scenario).ConfigureAwait(false);

            await Task.Run(async() =>
            {
                try
                {
                    scenario.StartTime = DateTime.Now;

                    TestOutputData.ClearCurrentTaskData();

                    if (scenario.RetryCount == 0)
                    {
                        WriteTestInformation(scenario);
                    }

                    if (ShouldSkip(scenario))
                    {
                        scenario.Status = Status.Skipped;
                        scenario.Steps.ForEach(step => step.Status = Status.Skipped);
                        return;
                    }

                    foreach (var step in scenario.Steps)
                    {
                        await step.Execute();
                    }

                    scenario.Status = Status.Passed;
                }
                catch (NotImplementedException)
                {
                    scenario.Status = Status.NotImplemented;
                    throw;
                }
                catch (Exception e) when(BDTestSettings.CustomExceptionSettings.SuccessExceptionTypes.Contains(e.GetType()))
                {
                    scenario.Status = Status.Passed;
                    throw;
                }
                catch (Exception e) when(BDTestSettings.CustomExceptionSettings.InconclusiveExceptionTypes.Contains(e.GetType()))
                {
                    scenario.Status = Status.Inconclusive;
                    throw;
                }
                catch (Exception e)
                {
                    var validRetryRules = BDTestSettings.GlobalRetryTestRules.Rules.Where(rule => rule.Condition(e)).ToList();
                    if (validRetryRules.Any() && scenario.RetryCount < validRetryRules.Max(x => x.RetryLimit))
                    {
                        scenario.ShouldRetry = true;
                        return;
                    }

                    var bdTestRetryAttribute = RetryAttributeHelper.GetBDTestRetryAttribute(scenario);
                    if (bdTestRetryAttribute != null && scenario.RetryCount < bdTestRetryAttribute.Count)
                    {
                        scenario.ShouldRetry = true;
                        return;
                    }

                    scenario.Status = Status.Failed;

                    ConsoleReporter.WriteLine($"{Environment.NewLine}Exception: {e.Message}{Environment.NewLine}{e.StackTrace}{Environment.NewLine}");

                    throw;
                }
                finally
                {
                    if (scenario.ShouldRetry)
                    {
                        await ExecuteAsync(scenario).ConfigureAwait(false);
                    }
                    else
                    {
                        foreach (var notRunStep in scenario.Steps.Where(step => step.Status == Status.Inconclusive))
                        {
                            notRunStep.SetStepText();
                        }

                        ConsoleReporter.WriteLine($"{Environment.NewLine}Test Summary:{Environment.NewLine}");

                        scenario.Steps.ForEach(step => ConsoleReporter.WriteLine($"{step.StepText} > [{step.Status}]"));

                        ConsoleReporter.WriteLine($"{Environment.NewLine}Test Result: {scenario.Status}{Environment.NewLine}");

                        scenario.EndTime   = DateTime.Now;
                        scenario.TimeTaken = scenario.EndTime - scenario.StartTime;

                        scenario.Output = string.Join(Environment.NewLine,
                                                      scenario.Steps.Where(step => !string.IsNullOrWhiteSpace(step.Output)).Select(step => step.Output));
                    }
                }
            });
        }