SOAP UI 删除自定义问题 属性

SOAP UI Problems to remove custom property

我目前正在尝试 'clean up' 使用 groovy 脚本从 SOAP UI 测试用例自定义属性。 来自 this 其他 post,我尝试这样做但我遇到了一个问题:我无法访问 removeProperty 方法。

我得到了我的数据:

data = context.testCase.testSuite.getTestCaseByName("Test multi TT");

从中我只能使用removePropertyChangeListener方法。

我尝试使用 data.getPropertyAt() 函数来获取合适的对象,但它没有 return 正确的数据 class。

如何从我的自定义 属性 中获取 PropertyChangeListener 参数,我可以使用它以编程方式将其删除? 我浏览过的所有 posts 都提供了 removeProperty 的答案,但我找不到任何提到 removePropertyChangeListener

的答案

感谢任何帮助

编辑:根据与 OP 聊天时的讨论,OP 希望删除现有属性并将外部文件中的属性添加到测试用例级别自定义属性。

下面是 soapui 测试用例的 Setup Script。这会执行以下操作(在聊天中与 OP 讨论后):

  1. 删除现有属性
  2. 将文件中的属性添加到测试用例级别自定义属性。

设置脚本:

//Change external properties file path as needed
def filename = 'C:/Users/apps/Documents/test.properties'
def properties = new Properties()
def propertiesFile = new File(flename)
assert propertiesFile.exists(), "$filename does not exists"
propertiesFile.withInputStream { properties.load(it) }
//Remove properties
testCase.propertyNames.collect { testCase.removeProperty(it) }

//load the properties of external file
properties.collect { k, v -> testCase.setPropertyValue(k, v) }

这是一个没有外部文件的解决方案。目的是只删除我为测试用例目的创建的新属性,在拆解脚本中:

import java.util.regex.Pattern

data = context.testCase.testSuite.getTestCaseByName("myTestCase");
log.info " ********************** old props ***********************"
String[] customProps = new String[data.getPropertyCount()];
customProps = data.getPropertyNames();

Pattern myRegex = ~/maProp_/  // I name my new properties with the same pattern and an index

for (propertyName in customProps){
    log.info "info = " + propertyName
    myMatcher = propertyName =~ /$myRegex/
    if (myMatcher.count != 0){
        match = myMatcher[0] == 'maProp_'
        //log.info "match ? " + match // to check only my maProp_xx properties are matching

        context.getTestCase().removeProperty(propertyName)
    }
}


// verification
newProps = data.getPropertyNames();

log.info " ********************** new props ***********************"
for (i in newProps){
     log.info "info = " +i
}