在SoapUI / Groovy中将属性ids(数组)传递给其他测试用例 [英] Transfer Property ids (Array) to other TestCases in SoapUI/Groovy

查看:491
本文介绍了在SoapUI / Groovy中将属性ids(数组)传递给其他测试用例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个API来获取ID,名称,数据等列表(TestCase名称 GET-APIs_OrderdByID_ASC


$ b 在SOAPUI中, Property Transfer $ c>可以在同一个TestCase中的TestSteps中工作。 (使用OpenSource版本)。我需要在不同的TestCases / TestSuite之间转移属性值。





以下是我可以提取的代码 ids 来自一个testCase,也是我想要传输的testCases / testSteps的名称。

  import com.eviware.soapui.impl.wsdl.teststeps。* 
import com.eviware.soapui.support .types.StringToStringMap
import groovy.json。*

def project = context.testCase.testSuite.project
def TestSuite = project.getTestSuiteByName(APIs)
def TestCase = TestSuite.getTestCaseList()
def TestStep = TestCase.testStepList
def request = testRunner.testCase.getTestStepByName(List_of_APIs_OrderByID_ASC)
def response = request.getPropertyValue(Response )
def JsonSlurperResponse = new JsonSlurper()。parseText(response)
def Steps = TestStep.drop(3)
log.info JsonSlurperResponse.data.id
def id = JsonSlurperResponse .data.id

Steps.each {
it.getAt(0).setPropertyValue(apiId,id.toString())
log.info it.getAt( 0).name
}

如果我在代码上面运行,所有id的数组值 [1,2,10,11,12,13,14,15,16,17,18] 设置为每个以下testSteps





我看了其他的SO问题



谁能帮我吗。 : - )

解决方案

您可以使用项目级属性或testSuiteLevel属性或testCase属性。



通过这种方式,您可以实现与Property Transfer步骤相同的操作,但方式不同。

在源测试用例中编写一个groovy步骤以setProperty(保存稍后要使用的值)

  testRunner.testCase.setPropertyValue (TCaseProp,TestCase)
testRunner.testCase.testSuite.setPropertyValue(TSuiteProp,TestSuite)

testRunner.testCase.testSuite.project.setPropertyValue(ProjectLevel,ProjectLevelProperty)

TCaseProp是属性的名称。你可以给任何名字
TestCase是你想存储的值。你可以提取这个值,并使用一个变量
例如

  def val =9000
testRunner .testCase.setPropertyValue(TCaseProp,val)

您可以在其他情况下使用该属性套房。如果你想在不同的套件中使用你可以定义项目级别的属性

在目标测试用例请求中使用以下语法

  $ {#Project#ProjectLevel} 
$ {#TestCase#TCaseProp}
$ {#TestSuite#TCaseProp}

< convertCurrency> $ {#的TestSuite#TCaseProp}< / SSP:SystemUsername>

系统会自动替换上述请求中的属性值

https://www.soapui.org/scripting-properties/ tips-tricks.html < - 有用的链接,可以详细解释有关财产转移的情况。

I have an API to get list of ids, name, data etc. (TestCase name GET-APIs_OrderdByID_ASC)

I want to transfer those IDs to other following TestCases in same TestSuite or other TestSuite.

In SOAPUI, Property Transfer works within TestSteps in same TestCase. (Using OpenSource version). I need to transfer the property value among different TestCases / TestSuites.

Below is the code that I can extract ids from one testCase and also name of testCases/testSteps where I want to transfer.

import com.eviware.soapui.impl.wsdl.teststeps.*
import com.eviware.soapui.support.types.StringToStringMap 
import groovy.json.*

def project = context.testCase.testSuite.project
def TestSuite = project.getTestSuiteByName("APIs")
def TestCase =  TestSuite.getTestCaseList() 
def TestStep = TestCase.testStepList
def request =  testRunner.testCase.getTestStepByName("List_of_APIs_OrderByID_ASC")
def response = request.getPropertyValue("Response")
def JsonSlurperResponse = new JsonSlurper().parseText(response)
def Steps = TestStep.drop(3)
log.info JsonSlurperResponse.data.id   
def id = JsonSlurperResponse.data.id

Steps.each {
    it.getAt(0).setPropertyValue("apiId", id.toString())   
    log.info it.getAt(0).name       
}

If I run above code, all the array values of id [1, 2, 10, 11, 12, 13, 14, 15, 16, 17, 18] are set to each of the following testSteps

I looked some other SO questions

Can anyone help me out. :-)

解决方案

You can use project level properties or testSuiteLevel properties or testCase Properties.

This way you can achieve the same thing that you get from Property Transfer step but in a different way.

Write a groovy step in the source test case to setProperty(save values you want to use later)

testRunner.testCase.setPropertyValue("TCaseProp", "TestCase")
testRunner.testCase.testSuite.setPropertyValue("TSuiteProp","TestSuite") 

testRunner.testCase.testSuite.project.setPropertyValue("ProjectLevel","ProjectLevelProperty")

"TCaseProp" is the name of the property. you can give any name "TestCase" is the value you want to store. You can extract this value and use a variable for example

def val="9000"
testRunner.testCase.setPropertyValue("TCaseProp", val)

You can use that property in other case of same suite. If you want to use across different suites you can define project level property

use the below syntax in target testcase request

${#Project#ProjectLevel}
${#TestCase#TCaseProp}
${#TestSuite#TCaseProp}

<convertCurrency>${#TestSuite#TCaseProp}</ssp:SystemUsername>

System will automatically replace the property value in above request

https://www.soapui.org/scripting-properties/tips-tricks.html <-- Helpful link which can explain in detail about property transfer

这篇关于在SoapUI / Groovy中将属性ids(数组)传递给其他测试用例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆