Adding screenshots to livingdoc using devops blob storage
I added this to an existing request, but not sure it got any attention so creating here
The documentation mentions having to create blob storage to host these files before adding to living doc, but they already exist in blob storage, see below.
When we upload screenshots using the specflow scenariocontext
context.AddResultFile(path);
inside our runs which are driven through azure devops pipelines, the screenshots are already uploaded and stored in blobstorage. We can even find out what that url is using
The problem is however, while the test is running we can find out everything except the resultID. So we can't call specFlowOutputHelper.AddAttachment with the correct url while the test is running. As a solution, perhaps we shouldn't have to call specFlowOutputHelper.AddAttachment at all? Perhaps the specflow plugin could be adjusted to scrape the correct resultID from the run after completion then populate the livingdoc file attachments using everything that is attached to the result in azure devops? If the correct positioning within the scenario steps is still required, we could call specFlowOutputHelper.AddAttachment with the filepath as we do now, which gives filepaths in living doc like this D:\a\1\s\TestAutomation\bin\DebugContacts_Making_a_call_210807134917.873.png then the livingdoc extension could use that filename to find the attachment in the azure devops result and simply add the correct url to that file?
-
From which test runner are you using the context class? Is this MSTest? I don't think that every testrunner does have an inbuild API that pushes the files to the Azure DevOps results.
About the ResultId:
As far as I remember, we don't even have this in the SpecFlow+ Runner, where we implement our own testrunner. So this information is very hard to access. Perhaps we could get it via the Azure DevOps APIs, but not sure.
0 -
Yes this is with MSTest , code below adds the attachment to the test result in azure devops. Regardless of how the attachment is added (specFlowOutputHelper.AddAttachment(path); also adds it to the result which appears in devops) it looks like the existing azure devops apis could be used to scrape the result, then update the living doc with a link to the correct place?
var context = scenarioContext.ScenarioContainer.Resolve<TestContext>();
public static void ReportScreenCapture(ScenarioContext scenarioContext, IWebDriver webDriver)
{
try
{
var context = scenarioContext.ScenarioContainer.Resolve<TestContext>();if (context.CurrentTestOutcome != UnitTestOutcome.Passed)
{
var screenShotter = ((ITakesScreenshot)webDriver).GetScreenshot();
var path = FormatScreenFilePath(scenarioContext, $"{Directory.GetCurrentDirectory()}");
screenShotter.SaveAsFile(path);
context.AddResultFile(path);
}
}
catch (Exception)
{
Console.WriteLine("Error creating screen capture");
}
}0
Please sign in to leave a comment.
Comments
2 comments