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

com.qa.utils.APIException: TestRail API returned HTTP 400("Field :case_id is not a valid ID.") #31

Open
wrathmelior opened this issue Dec 15, 2021 · 3 comments

Comments

@wrathmelior
Copy link

Getting 'TestRail API returned HTTP 400("Field :case_id is not a valid ID.")
It should be getting id="188056" set by the TestRails annotation and i'm not sure if it's just not getting that at all and where it is getting case_id from even because I only use caseId it my test.

Screenshot https://monosnap.com/file/ooAnQRTmQZw8bDA7lMT79pBXuEMqNz
Im using the instructions here https://www.swtestacademy.com/integrate-test-automation-results-with-testrail-testng/

Here is the code:

  public void beforeTest(ITestContext ctx,Method method) throws NoSuchMethodException {
	    Method m = OnboardingTests.class.getMethod(method.getName());
	    if (m.isAnnotationPresent(TestRails.class)) {
	        TestRails ta = m.getAnnotation(TestRails.class);
	        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);
}

@testrails(id="188056")
@test (groups = "1")
public void onBoarding() throws InterruptedException {

test steps ommited
}

}

@jonridera
Copy link
Contributor

Hi @wrathmelior,

When using add_result_for_case, you should be passing the test run ID and case ID as parameters in your request. Based on your code, you are submitting the suite ID instead of the run ID and this appears to be the cause of the error message.

If you continue to have issues submitting API requests, please reach out to the support team at [email protected].

The issues for this repository are primarily used for reporting issues with the TestRail API bindings, or other code inside this repository.

Regards,
Jon

@wrathmelior
Copy link
Author

wrathmelior commented Dec 15, 2021

The 'suite_id' being used here should be the test run id generated earlier in the run in my super class with this code

@BeforeSuite
public void createSuite(ITestContext ctx) throws IOException, APIException {
client = new APIClient("https://company.testrail.com/");
client.setUser("[email protected]");
client.setPassword("password");
long yourmilliseconds = System.currentTimeMillis();
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");    
Date resultdate = new Date(yourmilliseconds);
Map data = new HashMap();
data.put("suite_id", 856);
data.put("include_all", true);
data.put("name" ,"Android BVT Automation Run - " + resultdate);
JSONObject c = null;
System.out.println("data: " + data);
c = (JSONObject)client.sendPost("add_run/"+102,data);
Long suite_id = (Long)c.get("id");
ctx.setAttribute("suiteId",suite_id);
}

https://monosnap.com/file/4ySvninX8fzEmjYEZQK3MU6RvqsZrh
https://i.imgur.com/RGmimaL.png

@jonridera
Copy link
Contributor

Hi @wrathmelior,

Please reach out to our support team at [email protected] so one of our support engineers can further assist you.

Regards,
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