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

TestRail API returned HTTP 404(“Unsupported HTTP method “post” for this action.”)

Hi,

I am very new to Test Rail and Integrating Selenium with Test Rail. Followed the code and trying to run the test case through selenium and add result to Test Rail but getting Case id is not a valid test case

And, I don’t see Case ID in My Test Plan … Could you please help me asap?

Followed your test code:
Imported API Client.java and API exception.Java files

public class Google {

public static String  TEST_RUN_ID = "759";

public static String TESTRAIL_USERNAME = "agupta";
public static String TESTRAIL_PASSWORD = "password0";
public static String RAILS_ENGINE_URL = "https://abc.testrail.io/";
public static final int TEST_CASE_PASSED_STATUS = 1;
public static final int TEST_CASE_FAILED_STATUS = 5;
public static int status_id;

WebDriver driver;

/**
 * 
 */
@BeforeMethod
public void setUp() {
    System.setProperty("webdriver.gecko.driver", "C:\\Users\\agupta\\geckodriver.exe");
    driver = new FirefoxDriver();
    driver.manage().window().maximize();

}

/**
 * 
 */
@Test(description = "Title of Google page as expected. TC_ID=T7824")
public void verifyTtitle() {        
    driver.get("http://www.google.co.uk");
    String title = driver.getTitle(); 
    
    Assert.assertTrue(title.contains("Google"), "Title is correct");
}

/**
 * @param testResult
 * @throws APIException
 * @throws IOException
 */
@AfterMethod
public void testResults(ITestResult testResult) throws APIException, IOException {

  
    if (testResult.getStatus() == ITestResult.SUCCESS) {           
        Google.addResultForTestCase("7824", TEST_CASE_PASSED_STATUS, "");  
        System.out.println(testResult.getName() + " :Passed");

    }
    if (testResult.getStatus() == ITestResult.FAILURE) {
        
        Google.addResultForTestCase("7824", TEST_CASE_FAILED_STATUS, "");  
        System.out.println(testResult.getName() + " : failed --take screenshot and saved");

    } 
    if (testResult.getStatus() == ITestResult.SKIP) {
        System.out.println(testResult.getStatus() + ": Skipped");
    }        

}

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<String, Object> data = new HashMap<String, Object> ();
  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);
      
        }

Adding to this, I changed Case Id and Test Run Id but still getting error like

TestRail API returned HTTP 404(“Unsupported HTTP method “post” for this action.”)

Hello @Ankitaa,

Thanks for posting. While we do not assist with coding/programmed API scripts, one thing I recommend doing is executing the API request via Curl. This confirms if your API function is working as intended.

Thanks Eric for the response.

I will try Api using Postman and will let you know if this is working or not