Integrate Selenium test results with TestRail 4.0

时光怂恿深爱的人放手 提交于 2019-12-19 03:57:04

问题


I am working on Selenium test Automation. I create my Selenium test-suite to automate my test suite. Now i want to integrate the Selenium results with the TestRail. I am not sure how to integrate the results of the Selenium test runs to TestRail Test suite. I wrote all test cases in java. I am stuck now. It would be helpful to me with an example.

I am using testng framework, Maven build tool.


回答1:


The basic idea is that you need to be able to link your results back to the unique Test ID in TestRail, within the context of a given User. This can be done either as each test is executed and passes / fails, or after the entire run is complete.

If you want to push the results to TestRail after each test passes / fails, you would either create a TestNG listener which will listen for test results and then call the API to submit the result to TestRail. This approach is much cleaner than adding a function to each test.

If you want to push the results to TestRail after the run is completed, you may have to write a parser to read / process the entire results file and then call the TestRail APIs appropriately.

In terms of the APIs you need to call, you can either use the API methods "add_result" or "add_result_for_case" to do this. The key difference between the two methods is that "add_result_for_case" takes the Case ID and the Run ID, whereas "add_result" takes the Test ID. Either can be useful depending on your automation approach.

There is a Java API binding available at:

https://github.com/gurock/testrail-api

This is documented here.

You instantiate the API connection in Java via:

import com.gurock.testrail.APIClient;
import com.gurock.testrail.APIException;
import java.util.Map;
import java.util.HashMap;
import org.json.simple.JSONObject;

public class Program
{
    public static void main(String[] args) throws Exception
    {
        APIClient client = new APIClient("http://<server>/testrail/");
        client.setUser("..");
        client.setPassword("..");
    }
}

Here's an example of a GET request:

APIClient client = new APIClient("http://<server>/testrail/");
client.setUser("..");
client.setPassword("..");
JSONObject c = (JSONObject) client.sendGet("get_case/1");
System.out.println(c.get("title"));

And here's a POST request:

Map data = new HashMap();
data.put("status_id", new Integer(1));
data.put("comment", "This test worked fine!");
JSONObject r = (JSONObject) client.sendPost("add_result_for_case/1/1", data);


来源:https://stackoverflow.com/questions/31344490/integrate-selenium-test-results-with-testrail-4-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!