How To… SoapUI: Testing Client Timeouts and Delays

Every month on the third Tuesday as part of our How To…Series, we feature a new post with a guide on how to solve a particular problem with SOAP UI with guest blogger Brendan Connolly. This post looks at Soap UI Testing Client Timeouts and Delays.

Read the other posts in the How To series on Selenium, Appium and SOAP UI here.

And browse previous posts in the How..To SOAP UI series

How To…Use Dynamic Properties

How To…Test Client Timeouts and Delays

How To..Manage Basic Requests and Response Logging

How to…complete Parsing With Groovy

How To…Rest Without Wadl

———————————————————————————————-
A common concern when testing applications is how the client handles slow responses or timeout scenarios. Often times the challenge comes in finding a way to generate those conditions reliably for those test cases. While SoapUI may not be your first thought since it is an API testing tool, the ability to host Mock Services is built in for both SOAP and REST services. Lets take a look at how we can set up a basic mock service to test timeout conditions for our client applications.

If you don’t already have a SoapUI project you will need to create one.

Adding a Mock Service

SoapUI is a flexible tool and as usual there are multiple ways of accomplishing the same thing. It also allows you to mock a single request at a time or can autogenerate single mock service for all of your endpoints. Since the goal here is to introduce a delayed response to our application we will want to create separate mock services. This allows us to insert a delay for a specific service call without having to provide mock responses for all the services operations.

The steps are a subtly different when mocking SOAP and REST services.

SOAP

Right Click on the Operation or Request node you want to mock.

SoapAddToMockService

Enter the name of the new mock service, then click Ok.

SoapNameMockService

Click Yes on the Open MockResponse Editor Dialog.

SoapOpenMockResponseEditor

The Response Editor lets you define the response data that will be returned by the service.

SoapResponseEditor

REST

Right Click on the Request node you want to mock.

RestAddToMockService

Enter the name of the new mock service, then click Ok.

RestNameMockService

The mock service editor window will open.

Note: Rest Mock Services will be started automatically.

RestMockServiceEditor

Close the MockService Editor and follow the prompts to stop the service.

Open the MockResponse Editor Dialog.

RestOpenMockResponseEditor

The Response Editor lets you define the response data that will be returned by the service.

RestResponseEditor

Adding a Response Delay

Just like with setting up the mock services, adding a response delay is handled differently with SOAP and REST services.

SOAP

For Soap Services adding a response delay is as easy as editing a property.

Edit the response delay to your desired amount in milliseconds.

SoapAddResponseDelay

REST

For REST services its a little more complex, we’ll need to use the Groovy sleep command.

Open the Mock Service Editor

RestShowMockServiceEditor

Click on the On Request Script and enter the delay you want in milliseconds using the following command:  sleep([yourTimeoutHere])

RestOnRequestScript Soap UI Testing Client Timeouts and Delays

Start up your Mock Service

Open the Mock Service Editor by double clicking on your mock service in the navigation tree.
Click on the green triangle icon to start your service.

About the Author

Brendan

I am a Software Design Engineer in Test based out of Santa Barbara, California. Working in a variety of testing roles since 2009. I am responsible for creating and executing testing strategies and using his coding powers for developing tooling to help make testers lives easier. He writes tests at all levels from unit and integration tests to API and UI tests. I blog on testing and automation at Brendanconnolly.net or follow me on Twitter @theBConnolly
Find out more about @brendanconnolly