All Collections
Automation & API
Integrations
Integration with Katalon Studio using TestCollab API
Integration with Katalon Studio using TestCollab API

We will discuss a use case as an example

Vishal Vaswani avatar
Written by Vishal Vaswani
Updated over a week ago

This article discusses the steps that can be followed to get the test cases from TestCollab run automatically through Katalon Studio.

How it works?

As an example a simple Signup case targeted at TestCollab application's signup process is being used. It checks that the application should not allow a new signup when an email already registered in system is used. It also checks that the application should allow signup from an email that is not registered in the system so far.

Variables

Global as well as local (test case specific) variables used:

Name

Scope

Description

api_token

Global

Holds user's API token generated in TestCollab

project_id

Global

Holds id of TestCollab's project

testcase_id

Test Case

Holds id of the TestCollab's test case that need to be executed

Methods

Some of the methods that are used :

Name

Parameters

Returns

Description

get_user_id

-

Id of user

To get the Id of user whose API token is used

get_testplantestcases

-

JSONified response of API call

To fetch testplantestcases that are related to testcase to be executed

get_regression

testplan_id

JSONified response of API call

To fetch current testplanregressions of test plan

get_executabletests

testplantestcase_id , regression_id

JSONified response of API call

To fetch executedtestcases for regression and testplantestcase id passed

perform_test

-

Status of testcase execution (1=Passed, 2=Failed)

Performs the actual test on TestCollab instance

update_test

testplan_id, executed_testcase_id, testplan_testcase_id, testplan_config_id, testcase_status

JSONified response of API call

To call PUT method for executedtestcases so that the status for test cases can be updated in TestCollab

The Script

Here is the test case script :

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.testobject.ConditionType as ConditionType
import com.kms.katalon.core.testobject.RequestObject as RequestObject
import com.kms.katalon.core.testobject.TestObjectProperty as TestObjectProperty
import com.kms.katalon.core.testobject.impl.HttpTextBodyContent as HttpTextBodyContent
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import groovy.json.JsonSlurper as JsonSlurper
import internal.GlobalVariable as GlobalVariable

def response_getuser_id = get_user_id();

if (response_getuser_id == []) return 0;

assignee_id = response_getuser_id.get("id");

def response_gettestplantestcases = get_testplantestcases();

if (response_gettestplantestcases == []) return 0;

int cnt_gettestplantestcases = 0;

testplantestcase_id = 0;

response_gettestplantestcases.each({
int testplan_id = response_gettestplantestcases.get(cnt_gettestplantestcases)['testplan']['id'];

testplantestcase_id = response_gettestplantestcases.get(cnt_gettestplantestcases)['id'];

def response_getregression = get_regression(testplan_id);

if (response_getregression == []) return 0;

int cnt_getregression = 0;

response_getregression.each({
int regression_id = response_getregression.get(cnt_getregression)['id'];

def response_getexecutabletests = get_executabletests(testplantestcase_id, regression_id);

if (response_getexecutabletests == []) return 0;

int cnt_getexecutabletests = 0;

response_getexecutabletests.each({

int executed_testcase_id = (response_getexecutabletests['id']).get(cnt_getexecutabletests);

int testplan_testcase_id = response_getexecutabletests.get(cnt_getexecutabletests).test_plan_test_case["id"];

int testplan_config_id = (response_getexecutabletests['test_plan_config']).get(cnt_getexecutabletests) == null ? 0 : (response_getexecutabletests['test_plan_config']).get(cnt_getexecutabletests)['id'];

cnt_getexecutabletests++;

int testcase_status = 2;

testcase_status = perform_test();

response_updatetest = update_test(testplan_id, executed_testcase_id, testplan_testcase_id, testplan_config_id, testcase_status);

})

cnt_getregression++;
})

cnt_gettestplantestcases++;
})


def get_user_id() {
def slurper = new JsonSlurper();

RequestObject ro = new RequestObject('a');

ro.setRestRequestMethod('GET');

ro.setRestUrl('https://api.testcollab.io/users/me?token=' + api_token);

httpheader = new ArrayList<TestObjectProperty>();

httpheader.add(new TestObjectProperty('Content-Type', ConditionType.EQUALS, 'application/json'));

ro.setHttpHeaderProperties(httpheader);

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

response = WSBuiltInKeywords.sendRequest(ro);

return slurper.parseText(response.getResponseText());

}

def perform_test() {
int step_count = 1;

try {
WebUI.openBrowser('');

WebUI.navigateToUrl('https://testcollab.io');

step_count++;

WebUI.click(findTestObject('Object Repository/Page_Test Collab/a_Sign up'));

step_count++;

WebUI.setText(findTestObject('Object Repository/Page_Test Collab/input_Try Test Collab for Free_trial_email_email'),'vishal@gigapromoters.com');

WebUI.submit(findTestObject('Object Repository/Page_Test Collab/input_Try Test Collab for Free_trial_email_email'));

WebUI.verifyElementVisible(findTestObject('Object Repository/Page_Test Collab/p_It seems you already have account with us_f35e02'));

step_count++;

def dt = new Date().format('yyyyMMddHHmmss');

WebUI.setText(findTestObject('Object Repository/Page_Test Collab/input_Try Test Collab for Free_trial_email_email'), ('vishal+' + dt) + '@gigapromoters.com');

WebUI.submit(findTestObject('Object Repository/Page_Test Collab/input_Try Test Collab for Free_trial_email_email'));

WebUI.waitForElementVisible(findTestObject('Object Repository/Page_Test Collab/div_Email sent successfully'), 5);

WebUI.verifyElementVisible(findTestObject('Object Repository/Page_Test Collab/div_Email sent successfully'));

step_count++;

WebUI.closeBrowser();

return 1;
}
catch (com.kms.katalon.core.exception.StepFailedException e) {
println(('Step ' + step_count) + 'has failed');

WebUI.closeBrowser();

return 2;
}
catch (Exception e) {
println((('Step ' + step_count) + ' - Some other error has occurred ') + e.message);

WebUI.closeBrowser();

return 2;
}
}

def get_testplantestcases() {
def slurper = new JsonSlurper();

RequestObject ro = new RequestObject('a');

ro.setRestRequestMethod('GET');

ro.setRestUrl('https://api.testcollab.io/testplantestcases?token=' + api_token + '&project=' + GlobalVariable.project_id + '&test_case=' + testcase_id + '&_sort=ID:DESC');

def httpheader = new ArrayList<TestObjectProperty>();

httpheader.add(new TestObjectProperty('Content-Type', ConditionType.EQUALS, 'application/json'));

ro.setHttpHeaderProperties(httpheader);

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

def response = WSBuiltInKeywords.sendRequest(ro);

return slurper.parseText(response.getResponseText());
}

def get_regression(int testplan_id) {
def slurper = new JsonSlurper();

RequestObject ro = new RequestObject('a');

ro.setRestRequestMethod('GET');

ro.setRestUrl('https://api.testcollab.io/testplanregressions?token=' + api_token + '&project=' + GlobalVariable.project_id + '&testplan=' + testplan_id + '&_limit=1&_sort=ID:DESC');

def httpheader = new ArrayList<TestObjectProperty>();

httpheader.add(new TestObjectProperty('Content-Type', ConditionType.EQUALS, 'application/json'));

ro.setHttpHeaderProperties(httpheader);

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

def response = WSBuiltInKeywords.sendRequest(ro);

return slurper.parseText(response.getResponseText());
}

def get_executabletests(int testplantestcase_id, int regression_id) {
def slurper = new JsonSlurper();

RequestObject ro = new RequestObject('a');

ro.setRestRequestMethod('GET');

ro.setRestUrl('https://api.testcollab.io/executedtestcases?token=' + api_token + '&project=' + GlobalVariable.project_id + '&regression=' + regression_id + '&assigned_to='+assignee_id+'&test_plan_test_case='+testplantestcase_id);

httpheader = new ArrayList<TestObjectProperty>();

httpheader.add(new TestObjectProperty('Content-Type', ConditionType.EQUALS, 'application/json'));

ro.setHttpHeaderProperties(httpheader);

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

response = WSBuiltInKeywords.sendRequest(ro);

return slurper.parseText(response.getResponseText());
}

def update_test(int testplan_id, int executed_testcase_id, int testplan_testcase_id, int testplan_config_id, int testcase_status) {
def slurper = new JsonSlurper();

RequestObject ro = new RequestObject('a');

ro.setRestRequestMethod('GET');

ro.setRestUrl('https://api.testcollab.io/executedtestcases/' + executed_testcase_id + '?token=' + api_token);

def body = '{\n "project": ' + GlobalVariable.project_id + ',\n "status": ' + testcase_status + ',\n "_comment1": "Optional",\n "test_plan_config": '+ testplan_config_id + '\n}';

def httpheader = new ArrayList<TestObjectProperty>();

httpheader.add(new TestObjectProperty('Content-Type', ConditionType.EQUALS, 'application/json'));

ro.setHttpHeaderProperties(httpheader);

ro.setBodyContent(new HttpTextBodyContent(body, 'UTF-8', 'application/json'));

ro.setRestRequestMethod('PUT');

def response = WSBuiltInKeywords.sendRequest(ro);

return slurper.parseText(response.getResponseText());
}

Next step

In this example, we have not set the step wise results, this can be done by setting JSON for individual step of test case having step index , step , expected result , status, comment, mentions and attachments etc.

If you are using Katalon Runtime Engine then a middle tier utility can be developed that monitors the assignment of test cases that need automation, so that the scripts can automatically be triggered in Katalon Studio. You can also schedule execution for your test cases.

Please send your queries, concerns and feedback to support@testcollab.com

Did this answer your question?