Possible to customize Parameter Query in test script?

i updated this post as i have another question now.

I have many Parameter to test and thinking can I just use one object repo and move the query parameter to test scripts?
otherwise i have to created many GET objects repo with just different set of parameters.

please advise if Katalon allowed to do it in test script?

example the GET supporting 2 parameter , name, drugId
I want to create one GET object, and input all parameter in the object.
but at test script i want to have flexibility to call one param only. right now i saw the object URI has 2 param, how to call one param only? or i really have to create so many objects and keep one param in one object?

is that possible?

Test script

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static org.assertj.core.api.Assertions.*

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

import groovy.json.JsonOutput as JsonOutput
import groovy.json.JsonSlurper as JsonSlurper
import internal.GlobalVariable as GlobalVariable

GlobalVariable.TestIssueKey = ‘PM-6630’

GlobalVariable.Paramname = “Actiq”

GlobalVariable.ParamdrugId = “FF1/M2/P2”

///GET by param drugId
def test1 = WS.sendRequestAndVerify(findTestObject(‘Web Service Request/drug-service/ApiDrugbyParamQueryGet’, [(‘drugId’) : GlobalVariable.ParamdrugId,(‘SiteHostName’) : GlobalVariable.SiteHostName , (‘Port’) : GlobalVariable.Port]))
WS.verifyResponseStatusCode(test1, 200)

def test1List = new JsonSlurper().parseText(test1.getResponseText())

println(‘response text: \n’ + JsonOutput.prettyPrint(JsonOutput.toJson(test1List)))

assertThat(test1List.data[0].drugId).isEqualTo(“FF1”)

assertThat(test1List.total).isEqualTo(1)

///GET by param name

i am writing manual scrip like this, hardcoded param in the script. any better suggestion please let me know.

def SiteHostName = GlobalVariable.SiteHostName
def Port = GlobalVariable.Port

String endpoint1 = “http://${SiteHostName}:${Port}/api/items/drug?drugId=FF1/M2/P2”
String requestMethod = “GET”

/**

  • GET requests
    */
    //RequestObject ro = new RequestObject(“objectId”)
    RequestObject ro = new RequestObject()
    ro.setRestUrl(endpoint1)
    ro.setHttpHeaderProperties()
    ro.setRestRequestMethod(“GET”)
    //ro.setBodyContent(new HttpTextBodyContent(body))

///GET by param drugId
def test1 = WS.sendRequest(ro)
WS.verifyResponseStatusCode(test1, 200)
def test1List = new JsonSlurper().parseText(test1.getResponseText())
println(‘response text: \n’ + JsonOutput.prettyPrint(JsonOutput.toJson(test1List)))

Is this what you want?

String host = GlobalVariable.SiteHostName
String port = GlobalVariable.Port

List<String> list = ['FF1/M2/P2', "as","many","ids","you","want"]

list.each { drugId ->
    String endpoint = “http://${host}:${port}/api/items/drug?drugId=${drugId}”
    ...
    RequestObject ro = new RequestObject()
    ro.setRestUrl(endpoint)
    ...

i am doing something very linear now like this
i cannot make use of one generic endpoint, stop at the ?
then parse only variable after the ?
so i doing it linear, repeating many endpoints in the script.

/**

//RequestObject ro = new RequestObject(“objectId”)
RequestObject ro1 = new RequestObject()
ro1.setRestUrl(endpoint1)
ro1.setHttpHeaderProperties()
ro1.setRestRequestMethod(“GET”)
//ro.setBodyContent(new HttpTextBodyContent(body))

def test1 = WS.sendRequest(ro1)
WS.verifyResponseStatusCode(test1, 200)
def test1List = new JsonSlurper().parseText(test1.getResponseText())
println(‘response text Test 1: \n’ + JsonOutput.prettyPrint(JsonOutput.toJson(test1List)))

/**

  • Test 2
    */
    String endpoint2 = “http://${SiteHostName}:${Port}/api/items/drug?drugId=FF1/M2”

RequestObject ro2 = new RequestObject()
ro2.setRestUrl(endpoint2)
ro2.setHttpHeaderProperties()
ro2.setRestRequestMethod(“GET”)

def test2 = WS.sendRequest(ro2)
WS.verifyResponseStatusCode(test2, 200)
def test2List = new JsonSlurper().parseText(test2.getResponseText())
println(‘response text Test 2: \n’ + JsonOutput.prettyPrint(JsonOutput.toJson(test2List)))

@kazurayam this is for one param and repeating feeding different value, am I right?
I want something to handle multiple param. Object seems cannot works like one object holding multiple params and call one of the param or combination of param in test script, I am unable to do it.
Therefore I write Script directly.

one object holding multiple params

it is called Map in Groovy.

String host = GlobalVariable.SiteHostName
String port = GlobalVariable.Port

List<Map<String, String>> paramsList = [
    ["drugId":'FF1/M2/P2', "anotherParam": "foo", "moreParam": "bar"],
    ["drugId":"abc", "anotherParam": "def", "moreParam":"ghi"],
    .... as many as you want
]

paramsList.each { params ->
    String endpoint = "http:${host}:${port}/api/items/drug?drugId=${params.drugId}&anotherParam=${params.anotherParam}&moreParam=${params.moreParam}"
    ...
}