自动增加SOAPUI testSuite

时间:2015-06-25 17:03:09

标签: testing groovy soapui

我希望在我的SOAPUI测试运行时自动增加自定义属性。目前我的测试要求有一个独特的部分,称为UniqueUserPortion,当我测试用户名/电子邮件中的唯一性时,它会增加。有没有办法让我增加这个自定义属性(#Project#UniqueUserPortion),因为我需要它是唯一的下一步,检查唯一的用户名? 检查唯一的电子邮件:

    {  
  "UpdateIdentityRequest":{  
    "guid":"${#Project#UserGUID}",
    "emailAddress": "tomTestUser11@testit.com",
    "screenName": "UpdateUser${#Project#UniqueUserPortion}",
    "inputSystem":"${#Project#UserInputSystem}"
  }
}

检查唯一用户名:

    {  
  "UpdateIdentityRequest":{  
    "guid":"${#Project#UserGUID}",
    "emailAddress": "UpdateUser${#Project#UniqueUserPortion}@test.com",
    "screenName": "testUser2011",
    "inputSystem":"${#Project#UserInputSystem}"
  }
}

1 个答案:

答案 0 :(得分:6)

Remember that internally SoapUI keeps everything in XML, and so all properties are just strings. Further, every Groovy Script step get instantiated as a new class, so it cannot "remember" any previous state.

You will have to do something like:

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