09 July 2009 - 3.0 |
Using the Groovy TestStep, it is possible to create both input and output dialogs, which can be useful if you for example want to make it easy to run your tests with user-supplied in data or if you want to provide a soapUI project containing TestCases as demonstrations of your web services for your clients.
In this example we will create a TestCase that performs an Amazon Book search
on Author and displays the number of hits. We need the following TestSteps:
| ![]() |
The following properties will be defined:
| ![]() |
The following script will be used to ask the user for the author to search on:
// create dialog def dialog = com.eviware.soapui.support.UISupport.createConfigurationDialog( "Amazon Query" ); dialog.addTextField( "Author", "The Author to search on" ); // init values and show def map = new java.util.HashMap(); map.put( "Author", "" ); if( dialog.show( map )) { // get target step def step = testRunner.testCase.getTestStepByName( "Properties" ); // assign step.setPropertyValue( "Author", map.get( "Author" )); } else testRunner.cancel( "No author to search on!" );
When running the script, the user will be prompted with a dialog and the entered value will be set in the Global Properties Step.
The Search Args Transfer contains 2 property transfers, one for the SubscriptionID and one for the Author property. Each is transferred from the Global Properties step to the Search Request using an XPath expression. For the SubscriptionID this is:
declare namespace ns='http://webservices.amazon.com/AWSECommerceService/2006-03-08'; //ns:SubscriptionId/text()
and for the Author it is
declare namespace ns='http://webservices.amazon.com/AWSECommerceService/2006-03-08'; //ns:Author/text()
(See the following Request Step to see the target XML)
As of soapUI 1.6, it is possible to use the common ${propertyName}
to expand properties
as described in Property Expansion. Using this feature we
can remove the "Search Args Transfer" step and instead use the following request:
<ns:ItemSearch> <ns:SubscriptionId>${SubscriptionId}</ns:SubscriptionId> <ns:Request> <ns:SearchIndex>Books</ns:SearchIndex> <ns:Author>${Author}</ns:Author> </ns:Request> </ns:ItemSearch>
This will result in the values for SubscriptionId and Author being copies into the request just before it is sent (the inserted values will not be written into the request seen in the editor).
The following search request will be used:
<soapenv:Envelope xmlns:ns="http://webservices.amazon.com/AWSECommerceService/2006-03-08" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <ns:ItemSearch> <ns:SubscriptionId>?</ns:SubscriptionId> <ns:Request> <ns:SearchIndex>Books</ns:SearchIndex> <ns:Author>?</ns:Author> </ns:Request> </ns:ItemSearch> </soapenv:Body> </soapenv:Envelope>
This step extracts the number of hits in the result and transfers it to the Global Properties "ResultCount" property using the following XPath expression:
declare namespace ns1='http://webservices.amazon.com/AWSECommerceService/2006-03-08'; //ns1:TotalResults/text()
The following script will be used to display the result:
// get target step def step = testRunner.testCase.getTestStepByName( "Properties" ); com.eviware.soapui.support.UISupport.showInfoMessage( "Got " + step.getPropertyValue( "ResultCount" ) + " hits for author [" + step.getPropertyValue( "Author" ) + "]" );
Running the TestCase produces the following input dialog: ![]() | and shows the following result: ![]() |
The example above is very simple but shows the possibilities, creating more complex UI's and flows is definitely possible, but maybe questionable as soapUI is not (yet?) a BPEL tool and has been created for other purposes. But then again... if it works and helps you out... ;-)