如何在电子邮件(Outlook)正文中为测试执行摘要生成 HTML table

How to generate HTML table for test execution summary in Email (Outlook) body

背景: 在我们的项目 [selenium-cucumber-java-Mvn based] 中,我们通过 master thoughts Cucumber 报告(mvn 依赖)完成了测试执行报告。该报告在 test>target 目录中生成,我们正在共享此文件夹 Link 并将其嵌入电子邮件中自动发送给所有人以进行报告。此处收件人必须打开此 link 才能查看状态。 Link 看起来像- http://localhost:63342/Automation/TestExecutionReports/02-08-2018/Run-1/cucumber-html-reports/overview-features.html

问题: 现在我们还需要在电子邮件中发送执行摘要,这样就可以看到高级状态,甚至无需钻取 Link。 因此,除了上述 Link 之外,我们还需要在电子邮件正文本身中插入一个表格格式 - 包含列 -TC 名称、状态、执行时间、总计数等。 有人可以帮我做这个吗?

其他信息: 我不太了解内部 master 是如何工作的,但它通过 JSON 文件收集执行数据。我们在 TestNGExecutionListener 的 onExecutionfinish 方法中生成此报告。 我们当前的报告看起来像是一张随附的快照。 我们的 json 包含以下信息-

[
  {
    "line": 1,
    "elements": [
      {
        "before": [
          {
            "result": {
              "duration": 3849355155,
              "status": "passed"
            },
            "match": {
              "location": "CucumberHooks.InitBrowser()"
            }
          }
        ],
        "line": 3,
        "name": "Add Account and verify details",
        "description": "",
        "id": "add-account-and-verify-details;add-account-and-verify-details",
        "after": [
          {
            "result": {
              "duration": 129904,
              "status": "passed"
            },
            "match": {
              "location": "CucumberHooks.TearDownTest(Scenario)"
            }
          }
        ],
        "type": "scenario",
        "keyword": "Scenario",
        "steps": [
          {
            "result": {
              "duration": 13810592966,
              "status": "passed"
            },
            "line": 5,
            "name": "I have Logged in to Grid application",
            "match": {
              "location": "leaseSearchSteps.i_have_Logged_in_to_Grid_application()"
            },
            "keyword": "Given "
          },
          {
            "result": {
              "duration": 4659413417,
              "status": "passed"
            },
            "line": 6,
            "name": "I select Accounts and Contacts option from the Homepage",
            "match": {
              "location": "createAccountSteps.selectAccountsAndContactsOptionFromTheHomepage()"
            },
            "keyword": "And "
          },
          {
            "result": {
              "duration": 3470670155,
              "status": "passed"
            },
            "line": 7,
            "name": "Click on Add Account button",
            "match": {
              "location": "createAccountSteps.clickOnAddAccountButton()"
            },
            "keyword": "Then "
          },
          {
            "result": {
              "duration": 28732919407,
              "status": "passed"
            },
            "line": 8,
            "name": "Create Account with Account name as \"Pacific UAT Test Account\"",
            "match": {
              "arguments": [
                {
                  "val": "Pacific UAT Test Account",
                  "offset": 37
                }
              ],
              "location": "createAccountSteps.createAccountWithAccountName(String)"
            },
            "keyword": "Then "
          },
          {
            "result": {
              "duration": 2243415294,
              "status": "passed"
            },
            "line": 9,
            "name": "Click on View button",
            "match": {
              "location": "createAccountSteps.clickOnViewButton()"
            },
            "keyword": "Then "
          },
          {
            "result": {
              "duration": 121318771,
              "status": "passed"
            },
            "line": 10,
            "name": "Verify the newly created Account name",
            "match": {
              "location": "createAccountSteps.verifyTheNewlyCreatedAccountName()"
            },
            "keyword": "Then "
          }
        ],
        "tags": [
          {
            "line": 2,
            "name": "@Test"
          }
        ]
      }
    ],
    "name": "Add Account and verify details",
    "description": "",
    "id": "add-account-and-verify-details",
    "keyword": "Feature",
    "uri": "src/test/resources/cucumber/featureFiles/AU/addAccountAndVerify.feature"
  }
]

我没有代码,但我认为可能的方法如下所示 - 首先编写一些代码来生成 Table 模板及其页眉、主要 Table、行和列以及页脚。 然后通过从您拥有的 features.html 页面读取数据(如 url 中所述)将数据插入此 table 中。您应该能够通过 Selenium 的标准方法 [like-getText()] 从此 html 网页读取通过、失败或任何需要的数据。 最后,将整个 table 附加到 StringBuilder 并使用 thmlSourceEmbed 的设置内容作为 bu 发送电子邮件消息为 text/html..希望这个帮助