How to use ScreenshotInfo class of Atata package

Best Atata code snippet using Atata.ScreenshotInfo

RunContext.cs

Source:RunContext.cs Github

copy

Full Screen

1using Atata;2using Microsoft.VisualStudio.TestTools.UnitTesting;3using System;4using System.Diagnostics;5using System.IO;6namespace AtataPoc7{8 [TestClass]9 public class RunContext10 {11 public TestContext TestContext { get; set; }12 //private static readonly string BaseFile = $@"Logs\{DateTime.Now.ToString("yyyy-MM-dd HH_mm_ss")}";13 private string _folderName;14 [TestInitialize]15 public void Start()16 {17 _folderName = @$"{TestContext.ResultsDirectory}\{TestContext.TestName}";18 var browser = TestContext.Properties["browser"]?.ToString() ?? "chrome";19 var test = AtataContext.Configure()20 .UseTestName(TestContext.TestName)21 //.UseDriver(DriverAlias(browser))22 .AddScreenshotFileSaving().WithFolderPath(_folderName)23 .WithFileName(screenshotInfo => $"{screenshotInfo.Number:D2} - {screenshotInfo.PageObjectFullName}{screenshotInfo.Title?.Prepend(" - ")}")24 .AddLogConsumer(new TextOutputLogConsumer(TestContext.WriteLine))25 //.AddScreenshotFileSaving().WithFolderPath(() => $@"{TestContext.TestResultsDirectory}\{AtataContext.Current.TestName}")//.WithFileName(a => $"Image_{a.Number}")26 .Build();27 }28 private string DriverAlias(string browser)29 {30 switch (browser.ToLowerInvariant())31 {32 case "chrome":33 return DriverAliases.Chrome;34 case "firefox":35 return DriverAliases.Firefox;36 case "ie":37 return DriverAliases.InternetExplorer;38 default:39 throw new Exception("no browser");40 }41 }42 [TestCleanup]43 public void End()44 {45 //if (TestContext.CurrentTestOutcome == UnitTestOutcome.Error || TestContext.CurrentTestOutcome == UnitTestOutcome.Failed)46 //{47 // AtataContext.Current?.Log.Screenshot("Failure");48 //TestContext.AddResultFile($"{_folderName}\\01 - Test page - Failure.png");49 //}50 51 AtataContext.Current?.Log.Screenshot("Two");52 if (Directory.Exists(_folderName))53 {54 foreach (var f in Directory.GetFiles(_folderName))55 TestContext.AddResultFile(f);56 }57 58 //var apath = Path.Combine(_folderName);59 //var ap = Directory.GetParent(apath);60 //var at = Directory.GetParent(ap.FullName);61 //var att = Directory.GetParent(at.FullName);62 //63 //using (StreamWriter sw = File.CreateText($"{att}\\test2.txt"))64 //{65 // sw.WriteLine("Hello");66 // sw.WriteLine("And");67 // sw.WriteLine("Welcome");68 //}69 //70 //TestContext.AddResultFile($"{att}\\test2.txt");71 AtataContext.Current?.CleanUp();72 //var test = Directory.GetFiles(att.FullName);73 //string tests = "";74 //foreach (var t in test)75 //{76 // tests += t;77 //}78 //throw new Exception($"files count: {test.Length}...names: {tests}");79 }80 }81}...

Full Screen

Full Screen

TestBase.cs

Source:TestBase.cs Github

copy

Full Screen

1using Atata;2using Microsoft.VisualStudio.TestTools.UnitTesting;3namespace UITesting.TestsCore4{5 /// <summary>6 /// The class TestBase is used to setup the testing framework and the web driver7 /// </summary>8 [TestClass]9 public class TestBase10 {11 /// <summary>12 /// Gets or sets the test context.13 /// </summary>14 /// <value>15 /// The test context.16 /// </value>17 public TestContext TestContext { get; set; }18 /// <summary>19 /// Initialize.20 /// </summary>21 [TestInitialize]22 public void TestInitialize()23 {24 AtataContext.Configure()25 .UseChrome().WithArguments("disable-extensions", "no sandbox", "start-maximized")26 .UseBaseUrl(Configuration.BaseUrl)27 .UseTestName(TestContext.TestName)28 .AddNLogLogging()29 .UseCulture("de-de")30 .AddTraceLogging()31 .AddScreenshotFileSaving()32 .WithFolderPath(() => $@"Logs\{AtataContext.BuildStart:yyyy-MM-dd HH_mm}")33 .WithFileName(screenshotInfo => $"{AtataContext.Current.TestName} - {screenshotInfo.PageObjectFullName}")34 .Build();35 }36 /// <summary>37 /// Cleanup.38 /// </summary>39 [TestCleanup]40 public void TestCleanup()41 {42 AtataContext.Current.CleanUp();43 }44 }45}...

Full Screen

Full Screen

ExtentScreenshotConsumer.cs

Source:ExtentScreenshotConsumer.cs Github

copy

Full Screen

...5namespace SPLetsAutomate6{7 public class ExtentScreenshotConsumer : IScreenshotConsumer8 {9 public void Take(ScreenshotInfo screenshotInfo)10 {11 string title = $"{screenshotInfo.Number:D2} - {screenshotInfo.PageObjectFullName}{screenshotInfo.Title?.Prepend(" - ")}";12 string relativeFilePath = Path.Combine(AtataContext.Current.TestNameSanitized, $"{title.SanitizeForFileName()}.png");13 string absoluteFilePath = Path.Combine(ExtentContext.WorkingFolder, relativeFilePath);14 string targetDirectory = Path.GetDirectoryName(absoluteFilePath);15 if (!Directory.Exists(targetDirectory))16 Directory.CreateDirectory(targetDirectory);17 screenshotInfo.Screenshot.SaveAsFile(absoluteFilePath, ScreenshotImageFormat.Png);18 ExtentContext.CurrentTest.Log(19 Status.Info,20 MediaEntityBuilder.CreateScreenCaptureFromPath(relativeFilePath, title).Build());21 }22 }23}...

Full Screen

Full Screen

ScreenshotInfo

Using AI Code Generation

copy

Full Screen

1using Atata;2using NUnit.Framework;3using System;4using System.Collections.Generic;5using System.Linq;6using System.Text;7using System.Threading.Tasks;8{9 {10 public void _2()11 {12 Go.To<HomePage>()13 .Screenshot("homepage")14 .SearchFor("Atata Framework")15 .Screenshot("search results")16 .Results[1].Click()17 .Screenshot("Atata Framework page");18 }19 }20}21using Atata;22using NUnit.Framework;23using System;24using System.Collections.Generic;25using System.Linq;26using System.Text;27using System.Threading.Tasks;28{29 {30 public void _3()31 {32 Go.To<HomePage>()33 .Screenshot("homepage")34 .SearchFor("Atata Framework")35 .Screenshot("search results")36 .Results[1].Click()37 .Screenshot("Atata Framework page");38 }39 }40}41using Atata;42using NUnit.Framework;43using System;44using System.Collections.Generic;45using System.Linq;46using System.Text;47using System.Threading.Tasks;48{49 {50 public void _4()51 {52 Go.To<HomePage>()53 .Screenshot("homepage")54 .SearchFor("Atata Framework")55 .Screenshot("search results")56 .Results[1].Click()57 .Screenshot("Atata Framework page");58 }59 }60}61using Atata;62using NUnit.Framework;63using System;64using System.Collections.Generic;65using System.Linq;66using System.Text;67using System.Threading.Tasks;68{69 {70 public void _5()71 {72 Go.To<HomePage>()73 .Screenshot("homepage")74 .SearchFor("Atata Framework")75 .Screenshot("search results")76 .Results[1].Click()77 .Screenshot("Atata Framework page");78 }

Full Screen

Full Screen

ScreenshotInfo

Using AI Code Generation

copy

Full Screen

1using Atata;2using NUnit.Framework;3{4 {5 protected override void OnSetUp()6 {7 base.OnSetUp();8 Go.To<HomePage>();9 }10 }11 {12 public void SampleApp_ScreenshotInfo()13 {14 var screenshotInfo = ScreenshotInfo.Create();15 screenshotInfo.SaveScreenshot();16 screenshotInfo.SaveSource();17 screenshotInfo.SavePageSource();18 }19 }20}21using Atata;22using NUnit.Framework;23{24 {25 protected override void OnSetUp()26 {27 base.OnSetUp();28 Go.To<HomePage>();29 }30 }31 {32 public void SampleApp_ScreenshotInfo()33 {34 ScreenshotInfo.Create().SaveScreenshot();35 ScreenshotInfo.Create().SaveSource();36 ScreenshotInfo.Create().SavePageSource();37 }38 }39}40using Atata;41using NUnit.Framework;42{43 {44 protected override void OnSetUp()45 {46 base.OnSetUp();47 Go.To<HomePage>();48 }49 }50 {51 public void SampleApp_ScreenshotInfo()52 {53 ScreenshotInfo.Create().SaveScreenshot().SaveSource().SavePageSource();54 }55 }56}57using Atata;58using NUnit.Framework;59{60 {61 protected override void OnSetUp()62 {63 base.OnSetUp();64 Go.To<HomePage>();65 }66 }67 {68 public void SampleApp_ScreenshotInfo()69 {70 ScreenshotInfo.Create().SaveScreenshot().SaveSource().SavePageSource();71 }72 }73}

Full Screen

Full Screen

ScreenshotInfo

Using AI Code Generation

copy

Full Screen

1using Atata;2using NUnit.Framework;3{4 {5 public void ScreenshotInfoTest()6 {7 var screenshotInfo = new ScreenshotInfo("TestName");8 string fileName = screenshotInfo.FileName;9 string filePath = screenshotInfo.FilePath;10 string fileFullName = screenshotInfo.FileFullName;11 string fileFullNameWithExt = screenshotInfo.FileFullNameWithExt;12 string fileFullNameWithExtAndPath = screenshotInfo.FileFullNameWithExtAndPath;13 string fileFullNameWithExtAndPathAndName = screenshotInfo.FileFullNameWithExtAndPathAndName;14 }15 }16}

Full Screen

Full Screen

ScreenshotInfo

Using AI Code Generation

copy

Full Screen

1using Atata;2using NUnit.Framework;3using System;4using System.IO;5using System.Reflection;6{7 {8 public void SetUp()9 {10 Build();11 }12 public void TestMethod()13 {14 Go.To<GooglePage>();15 }16 public void TearDown()17 {18 AtataContext.Current.CleanUp();19 }20 }21}22using Atata;23using NUnit.Framework;24using System;25using System.IO;26using System.Reflection;27{28 {29 public void SetUp()30 {31 Build();32 }33 public void TestMethod()34 {35 Go.To<GooglePage>();36 }37 public void TearDown()38 {39 AtataContext.Current.CleanUp();40 }41 }42}43using Atata;44using NUnit.Framework;45using System;46using System.IO;47using System.Reflection;48{49 {50 public void SetUp()51 {52 Build();53 }54 public void TestMethod()55 {56 Go.To<GooglePage>();57 }58 public void TearDown()

Full Screen

Full Screen

ScreenshotInfo

Using AI Code Generation

copy

Full Screen

1using Atata;2using NUnit.Framework;3using NUnit.Framework.Interfaces;4using OpenQA.Selenium;5using System;6using System.IO;7{8 {9 public void SetUp()10 {11 WithArguments("enable-

Full Screen

Full Screen

ScreenshotInfo

Using AI Code Generation

copy

Full Screen

1using Atata;2using NUnit.Framework;3using OpenQA.Selenium;4using OpenQA.Selenium.Remote;5using System;6using System.IO;7using System.Linq;8using System.Text;9using System.Threading;10using System.Threading.Tasks;11{12 {13 public string FileName { get; set; }14 public string FullPath { get; set; }15 public string RelativePath { get; set; }16 public string Url { get; set; }17 public string Title { get; set; }18 public string Html { get; set; }19 public string Source { get; set; }20 }21 {22 public TOwner Owner { get; set; }23 public ScreenshotInfo(TOwner owner)24 {25 Owner = owner;26 }27 }28 {29 public void TestMethod()30 {31 Go.To<PageObject>();32 var screenshotInfo = new ScreenshotInfo<PageObject>(Go.To<PageObject>());33 screenshotInfo.FileName = "test";34 screenshotInfo.FullPath = "test";35 screenshotInfo.RelativePath = "test";36 screenshotInfo.Url = "test";37 screenshotInfo.Title = "test";38 screenshotInfo.Html = "test";39 screenshotInfo.Source = "test";40 }41 }42}43using Atata;44using NUnit.Framework;45using OpenQA.Selenium;46using OpenQA.Selenium.Remote;47using System;48using System.IO;49using System.Linq;50using System.Text;51using System.Threading;52using System.Threading.Tasks;53{54 {55 public string FileName { get; set; }56 public string FullPath { get; set; }57 public string RelativePath { get; set; }58 public string Url { get; set; }59 public string Title { get; set; }60 public string Html { get; set; }61 public string Source { get; set; }62 }63 {64 public TOwner Owner { get; set; }65 public ScreenshotInfo(TOwner

Full Screen

Full Screen

ScreenshotInfo

Using AI Code Generation

copy

Full Screen

1using System;2using System.IO;3using System.Reflection;4using System.Threading;5using NUnit.Framework;6using OpenQA.Selenium;7using OpenQA.Selenium.Chrome;8using OpenQA.Selenium.Support.UI;9using System.Linq;10using System.Collections.Generic;11using System.Text.RegularExpressions;12using OpenQA.Selenium.Interactions;13using System.Drawing;14using System.Drawing.Imaging;15using System.Drawing.Drawing2D;16using System.Drawing.Text;17using System.Text;18using System.Threading.Tasks;

Full Screen

Full Screen

ScreenshotInfo

Using AI Code Generation

copy

Full Screen

1ScreenshotInfo screenshotInfo = new ScreenshotInfo();2ScreenshotInfo screenshotInfo = new ScreenshotInfo("MyCustomScreenshotName");3ScreenshotInfo screenshotInfo = new ScreenshotInfo("MyCustomScreenshotName", "CustomScreenshotFolder");4ScreenshotInfo screenshotInfo = new ScreenshotInfo("CustomScreenshotFolder");5ScreenshotInfo screenshotInfo = new ScreenshotInfo(AtataContext.Current.TestName);6ScreenshotInfo screenshotInfo = new ScreenshotInfo(AtataContext.Current.TestName, "CustomScreenshotFolder");7ScreenshotInfo screenshotInfo = new ScreenshotInfo(AtataContext.Current.TestName, "CustomScreenshotFolder", "CustomScreenshotNumberFormat");8ScreenshotInfo screenshotInfo = new ScreenshotInfo(AtataContext.Current.TestName, "CustomScreenshotFolder", "CustomScreenshotNumberFormat", "CustomScreenshotNumber");9ScreenshotInfo screenshotInfo = new ScreenshotInfo(AtataContext.Current.TestName, "CustomScreenshotFolder", "CustomScreenshotNumberFormat", "CustomScreenshotNumber", "CustomScreenshotFileExtension");10ScreenshotInfo screenshotInfo = new ScreenshotInfo(AtataContext.Current.TestName, "CustomScreenshotFolder", "CustomScreenshotNumberFormat", "CustomScreenshotNumber", "CustomScreenshotFileExtension", "CustomScreenshotNameSeparator");11ScreenshotInfo screenshotInfo = new ScreenshotInfo(AtataContext.Current.TestName, "CustomScreenshotFolder", "CustomScreenshotNumberFormat", "CustomScreenshotNumber", "CustomScreenshotFileExtension", "CustomScreenshotNameSeparator", ScreenshotNameAppendDateTimeKind.Local);12ScreenshotInfo screenshotInfo = new ScreenshotInfo(AtataContext.Current.TestName, "CustomScreenshotFolder", "CustomScreenshotNumberFormat", "CustomScreenshotNumber", "CustomScreenshotFileExtension", "CustomScreenshotNameSeparator", ScreenshotNameAppendDateTimeKind.Local, "CustomScreenshotNameAppendDateTimeFormat");13ScreenshotInfo screenshotInfo = new ScreenshotInfo(AtataContext.Current.TestName, "CustomScreenshotFolder", "CustomScreenshotNumberFormat", "CustomScreenshotNumber", "CustomScreenshotFileExtension", "CustomScreenshotNameSeparator", ScreenshotNameAppendDateTimeKind.Local, "CustomScreenshotNameAppendDateTimeFormat", ScreenshotNameAppendDateTimeKind.Local);14ScreenshotInfo screenshotInfo = new ScreenshotInfo(AtataContext.Current.TestName, "CustomScreenshotFolder", "CustomScreenshotNumberFormat", "CustomScreenshotNumber", "CustomScreenshotFileExtension", "CustomScreenshotNameSeparator", ScreenshotNameAppendDateTimeKind.Local, "CustomScreenshotNameAppendDateTimeFormat", ScreenshotNameAppendDateTimeKind.Local, "CustomScreenshot

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atata automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful