jsonfirebasegoogle-cloud-platformcloudfirebase-test-lab

How do I get test cases results from Firebase Test Lab?


I have setup a Google Cloud function that reports Firebase Test Lab results to Slack with the help of some documentation

However, it currently only displays "PASSED" or "FAILED" which isn't that helpful. I want to display the total amount of tests passed e.g. 9/20 test cases passed.

I can't find any documentation detailing how to do this. Is it not possible?

This is my current function:

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));
  });

Below is a screenshot of the data I want but can't find out how to get: Results


Solution

  • There's no direct way through the Functions SDK to get this data. You will need to make a HTTPs call to the respective API endpoint to retrieve this.

    I don't have the JavaScript code at hand, but e.g. here's the curl/gcloud command to call this endpoint that has this data:

    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
    

    The historyid and executionid for this test are stored in TestMatrix.resultStorage. Don't overlook that you have to provide the projectid in 2 places.

    The result will be a JSON containing a list of Environments. The data you want is in the Environment.environmentResult.testSuiteOverviews field.