Hi all,
For May, we are going to focus on API Testing tips, tricks, and tutorials to help you test better with the Katalon Platform.
Have you ever encountered difficulties attempting to obtain online service approach suggestions? Like the screenshot below…
If you do, then you should apply the syntax below:
import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.testobject.ResponseObject
RequestObject requestObject = findTestObject('HTML_GetResponse')
ResponseObject response = WS.sendRequest(requestObject)
response.getResponseText()
After fixing the request and response methods, we will address the primary question of API testing, which is: how to obtain the properties of the HTTP header or Local Variables of the API requests.
HTTP Header
In the HTTP Header, we have Content-Type and the API Key. Now, we will get the value of API Key with the scripts below:
RequestObject requestObject_UploadFile = findTestObject('Katalon_API_Demo_Requests/Post_Upload_File')
List headerProperties = requestObject_UploadFile.getHttpHeaderProperties()
def array = []
for(TestObjectProperty i: headerProperties) {
array.add(i.getValue())
}
print array[1]
println GlobalVariable.apikey
GlobalVariable.apikey = array[1]
println GlobalVariable.apikey
You can refer to the video below to learn more on how it works:
Please also feel free to refer to the link bebelow for a sample project:
https://dev.azure.com/linhnguyen0979/_git/KShare_APITesting_GetHTTPHeaderValues
Variables
import com.kms.katalon.core.testobject.RequestObject
RequestObject requestObject = findTestObject('Object Repository/Post_Upload_File')
Map<String, Object> variables = requestObject.getVariables()
print(variables)
If you find this article helpful, then don’t forget to leave us a like or a heart and share this article with your colleagues and teammates!
To see more KShare articles, simply navigate to the support tag.