SOAPUI 使用 groovy 从文件加载自定义属性



我正在尝试编写一个时髦的脚本,该脚本使用属性文件中的信息加载测试套件的自定义属性。属性文件有大约 6 个不同的属性我已经看了不少不同的方法,即从属性加载测试步骤并尝试使用 groovy 扩展属性,但没有成功。

如果有人能就如何实现这一目标提出建议,将不胜感激。

提前谢谢。

下面是一个

groovy 脚本,它读取一个属性文件并将它们设置为 test suite level

def props = new Properties()
//replace the path with your file name below. use / instead of  as path separator even on windows platform.
new File("/absolute/path/of/test.properties").withInputStream { s ->
  props.load(s) 
}
props.each {
    context.testCase.testSuite.setPropertyValue(it.key, it.value)
}

上述脚本负载测试套件级别,适用于存在 groovy 脚本的当前套件。

不幸的是,就我而言,我希望属性与输入文件具有相同的顺序,即。 排序,并且此方法不起作用。我想加载一个包含排序属性的"项目属性"文件,每次使用此方法时,它都会将它们存储为未排序的。我不得不使用一种更直接的方法(见下文)。如果有人知道一种更优雅/实用的方法,我很感兴趣

def filename = context.expand( '${#TestCase#filename}' )
def propertiesFile = new File(filename)
assert propertiesFile.exists(), "$filename does not exist"
project = testRunner.testCase.testSuite.project
//Remove properties
project.propertyNames.collect{project.removeProperty(it)}
//load the properties of external file
propertiesFile.eachLine {
    line->
    firstIndexOf = line.indexOf('=') // properties as set as key=value in the file
    key = line.substring(0, firstIndexOf)
    value = line.substring(firstIndexOf+1)
    project.setPropertyValue(key, value)
}

最新更新