Comments (8)
That was it!! My tests are running now and the API was created. Thank you so much for your help!!
from testrail-api.
Hi @wrathmelior,
Looking at your code, it appears the suite_id field is missing from the URI.
The suite_id parameter should be added to this line:
c = (JSONObject)client.sendPost("add_run/"+102,data);
For example, if the suite ID is 462, you should have
c = (JSONObject)client.sendPost("add_run/"+102 + "&suite_id=462",data);
I hope this resolves your API issue. If you have additional questions, please reach out to our support team at [email protected].
Regards,
Jon
P.S. I noticed an issue in our documentation where the parameters and request fields are displayed in the same table, which can lead to confusion. I've requested our documentation team make some updates to clarify this as well.
from testrail-api.
I added the suite ID as you recommended to c but I am getting the same error.
Error:
com.qa.utils.APIException: TestRail API returned HTTP 400("Field :suite_id is a required field.")
Code:
@BeforeSuite
public void createSuite(ITestContext ctx) throws IOException, APIException {
client = new APIClient("https://companyqa.testrail.com/");
client.setUser("[email protected]");
client.setPassword("password");
Map data = new HashMap();
//JSONObject data = new JSONObject();
data.put(""suite_id"", 856);
data.put(""include_all"", true);
data.put(""name"" ,""Test Run " +System.currentTimeMillis()+""");
JSONObject c = null;
System.out.println("data: " + data);
c = (JSONObject)client.sendPost("add_run/"+102+"&suite_id=856",data);
Long suite_id = (Long)c.get("id");
ctx.setAttribute("suiteId",suite_id);
System.out.println("suiteID: "+ suite_id);
}
from testrail-api.
Hi @wrathmelior,
I'm sorry this is causing problems for you and I made a mistake in my first response. For post requests, the suite_id should be included in the body of the request, as you were doing.
The error message you received indicates TestRail is not receiving the suite_id for some reason, likely due to encoding, type casting, or a similar issue. (If the ID were incorrect, you'd get a different error message)
Looking at a sample script here: https://github.com/gurock/testrail-custom/blob/master/user-submitted/api-scripts/java/rerun_testrun.java#L69, the only differences I'm seeing are how suite_id is enclosed in quotes, and the example script typecasts the suite_id to a Long before putting it inside the data object.
After reviewing the sample script, and you continue to have issues, can you send an email to our support team at [email protected] so they can troubleshoot this further with you? Can you also attempt this via cURL or an API client such as Postman and let the support team know if you receive the same error?
Thank you,
Jon
from testrail-api.
When I remove the quotes I get this error instead:
java.lang.ClassCastException: class org.json.simple.JSONObject cannot be cast to class org.json.JSONObject (org.json.simple.JSONObject and org.json.JSONObject are in unnamed module of loader 'app')
This is what prompted us to add the "", because in postman the values must me enclosed in quotes like this
https://companyqa.testrail.com/index.php?/api/v2/add_run/102
{
"suite_id": 856,
"name": "MXC + {{currentDate}}",
"include_all": true
}
As you can see it runs fine in Postman
Screenshot: https://i.imgur.com/6jC172V.png
Screenshot: https://i.imgur.com/HCjEznh.png
Code without quotes:
@BeforeSuite
public void createSuite(ITestContext ctx) throws IOException, APIException {
client = new APIClient("https://companyqa.testrail.com/");
client.setUser("[email protected]");
client.setPassword("password");
Map data = new HashMap();
data.put("suite_id", 856);
data.put("include_all", true);
data.put("name" ,"Test Run " +System.currentTimeMillis());
JSONObject c = null;
System.out.println("data: " + data);
c = (JSONObject)client.sendPost("add_run/"+102+"&suite_id=856",data);
Long suite_id = (Long)c.get("id");
ctx.setAttribute("suiteId",suite_id);
}
from testrail-api.
Hi @wrathmelior,
If this works in Postman, there is likely an encoding or typecasting issue with 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
from testrail-api.
Interestingly! I found that when I remove the quotes, the I get the error from my last comment, however the test run IS created in Testrail. (but none of the tests run, it fails immediately after the test run is created)
Screenshot: https://i.imgur.com/qO010ao.png
from testrail-api.
Hi @wrathmelior,
The latest error message you provided is an error from JAVA, and not the TestRail API, likely due to how your code is processing the response object.
You may have an incorrect import statement. Your code should show:
import org.json.simple.JSONObject
Do you have:
import org.json.JSONObject
Regards,
Jon
from testrail-api.
Related Issues (20)
- "Field :suite_id is a required field." when suite_id is clearly provided HOT 3
- Dotnet get_attachments issue
- No ruby sample code for add_attachment HOT 1
- Feature request - Add sortable indexes on user defined entites (test runs, cases, plans, test inside of a test run) HOT 1
- python bindings has error handing issues and path name issues. HOT 1
- {"error"=>"Field :suite_id is a required field."} HOT 1
- is there a testrail-api nuget package available? HOT 1
- com.qa.utils.APIException: TestRail API returned HTTP 400("Field :case_id is not a valid ID.") HOT 3
- TestRail API returned HTTP 400 Field :suite_id is a required field - JAVA HOT 3
- Add Bindings For Dart HOT 5
- TestRail API returned HTTP 500("Undefined property: stdClass::$sso_enabled") HOT 1
- Consider Publishing to Maven Central
- Unexpected character encountered while parsing value: �. Path '', line 0, position 0. HOT 2
- Screenshots not accessible/downloadable through the API's methods
- PyTest to update test case results to TestRails by providing the RunID
- error when hit GET /get_plan using API v2 HOT 29
- get_results_for_run cannot be filtered to return the last set of results
- Failed to retrieve cases
- rate limit policy
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from testrail-api.