Elastic Path supports web services via the Simple Object Access Protocol (SOAP), and provides support for obtaining and updating information for orders. The problem is, how do we actually test the web services component? One could write a custom SOAP client that interacts with the the SOAP server. However, there is an excellent tool available currently (and free) that can simulate sending a SOAP request, getting a response from the server, and then examining the data.
*Drum roll*
Introducing SoapUI. SoapUI is a Java-based program that aims to automate web service calls and can integrate into your testing framework. In this article we will go through the steps and create a test case that can be run automatically after the initial setup. We will introduce scripting in Groovy, a derivative of Java language.
The goal of this exercise to get used to the SoapUI framework and making a test suite consisting of updating a SKU, then checking to make sure that SKU has been updated. It can be run from the command line, and can generate reports/results, which could potentially be used in build reports.
To get started, you will need to have the following things ready:
SoapUI software. To get SoapUI, please visit http://www.soapui.org and get the latest version (at the time of writing, 2.5 is the most current version and will be used in this article)
The address of the Web Service Description Language file (WSDL). In this example the address is https://<your_domain>/webservices/catalogwebservice?wsdl where <your_domain> refers to the domain of your deployment
Permission priliveges to access web services. To create permissions you have to select the Web Service Role when creating a new CM user in the Commerce Manager client.
Have available SKU code information for use by the web services.
Step 1 - Creating a project
Open SoapUI, and then click on File->New soapUI Project.
In the Project Name text box, put in example1
In the Initial WSDL/WADL, type in the URL of the web service definition file (bullet number 2 in the previous section)
Press OK
A list of operations should appear on the left hand column. For the purposes of this demonstration, we will only test two operations, getSku and updateSku. Next, we will need to create a new TestSuite. Right click on the project name and then click on New TestSuite. Name it TestSuite 1 for the purposes of this test.
Now create a new TestCase by right clicking on TestSuite1 and click on New TestCase. Name it TestCase 1 for the purposes of this test.
Step 2 - Configuring the test case
The next step is to configure the test case so we can run the test. First we need to set the global settings. Click on the key icon and set the credentials for the username and password.
This username/password combination should match the user that has Web Services permission set in the Commerce Manager. Leave the Domain blank in this case.
The next step involves setting a property that can be accessed by the whole test case. Click on the Properties button.
Now add a property name called 'start' by click on the left-most icon. For the purposes of this test, we will name it 'date'. Give it a value of '2050-01-01T12:12:12.643-08:00'.
Step 3 - Adding the first SOAP request
We need to add a few SOAP requests first. Add the first SOAP request by clicking the little SOAP icon.
Name that request 'getSku', press Ok and click on CatalogWebServicePort->getSku from the dropdown box in the next dialog. Finish by clicking 'OK'. Now request window will open. Now on the left pane, the XML generated using the schema from the WSDL will be present. For this test case, use a SKU code that exists in the system and enter it in the <SkuCode> element. I chose '1YESPE' for this particular test. If you know the catalog that the SKU belongs to, put it between the catalog tag. Next we have add an assertion that the response is successful. We do that by clicking on the Assertions button and then clicking on the '+' button, then select 'Xquery Match' from the dropdown box. Fill in the details based on the values from below.
Press Save. By doing this, every time the test step is run, a validation check will occur. It will pass the check only if we see that the status of the test is succesful.
Queries using XPath are invaluable because they test can expected node values coming from the response. Since EP's Web Services returns a result status, it is ideal to evaluate the result using XPath queries. For more information on how to use XPath queries, please goto http://msdn.microsoft.com/en-us/library/ms256086.aspx
Step 4 - Adding the first Groovy script
SoapUI uses Groovy, an agile dynamic language for the Java platform. I won't go into details about Groovy, but basically if you know Java, then you know Groovy. To learn more about Groovy, please visit http://groovy.codehaus.org/.
For the first step of this part, you will need to add a test step to the test case. Right click on the test step on the left hand column and then click on Add Step -> Groovy Script.
A new window will appear. Fill in the following information in the box.
//gets the xml utilities
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
//get the reponse part
def holder = groovyUtils.getXmlHolder( "getSku#Response" )
//get the original start date
def startDate = holder.getNodeValue( "//StartDate" )
//assign it to a session variable to be used later
testRunner.testCase.setPropertyValue('temp', startDate);
//now update the Request of the second request
def holder2 = groovyUtils.getXmlHolder( "updateSku#Request" )
//gets the start date node and set it to our date
def startDate2 = holder2.setNodeValue( "//StartDate", testRunner.testCase.getPropertyValue('date'))
//update the change
holder2.updateProperty()
What does this do? Basically this will retrieve the startDate timestamp from the previous soap request and assign it to a variable, which will be used later at the end. This script also sets the variable of the next request so that it can be sent to the server. To read more on how to script your tests with Groovy in SoapUI, please visit http://www.soapui.org/userguide/functional/groovystep.html.
Step 5 - Configuring the rest of the test
Next we configure the rest of the steps. The rest of the test consists of:
Adding a SOAP request to update the SKU, and then checking the results.
For this request, we once again use assertions to help us identify potential problems. Create a new Xquery Match assertion and copy the data below into the boxes and press Ok.
Adding a Groovy script to retrieve the time stamp that was saved previously, and set it in the subsequent request.
This step is similar to the one before, and it will update the next SOAP request with original value that we retrieved (and saved) in the first request. The code is listed below.
//gets the xml utilities
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
//now update the Request of the second request
def holder = groovyUtils.getXmlHolder( "updateSku2#Request" )
//gets the start date node and set it to our date
def startDate = holder.setNodeValue( "//StartDate", testRunner.testCase.getPropertyValue('temp'))
//update the changes
holder.updateProperty()
Adding a SOAP request to update the SKU again, this time we replace the start date with the original date we retrieved from the first request (so that we don't have actually change any data in this test).
This step is identical to the previous updateSku request. We can actually make a clone of the last request and run that. The only difference is the value of StartDate, which actually will be changed by the Groovy script from above. To make a clone of the previous step, right click on the last SOAP request, and then click 'Clone TestStep'. Name the new step updateSku2.
Running the test case and making sure they pass
- Run the test case by pressing the arrow button in the Test Case 1 window.
- If you have done everything correctly, all the tests should be green when you run the test. Your screen should look similar to the following.
SoapUI is a powerful tool that is designed to test web services. It can be used as a functional testing tool, a regression testing tool and an unit testing tool. Furthermore, it has built in capabilities to run using command line and can generate reports after each run. This tutorial is just a fraction of the things that SoapUI can provide a QA team when it comes to testing web services.













