private void HandleElementException(Action action)
 {
     try
     {
         action.Invoke();
     }
     catch (StaleElementReferenceException exception) //todo
     {
         Logger.Instance.Fatal($"{name} :: Invalid element state", exception);
         new AShot().CoordsProvider(new WebDriverCoordsProvider())
         .ImageCropper(new IndentCropper().AddIndentFilter(new BlurFilter()))
         .TakeScreenshot(Browser.GetInstance().GetDriver(), GetElement())
         .getImage()
         .Save(Path.Combine(FileProvider.GetFailedScreensDirectory(), $"FailedElement_{DateTime.Now.ToFileTime()}.png"));
         throw;
     }
     catch (InvalidElementStateException exception) //todo
     {
         Logger.Instance.Fatal($"{name} :: Invalid element state", exception);
         new AShot().CoordsProvider(new WebDriverCoordsProvider())
         .ImageCropper(new IndentCropper().AddIndentFilter(new BlurFilter()))
         .TakeScreenshot(Browser.GetInstance().GetDriver(), GetElement())
         .getImage()
         .Save(Path.Combine(FileProvider.GetFailedScreensDirectory(), $"FailedElement_{DateTime.Now.ToFileTime()}.png"));
         throw;
     }
 }
예제 #2
0
 public void Before()
 {
     Browser.GetInstance().WindowMaximize();
     FileProvider.CleanDirectory(FileProvider.GetFailedScreensDirectory());
     AllureLifecycle.Instance.SetCurrentTestActionInException(() =>
     {
         AllureLifecycle.Instance.AddAttachment("Screenshot", "image/png", MakeScreenshot());
     });
 }
예제 #3
0
 public void AfterScenarioSteps()
 {
     if (_scenarioContext.TestError != null)
     {
         foreach (var failedScreen in Directory.GetFiles(FileProvider.GetFailedScreensDirectory()))
         {
             _allureLifecycle.AddAttachment(failedScreen);
         }
         _allureLifecycle.AddAttachment(MakeScreenshot());
     }
     Browser.GetInstance().Quit();
     _allureLifecycle.AddAttachment(Logger.GetLogLocation());
 }
예제 #4
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();
 }
예제 #5
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);
            }
        }
예제 #6
0
 public void Setup()
 {
     Browser.GetInstance().WindowMaximize();
     FileProvider.CleanDirectory(FileProvider.GetFailedScreensDirectory());
 }