问题描述
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")
我想自动增加此自定义属性,在研究并查看类似问题Auto-increment Custom Properties for SOAPUI testSuite之后,我尝试了此解决方案并创建了一个名为TransID的自定义属性,该属性在我的请求消息中显示为"id": "${#TransID}"
,但是每当我运行groovy脚本时,我都会得到一条日志消息,指出该值是null,因此不能增加一个null值。这是否意味着我的值未从自定义属性中读取?。
解决方法
此部分有效:
<div class="f_container">
<div class="card">
<img id="coffeeImage1" src="static/images/coffees-background.jpg" alt="Coffee" style="width:100%">
<h1 id="name1">Название</h1>
<p id="price1" class="price">price</p>
<p id="weight1">weight</p>
<p id="country1">country</p>
<p><button>Добавить в корзину</button></p>
</div>
<div class="card">
<img id="coffeeImage1" src="static/images/coffees-background.jpg" alt="Coffee" style="width:100%">
<h1 id="name1">Название</h1>
<p id="price1" class="price">price</p>
<p id="weight1">weight</p>
<p id="country1">country</p>
<p><button>Добавить в корзину</button></p>
</div>
<div class="card">
<img id="coffeeImage1" src="static/images/coffees-background.jpg" alt="Coffee" style="width:100%">
<h1 id="name1">Название</h1>
<p id="price1" class="price">price</p>
<p id="weight1">weight</p>
<p id="country1">country</p>
<p><button>Добавить в корзину</button></p>
</div>
<div class="card">
<img id="coffeeImage1" src="static/images/coffees-background.jpg" alt="Coffee" style="width:100%">
<h1 id="name1">Название</h1>
<p id="price1" class="price">price</p>
<p id="weight1">weight</p>
<p id="country1">country</p>
<p><button>Добавить в корзину</button></p>
</div>
<div class="card">
<img id="coffeeImage1" src="static/images/coffees-background.jpg" alt="Coffee" style="width:100%">
<h1 id="name1">Название</h1>
<p id="price1" class="price">price</p>
<p id="weight1">weight</p>
<p id="country1">country</p>
<p><button>Добавить в корзину</button></p>
</div>
<div class="card">
<img id="coffeeImage1" src="static/images/coffees-background.jpg" alt="Coffee" style="width:100%">
<h1 id="name1">Название</h1>
<p id="price1" class="price">price</p>
<p id="weight1">weight</p>
<p id="country1">country</p>
<p><button>Добавить в корзину</button></p>
</div>
<div class="card">
<img id="coffeeImage1" src="static/images/coffees-background.jpg" alt="Coffee" style="width:100%">
<h1 id="name1">Название</h1>
<p id="price1" class="price">price</p>
<p id="weight1">weight</p>
<p id="country1">country</p>
<p><button>Добавить в корзину</button></p>
</div>
<div class="card">
<img id="coffeeImage1" src="static/images/coffees-background.jpg" alt="Coffee" style="width:100%">
<h1 id="name1">Название</h1>
<p id="price1" class="price">price</p>
<p id="weight1">weight</p>
<p id="country1">country</p>
<p><button>Добавить в корзину</button></p>
</div>
</div>
所以我认为您的财产不正确。属性有不同的级别或范围:
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")
但这不应该有所作为。