Forum Discussion

mitchellt's avatar
mitchellt
Occasional Contributor
10 years ago

SoapUI Load Test Properties

Hi,

I have a test suite containing multiple properties, example below:

Name: DynamicChangeId
Value: ${=context.changeIds.get((int)(Math.random()*context.changeIdsCount))}

changeIds is a list, changeIdsCount is the size of that list.

The in-line groovy script above will select a random value from the list.

The values are loaded into that list at the testsuite level in a "startup script", example below:

// Load Change Ids from file
try {
log.info("Loading Change Ids from file ...")
File file = new File('...\\Test_Data\\ChangeId.txt')
context.changeIds = file.readLines()
context.changeIdsCount = context.changeIds.size
log.info("ChangeIdsCount: " + context.changeIdsCount)
log.info("ChangeIds: " + context.changeIds)
log.info("Change Ids loaded Successfully!")
} catch (Exception e) {
testRunner.fail("Failed to load data file")
return
}

This all works fine at a testsuite level because I am able to access the properties via ${#TestSuite#DynamicChangeId} in a request.

My Problem:

When I create a load test (copying the startup script from testsuite) and try to access this property via ${#TestSuite#DynamicChangeId} I get the following error:

groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method java.lang.Double#multiply.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
[class java.lang.Character]
[class java.lang.Number]
at groovy.lang.MetaClassImpl.chooseMostSpecificParams(MetaClassImpl.java:2980)
at groovy.lang.MetaClassImpl.chooseMethodInternal(MetaClassImpl.java:2932)
at groovy.lang.MetaClassImpl.chooseMethod(MetaClassImpl.java:2875)
at groovy.lang.MetaClassImpl.getMethodWithCachingInternal(MetaClassImpl.java:1203)
at groovy.lang.MetaClassImpl.createPojoCallSite(MetaClassImpl.java:3079)

Is their anyway to setup dynamic properties in load tests in soap ui (like I've done above) ?

6 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    Not sure if the understanding is correct, please correct otherwise.

    Where do you keep the startup script? and how you run it? Do you mean to say setup script?
    And it was mentioned that the same script is copied to test for doing load test, that means you copied it to test case level
    context is different from suite level, test case level.

    In the test (load test) you may need to access it using ${#TestCase#PROPERTY} instead of ${#TestSuite#PROPERTY} to get the right value.
  • mitchellt's avatar
    mitchellt
    Occasional Contributor
    Hi,

    Yes I meant to say Setup Script.

    The properties are stored at the test suite level and I access them in the load test requests via ${#TestSuite#DynamicChangeId}.

    I know I can access them because if I change that properties value in the test suite properties section to:

    'hello world'

    From ...

    ${=context.changeIds.get((int)(Math.random()*context.changeIdsCount))}

    It works, in the request the in line groovy is substituted:

    <inc:ChangeID>${#TestSuite#DynamicChangeId}</inc:ChangeID> ........ ====> ........ <inc:ChangeID>hello world</inc:ChangeID>.

    I also know that context.changeIds.get((int)(Math.random()*context.changeIdsCount)) works if I paste it directly in the setup script but that doesn't make my properties dynamic which is the reason why this peice of inline groovy is in the test suite properties section; but for some reason it causes this exception:

    groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method java.lang.Double#multiply.
    Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
    [class java.lang.Character]
    [class java.lang.Number]
    at groovy.lang.MetaClassImpl.chooseMostSpecificParams(MetaClassImpl.java:2980)
    at groovy.lang.MetaClassImpl.chooseMethodInternal(MetaClassImpl.java:2932)
    at groovy.lang.MetaClassImpl.chooseMethod(MetaClassImpl.java:2875)
    at groovy.lang.MetaClassImpl.getMethodWithCachingInternal(MetaClassImpl.java:1203)
    at groovy.lang.MetaClassImpl.createPojoCallSite(MetaClassImpl.java:3079)
  • nmrao's avatar
    nmrao
    Champion Level 3
    Ok, may you can apply similarly in your case.

    Since I do not have the following two lines.
    File file = new File('...\\Test_Data\\ChangeId.txt')
    context.changeIds = file.readLines()


    Assuming a static list in place of that in the example, this script can be kept in setup script of test case level (similar to test suite level)
    def changeIds = ['item1','item2','item3']//can be replaced with file.readLines() code in your case. 
    def changeIdsCount = changeIds.size()
    def newValue = changeIds[(int)Math.random()*changeIdsCount]
    testCase.setPropertyValue('DYNAMIC_ID',newValue)


    And in the test case use ${#TestCase#DYNAMIC_ID}
  • mitchellt's avatar
    mitchellt
    Occasional Contributor
    Hi nmrao,

    If a setup script is in place will this only be run once? i.e. at the start of a test case / suite?

    If this is the case then this will not make each request have different / randomised parameters, which is what I am trying to achieve.

    This is the reason for using this statement in the properties section of the test suite:

    ${=context.changeIds.get((int)(Math.random()*context.changeIdsCount))}


    This statement would randomize the value it picks from a list which has been initialised previously (in the set-up script).

    If I try to access the test suite properties in my load test requests I get the following error:

    groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method java.lang.Double#multiply.
    Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
    [class java.lang.Character]
    [class java.lang.Number]
    at groovy.lang.MetaClassImpl.chooseMostSpecificParams(MetaClassImpl.java:2980)
    at groovy.lang.MetaClassImpl.chooseMethodInternal(MetaClassImpl.java:2932)
    at groovy.lang.MetaClassImpl.chooseMethod(MetaClassImpl.java:2875)
    at groovy.lang.MetaClassImpl.getMethodWithCachingInternal(MetaClassImpl.java:1203)
    at groovy.lang.MetaClassImpl.createPojoCallSite(MetaClassImpl.java:3079)

    Note: the list of id's is generated in the load test Start-Up Script.
  • mitchellt's avatar
    mitchellt
    Occasional Contributor
    OK so, I have managed to get it working.

    Rather than accessing the properties at a testsuite level, I access them at a test case level.

    I put the startup script in the test case and not the load test (although I am running the load test, makes no sense to me ...)