API Testing and passing HTTP body from data driven excel

Hi,
I am in process of recommending Katalon Studio for the entire enterprise organization of more than 5000 + people. We are in POC stage and checking how Katalon works for API Testing. We are enable to figure out how data from excel is passed as body to API request object ? We have followed the process of 1) Creating object repository 2) Test case is created and use test object created in object repository 3) Create excel file and filled in the request columns and data in excel. 4) In test suite, did mapping of data. 5) Created variables in test cases and mapped the variables with data columns in excel.
Code looks as below. In sendrequest how do we map the data from excel in request body is the question ?

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactory
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
import groovy.json.JsonSlurper

var1 = WS.sendRequest(findTestObject(‘CreateIssue’)

if (WS.verifyResponseStatusCode(var1, 200)) {
responseText = var1.getResponseText()
def jsonSlurper = new JsonSlurper()
def doc = jsonSlurper.parseText(responseText);
uniqueIdent1 = (doc.uniqueIdent);
print(doc);
print(doc.responses.uniqueIdent);

Hi,
You could have a look at this link (https://docs.katalon.com//display/KD/Parameterize+a+Web+Service+object) to know how to pass parameters into the request body. Then these parameters can be mapped with data files created from the excel files.

I have provided this code and it is working for me.

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.model.FailureHandling as FailureHandling

//def response = WS.sendRequest(findTestObject(‘Q1-New-2GetCVC’))

//Send a SOAP request and returns its response
//def response = WS.sendRequest(findTestObject([the ID of Web Service object]))
//Verify if a value at a specific location in response is as expected
//WS.verifyElementText(response, ‘[0].ERRMSG’, ‘Correct login information’)
/*
response.responseText = (response.responseText =~ ‘<soap:Envelope.* </soap:Envelope>’)//[0]
//WS.verifyElementText(response, “getProductResponse.Product.Reference”, “MyPreference”)

String xml = response.responseBodyContent

KeywordLogger log = new KeywordLogger()
log.logInfo(“xml”)
*/

//WS.verifyElementText(response, “PromoWorkResponse.AccountNumber”, “2000000006157438”) //https://docs.katalon.com/display/KD/Handle+Response+Messages
RequestObject request = findTestObject(‘Object Repository/Q2-New-Soap/CreateCardToBankACHTest’)

for (def row = 1; row <= findTestData(‘Q2-New-SOAP-API-DataFiles/TransferAmtC2B’).getRowNumbers(); row++) {

time_started = new Date()
println "TEST STARTED AT (America/New_York): " + time_started.format(“yyyyMMdd-HH-mm”, TimeZone.getTimeZone(‘America/New_York’))
runtime = time_started.format(“yyyyMMddHHmm”, TimeZone.getTimeZone(‘America/New_York’))
seconds = time_started.format(“HHmmss”, TimeZone.getTimeZone(‘America/New_York’))

/def cardNumber = GlobalVariable.Statuscode
println('Global Variable StatuCode: is ’ + GlobalVariable.Statuscode)
println('Card Number is ’ + cardNumber)
/

// Retrieving inputElements values from Excel file

CARD_NUMBER = findTestData(‘Q2-New-SOAP-API-DataFiles/TransferAmtC2B’).getValue(‘CardNumber’, row)
ACCOUNT_NO = findTestData(‘Q2-New-SOAP-API-DataFiles/TransferAmtC2B’).getValue(‘ACCOUNT_NO’, row)
println('Card Number is ’ + CARD_NUMBER)
RecipientID = findTestData(‘Q2-New-SOAP-API-DataFiles/TransferAmtC2B’).getValue(‘RecipientID’, row)
println('RecipientID is ’ + RecipientID)
TranactionAmount = findTestData(‘Q2-New-SOAP-API-DataFiles/TransferAmtC2B’).getValue(‘TranactionAmount’, row)
println('TranactionAmount is ’ + TranactionAmount)

def strSOAPBody = “”"<soapenv:Envelope xmlns:soapenv=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:ser=“http://www.example.com/abc/service”>
soapenv:Header
ser:UserCredentials

ser:useriduseridhere</ser:userid>

ser:passwordpasswordhere</ser:password>
</ser:UserCredentials>
</soapenv:Header>
soapenv:Body
ser:CardToBankAccount
ser:CNBCARDTOBANKACCOUNT

ser:CARD\_NUMBER${CARD_NUMBER}</ser:CARD_NUMBER>

ser:ACCOUNT\_NO</ser:ACCOUNT_NO>

ser:EmbAcctid</ser:EmbAcctid>

ser:RecipientID${RecipientID}</ser:RecipientID>

ser:RecipientName</ser:RecipientName>

ser:AccountType</ser:AccountType>

ser:ConfirmBankAccountNumber</ser:ConfirmBankAccountNumber>

ser:BankAccountNumber</ser:BankAccountNumber>

ser:RoutingNumber</ser:RoutingNumber>

ser:TranactionAmount${TranactionAmount}</ser:TranactionAmount>

ser:SetFlag2</ser:SetFlag>

ser:IVRSource</ser:IVRSource>

ser:IpAddress</ser:IpAddress>

ser:CallerId</ser:CallerId>

ser:CalledId</ser:CalledId>

ser:RequestTime</ser:RequestTime>

ser:SessionID</ser:SessionID>

ser:NICK\_NAME</ser:NICK_NAME>

ser:TransferType</ser:TransferType>

ser:Status</ser:Status>

ser:ActiveFlag</ser:ActiveFlag>
</ser:CNBCARDTOBANKACCOUNT>
</ser:CardToBankAccount>
</soapenv:Body>
</soapenv:Envelope>"""

‘Set Soap Body equal to XML string’
request.setSoapBody(String.format(strSOAPBody)) //https://forum.katalon.com/discussion/4361/replace-soap-test-object-body-xml

‘Send IP address and get response.’
//response = WS.sendRequest(request)

response = WS.sendRequest(request)
//def response = WS.sendRequest(findTestObject(‘Q1-New-2GetCVC’))

responseText = response.getResponseText()
println('Response body: is ’ + responseText) //https://forum.katalon.com/discussion/2557/how-do-i-verify-the-response-in-an-restful-api-call
System.out.println(response.getContentType())
WS.verifyResponseStatusCode(response, 200, FailureHandling.STOP_ON_FAILURE)

}

Link doesn’t work

@Trong_Bui, The link does not open. Can you please help me with the working link?