Home > Enterprise >  Getting the testrun ID after creating a test run in Testrail
Getting the testrun ID after creating a test run in Testrail

Time:12-13

I am trying to implement testrail integration using Testrail's API endpoint with Selenium C#. I have successfully created a test run. Now I want to get the test run ID that was just created. How can this be done?

Here is my code for creating the test run:

        [OneTimeSetUp]
        public async Task OneTimeSetUp()
        {
            RestRequest newRequest = new RestRequest($"index.php?/api/v2/add_run/{project_id}", Method.Post);
            string authInfo = Base64StringConverter.GetBase64String("email:password");
            newRequest.AddHeader("Authorization", "Basic "   authInfo);
            newRequest.AddHeader("Content-Type", "application/json");

            //reading json content
            string jsonFromFile;
            using (var reader = new StreamReader(_createrunpath))
            {
                jsonFromFile = reader.ReadToEnd();
            }

            var customerFromJson = JsonConvert.DeserializeObject<CreateRun>(jsonFromFile);
            newRequest.RequestFormat = DataFormat.Json;
            newRequest.AddJsonBody(customerFromJson);

            //act
            var newResponse = await restClient.ExecuteAsync(newRequest);
            HttpStatusCode statusCode = newResponse.StatusCode;

            //assert
            Console.WriteLine((int)statusCode);
            Assert.That((int)statusCode, Is.EqualTo(200));
        }

JSON File

{
  "assignedto_id": 1,
  "suite_id": 1111,
  "name": "This is a new test run test",
  "refs": "API Auto Tests",
  "description": "This is a description of the test"
}

CodePudding user response:

Documentation says that add_run method returns the same response as get_run, so you should be able to get the ID of the newly created run by fetching it from the id field of the resulting JSON

  • Related