0

I have recently taken over Test Suite creation for my team and I have encountered a rather annoying and time-consuming issue.

We are using Azure DevOps Test Suites.

Scenario: Let's say we have 5 Test Suites (folders) and each one needs to have 2 Test Result Charts:

  1. Outcome of Test
  2. Who ran the Test

Currently, I have to go into each Test Suite and add the same exact two Charts every time.

I need to know if there is a way that I can just select X Suites and add the Charts en-masse?

0

1 Answer 1

0

Via the UI, currently it is not possible. But you can use Azure API for this.

import requests
import json

organization = 'your_organization'
project = 'your_project'
plan_id = 'your_test_plan_id'
pat = 'your_pat'
suite_ids = ['suite_id1', 'suite_id2', 'suite_id3', ....]

headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Basic {pat}'
}

def create_chart(suite_id, chart_name, query, settings):
    url = f'https://dev.azure.com/{organization}/{project}/_apis/test/Plans/{plan_id}/suites/{suite_id}/charts?api-version=6.0-preview'
    payload = {
        "name": chart_name,
        "query": query,
        "settings": settings
    }
    response = requests.post(url, headers=headers, data=json.dumps(payload))
    if response.status_code == 200:
        print(f'Successfully created chart {chart_name} for suite {suite_id}')
    else:
        print(f'Failed to create chart {chart_name} for suite {suite_id}: {response.content}')

for suite_id in suite_ids:
    create_chart(suite_id, "Outcome of Test", "Outcome query", {/* your settings */})
    create_chart(suite_id, "Who ran the Test", "Runner query", {/* your settings */})

PATH is the token to the API. Replace also organization and project with your particular data.

The settings can be like this:

settings = {
"chartType": "Bar",
"xAxis": "Outcome",
"yAxis": "Count",
"series": [
    {
        "name": "Passed",
        "color": "Green"
    },
    {
        "name": "Failed",
        "color": "Red"
    }
],
"filters": {
    "testSuite": suite_id,
    "dateRange": {
        "start": "2023-01-01",
        "end": "2023-12-31"
    }
  }
}

Documentation: https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.tools.excel.chart?view=vsto-2022

1
  • I'm not sure this is what I need - but for clarity, I'm looking to create Test Result Charts within the Test Suites. I can't seem to find any documentation surrounding the 'settings' part of 'create_chart' - and the code cannot run with nothing defined. Are you able to provide some assistance as to where I might find this information?
    – BCE
    Commented May 29 at 10:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.