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

Create a new Test Run using get_case with type_id filter


#1

Objective: Creating TestRun by collecting multiple tests matching a filter ( using get_cases with type_id as a filter).
I am trying to filter and select test cases with a certain type_id = ‘Smoke_Automation’ and this is how it looks. I am getting the following error.

java.lang.ClassCastException: org.json.simple.JSONArray cannot be cast to org.json.JSONArray

Can someone please help if you have already created a TestRun using get_cases and type_id.

APIClient client = new APIClient(TESTRAIL_URL);
client.setUser(TESTRAIL_USERNAME);
client.setPassword(TESTRAIL_PASSWORD);

Map<String, Comparable> dataRun = new HashMap<>();
dataRun.put(“name”, “MyTestRun”);
dataRun.put(“include_all”, new Boolean(false));
JSONArray testCases = (JSONArray) client.sendGet(“get_cases/”+Constant.TESTRAIL_PROJECT_ID+"&type_id=15");

dataRun.put(“case_ids”, testCases);
dataRun.put(“milestone_id”, Constant.TESTRAIL_MILESTONE_ID);
JSONObject run = (JSONObject) client.sendPost(“add_run/” + TESTRAIL_PROJECT_ID, dataRun);

I have even tried using JSONArray testCases = (JSONArray) client.sendGet(“get_cases/”+Constant.TESTRAIL_PROJECT_ID+"&type_id=Smoke_Automation");

If I use the following, I am getting
JSONArray testCases = (JSONArray) client.sendGet(“get_cases/”+Constant.TESTRAIL_PROJECT_ID+"&type_id=15");
dataRun.put(“case_ids”, (Comparable)testCases);

java.lang.ClassCastException: org.json.simple.JSONArray cannot be cast to java.lang.Comparable

I have the following options available in my ‘Case Type’ field.

Acceptance
Accessibility
Compatibility
Destructive
Functional
Integration_Automation
Other
Performance
Place Holder
ProdBugs_Automation
Regression
Regression_Automation (Default)
Security
Smoke & Sanity
Smoke_Automation
Usability