自动递增SOAPUI测试的自定义属性

huangapple go评论77阅读模式
英文:

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(&quot;TransID&quot;)
    def TransIDInc = TransID.toInteger()+1 
    testRunner.testCase.testSuite.project.setPropertyValue(&quot;TransID&quot;,TransIDInc.toString())
    //checkin..
    log.info testRunner.testCase.testSuite.project.getPropertyValue(&quot;TransID&quot;)
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 `&quot;id&quot;: &quot;${#TransID}&quot;` , 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 = &quot;1&quot;
TransIDInc = TransID.toInteger()+1
assert TransIDInc.toString() == &quot;2&quot;

So I think your property is not accerssed correctly. There are different levels or scopes of properties:

testRunner.testCase.testSuite.project.getPropertyValue(&quot;TransID&quot;)
testRunner.testCase.testSuite.getPropertyValue(&quot;TransID&quot;)
testRunner.testCase.getPropertyValue(&quot;TransID&quot;)

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(&quot;TransID&quot;,&quot;${TransIDInc.toString()}&quot;)

But that shouldn't make a difference.

huangapple
  • 本文由 发表于 2020年9月16日 21:59:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/63921703.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定