【问题标题】:Update Cucumber features and test execution results on Xray in Jira在 Jira 中的 Xray 上更新 Cucumber 功能和测试执行结果
【发布时间】:2019-08-29 13:13:43
【问题描述】:

我正在尝试使用 Cucumber 和 Java 设置自动化框架。我使用 Itellij IDEA 作为我的 IDE。到目前为止,我能够自动化测试用例。我阅读了 Xray 文档并意识到我应该使用 REST API 来更新 Xray 上的功能文件。

我在 Cucumber 和 C# 上做了一些工作,我在 Visual Studio 上自动化了我的测试用例,并使用 Hooks 更新了 TFS 上的功能和执行状态。到目前为止,我希望通过 Xray 使用 Java 实现相同的功能。

我做了一些研究,并意识到我应该在 Xray 上创建一个用 Cucumber 编写的测试用例,然后将其导出以在 Intellij 上自动化,或者自动化测试用例并使用 Jenkins 在 Xray 上更新它们。

是否有解决方法或教程可以让我在 Intellij 上使用 Java 和 Cucumber 在 Xray 上更新我的功能?

【问题讨论】:

    标签: java intellij-idea cucumber jira-rest-api jira-xray


    【解决方案1】:

    对于那些和我遇到同样问题的人来说,这是我能够将黄瓜特征导出到 Xray 的方式。你只需要发送你的Cucumber特性文件的路径和这样的url - https://jira.yourdomain.com/rest/raven/1.0/import/feature 其他参数都很好理解。

    public static void importFeatureFilesToJira(String filePath, String resultTypeUrlValue){
        String jiraUrl = config.getJiraLoginValue();
        log.info(String.format("Starting upload of Cucumber features to XRAY on Jira project: %s\n Using Jira user: %s ", config.getJiraProjectValue(), config.getJiraLoginValue()));
        log.info(String.format("Path to Report: %s", filePath));
        String authentication = config.getJiraLoginValue() + ':' + config.getJiraPassword();
        BASE64Encoder encoder = new BASE64Encoder();
        String encoded = null;
        try {
            encoded = encoder.encode((authentication).getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        Client client = ClientBuilder.newBuilder()
                .register(MultiPartFeature.class).property(HttpHeaders.AUTHORIZATION, encoded).build();
    
        //Import type is dynamic below
        StringBuffer url = new StringBuffer(resultTypeUrlValue);
        url.append("?projectKey=").append(config.getJiraProjectValue());
        WebTarget webTarget = client.target(url.toString());
        log.info(String.format("URL of the XRAY API: %s", url.toString()));
        MultiPart multiPart = new MultiPart();
        multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);
        FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("file",
                new File(filePath),
                MediaType.APPLICATION_OCTET_STREAM_TYPE);
        multiPart.bodyPart(fileDataBodyPart);
    
        Response response = webTarget.request(
                MediaType.MULTIPART_FORM_DATA)
                .accept(MediaType.APPLICATION_JSON).
                        header(HttpHeaders.AUTHORIZATION, "Basic " + encoded).post(
                        Entity.entity(multiPart, multiPart.getMediaType()));
        log.info(response.getStatus() + " "
                + response.getStatusInfo() + " " + response);
        int responseBody = response.getStatus();
        String responseBodySting = response.toString();
        try{
            if(responseBody==200 && responseBodySting.contains("200")){
                log.info("Cucumber features were uploaded successfully");
            }
        }catch (Exception e){
            log.info("There was an error uploading the Cucumber feature file");
        }
        log.info("End of XRAY file upload publication");
    }
    

    【讨论】:

    • 你能粘贴整个类文件和你要导入的jar吗?什么是 config.getJiraLoginValue();你能提供更多细节吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多