当前位置: 首页 > 知识库问答 >
问题:

jobProgressToken:Jira(Zephy r)Rest API

靳高明
2023-03-14

我正在使用Jira(Zephyr)rest调用来创建测试周期并向其中添加测试用例。根据这里提到的信息1,如果我使用这个rest调用将测试添加到循环中,那么作为响应,我将获得JobProgressToken。JobProgressToken只是告诉测试周期中添加测试用例的进度。

现在我面临的问题是,我没有从这个JobProgressToken获得任何输出。我尝试使用上述格式启动GET-rest调用,但得到的是空响应。

有人能解释一下如何使用JobProgressToken来获取我的任务进度吗?我想验证我添加到循环中的测试是否成功添加?

共有1个答案

狄兴业
2023-03-14

就在今天,我也有同样的问题。ZAPI文档确实令人困惑。我找到了以下解决方案:

用于检索作业进度的GET请求具有以下形式:超文本传输协议://jira/rest/zapi/最新/执行/jobgres/0001498157843923-5056b64fdb-0001其中0001498157843923-5056b64fdb-0001是特定jobProgressToken的值

在通过某个异步操作获得jobProgressToken之后,我的代码正在等待进度变为1(从0增长到1)

    //get the job progress token as a result of some async operation invocation
    String jobProgressToken = new JSONObject(zapiResponse).getString("jobProgressToken");
    waitAsyncJobToBeCompleted(jobProgressToken);


void waitAsyncJobToBeCompleted(String jobProgressToken) {
    double jobProgress;
    do {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            LOG.error("Error while try to make the thread sleeping 500ms. " + e.getLocalizedMessage());
            e.printStackTrace();
        }
        jobProgress = getJobProgress(jobProgressToken);
    } while (Double.compare(jobProgress, 1) <0);

private double getJobProgress(String jobProgressToken) {
    URI uri = makeUriFromString(String.format(
            GET_GetJobProgress, //Get request pattern
            connectionParameters.getJiraUrl(),//host
            jobProgressToken)); //parameters

    HttpResponse response = executeHttpRequestWithResponse(new HttpGet(uri));
    String zapiResponse = null;
    try {
        zapiResponse = EntityUtils.toString(response.getEntity());
        LOG.trace("ZAPI RESPONSE: " + zapiResponse);
        EntityUtils.consumeQuietly(response.getEntity()); //cleanup the HTTP response
        double progress = new JSONObject(zapiResponse).getDouble("progress");
        LOG.debug("Job progress: " + progress);
        return progress;

    } catch (IOException e) {
        String err = String.format("Error while getting Zephyr API response: %s",
                e.getLocalizedMessage());
        LOG.fatal(err);
        throw new RestApiException(err, e);
    } catch (JSONException e) {
        String err = String.format("Error while retrieving the job progress from JSON: %s\n%s",
                zapiResponse, e.getLocalizedMessage());
        LOG.fatal(err);
        throw new RestApiException(err, e);
    }

}

这都是魔法:)

以下两个日志:第一个用于克隆测试周期,第二个用于删除

ZephyrClient.invokeHttpPost     - URI=http://jira/rest/zapi/latest/cycle JSON payload={"projectId": "13795","clonedCycleId": 2643,"name": "ZAPI client test","description": "Created With ZAPI client unit test","versionId": "-1"}
ZephyrClient.cloneTestCycle     - RESPONSE JSON: {"jobProgressToken":"0001498218783350-5056b64fdb-0001"}
ZephyrClient.executeHttpRequestWithResponse     - HTTP REQUEST: GET http://jira/rest/zapi/latest/execution/jobProgress/0001498218783350-5056b64fdb-0001 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse     - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.getJobProgress     - ZAPI RESPONSE: {"timeTaken":"0 min, 1 sec","stepMessage":"","summaryMessage":"","errorMessage":"","progress":0.56,"message":"","stepLabel":"","stepMessages":[]}
ZephyrClient.getJobProgress     - Job progress: 0.56
ZephyrClient.executeHttpRequestWithResponse     - HTTP REQUEST: GET http://jira/rest/zapi/latest/execution/jobProgress/0001498218783350-5056b64fdb-0001 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse     - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.getJobProgress     - ZAPI RESPONSE: {"timeTaken":"0 min, 1 sec","stepMessage":"","summaryMessage":"","errorMessage":"","progress":0.98,"message":"","stepLabel":"","stepMessages":[]}
ZephyrClient.getJobProgress     - Job progress: 0.98
ZephyrClient.executeHttpRequestWithResponse     - HTTP REQUEST: GET http://jira/rest/zapi/latest/execution/jobProgress/0001498218783350-5056b64fdb-0001 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse     - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.getJobProgress     - ZAPI RESPONSE: {"timeTaken":"0 min, 2 sec","stepMessage":"","summaryMessage":"","errorMessage":"","progress":0.98,"message":"","stepLabel":"","stepMessages":[]}
ZephyrClient.getJobProgress     - Job progress: 0.98
ZephyrClient.executeHttpRequestWithResponse     - HTTP REQUEST: GET http://jira/rest/zapi/latest/execution/jobProgress/0001498218783350-5056b64fdb-0001 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse     - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.getJobProgress     - ZAPI RESPONSE: {"timeTaken":"0 min, 3 sec","stepMessage":"","summaryMessage":"","errorMessage":"","progress":1.0,"message":"Cycle ZAPI client test created successfully.","stepLabel":"","stepMessages":[]}
ZephyrClient.getJobProgress     - Job progress: 1.0
ZephyrClient.executeHttpRequestWithResponse     - HTTP REQUEST: GET http://jira/rest/zapi/latest/cycle?projectId=13795&versionId=-1 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse     - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.invokeHttpDelete   - URI=http://jira/rest/zapi/latest/cycle/2727
ZephyrClient.deleteTestCycle    - RESPONSE JSON: {"jobProgressToken":"0001498218815183-5056b64fdb-0001"}
ZephyrClient.executeHttpRequestWithResponse     - HTTP REQUEST: GET http://jira/rest/zapi/latest/execution/jobProgress/0001498218815183-5056b64fdb-0001 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse     - HTTP RESPONSE: HTTP/1.1 200 OK
ZephyrClient.getJobProgress     - ZAPI RESPONSE: {"timeTaken":"0 min, 0 sec","stepMessage":"","summaryMessage":"","errorMessage":"","progress":1.0,"message":"{\"success\":\"Cycle ZAPI client test успешно удален\"}","stepLabel":"","stepMessages":[]}
ZephyrClient.getJobProgress     - Job progress: 1.0
ZephyrClient.executeHttpRequestWithResponse     - HTTP REQUEST: GET http://jira/rest/zapi/latest/cycle?projectId=13795&versionId=-1 HTTP/1.1
ZephyrClient.executeHttpRequestWithResponse     - HTTP RESPONSE: HTTP/1.1 200 OK

附言:这不是关于应该如何做。这是关于它如何为我工作;)

 类似资料:
  • Zephyr 是 Linux 基金会推出的一个适用于物联网的小型可伸缩的实时操作系统,支持多种处理器架构。Zephyr 是安全的、开源的、模块化的以及支持多种连接方式,将支持 Bluetooth, Bluetooth LE, WiFi, 802.15.4 以及 6Lowpan, CoAP, IPv4, IPv6, and NFC.。

  • zephyr 是一个 MVC (model-view-controller) 框架,支持业务逻辑和表现层的分离,后端使用非常成熟的库。 示例代码: <? //home.class.phpclass home implements action{ public $params; public function execute() { return array("view_file"=hello"

  • JIRA是否有任何选项可以将测试标记为自动化。我是JIRA的新手,我们使用Zephy进行测试用例管理。我正在为基于Web的应用程序编写测试用例,希望分别跟踪手动和自动化测试用例。

  • 我想为我的测试创建一个自动化的过程。我用的是jira和zapi。我想尝试使用postman api与zephyr jira中的测试进行交互。问题是没有太多关于如何使用zapi的文档。 首先,url是什么?这是测试吗。大西洋。净/吉拉/?/?//apifunction 第二件事,我可以生成一个访问密钥和密钥,但我似乎还需要一个授权jwt令牌,我如何生成一个我可以通过邮递员使用的令牌? 任何帮助都将受

  • 我已经在jenkins和ZAPI安装了Zephyr插件,在jira安装了Zephyr插件,并且能够建立连接 但是在下拉列表中我无法查看jira项目 有人能帮我解决这个问题吗?在构建后无法在下拉列表中查看项目名称

  • 我们正在尝试整合吉拉和詹金斯。我们使用Zephyr进行测试管理,对于Jenkins集成,我们已经安装了ZAPI。在Jenkins安装了Zephyr插头。到目前为止,Jenkins可以与Jira连接,并向我们展示项目。我们正在遵循这里描述的步骤,但是这个指导方针告诉我们要有一个Subversion存储库。目前我们的项目是驻留在Git中,我们希望保持它的这种方式。 为了测试的目的,我已经把项目放在一个