【问题标题】:Rally Test case result update using Rest API使用 Rest API 更新 Rally 测试用例结果
【发布时间】:2014-11-17 18:19:13
【问题描述】:

Rally 中有一个用于更新测试用例结果的 Rest Webservice URI。 https://rally1.rallydev.com/slm/webservice/v2.0/testcaseresult/create

有人能告诉我这个payload应该是什么吗? 可能会指向一个工作示例。

我已经搜索了 2 天,但找不到我想要的信息。 最接近的是:Rally add test case results in bulk using web services API

但是这也没有帮助..

【问题讨论】:

    标签: java web-services rest testing rally


    【解决方案1】:

    你的有效载荷是什么? 您收到的错误是什么? 您引用的帖子对于以前版本的 WS API 是正确的。 v2.0 不支持 XML,只支持 JSON。

    至少,必须在有效负载中设置以下字段

    "{"TestCaseResult":{"Build":"1","Date":"2014-09-04T19:56:05.000Z","TestCase":"/testcase/12358743669","Verdict":"Pass"}}"
    

    这是一个完整的 curl 示例。在 Windows 上转义双引号的地方:

    curl --header "zsessionid:_abc123" -H "Content-Type: application/json" -d"{\"TestCaseResult\":{\"Build\":\"1.0\",\"TestCase\":\"/testcase/12358743669\",\"Date\":\"2014-09-04T19:56:05.000Z\",\"Verdict\":\"Pass\"}}" https://rally1.rallydev.com/slm/webservice/v2.0/TestCaseResult/create
    

    由于您在帖子中使用了 java 标签,因此这里是基于 Rally Java toolkit 的示例。

    public class addTCRtoTC {
    
        public static void main(String[] args) throws URISyntaxException, IOException {
            String host = "https://rally1.rallydev.com";
                String username = "user@co.com";
                String password = "secret";
                String wsapiVersion = "v2.0";
                String projectRef = "/project/2222";      
                String workspaceRef = "/workspace/11111"; 
                String applicationName = "RestExample_AddTCR";
    
            RallyRestApi restApi = new RallyRestApi(
                    new URI(host),
                    username,
                    password);
            restApi.setWsapiVersion(wsapiVersion);
            restApi.setApplicationName(applicationName);   
    
            //Read User
            QueryRequest userRequest = new QueryRequest("User");
            userRequest.setFetch(new Fetch("UserName", "Subscription", "DisplayName", "SubscriptionAdmin"));
            userRequest.setQueryFilter(new QueryFilter("UserName", "=", "nick@wsapi.com"));
            QueryResponse userQueryResponse = restApi.query(userRequest);
            JsonArray userQueryResults = userQueryResponse.getResults();
            JsonElement userQueryElement = userQueryResults.get(0);
            JsonObject userQueryObject = userQueryElement.getAsJsonObject();
            String userRef = userQueryObject.get("_ref").getAsString();  
            System.out.println(userRef);
    
            // Query for Test Case to which we want to add results
            QueryRequest testCaseRequest = new QueryRequest("TestCase");
            testCaseRequest.setFetch(new Fetch("FormattedID","Name"));
            testCaseRequest.setWorkspace(workspaceRef);
            testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TC6"));
            QueryResponse testCaseQueryResponse = restApi.query(testCaseRequest);
            JsonObject testCaseJsonObject = testCaseQueryResponse.getResults().get(0).getAsJsonObject();
            String testCaseRef = testCaseQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").getAsString(); 
    
            try {
                for (int i=0; i<2; i++) {
    
                    //Add a Test Case Result    
                    System.out.println(testCaseRef);
                    System.out.println("Creating Test Case Result...");
                    JsonObject newTestCaseResult = new JsonObject();
                    newTestCaseResult.addProperty("Verdict", "Pass");
                    newTestCaseResult.addProperty("Date", "2014-03-07T18:00:00.000Z");
                    newTestCaseResult.addProperty("Notes", "Some Scheduled Test");
                    newTestCaseResult.addProperty("Build", "2.0");
                    newTestCaseResult.addProperty("Tester", userRef);
                    newTestCaseResult.addProperty("TestCase", testCaseRef);
                    newTestCaseResult.addProperty("Workspace", workspaceRef);
    
                    CreateRequest createRequest = new CreateRequest("testcaseresult", newTestCaseResult);
                    CreateResponse createResponse = restApi.create(createRequest);  
                    if (createResponse.wasSuccessful()) {
    
                        System.out.println(String.format("Created %s", createResponse.getObject().get("_ref").getAsString()));          
    
                        //Read Test Case
                        String ref = Ref.getRelativeRef(createResponse.getObject().get("_ref").getAsString());
                        System.out.println(String.format("\nReading Test Case Result %s...", ref));
                        GetRequest getRequest = new GetRequest(ref);
                        getRequest.setFetch(new Fetch("Date", "Verdict"));
                        GetResponse getResponse = restApi.get(getRequest);
                        JsonObject obj = getResponse.getObject();
                        System.out.println(String.format("my Read Test Case Result. Date = %s, Verdict = %s",
                                obj.get("Date").getAsString(), obj.get("Verdict").getAsString()));                 
                    } else {
                        String[] createErrors;
                        createErrors = createResponse.getErrors();
                        System.out.println("Error occurred creating Test Case Result: ");
                        for (int j=0; i<createErrors.length;j++) {
                            System.out.println(createErrors[j]);
                        }
                    }
                }
    
    
            } finally {
                //Release all resources
                restApi.close();
            }   
    
        } 
    
    }
    

    【讨论】:

    • { "TestCaseResult":{ "Build":"1", "Date":"2014-09-04T19:56:05.000Z", "TestCase":"这是什么?我可以在这里通过 TC Id?", "Verdict":"Pass" } }如何通过测试者的用户名,如何通过它所属的测试集??
    • 另外,用户如何通过笔记?我尝试使用您提到的有效负载并得到如下响应 { "CreateResult": { "_rallyAPIMajor": "1", "_rallyAPIMinor": "41", "Errors": [ "Cannot parse input stream due to I/O作为 JSON 文档的错误:解析错误:预期的 ':' 但看到了 '/' [ ​​chars read = >>>{ \"TestCaseResult\" : {\n \"Build\" : \"2345\",\n \"日期\" : \"2014-11-17T23:05:49.365Z\",\n \"TestCase\" : { \n \"_ref\" : \"/testcase/12345678910.js\"\n }, \n \"Tester\" : {\n \"_ref : \"/
    • 是测试用例ObjectID,不能传递Formatted ID。例如。 TC123 将无法工作。在 UI 中查看要在其上创建结果的测试用例的 URL,例如rally1.rallydev.com/#/12352608219/detail/testcase/12358743669 最后一个字符串 12358743669 是这个测试用例的 ObjectID。您可以传递任何有效字段,但启动速度较慢。确保您可以通过传递最少的必填字段来创建结果,然后在“游乐场”环境中逐步构建。
    • 好的,我会这样做的。有没有办法找到标准有效载荷,其中包含用于更新测试用例结果的所有标签/属性?
    • 检查 UI 中的必填字段。例如,如果在 UI 中您需要在创建 TCR 时提供“Build”,那么在通过 WS API 创建 TCR 时必须提供“Build”。如果您遗漏了什么,来自 WS API 的错误会告诉您需要什么字段,例如“构建不能为空”或类似的东西。
    【解决方案2】:

    正确的负载格式:

        {
            "TestCaseResult": {
                "Build": "1.0",
                "Date": "YYY-MM-DD",
                "TestCase": {
                    "_ref": ""
                },
                "TestSet": {
                    "_ref": ""
                },
                "Verdict": "Pass",
                "Workspace": {
                    "_rallyAPIMajor": "2",
                    "_rallyAPIMinor": "0",
                    "_ref": "",
                    "_refObjectUUID": "",
                    "_refObjectName": "",
                    "_type": "Workspace"
                }
            }
        }
    

    标题格式: 您可以从Rally Application manager获取API密钥。

    Rally_headers = {'ZSESSIONID' : API_KEY, 'Content-Type' : 'application/json', "Accept": "application/json"}
    

    更多详情请阅读文档here

    【讨论】:

    • 即使没有链接,也请提供有用的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多