Groovy 用于删除自定义属性的SOAP UI问题

Groovy 用于删除自定义属性的SOAP UI问题,groovy,soapui,Groovy,Soapui,我目前正在尝试使用groovy脚本从SOAP UI测试用例中“清理”自定义属性。 在另一篇文章中,我试图这样做,但我面临一个问题:我无法访问removeProperty方法 我得到我的数据: data = context.testCase.testSuite.getTestCaseByName("Test multi TT"); 从中我只能使用removePropertyChangeListener方法 我尝试使用data.getPropertyAt函数来获取合适的对象,但它没有返回正确的数据

我目前正在尝试使用groovy脚本从SOAP UI测试用例中“清理”自定义属性。 在另一篇文章中,我试图这样做,但我面临一个问题:我无法访问removeProperty方法

我得到我的数据:

data = context.testCase.testSuite.getTestCaseByName("Test multi TT");
从中我只能使用removePropertyChangeListener方法

我尝试使用data.getPropertyAt函数来获取合适的对象,但它没有返回正确的数据类

如何从自定义属性中获取PropertyChangeListener参数,以编程方式将其删除? 我读过的所有帖子都提供了关于removeProperty的答案,但我找不到任何提到removePropertyChangeListener的帖子

谢谢你的帮助

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

下面是soapui测试用例的设置脚本。与OP在聊天室中讨论后,会执行以下操作:

删除现有属性 将属性从文件添加到测试用例级自定义属性。 安装脚本:

//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) }

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

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
}

您是否正在尝试删除套件级属性?否,在测试用例级。我想删除自定义属性。您知道是否可以通过编程方式从外部文件重新加载属性吗?这可能是一个方便的解决办法…是的,这是可能的。您的用例是什么?您是否使用testrunner从命令行运行测试,并希望覆盖它们,或者只需要读取外部文件并使用groovy脚本步骤在测试用例级别加载它们?实际上,这两种情况都适合,到目前为止,我正在构建我的测试,我希望在groovy步骤中完成,但我将在不久的将来使用testrunner运行它们,但如果我从外部文件读取,在groovy步骤中,它将如何像通过GUI那样删除文件中没有的属性?