How to trim (space) the variables in the the assertion section in SoapUI?

Arbind Singh picture Arbind Singh · Oct 6, 2017 · Viewed 25.3k times · Source

How to trim (leading and trailing spaces) the variables in the the assertion section of SoapUI/ReadyAPI ?

Ex:
Input String : "Failure   "
Output String : "Failure"

Ready API Assertion Popup

Answer

Chris Adams picture Chris Adams · Oct 6, 2017

Use trim for trailing spaces. Use replace to get rid of spaces.

def trimExample = "Some string to be trimmed.      ";
def trimmed = trimExample.trim();

def removeSpacesExample = "Some String To Lose All Spaces."
def removedSpaces = removeSpacesExample.replace(' ', '');

Use log.info(varName) to see the effect.