I am producing screenshots using SpecFlow and Selenium by executing an xUnit test run with the VSTS Visual Studio Test
task:
I have configured the VS Test task
with the default parameter values, so (I believe) it simply finds any DLLs and runs them with the xUnit runner.
After running, the test report for the particular release shows the test results as intended. It does not, however, show the generated screenshots.
I am attempting to attach screenshots generated during the tests with this code:
string path = System.IO.Directory.GetCurrentDirectory() + "TestScreenshot.png";
OpenQA.Selenium.Screenshot ss = ((OpenQA.Selenium.ITakesScreenshot)Context.Driver).GetScreenshot();
ss.SaveAsFile(path);
var testContext = ScenarioContext.Current.ScenarioContainer.Resolve<Microsoft.VisualStudio.TestTools.UnitTesting.TestContext>();
testContext.AddResultFile(path);
But this does not get displayed in the attachments
section of the test report.
Having seen this SO post I thought that perhaps I need to store the screenshots in a particular "special folder", but I don't know which folder to use and how they would be arranged to indicate which test they are attached to.
Having seen this documentation I thought that all I need is a Publish Test Results
task and to indicate where the test attachments are stored, but this gives an error and complains that there are no TEST-*.xml
files found. I am not specifically configuring the VS Test task
to generate TEST-*.xml
files because the test results do appear to be detected automatically.
As far as I can see, the result I'm getting is the same as in this bug report as linked from this SO post, although the fix should be live.
How can I publish/upload/report my screenshots so that they are visible as part of the Test Report at the end of my release pipeline?