Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this article, we'll see an everyday use case: sharing test results with the team in their collaboration tool (i.e., "MS Teams"). However, Xray and Jira's built-in automation capabilities can implement many more use cases.


Image RemovedImage Added

Prerequisites

To integrate with Teams, we can set up an incoming webhook in a channel and use it to send notifications (i.e., "messages").

...

  1. .In Jira's project settings, under Automation, create the Jira automation rule
    1. define the trigger; we can have a manual trigger that will provide an action from the issue screen or a trigger based on creating a specific issue type. In this case, it would probably make the most sense to have a trigger based on the transition to some status (e.g., "Done"). We can also restrict this to the issue types "Test Execution" and "Sub-Test Execution" using an IF condition.
    2. create an action using the "Send web request" template to make the authentication request and obtain a token to be used on the GraphQL queries; we need a client_id and a client_secret (please see how to create API keys).
    3. save the response on a variable (e.g., "token")Image Removed
    4. make a GraphQL query to obtain the details of the Test Execution and its results
      1. Use the GraphQL API, namely the getTestExecution function. We'll need the issue id of the Test Execution that was triggered; we can use the smart values feature from Jira automation to obtain it. We need to also obtain the custom field id of the "Revision" custom field under the "Issue Fields" section of your Jira administration. 


        1. Code Block
          titlesample GraphQL query
          collapsetrue
          {
              getTestExecution(issueId: "{{issue.id}}") {
          				
                  issueId
                  jira(fields: ["key","customfield_10033"])
              
          				
                    testRuns(limit: 100){
                      results{
                        status{
                          name
                        }
            
                        test {
                            jira(fields: ["key"])
                              }
          							
                        }
                  }
          		
          				testEnvironments
          				testPlans(limit: 1) {
          					results{
          							jira(fields: ["key"])
          					}
          			
          				}
          
              }
          }

           

      2. Escape the GraphQL query (e.g., using the online GraphQL to JSON Body Converter tool)Image Removed
  2. get the total tests and store it in a variable(note that this is an approximate value as GraphQL results can be limited and paginated)
    1. Code Block
      {{webResponse.body.data.getTestExecution.testRuns.results.size|0}} 
  3. get the total tests passing and store it in a variable (note that this is an approximate value as GraphQL results can be limited and paginated)
    1. Code Block
      {{webResponse.body.data.getTestExecution.testRuns.results.status.name.match(".*(PASSED).*").size|0}} 
  4. get the total failed tests and store it in a variable (note that this is an approximate value as GraphQL results can be limited and paginated)
    1. Code Block
      {{webResponse.body.data.getTestExecution.testRuns.results.status.name.match(".*(FAILED).*").size|0}} 
  5. get the total tests in TO DO and store it in a variable (note that this is an approximate value as GraphQL results can be limited and paginated)
    1. Code Block
      {{webResponse.body.data.getTestExecution.testRuns.results.status.name.match(".*(TO DO).*").size|0}} 
  6. get the total tests in other statuses and store it in a variable (note that this is an approximate value as GraphQL results can be limited and paginated)

    1. Code Block
      {{#=}}{{totalTests}} - {{passedTests}} - {{failedTests}} - {{todoTests}}{{/}}
  7. get the linked Test Plan and store it in a variable
    1. Code Block
      {{webResponse.body.data.getTestExecution.testPlans.results.jira.key}}
  8. Use a "IF" block to store the URL of the linked Test Plan, if any
  9. get the associated Test Environments and store it in a variable
    1. Code Block
      {{webResponse.body.data.getTestExecution.testEnvironments.join(",")}}
  10. get the list of distinct statuses reported and store it in a temporary variable
    1. Code Block
      {{webResponse.body.data.getTestExecution.testEnvironments.join(",")}}
  11. make a IF THEN ELSE block to adjust the text message and image of the notification, to tailor our notification for successful and unsuccessful testing cases
    1. As a mere example, for the "failure" image we can use the following one.

    2. Code Block
      https://docs.getxray.app/s/e1tqew/8402/f0863dd17de361916f7914addff17e0432a0be98/_/images/icons/emoticons/error.png
    3. As a mere example, for the "success" image we can use the following one.

    4. Code Block
      https://docs.getxray.app/s/e1tqew/8402/f0863dd17de361916f7914addff17e0432a0be98/_/images/icons/emoticons/check.png
  12. send the notification by using a "Send web request" to invoke the webhook on Teams
    1. Code Block
      collapsetrue
      {
          "@type": "MessageCard",
          "@context": "http://schema.org/extensions",
          "themeColor": "0076D7",
          "summary": "{{issue.summary}}",
          "sections": [{
              "activitySubtitle": "{{issue.summary}}",
              "activityTitle": "Test results for project {{project.name}}",
              "activityImage": "{{notificationImageUrl}}",
              "facts": [
             {
                  "name": "Test Execution",
                  "value": "[{{issue.key}}]({{issue.url}})"
              }, {
                  "name": "Reporter",
                  "value": "{{issue.reporter.displayName}}"
              }, {
                  "name": "Version",
                  "value": "{{issue.fixVersions.name}}"
              }, {
                  "name": "Revision",
                  "value": "{{issue.Revision}}"
              }, {
                  "name": "Test Environment(s)",
                  "value": "{{testEnvironments}}"
              }, {
                  "name": "Test Plan",
                  "value": "{{testPlanUrl}}"
              }, {
                  "name": "Total tests",
                  "value": "{{totalTests}}"
              }, {
                  "name": "Passed tests",
                  "value": "{{passedTests}}"
              }, {
                  "name": "Failed tests",
                  "value": "{{failedTests}}"
              }, {
                  "name": "To Do tests",
                  "value": "{{todoTests}}"
              }, {
                  "name": "Other tests",
                  "value": "{{otherTests}}"
              }],
              "markdown": true
          }]
      }

Example of the output

Image RemovedImage Added

Further ideas to try out

...