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

How to get status_id from the get_results_


I am using “get_results_for_case/runId/caseId”
to get the result of the testcase,

I am using Java binding and the result is the below object,
how can I use it same as a Jsonobject and get only the "status_id " value?
any help would be appreciated, thanks in advance


Hi @qatester,
you have to get the label (or further info) for the Status via get_statuses.

		"color_bright": 12709313,
		"color_dark": 6667107,
		"color_medium": 9820525,
		"id": 1,
		"is_final": true,
		"is_system": true,
		"is_untested": false,
		"label": "Passed",
		"name": "passed"

Hi @kwirth

Thanks for your answer, but maybe my question is not clear.
I want to parse from the response only the status_id like any jsonobject

some thing like this:

JSONObject jsonObject =client.sendGet(“get_results_for_case/8677/1386325”);
String testStatus = jsonObject.getString(“status_id”);

Hi @qatester,
sorry I got you wrong…
Which error do you retrieve?

int testStatus = jsonObject.getInt(“status_id”);

Might be better, because the id is an integer, not a string.


I am using exactly the below code

JSONObject jsonObject =(JSONObject) client.sendGet(“get_results_for_case/8677/1386325”);
String testStatus = jsonObject.get(“status_id”).toString();

and I get this error

java.lang.ClassCastException: org.json.simple.JSONArray cannot be cast to com.github.openjson.JSONObject
at com.ale.rainbow.mobile_qa.tests.AppiumBaseTestListener.getResultForTestCase(
at com.ale.rainbow.mobile_qa.tests.AppiumBaseTestListener.onTestSuccess(
at org.testng.internal.TestListenerHelper.runTestListeners(
at org.testng.internal.Invoker.runTestListeners(
at org.testng.internal.Invoker.invokeMethod(
at org.testng.internal.Invoker.invokeTestMethod(
at org.testng.internal.Invoker.invokeTestMethods(
at org.testng.internal.TestMethodWorker.invokeTestMethods(
at org.testng.TestRunner.privateRun(
at org.testng.SuiteRunner.runTest(
at org.testng.SuiteRunner.runSequentially(
at org.testng.SuiteRunner.privateRun(
at org.testng.SuiteRunnerWorker.runSuite(
at org.testng.TestNG.runSuitesSequentially(
at org.testng.TestNG.runSuitesLocally(
at org.testng.TestNG.runSuites(
at org.testng.remote.RemoteTestNG.initAndRun(
at org.testng.remote.RemoteTestNG.main(

sorry I missed again the exact call. What you receive is a JSONArray, not a single object where you can get the status_id from. A test can have multiple results in a run, therefore sendGet can return a JSONObject or an JSONArray.

JSONArray jsonArray = (JSONArray ) client.sendGet(“get_results_for_case/8677/1386325”);
JSONObject jsonObject = jsonArray.get(0); // just an example!!!
int testStatus = jsonObject.getInt(“status_id”);

Hi @kwirth

I have tried your solution but not working again :

JSONArray jsonArray = (JSONArray ) client.sendGet(“get_results_for_case/8677/1386325”);
JSONObject jsonObject = (JSONObject) jsonArray.get(0); // just an example!!!
int testStatus = jsonObject.getInt(“status_id”);

the issue is that the SendGet function returns an object and I am not an expert in java , I am not sure how to deal with this object , please help am stuck here???

Again I am having same error:

java.lang.ClassCastException: org.json.simple.JSONArray cannot be cast to com.github.openjson.JSONArray
at com.ale.rainbow.mobile_qa.tests.AppiumBaseTestListener.getResultForTestCase(
at com.ale.rainbow.mobile_qa.tests.AppiumBaseTestListener.onTestSuccess(

Well, that looks easy now. You simply don’t use the same JSON implementation like Gurock has used for their APIClient. They are using JSON-simple from Google I think.

If you’re using Maven, try this instead of the openjson via github:


I haven’t tested it online, but I hope it’s correct.

Hi ,

Thanks @kwirth for you help

Gurock are using this JSON implementation : “org.json.simple”

I did implement a solution as below and now it works , the function will only retrieve the statusId, that am using for some if(statements) while updating test results

public int getResultForTestCase(String testRunId, String testCaseId) {

JSONArray resultsArray = new JSONArray();

try {

resultsArray = (JSONArray) client.sendGet(“get_results_for_case/” + testRunId + “/” + testCaseId);

} catch (IOException | APIException e) {


if (resultsArray.size() != 0) {

JSONObject resultObject = (JSONObject) resultsArray.get(0);

return Integer. parseInt (resultObject.get(“status_id”).toString());

} else{

return 0;



Thanks again for your help, If you have any comment on my implementation , I could use a good advice

damn, my maven reference was correct I think, but my code was using a different implementation. Sorry for the confusion, I usually use my own implementation with fasterxml and not the Gurock implementation…

Regarding your code I have a funtional question. I guess you want to get the status for a test in a run. In detail I think you want to get the latest status as int, like shown in the UI on a run, correct?

Why do I ask? I’m not sure about the order in wich the results will be listed, you can’t be sure there is only one. Probably you will return a different, maybe the oldest result for a test in the run and not the latest. You can simply sort by “created_on”, which is a unix timestamp as integer. The highest value is the newest.

HI @kwirth,

Actually I did not check what if the “status_id” is the latest one , because there is only one status entry in my test for now,
But sure its better to filter it as you suggested with “created_on”.