Search code examples
groovysoapuiload-testing

loadTestRunner - how to set parameters using groovy script


I'd like to run load tests in soap using groovy script (as test step or Setup Script - which is better?) I can already set threads and startDelay but I don't know how to set strategy and specific options for each strategy (for example Burst Delay or Burst Duration).

I'm stuck with below code:

import com.eviware.soapui.impl.wsdl.loadtest.*
import com.eviware.soapui.impl.wsdl.loadtest.strategy.*
import com.eviware.soapui.impl.wsdl.panels.support.*

def loadTest = testRunner.testCase.testSuite.project.getTestSuiteByName("Load").getTestCaseByName("testCase").getLoadTestByName("loadTestSelect")
def loadTestRunner = new WsdlLoadTestRunner(loadTest)

loadTestRunner.loadTest.setThreadCount(30)
loadTestRunner.loadTest.setStartDelay(2)
loadTestRunner.loadTest.setLoadStrategy("Simple")

loadTestRunner.start(true)
loadTestRunner.waitUntilFinished()

setThreadCount and setStartDelay works properly, but setLoadStrategy doesn't. I have an error:

groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest.setLoadStrategy() is applicable for argument types: (String) values: [Simple] Possible solutions: setLoadStrategy(com.eviware.soapui.impl.wsdl.loadtest.strategy.LoadStrategy), getLoadStrategy() error

I tried also find something (any expamples) in documentation - but I didn't.

I want to set these options:

screenshot from soapUI

Thanks for any suggestions.


Solution

  • Solved by...me :)

        def loadTest = testRunner.testCase.testSuite.project.getTestSuiteByName("Load").getTestCaseByName(testCaseSelect).getLoadTestByName(loadTestSelect)
    
    //strategy params
    def configSimple = """<xml-fragment>
    <testDelay>${testDelay}</testDelay>
    <randomFactor>${randomFactor}</randomFactor>
    </xml-fragment>
    """
    def configBurst = """<xml-fragment>
    <burstDelay>${burstDelay}</burstDelay>
    <burstDuration>${burstDuration}</burstDuration>
    </xml-fragment>
    """
    def configThread = """<xml-fragment>
    <startThreadCount>${startThreadCount}</startThreadCount>
    <endThreadCount>${endThreadCount}</endThreadCount>
    </xml-fragment>
    """
    def configVariance = """<xml-fragment>
    <interval>${interval}</interval>
    <variance>${variance}</variance>
    </xml-fragment>
    """
    
    switch (strategySelect) {
        case "Simple":
            xmlConfig = XmlObject.Factory.parse(configSimple)
            strategy = new SimpleLoadStrategy(xmlConfig, loadTest)
            break
        case "Burst":
            xmlConfig = XmlObject.Factory.parse(configBurst)
            strategy = new BurstLoadStrategy(xmlConfig, loadTest)
            break
        case "Thread":
            xmlConfig = XmlObject.Factory.parse(configThread)
            strategy = new ThreadCountChangeLoadStrategy(xmlConfig, loadTest)
            break
        case "Variance":
            xmlConfig = XmlObject.Factory.parse(configVariance)
            strategy = new VarianceLoadStrategy(xmlConfig, loadTest)
            break
        default:
            throw new IllegalArgumentException("Niepoprawna wartość parametru strategySelect: ${strategySelect}")
    }
    
    loadTest.setLoadStrategy(strategy)
    loadTest.setThreadCount(threads)
    loadTest.setLimitType(LoadTestLimitTypesConfig.Enum.forString(limitType))
    loadTest.setTestLimit(testLimit)