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



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

我得到我的数据 :

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

从中我只能使用removePropertyChangeListener方法。

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

如何从我的自定义属性中获取可用于以编程方式删除它的 PropertyChangeListener 参数?我看过的所有帖子都提供了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) }

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

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
}

最新更新