Test Automation Using SoapUI – How-To Guide

Hello! My name is Alexander Krylov, I am a Siebel CRM developer at Moscow Credit Bank.

After developing the next task, which is entirely based on integrations, we were faced with the question of functional testing before transferring it to full testing. The task was quite large, consisting of a dozen services, each of which was closely related to the previous business logic.

Just in case, I’d like to emphasize that test automation plays a key role in modern IT projects (in case anyone hasn’t guessed). This allows teams to speed up the testing process and improve product quality by increasing the number of test cases passed.

And just one of the powerful tools for testing web services is SoapUI, which offers ample opportunities for working with SOAP and REST. services. In this article, we'll look at how to effectively automate testing using SoapUI and integrate it into your CI/CD process.

So let's get started!

For example, let's build a simple service that checks a number – if the number consists of 3 characters, then the service will return Status – OK, otherwise NOT OK, and ERROR if internal errors are received.

image-2024-9-2_12-55-45

Putting together an autotest

First, you need to add a new TestSuite to your project (right-click on your project in the project tree):

image2022-2-15_13-6-49

Next, you need to create a TestCase on the created TestSuite. Added from the list when you right-click on TestSuite.

This is where the main logic of interaction between the steps of the case will take place. You can create more than one TestCase and describe different cases. The name speaks for itself.

image2022-2-15_13-26-36

After creating the case, you should get the following result:

ad956c3ac8f984c76c1a7916962c65bf

ad956c3ac8f984c76c1a7916962c65bf

Steps need to be added to the case itself. Let's add an XML request, fill it in Groovy scripts, condition on the parameter from the response, and execute the request in the database after 1 second when the OK status is received.

Additionally, we will add response validation and autotest parameterization, but first things first.

Adding steps

In the case window we can add steps that will be performed in order:

d3dbbd4726b6a745735461ee75232a96

We will need Properties, Groovy Script, SOAP request, Conditional GoTo, Delay and JDBC request:

4f2f3a794c1c2b7d6ce0c63bb1359614

After successfully creating the steps, each one needs to be configured. Access to the setting opens after double-clicking on the required step.

Properties

The Properties step does nothing; it is needed to store some data while the case is running. For example, UZ data or service address. Let's add them to our case:

ad05a5698a601e2cf71f0023efc0f7ff

SoapUI has an interesting feature: if you name the parameter “Password”, its value is masked.

We can also store the parameters themselves not only at the case level, but also higher in the hierarchy. For example, at the project level or create global ones for the application.

For our purposes, we will limit ourselves to case-level parameters.

Groovy Script

Groovy is a java-like language that greatly enhances the capabilities of SoapUI. In our example, we implement the generation of Number.

In order for the service to return different statuses, we will generate values ​​from 900 to 1100 and substitute them into the new parameter of the Properties step:

f682eba5a8e048389572b4ea7bf8533c

If the parameters used in the scripts are not created or deleted, the script will create them.

SOAP Request

Let's move on to the most interesting part – filling out the XML and setting up the entire request window.

Previously, we created parameters, now we have to use them. You can specify them anywhere and SoapUI will understand you.

Let's fill in what has already been created and make a test call to the service.

d47e0c5893b745822b50a68821f65cad

The service responded successfully, now let’s fill in the MessageId, also using generation, but in a different way.

In addition to specifying parameters in the request, we can write executable code. Here are some useful features:

Function

Description

${=java.util.UUID.randomUUID()}

UUID generation

${=(int)(Math.round((Math.random()*(ba))+a))}

Generating an integer in a span [a; b]

${=new Date().format('yyyy-MM-dd')}

Getting the current date

We use the first one for MessageId:

2e695e6f50de80ee6c2160ab6ecc4a99

To see what was inserted into the request, use the Raw tab:

58d116d24e96fa2f6d7abb8ad37a4994

For the current step, it remains to configure the validation so that when the ERROR status is received, the autotest stops.

d77497d2b2726acff4e4d8a79db7f907

Let's select XPath Match:

bd30ce072ba553b2dcb855a7498b708d
37802d9472fd46ce2affff2100822f9f

Now the autotest will stop if the service responded with ERROR status, in other cases it will continue to work.

147a0d2f02e2e01390f38bb982651e9b
d6358b69b77c3a8ff51e135c1765fc0b

Conditional GoTo

Next, according to the condition, we need to repeat the generation and send a second request after receiving the NOT OK status; the Conditional GoTo step will help us cope with this:

12ef32790e010caf0aa15b92b0e2429a

We have added a condition: If the status from the response is NOT OK, then go to the Groovy Script step, that is, go back 2 steps.

We will not add a condition to the OK status; the autotest will go to the next step without it, since it will not find a single suitable condition.

Delay

Above I wrote that we need to execute a query in the database in 1 second if we have passed the condition.

The Delay step is a regular timer that stops the execution of the case for the time specified in the settings. Specified in milliseconds:

1fb0d9c6ef10e7a4a4bb109ae3a17410

We will consider executing the request below.

JDBC Request

To execute a query in the database, we need to place the JDBC driver from the required database in the folder for the SoapUI application.

Next, open the settings window and specify the driver, connection string and the request itself.

Like the service address above, the connection string and the driver, I put them in the parameters:

cc7e36449672375b085d80208181c747

Since this is also a request, you can extract parameters from the response and process them in the case, but in the example we will not do this.

Validation is also present here. Apart from setting up a connection to the database, all settings are similar to the settings for a SOAP request.

Additionally

Also, in the example above, we did not consider transportation.

SoapUI allows you to do this using the Property Transfer step:

2d0aa369327a7ea6a02b94b9e547ac29

The image shows the setup for writing the MessageId parameter from the response to a SOAP request to the MessageId parameter of the Properties step.

This step can be useful, for example, to carry identifiers from a response to the next request.

Launch and results

In order to launch the entire case, you need to launch it in the case window:

5d5b8b105c7b4fe6b683a5a5c245bf5a
019c73bc36dc6baf1159fb62b6dd0410

FINISHED – means successful completion of all steps. The case logs describe which steps were performed and in what order. In case of errors, the status FAILED will be displayed.

After full setup, we got a full-fledged automated case, which:

  • Generates information for a SOAP request;

  • Performs a SOAP request;

  • When receiving the ERROR status, it stops;

  • When receiving the status NOT OK – starts from the beginning;

  • When receiving the status OK – waits 1 second and executes a query in the database;

Tips from the “thank you, I’ll think about it” or “best practice automation testing in SoapUI” sections:

  1. Data Validity Checking: Use various checks to ensure that the data returned by the service is correct.

  2. Decomposition of tests into projects: if there are many services, but they are not related, then it is worth dividing them into several projects.

Test automation with SoapUI is an effective way to improve development quality and speed up the release of new software versions. Using Groovy's power for complex scenarios, you can create a powerful automated testing process that works without your constant input.

If you have experience automating testing in SoapUI, share it in the comments. What tools and practices do you find most effective?

PS Test automation is not just a trend, but a real necessity in the context of the accelerating pace of development. Using SoapUI, you can significantly optimize your processes and improve product quality.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *