Forum Discussion

Knowledge's avatar
Knowledge
Contributor
9 years ago

Changing a value of project/test case property within REST Test Step

Hi,

 

 

Is it possible to change value of project/test case property within REST Test Step?

For example:

Custom property “MsgId” with certain initial value defined for SoapUI project.

This property can be used a number of times within a body of  a REST request for separate (sub-) requests and its value for each (sub-)request should be unique.

Simplified example of the REST request body:

<ReqSet>

     <Request1 MsgId=”${#Project#MsgId}” ... />

     <Request2 MsgId=”. . .” ... />      <!-- How to change value of MsgId for the Request2? -->

     <Request3 MsgId=”. . .” ... />      <!-- How to change value of MsgId for the Request3? -->

     . . .

</ReqSet>

 

Note that request 2 and request 3 are not different REST requests, but a part of the same REST request.

 

Any help would be much appreciated.

 

Thanks

  • Yes, you can retrieve the property value and then modify it, please see the following code:

     

    <request1>${#TestCase#i}${=testCase.setPropertyValue("i", String.valueOf(Integer.parseInt(testCase.getPropertyValue("i")) + 1))}<request1>
    <request2>${#TestCase#i}${=testCase.setPropertyValue("i", String.valueOf(Integer.parseInt(testCase.getPropertyValue("i")) + 1))}</request2>

    Karel

     

  • KarelHusa's avatar
    KarelHusa
    Champion Level 1

    Yes, you can retrieve the property value and then modify it, please see the following code:

     

    <request1>${#TestCase#i}${=testCase.setPropertyValue("i", String.valueOf(Integer.parseInt(testCase.getPropertyValue("i")) + 1))}<request1>
    <request2>${#TestCase#i}${=testCase.setPropertyValue("i", String.valueOf(Integer.parseInt(testCase.getPropertyValue("i")) + 1))}</request2>

    Karel

     

    • Knowledge's avatar
      Knowledge
      Contributor

      I had to change the order but it worked :)

      thanks a lot for the help!

  • KarelHusa's avatar
    KarelHusa
    Champion Level 1

    You can also use multiple statements in the inline code:

     

    	<request1>${=int n=Integer.parseInt(testCase.getPropertyValue("i")); n++; testCase.setPropertyValue("i", String.valueOf(n));n}<request1>
    	<request2>${=int n=Integer.parseInt(testCase.getPropertyValue("i")); n++; testCase.setPropertyValue("i", String.valueOf(n));n}<request2>

    Karel

     

  • nmrao's avatar
    nmrao
    Champion Level 3

    You may just use uuid which will be unique as shown below.

     

    <ReqSet>
         <Request1 MsgId="${=java.util.UUID.randomUUID().toString()}" ... />
         <Request2 MsgId="${=java.util.UUID.randomUUID().toString()}" ... />
         <Request3 MsgId="${=java.util.UUID.randomUUID().toString()}" ... />
         . . .
    </ReqSet>