SoapUI: What if REST API changes?

SoapUI: What if REST API changes?

There's a new REST API, version 1.0.0. Cool, let's test it... Finally, you have a bullet-proof test consisting of seven test cases, each with multiple test steps.

Two months later, a new REST API version came out. OK, why not? Let's import it into my SoapUI project and update my tests.

Oh no, I will have to go through all the test steps! 🤨 One by one?!

Even worse, I cannot change the API of the test step! There is no way to do it. I can only change the operation from the SAME API in the Test Step editor (see the screenshot below).

Article content
You cannot switch to another API

In the test step properties, the Service property is READ-ONLY (see below). Chess-mate.

Article content
The Service property is read-only.

Indeed, you are the first person🧍 on Earth🌍 to test REST APIs with SoapUI, whose API has changed. If you get into such an improbable situation, you must give up and create the tests once again from scratch. 🤦🏻

Never! Let's hack the good-old SoapUI to do what we need.

Changing the Test Step relation to the API

Let's import the new version's OpenAPI (use YAML format) into SoapUI. You can rename it in the Properties window below like I did, having two versions:

  • BankGround_v1.10
  • BankGround_v1.12

Article content
Import a new version of the API

SoapUI offers powerful scripting. You can do everything you do in GUI via scripting. But you can also script things you cannot do by GUI, such as in this case.

The usual challenge is to find how. You can look at the SoapUI javadoc (see [1] in References) or the source code.

We want to modify the REST Request test steps. The appropriate SoapUI Java class is RestTestRequestStep. See the following URL to get available methods:

https://www.soapui.org/apidocs/5.5.0/com/eviware/soapui/impl/wsdl/teststeps/RestTestRequest.html

If you go through the docs and some try-err attempts, you will find the method getRequestStepConfig().

We now have the test step's configuration and can set the new API using the setService() method. The following Groovy script goes through all the test steps of the test case and changes the API to "BankGround_v1.12" (the new version).

testRunner.testCase.getTestStepList().each(){
	step = it
	service = step.getService()
	log.info("TestStep: ${step.getName()}")
	config = step.getRequestStepConfig() 
	log.info "Before: ${step.getService()}"
	config.setService("BankGround_v1.12")
	log.info "After: ${step.getService()}"
}        

Once you execute the script, you can see the results in the Script log. Now, check your Test step.

There is a new API version! Excellent, it works!

Article content
The test step with the new API

Summary

This little hack can help you maintain your REST API tests. Have fun extending the script to suit your needs and automating what can be automated.

Let me know in the comments if you are one of the rare people who test REST APIs in SoapUI and come across new versions of the APIs. 😉

References

[1] SoapUI Javadoc Reference https://www.soapui.org/apidocs/5.5.0/index.html

Related Articles

SoapUI hack for OpenAPI 3, https://www.garudax.id/pulse/soapui-hack-openapi-3-karel-husa-9dsxf





Ondřej Škoda

Senior test automation and integration engineer

1y

Hned mi cvaklo, co myslel Filip, kdyz říkal ze s tebou mluvil 😁

Like
Reply

To view or add a comment, sign in

More articles by Karel Husa

  • Fix XML content-type recognition in SoapUI 5.8.0

    The latest open-source SoapUI 5.8.

    5 Comments
  • Test cases in Bruno, part 1

    Most 📍API operations are not isolated. We usually have an API use case where we call multiple operations in the proper…

    3 Comments
  • Bruno, helper dog for your APIs

    I love visual API tools. I have been playing with APIs for 20 years.

    12 Comments
  • SOAP in a REST room

    Recently, one of the API consumers asked me for an API definition. I told him the API is a SOAP service and offered to…

  • How GPT talks to APIs

    OpenAI GPTs are able to integrate with your favorite APIs via Actions. The question is, how to tell GPT enough about…

    3 Comments
  • Troubleshooting GPT Actions: Path parameters

    OpenAI Actions is a powerful tool to connect GPTs with any other applications via APIs. Sometimes the integration is…

    1 Comment
  • Postman jailed in an internal network

    Postman is a cool tool to work with APIs: publishing API definitions, testing APIs. creating virtual mock APIs or…

    2 Comments
  • SoapUI hack for OpenAPI 3

    SoapUI had been a leading testing tool and in many places it's still popular and in use. One of the main pain-points…

    4 Comments
  • SoapUI is over. What next?

    SoapUI has been a top-notch API exploratory and integration testing tool for almost 20 years. It is simple and friendly…

    3 Comments
  • A tricky difference between JSON(Path) and XML(Path)

    Developers and testers familiar with XPath may become frustrated when trying to make more complex JSONPath expressions.…

    2 Comments

Explore content categories