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

TestRail API returned HTTP 400("Field :run_id is not a valid ID.")

Hi ,
I’m new to integrate the Testrail with with selenium using java here is my code and the error i’m getting like this below.

`public class TestrailFirstSample {

public static String TEST_RUN_ID                = "R3";
public static String TESTRAIL_USERNAME          = "ahmed.ali@packagex.app";
public static String TESTRAIL_PASSWORD          = "PackageX@123";
public static String RAILS_ENGINE_URL           = "https://packagex.testrail.io/";
public static final int TEST_CASE_PASSED_STATUS = 1;
public static final int TEST_CASE_FAILED_STATUS = 5;
WebDriver driver;

@Test(description = "tetstes")
public void verifyTitle() throws Exception, APIException {
	
	System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/drivers/chromedriver.exe");
    driver= new ChromeDriver();
    driver.get("https://www.google.co.in");
    String actualTilte = driver.getTitle();
    if (actualTilte.contains("Google")) {
        Assert.assertTrue(actualTilte.contains("Google"));
        TestrailFirstSample.addResultForTestCase("C1", TEST_CASE_PASSED_STATUS, "");
        
    }

else{
TestrailFirstSample.addResultForTestCase(“C1”, TEST_CASE_FAILED_STATUS, “”);
}

    driver.quit();
}


public static void addResultForTestCase(String testCaseId, int status,
        String error) throws IOException, APIException {

    String testRunId = TEST_RUN_ID;

    APIClient client = new APIClient(RAILS_ENGINE_URL);
    client.setUser(TESTRAIL_USERNAME);
    client.setPassword(TESTRAIL_PASSWORD);
    Map data = new HashMap();
    data.put("status_id", status);
    data.put("comment", "Test Executed - Status updated automatically from Selenium test automation.");
    client.sendPost("add_result_for_case/"+testRunId+"/"+testCaseId+"",data );

}

}`

Error
TestRail API returned HTTP 400(“Field :run_id is not a valid ID.”)
at PackageX.app.config.APIClient.sendRequest(APIClient.java:217)
at PackageX.app.config.APIClient.sendPost(APIClient.java:116)
at PackageX.app.config.TestrailFirstSample.addResultForTestCase(TestrailFirstSample.java:52)
at PackageX.app.config.TestrailFirstSample.verifyTitle(TestrailFirstSample.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
atorg.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

Do not include he leading T, C, R is any API call. Those are added for the UI but in the table the ID is just the number.

I didn’t get your point could you please explain

R3 is not a valid Test Run Id - 3 is. The R is added for the UI only, the actual ID on the database table is 3.

So in the call - drop the R for the Run ID and only use “3”.

Okay Got it Thank you so much let me Run this again

Now error is appearing like
TestRail API returned HTTP 400("Field :case_id is not a valid ID.

C1 is not a valid test case - just use the 1 and not the C1 for the Case Id. The alpha characters in the UI are just for the UI and not used in the DB.

1 Like

Thank you so much its worked :slight_smile:

1 Like