Context missing from called test case

泄露秘密 提交于 2019-12-11 09:39:56

问题


In SoapUI I’m running a test case from a groovy script with this code:

def contextMap = new StringToObjectMap(context)
def myTestCase_1 = myTestSuite.getTestCaseByName("TestcaseName")
myTestCase_1.run(contextMap, false)

In the called test case I set some context properties in a groovy script in this way: context.setProperty(“ProperyName”,”Value”)

After the called test case has finished the created property values are missing in the context of the groovy script that has called this test case. How can I pass back property values to a test case that called another test case?


回答1:


Instead of using context if you want to share properties through different testCases in the same testSuite try to set the properties on the testSuite level which will be shared for all testCases in this testSuite. For example if you have a testSuite with two testCases: testCase 1 and testCase 2, on a groovy script from testCase 1 do:

testRunner.testCase.testSuite.setPropertyValue( "sharedVar", "someValue" )

Then to use this property from another groovy script in testCase 2 use:

def shared = testRunner.testCase.testSuite.getPropertyValue("sharedVar")
log.info shared

You can also use this testSuite property saved in the testCase 1 in the testCase 2 for example in testStep SOAP Request using: ${#TestSuite#sharedVar}

EDIT BASED ON OP COMMENT:

Since seems that the OP problem is how to get the properties from a testCase which is called from another testCase using groovy script; here is a possible work around, which consists in through the run result get the invoked testCase and then get his properties:

The first testCase which invokes the other testCase using groovy looks like:

import com.eviware.soapui.support.types.StringToObjectMap

def contextMap = new StringToObjectMap(context)
def testCase2 = testRunner.testCase.testSuite.getTestCaseByName("TestCase 2")
// get the result since is running sync
def result = testCase2.run(contextMap, false)
// from the result access the testCase and then the properties setted there
log.info result.getTestCase().getPropertyValue("varSettedOnTestCase2")

In the second testCase simply perform your logic and set the properties which will be get back from the first testCase:

testRunner.testCase.setPropertyValue("varSettedOnTestCase2","test")

Hope this helps,



来源:https://stackoverflow.com/questions/28159903/context-missing-from-called-test-case

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!