gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 09:37:56 25 4
gpt4 key购买 nike

我尝试将测试用例获取为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com