Reputation: 41
I'm using Visual Studio 2017, Visual Studio Test Tools and VSTFS v.15. I managed to take screenshots using Selenium and currently store them in 'TestLogsDir' folder. When I run UI tests locally I can easily locate my screenshots after each test run. But after running nightly build on a Virtual Machine 'TestLogsDir' is being deleted. Obviously, I can store screenshots somewhere else, but the thing is how can I attach the screenshot to a corresponding test case in TFS Test Report?
Upvotes: 3
Views: 3733
Reputation: 11
Below code, I used to take a screenshot, save it in the working directory and, update the file to TFS build.
using NUnit.Framework;
using System.Drawing;
using System.IO;
Screenshot screenshot = ((ITakesScreenshot)Webdriver).GetScreenshot();
string screenshotFile = Path.Combine(TestContext.CurrentContext.WorkDirectory, "screenshot.png");
screenshot.SaveAsFile(screenshotFile, ScreenshotImageFormat.Png);
TestContext.AddTestAttachment(screenshotFile, "Error Snapshot:");
Upvotes: 0
Reputation: 114887
Depending on the test framework you're using to run the UI tests:
Upvotes: 5