英文:
Auto-increment Custom Properties for SOAPUI testing
问题
def TransID = testRunner.testCase.testSuite.project.getPropertyValue("TransID")
def TransIDInc = TransID.toInteger() + 1
testRunner.testCase.testSuite.project.setPropertyValue("TransID", TransIDInc.toString())
//checkin..
log.info testRunner.testCase.testSuite.project.getPropertyValue("TransID")
我想要自动递增这个自定义属性,在研究和查看类似问题,比如 https://stackoverflow.com/questions/31056482/auto-increment-custom-properties-for-soapui-testsuite 之后,我尝试了这个解决方案,并创建了这个名为 TransID 的自定义属性,它在我的请求消息中显示为 "id": "${#TransID}"
,但无论何时我运行 Groovy 脚本,我都会收到日志消息,显示该值为空,因此无法对空值进行递增。这是否意味着我的值未从自定义属性中读取出来?
<details>
<summary>英文:</summary>
def TransID = testRunner.testCase.testSuite.project.getPropertyValue("TransID")
def TransIDInc = TransID.toInteger()+1
testRunner.testCase.testSuite.project.setPropertyValue("TransID",TransIDInc.toString())
//checkin..
log.info testRunner.testCase.testSuite.project.getPropertyValue("TransID")
I want to autoincrement this custom property, and after research and viewing similar issues such as https://stackoverflow.com/questions/31056482/auto-increment-custom-properties-for-soapui-testsuite I have tried this solution and created this custom property called TransID which is shown in my request message as `"id": "${#TransID}"` , but whenever i run the groovy script i get log message that value is null thus cannot increment a null value. Does this mean my value is not read from the custom properties?.
</details>
# 答案1
**得分**: 0
这部分有效:
```python
def TransID = "1"
TransIDInc = TransID.toInteger()+1
assert TransIDInc.toString() == "2"
因此,我认为您的属性未被正确访问。属性有不同的级别或范围:
testRunner.testCase.testSuite.project.getPropertyValue("TransID")
testRunner.testCase.testSuite.getPropertyValue("TransID")
testRunner.testCase.getPropertyValue("TransID")
确保您正在访问正确的属性,或者在正确的范围内访问属性。
您还可以尝试这个:
testRunner.testCase.testSuite.project.setPropertyValue("TransID","${TransIDInc.toString()}")
但这不应该有任何区别。
英文:
This part works:
def TransID = "1"
TransIDInc = TransID.toInteger()+1
assert TransIDInc.toString() == "2"
So I think your property is not accerssed correctly. There are different levels or scopes of properties:
testRunner.testCase.testSuite.project.getPropertyValue("TransID")
testRunner.testCase.testSuite.getPropertyValue("TransID")
testRunner.testCase.getPropertyValue("TransID")
Make sure you are accessing the correct property, or the property in the correct scope.
You can also try this:
testRunner.testCase.testSuite.project.setPropertyValue("TransID","${TransIDInc.toString()}")
But that shouldn't make a difference.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论