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).
In the test step properties, the Service property is READ-ONLY (see below). Chess-mate.
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:
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:
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!
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
Senior test automation and integration engineer
1yHned mi cvaklo, co myslel Filip, kdyz říkal ze s tebou mluvil 😁
📍API & Integration Architect
1yFilip Aron Ondřej Škoda