在Azure Pipelin中执行测试后发送电子邮件报告

时间:2019-06-11 13:47:46

标签: c# azure selenium c#-4.0

我已经使用Azure管道实现了C#硒自动化脚本。我想将执行测试结果发送到我的电子邮件ID。有什么办法可以做到这一点?

1 个答案:

答案 0 :(得分:0)

目前,您只能编写自定义扩展名以发送包含测试结果的电子邮件,您可以从Azure devops管道对其进行调用。

但是您可以使用以下一组API来获取测试结果。

GET https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/results?api-version=5.0

带有可选参数。

GET https://dev.azure.com/{organization}/{project}/_apis/test/Runs/{runId}/results?detailsToInclude={detailsToInclude}&$skip={$skip}&$top={$top}&outcomes={outcomes}&api-version=5.0

参数在哪里:

enter image description here

这是示例响应:

{
  "count": 3,
  "value": [
    {
      "id": 100000,
      "project": {
        "id": "5c3d39df-a0cb-49da-be01-42e53792c0e1",
        "name": "Fabrikam-Fiber-TFVC",
        "url": "https://dev.azure.com/fabrikam/_apis/projects/Fabrikam-Fiber-TFVC"
      },
      "startedDate": "2016-07-13T11:12:48.487Z",
      "completedDate": "2016-07-13T11:12:48.493Z",
      "durationInMs": 4,
      "outcome": "Passed",
      "revision": 1,
      "runBy": {
        "id": "a5cbf24d-799f-452e-82be-f049a85b5895",
        "displayName": "Fabrikam",
        "uniqueName": "fabrikamfiber.vsin@hotmail.com",
        "url": "https://dev.azure.com/fabrikam/_apis/Identities/a5cbf24d-799f-452e-82be-f049a85b5895",
        "imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=a5cbf24d-799f-452e-82be-f049a85b5895"
      },
      "state": "Completed",
      "testCase": {
        "name": "Pass1"
      },
      "testRun": {
        "id": "16",
        "name": "VSTest Test Run release any cpu",
        "url": "https://dev.azure.com/fabrikam/Fabrikam-Fiber-TFVC/_apis/test/Runs/16"
      },
      "lastUpdatedDate": "2016-07-13T11:12:49.123Z",
      "lastUpdatedBy": {
        "id": "375baa5b-5148-4e89-a549-ec202b722d89",
        "displayName": "Project Collection Build Service (fabrikam)",
        "uniqueName": "Build\\78b5727d-4a24-4ec8-9caf-704685572174",
        "url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/375baa5b-5148-4e89-a549-ec202b722d89",
        "imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=375baa5b-5148-4e89-a549-ec202b722d89"
      },
      "priority": 0,
      "computerName": "TASKAGENT5-0055",
      "build": {
        "id": "5",
        "name": "20160713.2",
        "url": "https://dev.azure.com/fabrikam/_apis/build/Builds/5"
      },
      "createdDate": "2016-07-13T11:12:49.123Z",
      "url": "https://dev.azure.com/fabrikam/Fabrikam-Fiber-TFVC/_apis/test/Runs/16/Results/100000",
      "failureType": "None",
      "automatedTestStorage": "unittestproject1.dll",
      "automatedTestType": "UnitTest",
      "automatedTestTypeId": "13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b",
      "automatedTestId": "aefba017-ab06-be36-6b92-de4e29836f72",
      "area": {
        "id": "37528",
        "name": "Fabrikam-Fiber-TFVC",
        "url": "vstfs:///Classification/Node/ebe8ac79-8d9f-4a5b-8d0a-c3095c81e70e"
      },
      "testCaseTitle": "Pass1",
      "customFields": [],
      "automatedTestName": "UnitTestProject1.UnitTest1.Pass1"
    },
    {
      "id": 100001,
      "project": {
        "id": "5c3d39df-a0cb-49da-be01-42e53792c0e1",
        "name": "Fabrikam-Fiber-TFVC",
        "url": "https://dev.azure.com/fabrikam/_apis/projects/Fabrikam-Fiber-TFVC"
      },
      "startedDate": "2016-07-13T11:12:48.547Z",
      "completedDate": "2016-07-13T11:12:48.62Z",
      "durationInMs": 74,
      "outcome": "Failed",
      "revision": 1,
      "runBy": {
        "id": "a5cbf24d-799f-452e-82be-f049a85b5895",
        "displayName": "Fabrikam-Fiber-TFVC",
        "uniqueName": "fabrikamfiber.vsin@hotmail.com",
        "url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/a5cbf24d-799f-452e-82be-f049a85b5895",
        "imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=a5cbf24d-799f-452e-82be-f049a85b5895"
      },
      "state": "Completed",
      "testCase": {
        "name": "Fail1"
      },
      "testRun": {
        "id": "16",
        "name": "VSTest Test Run release any cpu",
        "url": "https://dev.azure.com/fabrikam/Fabrikam-Fiber-TFVC/_apis/test/Runs/16"
      },
      "lastUpdatedDate": "2016-07-13T11:12:49.123Z",
      "lastUpdatedBy": {
        "id": "375baa5b-5148-4e89-a549-ec202b722d89",
        "displayName": "Project Collection Build Service (fabrikam)",
        "uniqueName": "Build\\78b5727d-4a24-4ec8-9caf-704685572174",
        "url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/375baa5b-5148-4e89-a549-ec202b722d89",
        "imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=375baa5b-5148-4e89-a549-ec202b722d89"
      },
      "priority": 10,
      "computerName": "TASKAGENT5-0055",
      "build": {
        "id": "5",
        "name": "20160713.2",
        "url": "https://dev.azure.com/fabrikam/_apis/build/Builds/5"
      },
      "errorMessage": "Assert.Fail failed. ",
      "createdDate": "2016-07-13T11:12:49.123Z",
      "url": "https://dev.azure.com/fabrikam/Fabrikam-Fiber-TFVC/_apis/test/Runs/16/Results/100001",
      "failureType": "None",
      "automatedTestStorage": "unittestproject1.dll",
      "automatedTestType": "UnitTest",
      "automatedTestTypeId": "13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b",
      "automatedTestId": "7c66fbda-2d0e-a714-e18d-83c0464019a5",
      "area": {
        "id": "37528",
        "name": "Fabrikam-Fiber-TFVC",
        "url": "vstfs:///Classification/Node/ebe8ac79-8d9f-4a5b-8d0a-c3095c81e70e"
      },
      "testCaseTitle": "Fail1",
      "stackTrace": "   at UnitTestProject1.UnitTest1.Fail1() in C:\\a\\1\\s\\UnitTestProject1\\UnitTestProject1\\UnitTest1.cs:line 20\r\n",
      "customFields": [],
      "failingSince": {
        "date": "2016-07-13T11:11:17.587Z",
        "build": {
          "id": 4,
          "definitionId": 0,
          "number": "20160713.1",
          "buildSystem": "Azure DevOps Services"
        }
      },
      "automatedTestName": "UnitTestProject1.UnitTest1.Fail1"
    },
    {
      "id": 100002,
      "project": {
        "id": "5c3d39df-a0cb-49da-be01-42e53792c0e1",
        "name": "Fabrikam-Fiber-TFVC",
        "url": "https://dev.azure.com/fabrikam/_apis/projects/Fabrikam-Fiber-TFVC"
      },
      "startedDate": "2016-07-13T11:12:48.623Z",
      "completedDate": "2016-07-13T11:12:48.623Z",
      "outcome": "NotExecuted",
      "revision": 1,
      "runBy": {
        "id": "a5cbf24d-799f-452e-82be-f049a85b5895",
        "displayName": "Fabrikam-Fiber-TFVC",
        "uniqueName": "fabrikamfiber.vsin@hotmail.com",
        "url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/a5cbf24d-799f-452e-82be-f049a85b5895",
        "imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=a5cbf24d-799f-452e-82be-f049a85b5895"
      },
      "state": "Completed",
      "testCase": {
        "name": "Ignore1"
      },
      "testRun": {
        "id": "16",
        "name": "VSTest Test Run release any cpu",
        "url": "https://dev.azure.com/fabrikam/Fabrikam-Fiber-TFVC/_apis/test/Runs/16"
      },
      "lastUpdatedDate": "2016-07-13T11:12:49.123Z",
      "lastUpdatedBy": {
        "id": "375baa5b-5148-4e89-a549-ec202b722d89",
        "displayName": "Project Collection Build Service (fabrikam)",
        "uniqueName": "Build\\78b5727d-4a24-4ec8-9caf-704685572174",
        "url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/375baa5b-5148-4e89-a549-ec202b722d89",
        "imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=375baa5b-5148-4e89-a549-ec202b722d89"
      },
      "priority": 20,
      "computerName": "TASKAGENT5-0055",
      "build": {
        "id": "5",
        "name": "20160713.2",
        "url": "https://dev.azure.com/fabrikam/_apis/build/Builds/5"
      },
      "createdDate": "2016-07-13T11:12:49.123Z",
      "url": "https://dev.azure.com/fabrikam/Fabrikam-Fiber-TFVC/_apis/test/Runs/16/Results/100002",
      "failureType": "None",
      "automatedTestStorage": "unittestproject1.dll",
      "automatedTestType": "UnitTest",
      "automatedTestTypeId": "13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b",
      "automatedTestId": "ef9123e0-a097-7e9b-9a02-f526c7a640c0",
      "area": {
        "id": "37528",
        "name": "Fabrikam-Fiber-TFVC",
        "url": "vstfs:///Classification/Node/ebe8ac79-8d9f-4a5b-8d0a-c3095c81e70e"
      },
      "testCaseTitle": "Ignore1",
      "customFields": [],
      "automatedTestName": "UnitTestProject1.UnitTest1.Ignore1"
    }
  ]
}

您可以编写一个自定义实用程序,在其中可以编写一个函数来获取测试结果并使用电子邮件将其发布,然后再从Azure devops管道任务中调用它。

Here,您可以找到自定义任务的示例文档。

希望有帮助。