Monday, February 13, 2017

How to modify testStepResult fields in SoapUI NG PRO

It was needed to modify standard JUnit style report in SoapUI NG (aka ReadyAPI! tool). testStepResult object has no writable fields ;( , but we know Java and especially its Reflection API ;)

Full problem history - https://community.smartbear.com/t5/SoapUI-NG/How-to-modify-testStepResult/m-p/135425#M30786

Hi,
I use log processing script (as TestSuite tear down script) used for a lot of our projects.
It gets information (like request URL) from testStepResult. But I need to add more information unique for every test step run into this object testStepResult. But it seems has only get... methods.
Is it possible to add custom fields and values into testStepResult object?



While deep learning Java I  found another solution, but it risky because you can modify testStepResult as much as you can and possibly lost test consistency.  Solution is Java Reflection API in general, but I use version from apache commons FieldUtils library:

In Events window:

import static org.apache.commons.lang3.reflect.FieldUtils.writeDeclaredField;

writeDeclaredField(testStepResult, "messages", ["Hiiiiiiiiiiiii!"], true);
log.info testStepResult.getMessages()[0]
Code modify private field  "messages" with List<String> type in testStepResult object.

Output:
<...> :INFO:Hiiiiiiiiiiiii!



No comments:

Post a Comment