Forum Discussion

jsreesoap's avatar
jsreesoap
Contributor
12 years ago

[Resolved]Dynamic proplerties not getting values assigned

for (x in 0..1)
{

//testRunner.testCase.setPropertyValue("IndAcct",myArray[x])
testRunner.testCase.setPropertyValue("AccountId",myArray[x])
def responseAsXml = context.expand( '${GET Restrictions on an Account#ResponseAsXml#//Response[1]/e[1]/accountRestrictionId[1]}' )

testRunner.testCase.setPropertyValue("Restriction"+[x],responseAsXml)
}
I created an array and assigned account numbers accordingly. So myArray[0] has value 123 and myArray[1] has value 456.
I have the above code to run 2 account numbers and get restrictions on those respectively. The restriction id comes in the same node every time as shown in the script. As the value is dynamic I am writing to dynamic property (every time I run it is supposed to create the property and write the value. For example first time it runs account 123 whcih has restrictions id as abc123 it writes the restrictions id to Restriction0 property.Second time it picks up the other account 456 with restrictions id xyz456 and writes to Restriction1 property. When I execute the script it is creating the dynamic properties but not writing the values. I have to click on the play button in groovy script to make it write. Then it writes the last value to both the properties.
Attached is the screen shot. Basically I need to run bunch of accounts in iterations and each iteration will pick up the restricion id for that account. This restriction id and the corrosponding account number should be written to different properties so that I can use those account and restriction pair in my other script to delete restriction on each account.
I understand you dont support the coding but in this case when I retrieve the response value from the response with built in funtion and assign to dynamic property it is not writing the value.
Any help is appreciated

3 Replies

  • Hello,

    Is it possible for you to send me the screen shot you are talking about, I dont see it on this post. The project file will also help, If this is an issue with SoapUI, we will let you know. Thanks.

    Regards,
    Temil
  • Hi
    It is writing the values now (Thanks to Jeshtha) but my problem is I need to pick up the value from the same location like 'def responseAsXml1 = context.expand( '${GET Restrictions on an Account#ResponseAsXml#//Response[1]/e[1]/accountRestrictionId[1]}' )' and write it to a dynamically created property. In each iteration the value changes. In each iteration I am feeding a different account number. So first time it picks up the restriction id and writes it to RestrictionIdi1 but when it runs second time (x==1) it is replacing the RestrictionIdi1 with the latest (restriction id of the second account number) which in my opinion should not as it is not executing condition x==0. Attached is my project file, I removed authorization step for security reasons.

    Here is my code:
    for (x in 0..1)
    {
    if (x==0)
    {
    def responseAsXml0 = context.expand( '${GET Restrictions on an Account#ResponseAsXml#//Response[1]/e[1]/accountRestrictionId[1]}' )
    testRunner.testCase.setPropertyValue("RestrictionIndi" +[x],responseAsXml0)
    }
    if (x==1)
    {
    def responseAsXml1 = context.expand( '${GET Restrictions on an Account#ResponseAsXml#//Response[1]/e[1]/accountRestrictionId[1]}' )
    testRunner.testCase.setPropertyValue("RestrictionIndi" +[x],responseAsXml1)
    }
    }

    Thanks
  • This is resolved. Thanks again to Jeshtha.
    I want to share the resolution here, just in case any one is trying to get the dynamic value from response from the same node like I mentioned above.
    In each iteration it should pick up a new input value and feed it to the URL, get the the node value from response and write to the newly created property. If you need to pick up more values from the nodes then you need to experiment, and pls let me know how it is done.
    --
    We used data source grid to create iterations and input values.
    In test case right click and add data source
    In data source window click on + sign and add a property/parameter and name it 'rows' something like that
    Follow the same step and create one more parameter and name it appropriately. Mine is 'ActNumber. This parameter will be used in URL as well. So pick a name that is not confusing later
    In rows parameter type 1 to 4 for example to create 4 rows
    In each row for the second parameter add the values. The value could be hard coded or using get data method retrieve a value from project or test suite level parameter value.
    In the URL if you have to pass the account number like in my case. Use 'ActNumber' instead of the actual account number.
    For example: https:// accounts/${DataSource#ActNumber}/restrictions
    Add groovy script below the test step which retrieves the restrictions
    =================
    Def rows = context.expand( '${DataSource#rows}' )
    def indAcct = context.expand( '${DataSource#ActNumber}' )
    testRunner.testCase.setPropertyValue("AccountId" +[rows],ActNumber)
    def responseAsXml = context.expand( '${test step name here#ResponseAsXml#//Response[1]/e[1]/ActResId[1]}' )
    testRunner.testCase.setPropertyValue("ResID" +[rows],responseAsXml)

    ===============
    Note: It creates dynamic properties, there is no need to add them in advance.
    For example ResID1 and then the value for ResID1 is 123
    Add data source loop at the end and make sure the target step is set properly covering the needed steps.
    Run the test case

    Thats it. Hope this is helpful