Forum Discussion

smartTest's avatar
smartTest
Contributor
15 years ago

Multiple Contains Assertions - Can they be grouped?

I'm a relative newcomer to both SoapUI and Groovy/xPath and am struggling to find a way of creating a single assertion to check a response message for a set of different nodes and their attributes. I have one test now that includes over 10 'Contains' assertions looking at different sections of the message and I'm sure there must be a simpler way!

Can anyone help?

2 Replies

  • I think you could do one big script assertion with multiple assertions; I believe the script assertion feature is available in the free version.

    For example, say your response had three nodes you wanted to check, Node1, Node2, and Node3.

    Your script assertion might look something like this:


    def node1 = context.expand {Node1} /// you can right-click inside a script assertion to create a new variable that references any node in the response. From the right-click
    def node2 = context.expand {Node2} /// popup, choose your request step, then choose Property [Response], then click the node whose value you want.
    def node3 = context.expand {Node3}

    assert node1 == 'a' /// you'll have to create the assertions yourself; this assertion checks to see if node1's text is equal to 'a'.
    assert node2 == 'b'
    assert node3 == 'c'


    The assertion should fail if any one of the asserts fails, and should pass if they all pass.

    I haven't tried this myself but in theory it should work. (I like to keep the node assertions separate so I can report on each node assertion result.)
  • deepesh_jain's avatar
    deepesh_jain
    Frequent Contributor
    The code explained above would work, however, there is a slight problem, since this is groovy script, if the first of the assertions fails, it won't even check for the remaining two. The tackle that, its best to initialize a counter to 0 and increment that whenever the test fails.

    And finally assert the script to true if the value of counter is 0 or else false.