How can I add UI test screenshot to TFS Test Report as an attachment How can I add UI test screenshot to TFS Test Report as an attachment selenium selenium

How can I add UI test screenshot to TFS Test Report as an attachment


Depending on the test framework you're using to run the UI tests:


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:");