Best Atata code snippet using Atata.LogManager.Screenshot
SpecFlowHooks.cs
Source:SpecFlowHooks.cs
...52 public static void AfterStep(ScenarioContext scenarioContext)53 {54 scenarioContext.Get<ScenarioPOCO>().Steps.Add(new StepPOCO(scenarioContext.StepContext.StepInfo.Text, scenarioContext.StepContext.StepInfo.StepDefinitionType));55 scenarioContext.Get<ScenarioPOCO>().Steps.Last().StepStatus = Status.Pass;56 scenarioContext.Get<ScenarioPOCO>().Steps.Last().Screenshot = Providers.GetScreenshot(scenarioContext);57 if (scenarioContext.TestError != null)58 {59 scenarioContext.Get<ScenarioPOCO>().Steps.Last().PageSource = Providers.GetPageSource(scenarioContext);60 scenarioContext.Get<ScenarioPOCO>().Steps.Last().URL = Providers.GetUrl(scenarioContext);61 scenarioContext.Get<ScenarioPOCO>().Steps.Last().StepStatus = Status.Error;62 scenarioContext.Get<ScenarioPOCO>().Steps.Last().Exception = scenarioContext.TestError;63 }64 }65 [AfterScenario]66 public static void TearDownScenario(ScenarioContext scenarioContext, FeatureContext featureContext)67 {68 scenarioContext.ScenarioInfo.Tags.ToList().ForEach(tag => scenarioContext.Get<ScenarioPOCO>().Categories.Add(tag));69 scenarioContext.Get<ScenarioPOCO>().Categories.Add("All_tests");70 if (scenarioContext.TestError != null && scenarioContext.Get<ScenarioPOCO>().Steps.Count == 0)71 {72 scenarioContext.Get<ScenarioPOCO>().Steps.Add(new StepPOCO($"scenario failed: {scenarioContext.TestError.Message}", StepDefinitionType.Given, Status.Error));73 scenarioContext.Get<ScenarioPOCO>().Steps.Last().Exception = scenarioContext.TestError;74 }75 featureContext.Get<FeaturePOCO>().Scenarios.Add(scenarioContext.Get<ScenarioPOCO>());76 AtataContext.Current?.CleanUp();77 }78 [AfterFeature]79 public static void AfterFeature(FeatureContext featureContext)80 {81 reportPOCO.Features.Add(featureContext.Get<FeaturePOCO>());82 foreach (var feature in reportPOCO.Features)83 {84 Reporter.Feature = Reporter.GetReport().CreateTest<AventStack.ExtentReports.Gherkin.Model.Feature>(feature.Title, feature.Description);85 foreach (var scenario in feature.Scenarios)86 {87 Reporter.Scenario = Reporter.Feature.CreateNode<Scenario>(scenario.Title);88 scenario.Categories.Sort();89 scenario.Categories.ForEach(category => Reporter.Scenario.AssignCategory(category));90 foreach (var step in scenario.Steps)91 {92 switch (step.StepType)93 {94 case StepDefinitionType.Given:95 Reporter.Step = Reporter.Scenario.CreateNode<Given>(step.Title);96 break;97 case StepDefinitionType.When:98 Reporter.Step = Reporter.Scenario.CreateNode<When>(step.Title);99 break;100 case StepDefinitionType.Then:101 Reporter.Step = Reporter.Scenario.CreateNode<Then>(step.Title);102 break;103 }104 if (step.StepStatus is Status.Error)105 {106 var data = new string[4, 2]107 {108 { "Exception", $"{step.Exception.Message}"},109 { "StackTrace", $"{step.Exception.StackTrace}"},110 { "URL", $"<a href=\"{step.URL}\">{step.URL}</a>"},111 { "PageSource", $"<a href=\"{step.PageSource}\">{step.PageSource}</a>"}112 };113 Reporter.Step.Fail(MarkupHelper.CreateTable(data));114 }115 if (step.Screenshot != null) Reporter.Step.Log(Status.Info, MediaEntityBuilder.CreateScreenCaptureFromPath(step.Screenshot).Build());116 }117 }118 }119 reportPOCO = new ReportPOCO();120 Reporter.GetReport().Flush();121 }122 [AfterTestRun]123 public static void AfterTestRun()124 {125 Reporter.GetReport().Flush();126 NLog.LogManager.Shutdown();127 }128 }129}...
Providers.cs
Source:Providers.cs
...43 }44 }45 return null;46 }47 public static string GetScreenshot(ScenarioContext scenarioContext)48 {49 Logger.Info("Trying to get screenshot");50 var title = RemoveCharactersUnsupportedByWindowsInFileNames(scenarioContext.StepContext.StepInfo.Text);51 var runName = $"_{DateTime.Now:yyyy-MM-dd-HH_mm_ss}";52 var filename = runName +$"{title.SanitizeForFileName()}.png";53 var path = $"{Path.Combine(Reporter.ReportDir, filename)}";54 {55 var absoluteFilePath = path;56 try57 {58 var targetDirectory = Path.GetDirectoryName(absoluteFilePath);59 if (!Directory.Exists(targetDirectory))60 Directory.CreateDirectory(targetDirectory);61 ;62 var screenShot = AtataContext.Current.Driver.GetScreenshot();63 screenShot.SaveAsFile(path);64 return filename;65 }66 catch (Exception e)67 {68 Logger.Warn(e, "Unable to get screenshot");69 }70 }71 return null;72 }73 private static string RemoveCharactersUnsupportedByWindowsInFileNames(string input)74 {75 return input.Replace(" ", "").Replace("\"", "").Replace("\\", "").Replace("/", "").Replace(":", "").Replace("*", "").Replace("?", "").Replace("<", "").Replace(">", "").Replace("'", "");76 }...
Screenshot
Using AI Code Generation
1using Atata;2using NUnit.Framework;3{4 {5 public void Test()6 {7 Build();8 AtataContext.Current.AutoSetUp();9 Go.To<GooglePage>();10 Screenshot();11 }12 }13}14using Atata;15using NUnit.Framework;16{17 {18 public void Test()19 {20 Build();21 AtataContext.Current.AutoSetUp();22 Go.To<GooglePage>();23 AtataContext.Current.Log.Screenshot();24 }25 }26}27using Atata;28using NUnit.Framework;29{30 {31 public void Test()32 {33 Build();34 AtataContext.Current.AutoSetUp();35 Go.To<GooglePage>();36 AtataContext.Current.Log.Screenshot();37 }38 }39}40using Atata;41using NUnit.Framework;42{43 {44 public void Test()45 {46 Build();47 AtataContext.Current.AutoSetUp();48 Go.To<GooglePage>();49 AtataContext.Current.Log.Screenshot();50 }51 }52}
Screenshot
Using AI Code Generation
1public void TestMethod1()2{3 AtataContext.Configure()4 .UseChrome()5 .UseNUnitTestName()6 .UseAllNUnitFeatures()7 .LogNUnitError()8 .LogNUnitErrorWithScreenshot()9 .Build();10 Go.To<GooglePage>().SearchFor("Atata").Results.Should.Contain("atata.io");11 AtataContext.Current.Log.Screenshot();12 AtataContext.Current.Log.Screenshot("My screenshot");13}14public void TestMethod1()15{16 AtataContext.Configure()17 .UseChrome()18 .UseNUnitTestName()19 .UseAllNUnitFeatures()20 .LogNUnitError()21 .LogNUnitErrorWithScreenshot()22 .Build();23 Go.To<GooglePage>().SearchFor("Atata").Results.Should.Contain("atata.io");24 AtataContext.Current.Log.Screenshot();25 AtataContext.Current.Log.Screenshot("My screenshot");26}27public void TestMethod1()28{29 AtataContext.Configure()30 .UseChrome()31 .UseNUnitTestName()32 .UseAllNUnitFeatures()33 .LogNUnitError()34 .LogNUnitErrorWithScreenshot()35 .Build();36 Go.To<GooglePage>().SearchFor("Atata").Results.Should.Contain("atata.io");37 AtataContext.Current.Log.Screenshot();38 AtataContext.Current.Log.Screenshot("My screenshot");39}40public void TestMethod1()41{42 AtataContext.Configure()43 .UseChrome()44 .UseNUnitTestName()45 .UseAllNUnitFeatures()46 .LogNUnitError()47 .LogNUnitErrorWithScreenshot()48 .Build();49 Go.To<GooglePage>().SearchFor("Atata").Results.Should.Contain("atata.io");50 AtataContext.Current.Log.Screenshot();
Screenshot
Using AI Code Generation
1Atata.LogManager.Screenshot();2Atata.LogManager.Screenshot();3Atata.LogManager.Screenshot();4Atata.LogManager.Screenshot();5Atata.LogManager.Screenshot();6Atata.LogManager.Screenshot();7Atata.LogManager.Screenshot();8Atata.LogManager.Screenshot();9Atata.LogManager.Screenshot();10Atata.LogManager.Screenshot();11Atata.LogManager.Screenshot();12Atata.LogManager.Screenshot();
Screenshot
Using AI Code Generation
1using Atata;2using NUnit.Framework;3using OpenQA.Selenium;4using OpenQA.Selenium.Chrome;5{6 {7 public void Test()8 {9 using (var driver = new ChromeDriver())10 {11 var log = AtataContext.Configure()12 .UseDriver(driver)13 .UseNUnitTestName()14 .UseCulture("en-US")15 .UseAllNUnitFeatures()16 .Build();17 log.Screenshot("Screenshot of Google page");18 log.Go.To<GooglePage>()19 .SearchFor("Atata");20 }21 }22 }23}24using Atata;25using NUnit.Framework;26using OpenQA.Selenium;27using OpenQA.Selenium.Chrome;28{29 {30 public void Test()31 {32 using (var driver = new ChromeDriver())33 {34 var log = AtataContext.Configure()35 .UseDriver(driver)36 .UseNUnitTestName()37 .UseCulture("en-US")38 .UseAllNUnitFeatures()39 .Build();40 log.Screenshot("Screenshot of Google page");41 log.Go.To<GooglePage>()42 .SearchFor("Atata");43 }44 }45 }46}47using Atata;48using NUnit.Framework;49using OpenQA.Selenium;50using OpenQA.Selenium.Chrome;51{52 {53 public void Test()54 {55 using (var driver = new ChromeDriver())56 {57 var log = AtataContext.Configure()58 .UseDriver(driver)59 .UseNUnitTestName()60 .UseCulture("en-US")61 .UseAllNUnitFeatures()62 .Build();63 log.Screenshot("Screenshot of Google page");64 log.Go.To<GooglePage>()65 .SearchFor("Atata");66 }67 }68 }69}70using Atata;71using NUnit.Framework;
Screenshot
Using AI Code Generation
1{2 {3 public void Consume(LogEventInfo logEvent)4 {5 if (logEvent.Level == LogLevel.Debug)6 {7 string screenshotPath = @"C:\Users\Public\Pictures\Sample Pictures\";8 string screenshotName = "Screenshot_" + DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss") + ".png";9 string screenshotFullPath = screenshotPath + screenshotName;10 AtataContext.Current.Driver.TakeScreenshot().SaveAsFile(screenshotFullPath, ScreenshotImageFormat.Png);11 AtataContext.Current.Log.Info("Screenshot taken: " + screenshotFullPath);12 }13 }14 }15}16{17 {18 public void Consume(LogEventInfo logEvent)19 {20 if (logEvent.Level == LogLevel.Debug)21 {22 string screenshotPath = @"C:\Users\Public\Pictures\Sample Pictures\";23 string screenshotName = "Screenshot_" + DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss") + ".png";24 string screenshotFullPath = screenshotPath + screenshotName;25 AtataContext.Current.Driver.TakeScreenshot().SaveAsFile(screenshotFullPath, ScreenshotImageFormat.Png);26 AtataContext.Current.Log.Info("Screenshot taken: " + screenshotFullPath);27 }28 }29 }30}31{32 {33 public void Consume(LogEventInfo logEvent)34 {35 if (logEvent.Level == LogLevel.Debug)36 {37 string screenshotPath = @"C:\Users\Public\Pictures\Sample Pictures\";38 string screenshotName = "Screenshot_" + DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss") + ".png";39 string screenshotFullPath = screenshotPath + screenshotName;40 AtataContext.Current.Driver.TakeScreenshot().SaveAsFile(screenshotFullPath, ScreenshotImageFormat.Png);41 AtataContext.Current.Log.Info("Screenshot taken: " + screenshotFullPath);42 }43 }44 }45}
Screenshot
Using AI Code Generation
1using Atata;2using NUnit.Framework;3{4 {5 public void Test()6 {7 Go.To<HomePage>()8 .Header.Should.Contain("Home")9 .Screenshot();10 }11 }12}13using Atata;14using NUnit.Framework;15{16 {17 public void Test()18 {19 Go.To<HomePage>()20 .Header.Should.Contain("Home")21 .Screenshot();22 }23 }24}25using Atata;26using NUnit.Framework;27{28 {29 public void Test()30 {31 Go.To<HomePage>()32 .Header.Should.Contain("Home")33 .Screenshot();34 }35 }36}37using Atata;38using NUnit.Framework;39{40 {41 public void Test()42 {43 Go.To<HomePage>()44 .Header.Should.Contain("Home")45 .Screenshot();46 }47 }48}49using Atata;50using NUnit.Framework;51{52 {53 public void Test()54 {55 Go.To<HomePage>()56 .Header.Should.Contain("Home")57 .Screenshot();58 }59 }60}61using Atata;62using NUnit.Framework;63{64 {65 public void Test()66 {67 Go.To<HomePage>()68 .Header.Should.Contain("Home")69 .Screenshot();70 }71 }72}73using Atata;74using NUnit.Framework;
Screenshot
Using AI Code Generation
1Atata.LogManager.Screenshot().SaveAs("screenshot.png");2Atata.LogManager.Screenshot().SaveAs("screenshot.png");3Atata.LogManager.Screenshot().SaveAs("screenshot.png");4Atata.LogManager.Screenshot().SaveAs("screenshot.png");5Atata.LogManager.Screenshot().SaveAs("screenshot.png");6Atata.LogManager.Screenshot().SaveAs("screenshot.png");7Atata.LogManager.Screenshot().SaveAs("screenshot.png");8Atata.LogManager.Screenshot().SaveAs("screenshot.png");9Atata.LogManager.Screenshot().SaveAs("screenshot.png");10Atata.LogManager.Screenshot().SaveAs("screenshot.png");11Atata.LogManager.Screenshot().SaveAs("screenshot.png");
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!