SoapUI - 为每个测试用例增加 属性 值

SoapUI - Increase property value for each test case

我想使用具有特定起始值的 属性 ('currentId')。对于每个测试用例,该值应增加 1。我可以通过在每个测试用例中添加一个额外的测试步骤来增加值,但这会增加很多复制粘贴。代码为(参见 ):

def uniqueUserPortion = testRunner.testCase.testSuite.project.getPropertyValue("currentId")
// convert it to an Integer, and increment
def uniqueUserPortionInc = uniqueUserPortion.toInteger() + 1
// set the property back as string
testRunner.testCase.testSuite.project.setPropertyValue("currentId", uniqueUserPortionInc.toString())

为避免复制和粘贴,我已将上面的代码添加到项目的加载脚本中,但它不起作用:

testSuite.testCases.each {
    *code above*
}

如何才能将一个 script/call 中的代码用于所有测试用例? 我可以将 属性 定义为起始值加上测试用例 ID,但这将再次成为每个测试用例中的定义,因为我无法在项目 level/property.[=14 中引用 #TestCase#ID =]

你正在尝试的问题

  • 将项目导入到soapui工作区时,会执行一次项目的Load Script。所以,这个方法是行不通的。
  • 正如您正确提到的那样,您需要将它放在每个测试用例的单独步骤中,或者您可以添加与 setup script 相同的代码。是的,只是复制粘贴

使用SoapUI NG可以轻松实现,其中专业版使用事件功能。

那么你的下一个问题可能是:如何在 SoapUI 的开源版本中做到这一点。

这是我前段时间做的 soapuiExtensions,它允许您做同样的事情,而不必为开源版本中的每个测试用例复制粘贴。

您需要做的就是将 groovy 脚本放入一个名为 'TestCaseBeforeRun.groovy' 的特定文件中。这意味着,脚本在 运行 每个测试用例之前执行。

有关详细信息,请参阅 README

This soapuiExtensions library allows users to have some additional functionality in soapUI(free edition) tool, like soapui pro allows to do something before, after doing something.

For eg: User may want to do something before running a test case or after running a test case etc by implementing appropriate groovy script as required. Allow me to add an example here. Usually user may want to add credentials for the request step automatically, see the script samples/scripts/TestSuiteTestStepAdded.groovy

How to use this library:

set SOAPUI_HOME environment variable.

copy lib/SoapUIExtListeners.jar file under $SOAPUI_HOME/bin/ext directory

copy samples/listeners/custom-listeners.xml file under $SOAPUI_HOME/bin/listeners directory

copy samples/scripts directory under $SOAPUI_HOME

And implement appropriate groovy script available under $SOAPUI_HOME/scripts. Refer Mappings file in order to implement respective groovy script.

Note: for windows users, you may need to check %SOAPUI_HOME%\bin\soapui.bat which actually overwrites SOAPUI_HOME, need to fix soapui.bat script if requires.

Uses jdk 7, soapUI 4.5.1, and groovy 1.8.9

Dependency

log4j

更新:这与上面的注释有关。

正如注释中提到的,soapui.bat 覆盖了 windows 上的 SOAPUI_HOME 环境变量,需要稍微调整一下。可能您想复制 %SOAPUI_HOME%\bin\scripts 下的 groovy 文件(无需调整 soapui.bat)并重试。如果您的机器是 linux 那么如果您将 groovy 文件复制到 $SOAPUI_HOME/scripts 目录下

它应该可以工作