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; } }
public void Before() { Browser.GetInstance().WindowMaximize(); FileProvider.CleanDirectory(FileProvider.GetFailedScreensDirectory()); AllureLifecycle.Instance.SetCurrentTestActionInException(() => { AllureLifecycle.Instance.AddAttachment("Screenshot", "image/png", MakeScreenshot()); }); }
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()); }
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(); }
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); } }
public void Setup() { Browser.GetInstance().WindowMaximize(); FileProvider.CleanDirectory(FileProvider.GetFailedScreensDirectory()); }