GithubHelp home page GithubHelp logo

gurock / testrail-api Goto Github PK

View Code? Open in Web Editor NEW
114.0 22.0 86.0 93 KB

TestRail API: Examples on how to use TestRail's API from various languages

License: Other

C# 31.60% Java 24.17% PHP 15.63% Ruby 9.95% Python 18.66%

testrail-api's Introduction

testrail-api's People

Contributors

allanlewis avatar gurock-b1cc2c35 avatar jonathanlalou avatar jonrgurock avatar tgurock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

testrail-api's Issues

error when hit GET /get_plan using API v2

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"
}

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

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
}

}

Screenshots not accessible/downloadable through the API's methods

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

PyTest to update test case results to TestRails by providing the RunID

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

Functional: No way to add the test case to a test run while creating the test case

Pre requisite: Existing Test run with some test cases selected from Test Suites section

Steps:

  1. Go to Test Suites, add a new test case. Check if you can add this test case to active test runs

Actual Result:

  1. No option to add current test case to an active test run

Expected result:

  1. Add a drop list feature 'Add to Test Run' (or Test Plan) in the navigation bar between Add Case, and Edit.
  2. Clicking on the drop list should display a list of active test runs only
  3. Should allow selecting multiple cases at once from test suite section and add to a test run without requiring to go to test run tab

"Field :suite_id is a required field." when suite_id is clearly provided

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"]}>

{"error"=>"Field :suite_id is a required field."}

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!

get_results_for_run cannot be filtered to return the last set of results

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.

Consider adding a license to the various libraries

"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.

500 issue

Hi guys,

Every time when I try get or set any attribute in test or testcase I see 500 error. It looks like you forgot to add httpWebRequest.UserAgent = ".NET Framework Test Client"; to the SendRequest method. With this string of code all works fine. Could you please recheck and update codebase?
image

Dotnet get_attachments issue

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/")))

Provide Swagger spec, for generating better clients in many languages

Why?

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.

What?

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

How?

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:

  • The line host: mydomain.testrail.com should really be supplied by a value from $_SERVER.
  • Custom fields of tests cases will change the object definitions and method parameters of the API (in a predictable and scriptable way), and it should be done server-side rather than manually updating the spec every time a custom field is edited.

If I finish transcribing the API spec into YAML, can this dynamic functionality be added to the server?

Failed to retrieve cases

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

python bindings has error handing issues and path name issues.

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.

TestRail API returned HTTP 400 Field :suite_id is a required field - JAVA

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.")

Consider Publishing to Maven Central

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:

  • Gradle
  • Scala
  • Groovy Grape
  • Leiningen
  • Apache Ivy
  • Apache Buildr
  • PURL
  • Bazel

Thanks for your consideration!

com.qa.utils.APIException: TestRail API returned HTTP 400("Field :suite_id is a required field.")

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);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.