java - 我在拉力赛中有一个测试用例。我想使用 java API 获取其中存在测试用例的测试文件夹的名称

标签 java rally code-rally

我尝试将测试用例获取为 json 对象。它将包含测试文件夹信息作为 uri。如何在不再次点击此 uri 的情况下获取该测试文件夹的名称。

当我点击 URI 时,它会给我 TFxxx,这就是我直接需要的..

我尝试获取为 jsonObj.get("TestFolder.Name").toString(); ,它只返回 null。

有什么帮助吗?

最佳答案

在下面的代码中,我查询恰好位于 TestFolder 中的 TestCase,然后遍历到该文件夹​​,如下所示:

testCaseJsonObject.get("TestFolder").getAsJsonObject().get("Name")

下面是返回 TestFolder 名称的完整示例:

public class GetTestFolder {

    public static void main(String[] args) throws Exception {

        String host = "https://rally1.rallydev.com";
        String applicationName = "Example: get Folder of TestCase";
        String projectRef = "/project/12352608219";
        String apiKey = "_abc123";
        RallyRestApi restApi = null;
        try {
            restApi = new RallyRestApi(new URI(host),apiKey);
            restApi.setApplicationName(applicationName);
            QueryRequest testCaseRequest = new QueryRequest("TestCase");
            testCaseRequest.setProject(projectRef);

            testCaseRequest.setFetch(new Fetch(new String[] {"FormattedID","Name","TestFolder"}));
            testCaseRequest.setQueryFilter(new QueryFilter("FormattedID", "=", "TC47"));
            testCaseRequest.setScopedDown(false);
            testCaseRequest.setScopedUp(false);

            QueryResponse testCaseResponse = restApi.query(testCaseRequest);
            System.out.println("Successful: " + testCaseResponse.wasSuccessful());
            for (int i=0; i<testCaseResponse.getResults().size();i++){
                JsonObject testCaseJsonObject = testCaseResponse.getResults().get(i).getAsJsonObject();
                System.out.println("Name: " + testCaseJsonObject.get("Name") + " FormattedID: " + testCaseJsonObject.get("FormattedID") + " TestFolder: " + testCaseJsonObject.get("TestFolder").getAsJsonObject().get("Name"));

            }
        } finally {
            if (restApi != null) {
                restApi.close();
            }
        }
    }
}

关于java - 我在拉力赛中有一个测试用例。我想使用 java API 获取其中存在测试用例的测试文件夹的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38696239/

相关文章:

java - java中两个对象是否必须具有相同的内存地址才能指向同一个对象

java - 读取一个jsp传递给另一个jsp的参数

javascript - CA Rally - 并发冲突 : [Object has been modified since being read for update in this context] Error

java - 用于下载的 Spring Action 在 Android 浏览器中不起作用

java - String.equals() 通过按位 AND 对二进制数进行更改

java - 使用 Rally API 处理自定义字段

rally - 将 Ext "Neptune"主题与 App SDK 2.0 一起使用

javascript - Rally App SDK 2.0rc1 - 为什么我的组合框仅在第一次单击时忽略数据存储过滤器?

Java Rally api 回溯 api 身份验证

python - 使用 API 检索子项目并更新 Rally 中选定项目的父项目