gurock / testrail-api Goto Github PK
View Code? Open in Web Editor NEWTestRail API: Examples on how to use TestRail's API from various languages
License: Other
TestRail API: Examples on how to use TestRail's API from various languages
License: Other
Hello, I'm trying to write some Ruby bindings that can create a test run after through the Testrail API.
I keep running into this error:
{"error"=>"Field :suite_id is a required field."}
I have been providing the suite_id, but I'm wondering it it's in the wrong format. My method looks like:
def add_new_run(path, options = {})
body = {"suite_id": 632,
"name": "Automation run: TEST"}
options = request_options.merge(options, body)
url = "#{base_uri}#{path}"
self.class.post(url, options)
end
The resulting total options before making that POST call looks like (email and password obviously removed):
{:headers=>{"Accept"=>"application/json", "Content-Type"=>"application/json"},
:basic_auth=>{:username=>"email", :password=>"password"},
:suite_id=>632,
:name=>"Automation run: #test"}
Does that look correct? Should it be wrapped in a :body =>? I've tried that as well, to no avail.
Let me know any ideas. Thanks!
There is sample code in Java and Python but not in Ruby now for add attachment api. Could you add some?
Hey @JonathanLalou just wanted to let you know that we created an API wrapper in Flutter and was curious we could add it to the site?
I'm trying to get the last set of results for a test run.
This test run is automatically executed by our CI.
The test run had about 700 test cases, but it can be executed several times in a day several times a week.
Thus, when I retrieve the results using get_results_for_run, i'm getting about 25,000 results. building and returning the result set of this size takes too long.
I cannot filter by date, since it is unknown to me when the last run was executed.
I need a way to thel the server to give me just the last set of results.
In the section
object, there is a display_order
field that I expect to be able to modify with update_section. It would be very useful to have a similar functionality with all user defined entities.
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
}
}
I am just wondering if there is a nuget testrail-api package available?
I'm using the APIs to retrieve the data from testrail, and it gives this error:
Failed to retrieve cases: {"error":"API Rate Limit Exceeded - 500 per minute maximum allowed. Retry after 1 seconds."}
and then after a while, it gives wrong data
hi, referring to this link https://support.testrail.com/hc/en-us/articles/7077083596436-Introduction-to-the-TestRail-API#:~:text=Rate%20limits%20for%20TestRail%20Cloud,for%20TestRail%20Cloud%20Enterprise%20subscriptions. the limit for profesional subs is 180 hit per-minute, but since this week I got 429 error with message 19 hit per-minute maximum allowed.
Is the rate limit policy changing or?
kindly need help, i'm implementing java code with testrail API, got this when login
testrail.APIException: TestRail API returned HTTP 500("Undefined property: stdClass::$sso_enabled")
500 status code error was occurred when I tried to hit /get_plan endpoint.
Body response: Undefined property: stdClass::$dataset_id
{
"error": "Undefined property: stdClass::$dataset_id"
}
Hey,
Just wanted guidance (or to report a bug) when trying to hook up the API to my testrail plan. Here is my custom code:
class TestrailConnect
include HTTParty
format :json
base_uri 'http://testrail.wowzaquality.com/index.php?/api/v2'
debug_output
def initialize(username, password)
@options = {
basic_auth: {
username: username,
password: password
},
headers: {
"Content-Type" => "application/json"
}
}
end
def add_cases_to_plan(plan_id)
options = @options.merge({
"suite_id": 422,
"include_all": false,
"runs": [
"include_all": false,
"case_ids": ["59361", "61217","61215"]
]
})
self.class.post("/add_plan_entry/#{plan_id}", options)
end
end
testrail = TestrailConnect.new('[email protected]', '#{API_KEY}')
p testrail.add_cases_to_plan(1541)
And the full errors I get:
<HTTParty::Response:0x7ff7231f06b8 parsed_response={"error"=>"Field :suite_id is a required field."}, @response=#<Net::HTTPBadRequest 400 Bad Request readbody=true>, @headers={"date"=>["Thu, 26 Apr 2018 16:54:49 GMT"], "server"=>["Apache/2.2.15 (CentOS)"], "x-powered-by"=>["PHP/5.4.45"], "content-length"=>["48"], "connection"=>["close"], "content-type"=>["application/json; charset=utf-8"]}>
Hello!
I looked but was unable to find this library in the Maven Central dependency repository.
I think having it published would allow developers much easier access to using and upgrading the library.
An added bonus: Maven Central is used by more than just Maven. It's also used by developers who use:
Thanks for your consideration!
The python binding code has a couple of error handling issues:
fails to process error when it does return JSON. In all cases it returns a string which is often of a python dict from json and not just the error msg
try blocks are catching exceptions they should not. For example KeyboardInterrupt which can be an issue if user tried to stop code at the unlucky time.
Additionally it would be great if this repo could be used in existing python based git repo as a submodule but the path names make it impossible to import as a git submodule.
I can provide a pull request if it will be desired. Just not sure from some of the response times for other pull requests.
I have explored and tried all the possible ways to update the test case results using PyTest to TestRails by providing the RunID and giving the Case ID as below. But it's not working for me.
@testrail('5348')
@pytestrail.case('5348')
Earlier i used Test Rails API to update the Results to Test Rails using Python. But right now am trying to update the test case result to TestRails using PyTest with decorators as above which is not working for me. Is there any proper documentation for it?
Note: I don't want to create any TestRuns using the Pytest. Just want to update only test case results for already existing RunID
Because of missing slash in StartsWith, get_attachments requests working just like get_attachment - creating file and putting json responce in it, instead of just returning Json responce.
if ((response != null) && ((int)response.StatusCode == 200) && (uri.StartsWith("get_attachment")))
Should be
if ((response != null) && ((int)response.StatusCode == 200) && (uri.StartsWith("get_attachment/")))
Hi,
with the following code :
I have the following error :
the attachment id is correct, and the authentication is correct too. If I call the same API direcly with the same attachment ID it works :
could you help me please?
and could you also tell me how to download the picture? (am I to serialize or deserialize something?)
Thanks
Hi,
I would like to download the screenshots present in the steps of the test cases (With C#) for a migration.
I can access to the screenshots in the browser with this kind of link "https://url.testrail.com/index.php?/attachments/get/attachmentNumber", but when I call the API method called "index.php?/api/v2/get_attachments_for_case/caseNumber" I can't see the screenshots in the attachments list returned by the method, so I can't download the screenshots with the method "index.php?/api/v2/get_attachment/attachmentID".
Is there a way to download the screenshots please? Or is it a bug?
Thank you
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.")
Pre requisite: Existing Test run with some test cases selected from Test Suites section
Steps:
Actual Result:
Expected result:
"All rights reserved" is generally regarded as a very, very bad idea, as it means that in principle users aren't even allowed to use the library without your express permission. Please consider using a standard open source license instead.
I am getting this error, but the suite id is provided in data. I was getting a different error before adding quotes (\") around the labels suite id, include all, and name and it was recommended to me by a coworker to add quotes. I printed the value of data in the console and this is what I get:
data: {"include_all"=true, "name"="Test Run 1638908713474", "suite_id"=856}
Here is the code (username, pw and company name have been updated for privacy)
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,data);
Long suite_id = (Long)c.get("id");
ctx.setAttribute("suiteId",suite_id);
System.out.println("suiteID: "+ suite_id);
The API clients that you’ve made available on do indeed work, and your documentation is reasonable. However, for the same effort it takes to write good documentation, you can write a Swagger spec – then you get not only the documentation, but also the ability to code-generate clients whose methods are already declared and whose objects/properties are strongly typed.
At ~1000 lines of Swagger YAML, I’m roughly halfway done writing the entire TestRail spec in Swagger.
Pasting that file into the online Swagger editor will show you the generated documentation and allow you to download a generated client.
Here’s an example of printing out the names of test case types, with the generated Ruby client:
require 'swagger_client'
SwaggerClient.configure do |c|
c.username = '[email protected]'
c.password = '[one of my TestRail API keys]'
end
client = SwaggerClient::CasesApi.new()
puts "Case types"
client.get_case_types_get().each do |c|
puts " - " + c.name
end
The only correct way to finish this task would be to host the YAML file for the Swagger spec as a PHP file within the TestRail installation. This is because some parts of the spec are dynamic:
host: mydomain.testrail.com
should really be supplied by a value from $_SERVER
.If I finish transcribing the API spec into YAML, can this dynamic functionality be added to the server?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.