title: NUnit How to attach screenshot to test attachments in Azure Pipeline
body: <p>We want to attach screenshots to the Test Attachment in Azure pipeline. Currently, we use</p>
  
  <ul>
  <li>.NET 4.5.2</li>
  <li>Selenium.WebDriver 3.141</li>
  <li>Selenium.Chrome.WebDriver</li>
  <li>Nunit 3.12.0</li>
  <li>Specflow.Nunit 2.4.0</li>
  </ul>
  
  <p>It is similar with the follwing example but we use NUnit rather than MSTest <a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/test/collect-screenshots-and-video?view=azure-devops#collect-screenshots-logs-and-attachments" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/azure/devops/pipelines/test/collect-screenshots-and-video?view=azure-devops#collect-screenshots-logs-and-attachments</a></p>
  
  <p>When run the program in VS2017, the screenshots are accessible from the test report. Also, we can see the screenshots in the azure build output.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>string fileName = string.Format("Screenshot_" + DateTime.Now.ToString("dd-MM-yyyy-hhmm-ss") + ".jpg");
  
  var artifactDirectory = Directory.GetCurrentDirectory();
  
  ITakesScreenshot takesScreenshot = _driver as ITakesScreenshot;
  
  if (takesScreenshot != null)
  {
      var screenshot = takesScreenshot.GetScreenshot();
  
      string screenshotFilePath = Path.Combine(artifactDirectory, fileName);
  
      screenshot.SaveAsFile(screenshotFilePath, ScreenshotImageFormat.Jpeg);
      TestContext.AddTestAttachment(screenshotFilePath, "screenshot");
      Console.WriteLine($"Screenshot: {new Uri(screenshotFilePath)}");
  }
  </code></pre>
  
  <p>Visual Studio Test step in Azure pipeline</p>
  
  <p><a href="https://i.stack.imgur.com/ogyaZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ogyaZ.png" alt="Visual Studio Test step"></a></p>
  
  <p><a href="https://i.stack.imgur.com/22RbT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/22RbT.png" alt="upload test attachments"></a></p>
  
  <p>After the build runs, there is no attachment</p>
  
  <p><a href="https://i.stack.imgur.com/fgZjx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fgZjx.png" alt="no attachments"></a></p>
  
  <p>Any help would be appreciated.</p>