Reputation: 912
I have a TFS build definition that runs some test cases using selenium. I do the log using TestContext.WriteLine (we are using MSTest)
That works just fine when the test cases fail (I see an attachment called Standard Console Output.log). But, when they pass no file is attached. I would like to see the log file to verify that the test is passing for the right reasons when running on the test agents.
Does anyone knows how to achieve this?
Upvotes: 2
Views: 602
Reputation: 51143
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.
Upvotes: 1