26 September 2007 - 1.7.6 home user-guide eclipse jbossws intellij netbeans maven 1.X/2.X PDF files forums bugs sourceforge






Interactive Testing

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 indata 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:
  • A Properties Step to hold global properties
  • A Groovy Step for showing an input dialog
  • A Property Transfer that transfers the input value to the search request
  • A Request Step that performs the search
  • A Property Transfer that gets the result to a global property
  • A Groovy Step for displaying the result

Properties

The following properties will be defined:
  • Author : holds the author entered by the user
  • SubscriptionID : holds the Amazon subscription id
  • ResultCount : holds the result count for display

Groovy Input

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.

Search Args Transfer

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 epression. 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)

Using Property Replacement

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).

Search Request

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>

Result Transfer

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()

Groovy Display Result

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

Running the TestCase produces the following input dialog:

and shows the following result:

Summary

The example above is very simple but shows the possibilites, 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... ;-)


Next: Surveillance Testing