Dragonfly
Dragonfly

Reputation: 217

SoapUI groovy script build string on condition

I have this string

log.info("My name is :" + name)

where name is a predefined String.

Now name can be either Peter or Mary depending on some boolean X. So result can be "My name is Mary" if X is true or "My name is Peter" if X is false. Now I know I can predetermine 'name' before doing log.info, but what if I wanted to do that within the same line? Something like:

log.info("My name is: " + if (X) then "Mary" else "Peter")

The above will give me unexpected token "+"

Upvotes: 0

Views: 105

Answers (1)

aristotll
aristotll

Reputation: 9175

This is quite simple. You can use ternary operator

log.info("My name is: " + X ? "Mary" : "Peter")

Upvotes: 1

Related Questions