
If you missed the first two parts of this series, you may want to check them out first here and here. Today I want to show a few more enhancements to make a test case more flexible. We’ll be using the simple add method of the Arithmatics service to calculate the beginning of the Fibonacci Sequence (Wikipedia).
The screenshot below shows the initial Test Case setup: I added two properties, Number1 and Number2, and initialized them to the start values of the Fibonacci series (0 and 1). There is also the first addition step (in this case we won’t loop over the step but add a new step for each addition. Looping has to be scripted in the Open Source edition of soapUI).

def tc = testRunner.testCase; //Get a handle for the test case object def tc = testRunner.testCase; //Reset "Number1" to 0 tc.setPropertyValue("Number1", "0"); //This is just to show how to log and assert property values def num1 = tc.getProperty("Number1").value; log.info("Number1 was set to " + num1); assert num1 == "0" : "Updating Number1 failed"; //Reset "Number2" to 1 tc.setPropertyValue("Number2", "1");
def tc = testRunner.testCase; def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) // create holder for the response of "Add 1" Test Step def holder = groovyUtils.getXmlHolder( "Add 1#Response" ); // register the namespace (needed for XPath expression below) holder.namespaces["qat"] = 'http://math.qat.com/'; //Get handle for test case def tc = testRunner.testCase; //Set Number1 to current value of Number2 tc.setPropertyValue("Number1", tc.getPropertyValue("Number2")); assert tc.getProperty("Number1").value == "1" : "Updating Number1 failed"; // Set Number2 to the result of the "Add 1" Request log.info(holder.getNodeValue('//qat:addReturn')); tc.setPropertyValue("Number2", holder.getNodeValue('//qat:addReturn')); assert tc.getProperty("Number2").value == "1" : "Updating Number2 failed";
Tip: When editing properties like that, it may be better to test the script by running the whole test case or temporarily add a section to initialize the properties to the expected values to guarantee that the properties are in the right state.
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) // create holder for response of "Add 1" to obtain first operand def holder = groovyUtils.getXmlHolder( "Add 1#Response" ) // register namespace holder.namespaces["qat"] = "http://math.qat.com/" def num1 = holder.getNodeValue( "//qat:addReturn" ) assert num1 == "1" : "Retrieving 'Add 1' result failed" // create holder for response of "Add 2" to obtain second operand holder = groovyUtils.getXmlHolder( "Add 2#Response" ) holder.namespaces["qat"] = "http://math.qat.com/" def num2 = holder.getNodeValue( "//qat:addReturn" ) assert num2 == "2" : "Retrieving 'Add 2' result failed" // create holder for request of "Add 3" and set operands holder = groovyUtils.getXmlHolder( "Add 3#Request" ) holder.namespaces["qat"] = "http://math.qat.com/" holder.setNodeValue( "//qat:number1", num1 ) holder.setNodeValue( "//qat:number2", num2 ) // update "Add 3" request holder.updateProperty()

Of course, there are lot more efficient strategies to set up this particular scenario than shown here, especially in soapUI Pro. I just wanted to show a few options for passing properties from one request to the next to build a more complex test case where the next request depends on the outcome of a previous call.
Anke
Written by: Anke Doerfel-Parker |
Connect with us: