Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

Adding new test plan to testrail for specflow test c#

Hello there,
I am trying to add a test plan with add_plan api for a specflow test, please check my code below,

[AfterScenario]
public static void AfterScenario()
{
APIClient client = new APIClient(“http:///testrail/”); This is hidden
client.User = “…”; This is hidden
client.Password = “…”; This is hidden

        Dictionary<string, object> testResult = new Dictionary<string, object>();
        if (null != ScenarioContext.Current.TestError)
        {

            testResult["status_id"] = "5"; //failed;
            testResult["comment"] = ScenarioContext.Current.TestError.ToString();
        }
        else
        {
            testResult["status_id"] = "1"; //passed
        }
         client.SendPost("add_plan/10/Google_Search", testResult);
    }

However, its giving me an error saying,
Message: TearDown : Gurock.TestRail.APIException : TestRail API returned HTTP 400 (“Field :name is a required field.”)

Please help!
Prachi

Hi Prachi,

Your code seems to be doing two things incorrectly.

The first is including “Google_Search” which I’m assuming is the title within the API post. This should only contain “add_plan/10” the test plan name would be another field within the body.

http://docs.gurock.com/testrail-api2/reference-plans#add_plan

I also see that you are trying to add test results as well, which is not suppose to be added using the add_plan. Test results are added using a different API calls.

http://docs.gurock.com/testrail-api2/reference-results

Also keep in mind that simply creating a test plan along wouldn’t create any test run or tests to which test results can be added. I would recommend both reviewing our API documentation and trying out TestRail Web GUI as the two function identically.