Ask a Question

I am not able to get output of remote shell script from groovy script in soapui

SOLVED
Mini
New Contributor

I am not able to get output of remote shell script from groovy script in soapui

for an example I have added below dummy code in shell file auto.sh -

CURRENTDATEONLY=`date +"%b %d, %Y"`
echo Current Date is: ${CURRENTDATEONLY}
sleep 2

 

and calling above shell script auto.sh from groovy script in soapui

 

def command = "C:/Program Files/PuTTY/putty.exe -ssh root@ip -pw passwd -m C:/auto.sh"
log.info command
def process = command.execute()
def outputStream = new StringBuffer()
def errorStream = new StringBuffer()
process.consumeProcessOutput(outputStream, errorStream)
process.waitFor()
log.info("return code: ${process.exitValue()}")
log.error("standard error: ${process.err.text}")
log.info("standard out: ${process.in.text}" + outputStream.toString())
context.testCase.setPropertyValue("propertyName", outputStream.toString())

 

running above groovy script opens a new putty prompt and runs command as expected, but i am unable to capture the output in testCase propertyName

 

o/p of groovy

Tue Jan 19 16:13:47 IST 2021:INFO:C:/Program Files/PuTTY/putty.exe -ssh root@ip -pw passwd -m C:/auto.sh
Tue Jan 19 16:13:54 IST 2021:INFO:return code: 0
Tue Jan 19 16:13:54 IST 2021:ERROR:standard error:
Tue Jan 19 16:13:54 IST 2021:INFO:standard out:

 

it would be great if someone can help me how to capture the o/p and store it in testcase property 

please correct me if something is wrong with code

4 REPLIES 4
Mini
New Contributor

I hope there is a solution for this but I am stuck here, can someone please help me @TanyaYatskovska  @nmrao @Lucian and team?

 

SiKing
Community Expert

Try replacing new StringBuffer() with new StringBuilder().

Mini
New Contributor

Hi @SiKing I tried replacing new StringBuffer() with new StringBuilder()

but neither o/p showed in groovy logs nor stored in testcase property

Mon Jan 25 17:09:05 IST 2021:INFO:return code: 0
Mon Jan 25 17:09:05 IST 2021:ERROR:standard error:
Mon Jan 25 17:09:05 IST 2021:INFO:standard out:

SiKing
Community Expert

I think you are looking for the output in the wrong place.

log.info("return code: ${process.exitValue()}")
log.error("standard error: ${errorStream}")
log.info("standard out: ${outputStream}")

Have a look here.

cancel
Showing results for 
Search instead for 
Did you mean: