Help adding Assertions with Groovy Script
Hi gents,
First time poster here, I am in desperate need of your help. I've tried scouring the web trying to find a simple solution to my problem, but haven't been able to find it. I am a total SoapUI noob, and what little I know has been self-taught.
First off let me put you in perspective of why I need a quicker solution for my problems. I'll try not to provide too much details as I'm not sure what I am allowed to talk about/post.
I've been given a task of curating a rather large (at least in my mind) library of REST tests. I have multiple SoapUI projects which contain 10 Test Cases each (one for each user), which further contain between 50 and 300 Test Steps Each.
A Project has the following structure:
- Project Name:
- Test Case Alpha User:
- Authentication Step
- Property Transfer Step
- Test Step With a Name
- Test Step With a Name
- Test Step With a Name
- Test Step With a Name
- etc...
- Test Case Beta User:
- Authentication Step
- Property Transfer Step
- Test Step With a Name
- Test Step With a Name
- Test Step With a Name
- etc...
- Test Case etc...
The Project has 11 Custom Properties:
- DB Name property
- User Auth. Token Alpha
- User Auth. Token Beta
- etc.
Steps are configured like this:
The Authentication step contains a pointer to the DB Name property and contains User Name/ID, User Password and some filter values, and returns (among other things) an Auth. Token.
The Property Transfer step takes that Auth. Token and writes it into the appropriate Custom Property (Let's say "User Auth. Token Alpha")
A Test Step contains a field that points to the DB Name property, a field that points to the User Token property and some filters.
For Assertions, I used the "Contains" type to input an exact string I would receive as a part of the Raw Response (different for each test).
Example of Raw Response:
HTTP/1.1 200 OK Content-Security-Policy: default-src *.environment.com 'unsafe-inline' 'unsafe-eval' Content-Type: application/json Date: Thu, 01 Mar 2018 01:01:01 GMT Referrer-Policy: no-referrer-when-downgrade Strict-Transport-Security: max-age=31536000; includeSubDomains X-Powered-By: Servlet/2.5 JSP/2.1 X-XSS-Protection: 1; mode=block transfer-encoding: chunked Connection: keep-alive {loooooong string that is actually used in the Assertion}
So, the problem is that the string can change when there is some new development on the REST API's, which invalidates all my tests which were working so far.
My question is:
Is there an easy way I can use Groovy Script to create Assertions in my Projects?
I was thinking about something like:
- Run All Test Cases without Assertions (which will give me the needed Responses)
- Create a Groovy Script step which will take the string from the Raw Response from each of the Test Steps and make an Assertion for each of them.
- Disable the Groovy Script step
- Test if all Test Steps Pass
- Delete the Groovy Script step
- Rinse and repeat for all Test Cases and all Projects
I am ashamed to admit this, but doing this manually will take me two months and it's just not feasible to do it every time there's a change in the API's.
I something like this doable?
If you need more info or details, please let me know, I will provide whatever I can just to get this sorted out.
Thanks in advance to the SoapUI community!