loadTestRunner - 如何使用groovy脚本设置参数

问题描述 投票:0回答:3

我想使用groovy脚本在soap中运行负载测试(作为测试步骤或设置脚本 - 哪个更好?)我已经可以设置线程和startDelay,但我不知道如何设置策略和每个策略的特定选项(例如突发延迟或突发持续时间)。

我被下面的代码困住了:

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 和 setStartDelay 可以正常工作,但 setLoadStrategy 不能。我有一个错误:

groovy.lang.MissingMethodException:没有方法签名:com.eviware.soapui.impl.wsdl.loadtest.WsdlLoadTest.setLoadStrategy() 适用于参数类型:(字符串)值:[简单] 可能的解决方案:setLoadStrategy(com. eviware.soapui.impl.wsdl.loadtest.strategy.LoadStrategy),getLoadStrategy()错误

我也尝试在文档中找到一些东西(任何例子) - 但我没有。

我想设置这些选项:

screenshot from soapUI

感谢您的任何建议。

groovy soapui load-testing
3个回答
1
投票

由我解决:)

    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)

0
投票

谢谢马雷基!

这是一个为项目中的所有案例添加负载测试的脚本(当然您可以缩小范围):

import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase
import com.eviware.soapui.impl.wsdl.loadtest.*
import com.eviware.soapui.impl.wsdl.loadtest.strategy.*


def project = testRunner.testCase.testSuite.project

// Define the load test properties
def loadTestName = "LoadTest - Burst Strategy"
def threadCount = 50
def burstDelay = 10000
def burstDuration = 10000

project.getTestSuiteList().each { testSuite ->
    testSuite.getTestCaseList().each { testCase ->
        if (testCase instanceof WsdlTestCase) {
            def loadTest = testCase.getLoadTestByName(loadTestName)
            if (loadTest == null) {
                loadTest = testCase.addNewLoadTest(loadTestName)
            }

            def configBurst = "<Burst><burstDelay>${burstDelay}</burstDelay><burstDuration>${burstDuration}</burstDuration></Burst>"
            def xmlHolder = new com.eviware.soapui.support.XmlHolder(configBurst)
            def strategy = new BurstLoadStrategy(xmlHolder.getXmlObject(), loadTest)
          
            loadTest.setLoadStrategy(strategy) // Set the strategy to Burst
            loadTest.setThreadCount(threadCount)
        }
    }
}

log.info("Load test with name $loadTestName has been added to all test cases in the project.")

⚠️🚧*PS:我找不到一种方法来考虑burstDelay和burstDuration值。*🚧⚠️


-1
投票

根据提供的代码片段,您似乎正在尝试为 SoapUI 负载测试设置负载策略。但是,该错误表明没有名为

setLoadStrategy
的方法可用于
WsdlLoadTest

要设置 SoapUI 负载测试的负载策略,您应该使用

setStrategy
方法。这是使用更正方法的更新后的代码片段:

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.setStrategy(new SimpleLoadStrategy())
loadTestRunner.start(true)
loadTestRunner.waitUntilFinished()

在更新后的代码中,使用

setStrategy
代替了
setLoadStrategy
。此外,加载策略
SimpleLoadStrategy
作为参数传递给
setStrategy
方法。您可以使用 SoapUI 提供的可用加载策略类之一根据您的要求调整加载策略。

确保您已导入加载策略所需的类,并根据您的特定负载测试需求调整代码。

© www.soinside.com 2019 - 2024. All rights reserved.