Question

I have constructed a string which has property names mixed in. I was expecting that when i use the string, the properties would be filled in with actual values. However this doesn't happen when i do a log.info instead it works only when i put the string/string parameter in the test request step.

//This string is stored in a test suite property.
//All the properties mentioned in the string, exist and have values.
<key xmlns="URL"><ownerDN>${#TestSuite#btc_OwnerDN}</ownerDN><context><contextItem name="${#TestSuite#btc_ContextItemName_1}">${#TestSuite#btc_ContextItemValue_1}</contextItem><contextItem name="${#TestSuite#btc_ContextItemName_2}">${#TestSuite#btc_ContextItemValue_2}</contextItem><contextItem name="${#TestSuite#btc_ContextItemName_3}">${#TestSuite#btc_ContextItemValue_3}</contextItem></context><type>${#TestSuite#btc_Type}</type><value>${#TestSuite#btc_Value}</value></key>

I want to use the string/string property in a groovy step Does anyone know if what i am trying to achieve possible? If yes, how to achieve this?

Was it helpful?

Solution

It seems context.expand is the answer to my problem. Printing just the content of the property or extracting the value of the property will not help as the properties within the string have to be expanded which seems to be automatic in a test request step.

prop = "PropertyName"
log.info testRunner.getTestCase().getTestSuite().getPropertyValue( prop )
//returns
<key xmlns="URL"><ownerDN>${#TestSuite#btc_OwnerDN}</ownerDN><context><contextItem name="${#TestSuite#btc_ContextItemName_1}">${#TestSuite#btc_ContextItemValue_1}</contextItem><contextItem name="${#TestSuite#btc_ContextItemName_2}">${#TestSuite#btc_ContextItemValue_2}</contextItem><contextItem name="${#TestSuite#btc_ContextItemName_3}">${#TestSuite#btc_ContextItemValue_3}</contextItem></context><type>${#TestSuite#btc_Type}</type><value>${#TestSuite#btc_Value}</value></key>

however if we use

log.info context.expand('${#TestSuite#btc_PartyKey}')

or

prop = "PropertyName"
pValue testRunner.getTestCase().getTestSuite().getPropertyValue( prop )
context.expand(pValue)

returns the string with values instead of property names

Sorry, I should have thought of context.expand before posting the question but leaving it here just in case someone else is thinking of this same problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top