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

时间:2018-08-02 17:18:23

标签: selenium selenium-webdriver cucumber

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

问题: 现在,我们还需要在电子邮件中发送执行摘要,这样即使没有通过Link进行钻取,也可以看到高级状态。 因此,除了上述链接之外,我们还需要在电子邮件正文中插入表格格式-带有-TC名称,状态,执行时间,总体计数等列。 有人可以帮我这样做吗?

其他信息: 我不太了解内部大师的工作原理,但是它通过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"
  }
]

enter image description here

1 个答案:

答案 0 :(得分:1)

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