jeudi 26 avril 2018

How to use setBodyContent(HttpBodyContent) in Katalon

I have been trying to update our test management API once the Katalon test has completed running.

We are using Adaptavist Test Management in JIRA. I am not trying to update the Katalon JIRA add-on by the way.

The API call, for Adaptavist, needs to be a POST and have a body message of items like the example {"projectKey": "FVS", "testCaseKey": "FVS-T1", "status": "Pass", "environment": "DEV"} I would eventually replace these items with the Katalon test result variables as appropriate.

I have created a Service Call in the Object Repository which deals with auth settings, this works fine if I test the request in the editor with these sample values.

When I come to add the script in the Test Case itself I am struggling to get it work, let alone replace the variables with the actual values.

I current have this :

//run test
WebUI.openBrowser('')

WebUI.navigateToUrl(GlobalVariable.MainURL)

WebUI.verifyElementClickable(findTestObject('img_img-responsive_1'))

WebUI.verifyElementClickable(findTestObject('img_img-responsive_2'))

WebUI.verifyElementClickable(findTestObject('img_img-responsive_3'))

WebUI.closeBrowser()

//update JIRA
RequestObject getJIRAUpdateObject = (RequestObject)findTestObject('Web Service 
Calls/Update JIRA')

String vsRequestBody = '{"projectKey": "FVS",  "testCaseKey": "FVS-T1",  
"status": "Pass", "environment": "DEV"}';

body = getJIRAUpdateObject.setHttpBody(vsRequestBody)

WS.sendRequest(getJIRAUpdateObject)

I also have the following additional imports

import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.testobject.RequestObject

Now in the script editor I am told that setHttpBody is now depreciated in Katalon version 5.4+ (I am using 5.4.1) and I should use setBodyContent(HttpBodyContent) instead, but when I look at the API documentation for this, I cannot work out the syntax of how I am supposed to use this instead.

Does anyone know how I should change the code, or have examples of how I need to change the above code to use this new method ??

Any help is much appreciated.

Aucun commentaire:

Enregistrer un commentaire