【问题标题】:How do I get test cases results from Firebase Test Lab?如何从 Firebase 测试实验室获取测试用例结果?
【发布时间】:2021-12-17 00:06:45
【问题描述】:

我已经设置了一个 Google Cloud 函数,它在一些 documentation 的帮助下向 Slack 报告 Firebase 测试实验室结果

但是,它目前只显示“PASSED”或“FAILED”,这没什么帮助。我想显示通过的测试总数,例如9/20 test cases passed.

我找不到任何详细说明如何执行此操作的文档。不可能吗?

这是我目前的功能:

exports.postTestResultsToSlack = functions.testLab
  .testMatrix()
  .onComplete(async testMatrix => {

    if (testMatrix.clientInfo.details['testType'] != 'regression') {
      // Not regression tests
      return null;
    }

    const { testMatrixId, state, outcomeSummary, resultStorage } = testMatrix;

    const colour = getSlackColour(outcomeSummary)

    const title = `*Test Session: ${testMatrixId}*`;

    const details = `7/10 passed (58%)`;  // Replace hardcoded data here

    const resultURL = resultStorage.resultsUrl

    const slackResponse = await postToSlack(colour, title, details, resultURL);

    functions.logger.log(JSON.stringify(slackResponse.data));
  });

下面是我想要但不知道如何获取的数据的截图:

【问题讨论】:

  • 嘿,所以您提供的屏幕截图是您想要从测试实验室检索的内容作为 Cloud Functions 的输出,这是您想要做的吗?
  • @ZeenathSN 是的,CI 系统运行自动化测试,完成后触发云功能,所以我想将数据从云功能发送到 Slack。

标签: json firebase google-cloud-platform cloud firebase-test-lab


【解决方案1】:

无法通过 Functions SDK 直接获取此数据。您需要对相应的 API 端点进行 HTTPs 调用来检索它。

我手头没有 JavaScript 代码,但是例如这是curl/gcloud 命令来调用具有此数据的端点:

curl \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
  -H "X-Goog-User-Project: <projectid>" \
https://toolresults.googleapis.com/toolresults/v1beta3/projects/<projectid>/histories/<historyid>/executions/<executionid>/environments

此测试的historyidexecutionid 存储在TestMatrix.resultStorage 中。不要忽视您必须在两个地方提供projectid

结果将是一个包含Environments 列表的 JSON。您想要的数据在Environment.environmentResult.testSuiteOverviews 字段中。

【讨论】:

    猜你喜欢
    • 2017-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多