Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to update CustomFields #71

Open
MateuszAlcumus opened this issue Jun 6, 2022 · 3 comments
Open

How to update CustomFields #71

MateuszAlcumus opened this issue Jun 6, 2022 · 3 comments

Comments

@MateuszAlcumus
Copy link

Hello, I am struggling to understand how to update CustomFields, when creating new TestCase

            // download custom case fields for my project
            List<CaseField> customCaseFields = testRail.caseFields().list().execute();

            // add new case
            Case testCase = testRail.cases().add(suiteID, new Case().setTitle("New Test Case"), customCaseFields).execute();

Now I know that my customCaseFields, contains field called 'steps' (index 1 in the list)

How can I set value for this custom field when adding new test case?

@AbdelrhmanHamouda
Copy link

Hello,
I am not the maintainer of this project, so keep that in mind. That being said, this is how i'm creating a testcase with custom fields in addition to other few fields that are interesting to me.

/**
     * Dynamic creation of the test cases
     */
    private static int createTestCase(String testTitle, String testJiraRef, Section section) {
        Case testCase = new Case();
        testCase.setTitle(testTitle.toLowerCase().trim());
        testCase.setSectionId(section.getId());
        testCase.setRefs(testJiraRef);

        java.util.List<CaseField> caseFields = testRail.caseFields().list().execute();

        setCustomFields(testCase, Map.of(
                "CustomField1","field value 1"),
                "CustomField2", "field value 1"),
                "CustomField3", "field value 1"));

        testCase = testRail
                .cases()
                .add(section.getId(), testCase, caseFields)
                .execute();

        log.info("Created test case {}", testCase);
        return testCase.getId();
    }

Hope this helps.

@MateuszAlcumus
Copy link
Author

Hello, I am not the maintainer of this project, so keep that in mind. That being said, this is how i'm creating a testcase with custom fields in addition to other few fields that are interesting to me.

/**
     * Dynamic creation of the test cases
     */
    private static int createTestCase(String testTitle, String testJiraRef, Section section) {
        Case testCase = new Case();
        testCase.setTitle(testTitle.toLowerCase().trim());
        testCase.setSectionId(section.getId());
        testCase.setRefs(testJiraRef);

        java.util.List<CaseField> caseFields = testRail.caseFields().list().execute();

        setCustomFields(testCase, Map.of(
                "CustomField1","field value 1"),
                "CustomField2", "field value 1"),
                "CustomField3", "field value 1"));

        testCase = testRail
                .cases()
                .add(section.getId(), testCase, caseFields)
                .execute();

        log.info("Created test case {}", testCase);
        return testCase.getId();
    }

Hope this helps.

Thank you for that, really helpful, could you please provide content of the 'setCustomField' method? Regards

@AbdelrhmanHamouda
Copy link

Hello,
I missed including it. my bad.

implementation of setCustomFields called by createTestCase

private static Case setCustomFields(Case caseToUpdate, Map customFields) {

        Set fieldNames = getCustomFields().stream().map(field->field.getName()).collect(Collectors.toSet());

        if (fieldNames.containsAll(customFields.keySet())) {
            caseToUpdate.setCustomFields(customFields);
        }
        else
            log.error("Could not update custom fields for case {}", caseToUpdate.getId());

        return caseToUpdate;
    }

implementation of getCustomFields called by setCustomFields

 private static List<CaseField> getCustomFields() {
        return testRail.caseFields().list().execute();
    }

The testRail object is just a simple object that is initialised earlier

private static TestRail testRail;

public static void initTestRail(){
            // create a TestRail instance
            testRail = TestRail
                    .builder(TEST_RAIL_ENDPOINT,"user name", "password")
                    .applicationName("TOOLBOX_TEST_RAIL_BOT").build();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants