I'm trying to attach the log file that I have generated, during the run of my automated tests in the Azure Release pipeline. I am running Automated UI tests using selenium and MSTest. Originally, I was under the impression that I could attach the file in the AssemblyCleanup Method of MSTest, using the TestContext object. However, it seems that that TestContext can only be used for Attaching results to individual test cases? After Searching around the web a bit I found this API call:
POST https://dev.azure.com/{Organization}/{Project}/_apis/test/Runs/{runId}/attachments?api-version=5.1-preview.1
in the Microsoft Documentation :https://docs.microsoft.com/en-us/rest/api/azure/devops/test/attachments/create%20test%20result%20attachment?view=azure-devops-rest-5.1
However, I don't understand how to get ahold of the test runId in my test code or how to authenticate with OAuth2. Here is as far as I could get using RestSharp to make the call;
RestClient httpClient = new RestClient("");
//I have no clue if this is even close to right with the OAuth stuff
httpClient.Authenticator = new RestSharp.Authenticators.OAuth2AuthorizationRequestHeaderAuthenticator("");
RestRequest request = new RestRequest(Method.POST);
APIRequestBody body = new APIRequestBody
{
//not sure if this is the right stream
Stream = "",//not sure what to put in here
FileName = "TestRun.log",
Comment = "Test run log file.",
AttachmentType = "GeneralAttachment"
};
request.AddJsonBody(body);
IRestResponse response = httpClient.Execute(request);
Any help would be really great... I'm in a bit over my head here.