Problems in integrating with TestRail

Since I already have some test cases in TestRail, I’m not sure what url should I use to replace the one in Katalon Studio Integration with TestRail. For example:

ro.setRestUrl('https://%YOUR PROJECT%.testrail.io/index.php?/api/v2/get_tests/' + id)

Should I do anything with api/v2/get_tests/’ + id? Nothing happened if I merely set G_testrail_run_id to my TestRail test case id, ex. 14546874. I have noticed that I can set my API key in TestRail as follows:

My Settings → API Keys → Add Key → Enter key name

Then I can get an API Key. Should I generate an API Key? If so, what is it for?

I think you have to add your credentials to the Authorization header.

@Keyword
def get_tests(String id) {
    def slurper = new JsonSlurper()
    RequestObject ro = new RequestObject('Get TestRail tests')
    ro.setRestRequestMethod('GET')
    ro.setRestUrl('https://%YOUR PROJECT%.testrail.io/index.php?/api/v2/get_tests/' + id)

    def httpheader = new ArrayList<TestObjectProperty>()
    httpheader.add(new TestObjectProperty(
            'Content-Type', ConditionType.EQUALS, 'application/json'))

    httpheader.add(new TestObjectProperty(
            'Authorization', ConditionType.EQUALS,
            '%YOUR TESTRAIL CREDENTIALS ENCODED TO BASE64%'))

    ro.setHttpHeaderProperties(httpheader)
    ro.setBodyContent(
            new HttpTextBodyContent('', 'UTF-8', 'application/json'))

    def response = WSBuiltInKeywords.sendRequest(ro)
    return slurper.parseText(response.getResponseText())
}

I did add the credentials but not sure if it is in the right format:

httpheader.add(new TestObjectProperty(
            'Authorization', ConditionType.EQUALS,
            'Basic <MY ENCODED CREDENTIALS>'))

To be more specific, here is the error log:

response = get_tests(G_testrail_run_id) FAILED.
Reason:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
	at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:43)
	at Communicate With TestRail.run(Communicate With TestRail:16)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:328)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)
	at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.doCall(CallTestCaseKeyword.groovy:59)
	at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword$_callTestCase_closure1.call(CallTestCaseKeyword.groovy)
	at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:54)
	at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.callTestCase(CallTestCaseKeyword.groovy:80)
	at com.kms.katalon.core.keyword.builtin.CallTestCaseKeyword.execute(CallTestCaseKeyword.groovy:44)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:53)
	at com.kms.katalon.core.keyword.BuiltinKeywords.callTestCase(BuiltinKeywords.groovy:334)
	at ResultsCollector.afterTestSuite(ResultsCollector.groovy:42)
	at ResultsCollector.invokeMethod(ResultsCollector.groovy)
	at com.kms.katalon.core.context.internal.TestHooker.invokeMethod(TestHooker.java:132)
	at com.kms.katalon.core.context.internal.TestHooker.lambda$3(TestHooker.java:116)
	at com.kms.katalon.core.context.internal.TestHooker.invokeContextMethods(TestHooker.java:115)
	at com.kms.katalon.core.context.internal.TestListenerCollector.lambda$3(TestListenerCollector.java:60)
	at com.kms.katalon.core.context.internal.TestListenerCollector.handleListenerEvent(TestListenerCollector.java:57)
	at com.kms.katalon.core.context.internal.ExecutionEventManager.publicEvent(ExecutionEventManager.java:36)
	at com.kms.katalon.core.main.TestSuiteExecutor.execute(TestSuiteExecutor.java:89)
	at com.kms.katalon.core.main.TestCaseMain.startTestSuite(TestCaseMain.java:149)
	at com.kms.katalon.core.main.TestCaseMain$startTestSuite$0.call(Unknown Source)
	at TempTestSuite1545805078472.run(TempTestSuite1545805078472.groovy:36)

May I see line 16 of your test case?

Hi, I just resolved the issue. I didn’t include my package name when calling keywords. In addition, there are typos in the tutorial:

in def update_run(String id, String array),

String array -> ArrayList<String> array

response = CustomKeywords.‘com.trendmicro.testrail.TestRailHandler.add_results’(id, request)
-> response = CustomKeywords.‘com.trendmicro.testrail.TestRailHandler.add_results’(GlobalVariable.G_testrail_run_id, request)

Thanks a ton.

1 Like

Just FYI - we’ve built a TestRail integration plugin for Katalon Studio. If you have any feedback or suggestions we are happy to hear from you.

https://store.katalon.com/product/13/TestRail-Integration

Hi @devalex88 I am already following the documentation that plugin, but for me it’s not working. can you help me?
thank you

Hi sir @Eric_Hung can you help me to following your step to complete the case?

@januari Please create a new topic and describe your issue.

Well noted