简体   繁体   中英

Is there a way to use Azure DevOps Test Plan parameters for each test case as part of automate testing from pipeline?

One of my automated testing projects is looking to use parameters under Azure DevOps Test Plan as an input for each test case. After I did my research I cannot find anything that relates to it. All I found is how to use test cases with parameters manually but I need to use it for automation testing.

I checked ADO API documents from version 5.0, 5.1, and 6.0. There is no information talking about how to use parameters automatically. The closest one that I can find from ADO Documents is Result with Parameters. But that is after manual testing not before.

My unit testing code currently reading those test inputs from a.xml file. But I need to read those inputs from ADO->TestPlan->Parameters. I hope anyone can point me in a direction if it is possible to achieve this goal.

    public static async void GetTestCase(string pat, int TestPlanID, int TestSuiteID, int TestCaseID)
    {
        using (HttpClient client = new HttpClient())
        {
            client.DefaultRequestHeaders.Accept.Add(
                new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
                Convert.ToBase64String(
                    System.Text.ASCIIEncoding.ASCII.GetBytes(
                        string.Format("{0}:{1}", "", pat))));

            using (HttpResponseMessage response = client.GetAsync("https://dev.azure.com/natescott/E2E-ATF/_apis/test/Plans/"+ TestPlanID +"/suites/"+ TestSuiteID + "/testcases/"+ TestCaseID + "?api-version=6.0-preview.3").Result)
            {
                Console.WriteLine("StatusCode: " + response.StatusCode);
                response.EnsureSuccessStatusCode();
                string responseBody = await response.Content.ReadAsStringAsync();
                Console.WriteLine("JSON: " + responseBody);
            }
        }
    }

I hope I can replace that.xml with Azure DevOps->TestPlan->Parameters.

I looked into defining all my tests in Azure Dev Ops test plans and then using that to automate my test runs. After alot of investigation I discovered that the focus of the Azure Dev Ops Test Plans feature is to support people coming in with legacy tests from previous versions of TFS where this was a common thing.

Run Automated Tests from Azure Test Plans

This link might help you, but for me this would only make sense to use if we were going to bring over existing test plans etc. Basically I recommend using an Azure DevOps pipeline to run your tests and write them as Unit tests. This way the results are captured as part of the build pipeline etc. If you need test plans specifically, hopefully this link will help.

Go to ADO-->Test Plans-->Parameters

Step 1: Create a Shared Parameter set like below Here

Step 2: Go to any of your test case and scroll down and check for Parameter values

Here

Step 3: Click on that Parameter value and click on add parameters and then select the parameter set you have created as shared parameters.

Step 4: After invoking the shared parameter set,now you have to use those parameters in your test case steps . For that go to Steps field.

Step 5: By assigning " @ " to every parameter. See below Picture.

Here

Step 6: Now you can run your test case and see these parameters and use it efficiently.

I've found something here. But it seems working only for the manual run. https://docs.microsoft.com/en-us/rest/api/azure/devops/test/parameter%20results/list?view=azure-devops-rest-5.1

Example: Request:

GET 
https://dev.azure.com/fabrikam/fabrikam-fiber-tfvc/_apis/test/Runs/results/Results/{testCaseResultId}/Iterations/{iterationId}/parameterresults?api-version=5.1
    Response:
    {
      "count": 2,
      "value": [
        {
          "url": "https://dev.azure.com/fabrikam/fabrikam-fiber-tfvc/_apis/test/Runs/4/Results/100000/Iterations/1/ParameterResults?paramName=username",
          "iterationId": 1,
          "actionPath": "00000002",
          "parameterName": "username",
          "value": "abc"
        },
        {
          "url": "https://dev.azure.com/fabrikam/fabrikam-fiber-tfvc/_apis/test/Runs/4/Results/100000/Iterations/1/ParameterResults?paramName=password",
          "iterationId": 1,
          "actionPath": "00000003",
          "parameterName": "password",
          "value": "new"
        }
      ]
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM