diff --git a/src/FlaUI.TestUtilities/FlaUITestBase.cs b/src/FlaUI.TestUtilities/FlaUITestBase.cs index 468aaeeef..a947a0137 100644 --- a/src/FlaUI.TestUtilities/FlaUITestBase.cs +++ b/src/FlaUI.TestUtilities/FlaUITestBase.cs @@ -55,11 +55,16 @@ public abstract class FlaUITestBase /// protected virtual VideoRecordingMode VideoRecordingMode => VideoRecordingMode.OnePerTest; + /// + /// static member which holds the current execution date and time + /// + private static string _testDateTime = DateTime.Now.ToString("yyyyMMddHHmmss"); + /// /// Path of the directory for the screenshots and videos for the tests. /// Defaults to c:\temp\testsmedia. /// - protected virtual string TestsMediaPath => @"c:\temp\testsmedia"; + protected virtual string TestsMediaPath => $@"c:\temp\testsmedia\{SanitizeFileName(TestContext.CurrentContext.Test.Name)}\{_testDateTime}"; /// /// Gets the automation instance that should be used. @@ -140,6 +145,9 @@ public virtual void UITestBaseTearDown() if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed) { TakeScreenShot(TestContext.CurrentContext.Test.FullName); + TestContext.AddTestAttachment( + CreateScreenShotPath(TestContext.CurrentContext.Test.FullName), + TestContext.CurrentContext.Test.FullName); } if (ApplicationStartMode == ApplicationStartMode.OncePerTest) @@ -251,9 +259,7 @@ private void StopVideoRecorder() /// private void TakeScreenShot(string testName) { - var imageName = SanitizeFileName(testName) + ".png"; - imageName = imageName.Replace("\"", String.Empty); - var imagePath = Path.Combine(TestsMediaPath, imageName); + var imagePath = CreateScreenShotPath(testName); try { Directory.CreateDirectory(TestsMediaPath); @@ -273,5 +279,15 @@ private string SanitizeFileName(string fileName) fileName = string.Join("_", fileName.Split(Path.GetInvalidFileNameChars())); return fileName; } + + /// + /// Generates full path for screenshot. + /// + private string CreateScreenShotPath(string testName) + { + var imageName = SanitizeFileName(testName) + ".png"; + imageName = imageName.Replace("\"", String.Empty); + return Path.Combine(TestsMediaPath, imageName); + } } }