BaymaxSky / postman-api

0 stars 0 forks source link

Update the ticket Issue #3

Open Jacobvu84 opened 1 year ago

Jacobvu84 commented 1 year ago
        static String UPDATE_TESTCASE = JIRA_BASE + "/rest/api/latest/issue/{id}";

        TestOutcome testOutcome = getLastOutcome(); // (1)
        StringBuilder steps = new StringBuilder();

        String testId = getTestCaseId(testOutcome);  // (2)

        testOutcome.getTestSteps().forEach(stepsRow -> {
            steps.append("*"+stepsRow.getDescription()+"*");
            steps.append("\n\r");

            stepsRow.getChildren().forEach(action -> {
                steps.append("\n\r  - ");
                steps.append(action.getDescription());
                steps.append("\n\r");

            });
        });

        steps.append("\n\r ==Written By Automation Test==");

        JSONObject fields = new JSONObject()
                .element("summary", testOutcome.getTitle())
                .element("description", steps.toString());

        JSONObject testcase = new JSONObject().element("fields", fields);

        SerenityRest.given()
                .header("Authorization", JIRA_TOKEN)
                .pathParam("id", testId)
                .contentType(ContentType.JSON)
                .body(testcase)
                .put(UPDATE_TESTCASE);
Jacobvu84 commented 1 year ago

(1)

    public static TestOutcome getLastOutcome() {
        return StepEventBus.getEventBus().getBaseStepListener().latestTestOutcome().get();
    }

(2)

Đặt @Tag("TestCase:TEST-12345")

    @Nullable
    private static String getTestCaseId(TestOutcome testOutcome) {
        TestTag testId = testOutcome.getTags()
                .stream()
                .filter(tag->"TestCase".equals(tag.getType())).findAny().orElse(null);
        return testId.getName();
    }