Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestRail API returned HTTP 400 Field :suite_id is a required field - JAVA #32

Open
syedghayyour opened this issue Dec 16, 2021 · 3 comments

Comments

@syedghayyour
Copy link

Hi I am having the same problem here, however I am working with Java and I am also passing the Suite ID: Here is my code:

int PROJECT_ID = 1;
Long SUITE_ID = (long) 1286;
APIClient client = null;

@BeforeSuite
public void createSuite(ITestContext ctx) throws IOException, APIException {
client = new APIClient("https://testrail.net");
client.setUser("[email protected] );
client.setPassword("########");
Map data = new HashMap();
data.put("include_all",true);
data.put("name","Test Run "+System.currentTimeMillis());
JSONObject c = null;

c = (JSONObject)client.sendPost("add_run/"+PROJECT_ID,data);
long suite_id = SUITE_ID; 
ctx.setAttribute("suiteID" ,suite_id);

}

@BeforeMethod
public void beforeTest(ITestContext ctx,Method method) throws NoSuchMethodException {
Method m = TestNGProject.class.getMethod(method.getName());

if (m.isAnnotationPresent(TestRail.class)) {
	TestRail ta = m.getAnnotation(TestRail.class);
	System.out.println(ta.id());
	ctx.setAttribute("caseId",ta.id());
}

}

@AfterMethod
public void afterTest(ITestResult result, ITestContext ctx) throws IOException, APIException {
Map data = new HashMap();
if(result.isSuccess()) {
data.put("status_id",1);
}
else {
data.put("status_id", 5);
data.put("comment", result.getThrowable().toString());
}

String caseId = (String)ctx.getAttribute("caseId");
Long suiteId = (Long)ctx.getAttribute("suiteId");
client.sendPost("add_result_for_case/"+suiteId+"/"+caseId,data);

}
Error Message:

RemoteTestNG] detected TestNG version 7.4.0
FAILED CONFIGURATION: @BeforeSuite createSuite(org.testng.TestRunner@1f2586d6)
com.uitesting.testRail.APIException: TestRail API returned HTTP 400("Field :suite_id is a required field.")

@jonridera
Copy link
Contributor

Hi @syedghayyour ,

Looking at your code sample, I do not see where you add the suite_id key/value pair to the data object.
Can you ensure the field is being added to the body of your POST request via debug lines?

If you continue to have issues after verifying the field is in the body of your request, please reach out to our support team at [email protected] and mention this thread so our team can assist you further with this issue.

Regards,
Jon

@syedghayyour
Copy link
Author

HI Jon I have added the key and value pair here: #12

ctx.setAttribute("suiteID" ,suite_id);

@jonridera
Copy link
Contributor

@syedghayyour

In your code, I see the following:

	Map data = new HashMap();
	data.put("include_all",true);
	data.put("name","Test Run "+System.currentTimeMillis());
	JSONObject c = null;
	
	c = (JSONObject)client.sendPost("add_run/"+PROJECT_ID,data);

The error is appears to be returned by line:

c = (JSONObject)client.sendPost("add_run/"+PROJECT_ID,data);

Prior to sending the API request, the data object does not contain the suite_id and value.

Please try updating your code to the following:

	Map data = new HashMap();
	data.put("include_all",true);
	data.put("name","Test Run "+System.currentTimeMillis());
	data.put("suite_id",SUITE_ID);  //Add this or a similar line which aligns with your code and variables
	JSONObject c = null;
	
	c = (JSONObject)client.sendPost("add_run/"+PROJECT_ID,data);

If you continue to have issues after adding the field to the data object, please reach out to our support team at [email protected] and mention this thread so our team can assist you further with this issue.

Thank you,
Jon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants