dav*_*_jr 3 testing groovy soapui
我希望在我的SOAPUI测试运行时自动增加自定义属性.目前我的测试要求有一个独特的部分,称为UniqueUserPortion,当我测试用户名/电子邮件中的唯一性时,它会增加.有没有办法让我增加这个自定义属性(#Project#UniqueUserPortion),因为我需要它是唯一的下一步,检查唯一的用户名?检查唯一的电子邮件:
{
"UpdateIdentityRequest":{
"guid":"${#Project#UserGUID}",
"emailAddress": "tomTestUser11@testit.com",
"screenName": "UpdateUser${#Project#UniqueUserPortion}",
"inputSystem":"${#Project#UserInputSystem}"
}
}
Run Code Online (Sandbox Code Playgroud)
检查唯一用户名:
{
"UpdateIdentityRequest":{
"guid":"${#Project#UserGUID}",
"emailAddress": "UpdateUser${#Project#UniqueUserPortion}@test.com",
"screenName": "testUser2011",
"inputSystem":"${#Project#UserInputSystem}"
}
}
Run Code Online (Sandbox Code Playgroud)
请记住,内部SoapUI将所有内容保存在XML中,因此所有属性都只是字符串.此外,每个Groovy Script步骤都被实例化为一个新类,因此它不能"记住"任何先前的状态.
你将不得不做以下事情:
// read the property as a string
def uniqueUserPortion = testRunner.testCase.testSuite.project.getPropertyValue("UniqueUserPortion")
// convert it to an Integer, and increment
def uniqueUserPortionInc = uniqueUserPortion.toInteger() + 1
// set the property back as string
testRunner.testCase.testSuite.project.setPropertyValue("UniqueUserPortion", uniqueUserPortionInc.toString())
// check
log.info testRunner.testCase.testSuite.project.getPropertyValue("UniqueUserPortion")
Run Code Online (Sandbox Code Playgroud)