示例#1
0
 public void TearDown()
 {
     if (TestContext.CurrentContext.Result.Outcome != ResultState.Success)
     {
         foreach (var failedScreen in Directory.GetFiles(FileProvider.GetFailedScreensDirectory()))
         {
             AllureLifecycle.Instance.AddAttachment(failedScreen);
         }
         AllureLifecycle.Instance.AddAttachment("Screenshot", "image/png",
                                                ScreenshotProvider.PublishScreenshot($"Screenshot_{DateTime.Now.ToFileTime()}"));
     }
     Browser.GetInstance().Quit();
 }
示例#2
0
        public void Step(string name, Action action)
        {
            var caseId = TestExecutionContext.CurrentContext.CurrentTest.Id;
            var uuid   = Guid.NewGuid().ToString("N");

            Allure.StartStep(caseId, uuid, new StepResult()
            {
                name = name
            });

            int       logLength     = TestExecutionContext.CurrentContext.CurrentResult.Output.Length;
            Exception stepException = null;

            try
            {
                action();
            }
            catch (Exception e)
            {
                stepException = e;
                AllureHelper.AttachPng("FailedElement", File.ReadAllBytes(new DirectoryInfo(FileProvider.GetFailedScreensDirectory())
                                                                          .GetFiles().OrderByDescending(file => file.LastWriteTime).First().FullName));
                AllureHelper.AttachPng("Screenshot",
                                       File.ReadAllBytes(ScreenshotProvider.PublishScreenshot($"Screenshot_{DateTime.Now.ToFileTime()}")));
                throw;
            }
            finally
            {
                Allure.UpdateStep(uuid, x =>
                {
                    x.status        = GetStatusFromException(stepException);
                    x.statusDetails = new StatusDetails
                    {
                        message = stepException?.Message,
                        trace   = stepException?.StackTrace
                    };
                    x.attachments.AddRange(AllureHelper.GetAttaches());
                });
                Allure.StopStep(uuid);
            }
        }
示例#3
0
 private string MakeScreenshot()
 {
     return(ScreenshotProvider.PublishScreenshot($"Screenshot_{DateTime.Now.ToFileTime()}"));
 }