We want to attach screenshots to the Test Attachment in Azure pipeline. Currently, we use
- .NET 4.5.2
- Selenium.WebDriver 3.141
- Selenium.Chrome.WebDriver
- Nunit 3.12.0
- Specflow.Nunit 2.4.0
It is similar with the follwing example but we use NUnit rather than MSTest https://learn.microsoft.com/en-us/azure/devops/pipelines/test/collect-screenshots-and-video?view=azure-devops#collect-screenshots-logs-and-attachments
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.
Here is the 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)}");
}
Visual Studio Test step in Azure pipeline
After the build runs, there is no attachment
Any help would be appreciated.