如何使用API​​从Rally testcase导出“Steps”,“Input”和“ExpectedResult”?

时间:2016-01-07 11:37:03

标签: java rest rally

我尝试了下面的代码,stepsArray将始终为null,尽管有测试步骤。

    rallyTypeRequest.setFetch(new Fetch("FormattedID","Name","Steps"));
    rallyTypeRequest.setQueryFilter(new QueryFilter("FormattedID", "=",existFormattedId));

    QueryResponse rallyTypeQueryResponse = restApi.query(rallyTypeRequest);
    System.out.println("TestCase response:" + rallyTypeQueryResponse.getResults().toString());
    JsonObject rallyTypeJsonObject = new JsonObject();
    rallyTypeJsonObject = rallyTypeQueryResponse.getResults().get(0).getAsJsonObject();
    JsonObject stepsJsonObject = rallyTypeJsonObject.getAsJsonObject("Steps");
    QueryRequest stepsRequest = new QueryRequest(stepsJsonObject);
    stepsRequest.setFetch(new Fetch("StepIndex","ExpectedResult","Input"));
    JsonArray stepsArray = restApi.query(stepsRequest).getResults();

1 个答案:

答案 0 :(得分:1)

我实际上不太确定为什么上面的代码不起作用,但我能够修改一个现有的例子,我已经坐在那里阅读测试用例步骤,以下工作很棒:

QueryRequest testCaseRequest = new QueryRequest("testcase");
testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TC1"));
testCaseRequest.setFetch(new Fetch("FormattedID", "Name", "Steps"));

QueryResponse testCaseResponse = restApi.query(testCaseRequest);
JsonObject testCase = testCaseResponse.getResults().get(0).getAsJsonObject();
System.out.println(String.format("Found: %s - %s", testCase.get("FormattedID").getAsString(), testCase.get("Name").getAsString()));

//Inspect the steps collection
JsonObject steps = testCase.getAsJsonObject("Steps");
int stepCount = steps.get("Count").getAsInt();
System.out.println(String.format("\nTotal steps: %d", stepCount));

//Query the steps collection
QueryRequest stepRequest = new QueryRequest(steps);
stepRequest.setFetch(new Fetch("StepIndex","ExpectedResult","Input"));
QueryResponse queryResponse = restApi.query(stepRequest);
if (queryResponse.wasSuccessful()) {
    for (JsonElement result : queryResponse.getResults()) {
        JsonObject step = result.getAsJsonObject();
        System.out.println(String.format("\t%d: Input=%s, ExpectedResult=%s",
                step.get("StepIndex").getAsInt(),
                step.get("Input").getAsString(),
                step.get("ExpectedResult").getAsString()));
    }
}