Forum Discussion

Clear_Capital__'s avatar
Clear_Capital__
Contributor
11 years ago

[Resolved] assertion against multiple expected values

I am using soapUI Pro 4.6.4

I have a need were I need to make sure say a "State" field in xml or Json response should have the value of CA or AZ or OR or MA. This is for a REST service.

How do i do it ?

Someone asked similar question, but I believe the reply does not solve the need.

viewtopic.php?f=14&t=21121&p=47544&hilit=validate+multiple+value&sid=7994fae8c6058f407d902bbdd59a4f03#p47544

thanks

Jignesh
  • SiKing's avatar
    SiKing
    Community Expert
    As an XPath assertion
    exists(//*:State[text()='CA'] | //*:State[text()='AZ'] | //*:State[text()='OR'] | //*:State[text()='MA'])

    As a Script assertion

    def state = context.expand('${' + context.currentStep.name + '#ResponseAsXml#//*:State}')
    assert ['CA', 'AZ', 'OR', 'MA'].contains(state)
    • aedahh's avatar
      aedahh
      New Contributor

      Hello, newbie to soapui here...

      The answers provided seem to be for response content that is XML only not JSON, is this correct?

      How would assert for contains multiple values on a json response that is something like this:

       

      {
      "result": true,
      "content": [
      "abc",
      "def",
      "ijk",
      [... <more content>...]
      ]
      }

       

      Thanks

  • thanks a lot SiKing

    How would the "Expected Result" in Xpath assertion look like for the following "Xpath Expression"

    //ns1:Response[1]/ns1:address[1]/ns1:state[1]
  • this script assertion seem to be working.

    utils = new com.eviware.soapui.support.GroovyUtils( context )
    holder = utils.getXmlHolder("myRestStep#ResponseAsXml" )
    StateField = holder.getNodeValue( "//*[local-name()='state']" )
    assert StateKey != null
    assert ['CA', 'AZ', 'IL', 'MA'].contains(StateField)

    thanks again Siking
  • SiKing's avatar
    SiKing
    Community Expert
    Clear Capital* Support wrote:
    How would the "Expected Result" in Xpath assertion look like for the following "Xpath Expression"

    //ns1:Response[1]/ns1:address[1]/ns1:state[1]

    Is this a new question, or is this still related to the discussion here? I don't know, probably some kind of string?

    Clear Capital* Support wrote:
    this script assertion seem to be working.

    More than one way to skin a cat.
  • That was the question before I put together what I needed with the help of your first response. I am good now . Thanks again.