** How to set string as setBodyContent **


#1

Can someone help !!!

How to set String as setBodyContent(HttpBodyContent)

The below doesn’t seems to work

//for text in bodyimport
import com.kms.katalon.core.testobject.impl.HttpTextBodyContent

def json=’’’{
“data”: {
“id”: 2,
“email”: “janet.weaver@reqres.in”,
“first_name”: “Janet”,
“last_name”: “Weaver”,
“avatar”: “https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg
}
}’’’

setBodyContent(new HttpTextBodyContent(json))

@duyluong


#2

Hello, you miss import for HttpTextBodyContent class. Press Ctrl + Shift + O to fix.


#3

Hi @Marek_Melocik

The import is available …
import com.kms.katalon.core.testobject.impl.HttpTextBodyContent
But still getting issue.


#4

And do you get the same exception? Can you share full console log?

I noticed that you do not call setBodyContent method on any instance - you should call it on RequestObject instance.


#5

SLF4J: The requested version 1.7.16 by your slf4j binding is not compatible with [1.6]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.
2019-06-06 13:23:47.827 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2019-06-06 13:23:47.835 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/Set/set response body
2019-06-06 13:23:48.229 ERROR c.k.katalon.core.main.TestCaseExecutor - :x: Test Cases/Set/set response body FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: Script1559796598318.setBodyContent() is applicable for argument types: (com.kms.katalon.core.testobject.impl.HttpTextBodyContent) values: [com.kms.katalon.core.testobject.impl.HttpTextBodyContent@74eb909f]
at set response body.run(set response body:14)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1559807624974.run(TempTestCase1559807624974.groovy:21)

2019-06-06 13:23:48.259 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/Set/set response body


#6

That’s the issue, you are trying to set body content to no object. You should create RequestObject instance first and set body content to the instance.


#7

I am not sure … can you help me on this.


#8

This may be helpful for you.