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

Getting 404 error ("Unknown method")


#1

Hello,

I am new to TestRail and am trying to setup a simple connection between Selenium Web with Eclipse and TestRail using Java. When I run my code I am getting the error.

testrail.APIException: TestRail API returned HTTP 404("Unknown method 'test'")
at testrail.APIClient.sendRequest(APIClient.java:216)
at testrail.APIClient.sendGet(APIClient.java:91)
at test.test.main(test.java:48)

I am wondering what could be the issue. Below is the code:

import java.io.IOException;
import java.util.Arrays;
import testrail.APIClient;
import testrail.APIException;
import org.json.simple.JSONObject;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

public class test {

public static void main(String[] args) throws InterruptedException, IOException 
{
  //Points to the browser driver
  System.setProperty("webdriver.chrome.driver", "directory");
  
  //Cleans session and goes into incognito mode
  DesiredCapabilities cleanSession = DesiredCapabilities.chrome();
  cleanSession.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
  cleanSession.setCapability("chrome.switches", Arrays.asList("--incognito"));
  APIClient client = new APIClient("https://servername.testrail.io");
  client.setUser("username");
  client.setPassword("password");
  //Creates the browser driver that runs the automation. The driver is called CDriver
  ChromeDriver CDriver = new ChromeDriver();
  
  try
  {
	  CDriver.get("https://url/signin/");	  
  }catch (Exception e)
  {
	  e.printStackTrace();
	  CDriver.close();   
	  System.exit(0);
  }	 


  CDriver.findElement(By.xpath("//*[@id=\"j_username\"]")).sendKeys("lc@qatest.com");
  CDriver.findElement(By.xpath("//*[@id=\"j_password\"]")).sendKeys("aaaaaa");
  CDriver.findElement(By.xpath("//*[@id=\"id-forgot-pass-inline\"]/a")).click();
  
  try {
	JSONObject c = (JSONObject) client.sendGet("test/180254");
	System.out.println(c.get("test"));
} catch (APIException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}

}
}


#2

there is no API method called test

did you mean GET index.php?/api/v2/get_test/:test_id ?


#3

I am still a bit confused on the process. I was looking at the examples in http://docs.gurock.com/testrail-api2/bindings-java. Do I need to include index.php for GET?


#4

No - if you use the java bindings for example you only need to specify the actual method you need to call and the parameters.

Here is a code example from me, where I add a new case to TestRail

public String addCase(int sectionId, JSONObject data) throws IOException, APIException {
    JSONObject result = (JSONObject) client.sendPost("add_case/" + sectionId, data);
    return result.get("id");
}

the method is add_case and it requires the section where the case shall be added. In addition the post method requires the data which is send as a JSONObject.

As an example of a get method

  public String getSection(int sectionId) throws IOException, APIException {
    JSONObject get = (JSONObject) client.sendGet("get_section/" + sectionId);
    return String.valueOf(get.get("name"));
}

here the method is get_section and this also requires the sectionId as parameter. From the returned data I want the name

I hope this helps a bit - just ask if anything more is unclear