Search code examples
restgroovysoapuitestcase

Making testSteps interact with each others using SOAPUI


I'm new at using SOAPUI and I can't find how to properly test the REST URI on my server.

I want to test POST, PUT and DELETE on a given URI.

The POST method should create a new entry in my database and the server returns the generated key to access this element.

The PUT method is used to update an entry and required a JSON containing the key of the entry to be updated.

The DELETE method takes the key of the entry to be deleted.

So, I want to create a testCase for each URI with 3 testSteps

  • first step: Posting JSON to that URI, create a new entry and retrieve its key
  • second step: Updating the previous entry (I don't know how to generate a JSON containing the key)
  • third step: deleting that entry (same problem)

The key is generated by the server, so I have to retrieve it and pass it to the other steps.

So my question is in two parts:

  • How can I retrieve the response of the server ?
  • How can I generate the JSON to be sent by the two others steps ?

If you need more informations to answer my question, feel free to ask :)

I hope someone could give me some clues in order to do so.


Solution

  • Well, I am not sure if this answers your question, but this is what I did to grab JSON from the response string

    import groovy.json.JsonSlurper
    
    def slurper = new JsonSlurper() 
    
    def prevStepResponse = '${Create Customer - All fields#Response}'
    def prevRespString = context.expand(prevStepResponse) 
    def prev = slurper.parseText(prevRespString)
    
    assert prev.customerId > 0