将 grooving 脚本结果转移到测试用例中

transferring grooving script result into test cases

我正在从一个标签中获取数据,比如 111 22222 并使用 space 进行拆分 比如 111 和 22222.

我想将两个不同标签的值转移到不同的请求中 让我们说

Tag1 为 111,Tag2 为 22222

如果您已经为变量分配了两个不同的值,您可以执行以下操作

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

//get field value from first test step response
def tagOne = 111
def tagTwo = 22222

//Define request you would like to add data to
def holderRequestOne = groovyUtils.getXmlHolder("RequestOneName#Request")
def holderRequestTwo = groovyUtils.getXmlHolder("RequestTwoame#Request")

//Find the fields in the request and set the value you would like in those fields 
holderRequestOne.setNodeValue("//XPath","$tagOne")
holderRequestTwo.setNodeValue("//XPath","$tagTwo")

//Update the requests
holderRequestOne.updateProperty()
holderRequestTwo.updateProperty()

这是我使用 Groovy 脚本的方式。您只需要添加相关的 XPath 和测试步骤名称。

您也可以使用 属性 传输测试步骤执行此操作。您可以在这里找到更多信息:

https://www.soapui.org/docs/functional-testing/properties/transferring-properties.html

关于你的问题的更多信息,你尝试过的代码和你期望的代码结果不会出错

@Tanveer 根据您对 Ross 的回答的评论,这里是解决方案

您已将响应获取为 111 222

log.info Response  // 111 222
String [] s = s.split(" ") 
log.info s[0] //111 
log.info s[1] //222 

将值保存在 groovy 脚本中的 testCase 属性中

 testRunner.testCase.setPropertyValue("tagone",s[0])
 testRunner.testCase.setPropertyValue("tagtwo",s[1])

在您要使用此的另一个 testStep 请求中

<xmltag1>${#TestCase#tagone}</xmltag1>
<xmltag1>${#TestCase#tagtwo}</xmltag1>

所以我们在 TestCase 级别存储 属性 并在同一 Testcase 的另一个步骤中使用它

如果您希望 属性 在另一个测试用例中使用,您可以将其存储在 TestSuite 级别

 testRunner.testCase.testSuite.setPropertyValue("tagone",s[0])