Skip to content

Commit ee057ff

Browse files
author
Jake Ginnivan
committed
Fixing issue with taking screenshot of failing test
1 parent bc4ba4f commit ee057ff

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/TestStack.White.UITests/WhiteTestBase.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Drawing.Imaging;
45
using System.IO;
56
using System.Linq;
6-
using System.Threading;
77
using Castle.Core.Logging;
88
using TestStack.White.Configuration;
99
using TestStack.White.InputDevices;
@@ -75,7 +75,18 @@ protected void RunTest(Action testAction, params WindowsFramework[] runFor)
7575
}
7676
catch (Exception ex)
7777
{
78-
new ScreenCapture().CaptureScreenShot().Save(Path.Combine(screenshotDir, testAction.Method.Name + ".png"), ImageFormat.Png);
78+
string path2 = string.Empty;
79+
try
80+
{
81+
path2 = testAction.Method.Name + ".png";
82+
var filename = Path.Combine(screenshotDir, path2);
83+
new ScreenCapture().CaptureScreenShot().Save(filename, ImageFormat.Png);
84+
Trace.WriteLine(string.Format("Screenshot taken: {0}", filename));
85+
}
86+
catch (Exception)
87+
{
88+
Trace.TraceError(string.Format("Failed to save screenshot to directory: {0}, filename: {1}", screenshotDir, path2));
89+
}
7990
throw new TestFailedException(string.Format("Failed to run {0} for {1}. Details:\r\n\r\n{2}",
8091
testAction.Method.Name, currentFramework, ex), ex);
8192
}

0 commit comments

Comments
 (0)