How to I attach files on TFS Build Tests when they pass? How to I attach files on TFS Build Tests when they pass? selenium selenium

How to I attach files on TFS Build Tests when they pass?


The method you mention is part of the TestContext class in Microsoft's test framework.

There is also an AddResultFile(String) method, not sure if this could handle it with selenium. You should first make this work in local development and then move to TFS build pipeline.

Besides, in TFS side, you could use REST API to add an attachment to Test run like the following.

POST https://dev.azure.com/fabrikam/Fabrikam/_apis/test/Runs/49/attachments?api-version=5.0-preview.1

{  "stream": "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAIAAABvFaqvAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABlSURBVDhP7cxBCsAgDERR739pG/CnGJI0FopQ8O2cjNP6R85QbeNQU7wT1dkijaQ3vkZoWElaoTeJojW01cYh0jwfgiFBV/lEjOZtacijN/nLkOBHhIaVDgn+Wdycp6FXzlCl9wt0Y0cAzHo/zgAAAABJRU5ErkJggg==",  "fileName": "imageAsFileAttachment.png",  "comment": "Test attachment upload",  "attachmentType": "GeneralAttachment"}

Each test (including the automation test) will has a test run ID when running it. Next time to run the same test will be another run ID, it's unique. So, if you want to attach the files to the specific test run, you need to get the test run ID first, the {run} means the specific test run ID.

You could fetch these run IDs during your running build pipeline logs through Rest API. Then add a powershell script/task to involve above API during your build.