【发布时间】:2020-03-30 22:02:31
【问题描述】:
我正在尝试附加在 Azure 发布管道中运行自动化测试期间生成的日志文件。我正在使用 selenium 和 MSTest 运行自动化 UI 测试。最初,我的印象是我可以使用 TestContext 对象在 MSTest 的 AssemblyCleanup 方法中附加文件。但是,似乎 TestContext 只能用于将结果附加到单个测试用例?在网上搜索了一下后,我发现了这个 API 调用:
POST https://dev.azure.com/{Organization}/{Project}/_apis/test/Runs/{runId}/attachments?api-version=5.1-preview.1
但是,我不明白如何在我的测试代码中获取测试 runId 或如何使用 OAuth2 进行身份验证。 这是我可以使用 RestSharp 拨打电话的情况;
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);
任何帮助都会非常棒......我有点过头了。
【问题讨论】:
-
嗨@MitchelB123 您是否尝试过以下代码,效果如何?如果有任何问题,请告诉我。
标签: c# selenium azure-devops mstest web-api-testing