被调用的测试用例缺少上下文 [英] Context missing from called test case

查看:151
本文介绍了被调用的测试用例缺少上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SoapUI中,我使用以下代码从groovy脚本运行测试用例:
$ b $ pre $ def $ context context = new StringToObjectMap(上下文)
def myTestCase_1 = myTestSuite.getTestCaseByName(TestcaseName)
myTestCase_1.run(contextMap,false)

在被调用的测试用例中,我以这种方式在groovy脚本中设置了一些上下文属性: context.setProperty(ProperyName,Value)



调用测试用例完成后,在调用此测试用例的groovy脚本的上下文中缺少创建的属性值。
如何将属性值传递给调用另一个测试用例的测试用例?

解决方案

如果你想通过不同的 testCases 共享属性同样 testSuite 尝试设置 testSuite 级别的属性,这个属性将被所有测试用例共享 testSuite 中。例如,如果你有一个 testSuite 和两个 testCases testCase 1 testCase 2 ,从 testCase 1 do的groovy脚本中:

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

然后从 testCase 2 中的另一个groovy脚本使用此属性:使用

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

您也可以使用保存在 testCase 1 testSuite >在 testCase 2 中,例如在 testStep SOAP Request 中使用: $ {#TestSuite#



$ b

由于似乎OP问题是如何从 testCase 从另一个 testCase u调用的属性唱独特的剧本;这里有一个可能的解决方法,它通过运行结果获取调用的 testCase 然后获取他的属性:



使用groovy调用其他 testCase 的第一个 testCase 看起来像:

  import com.eviware.soapui.support.types.StringToObjectMap 
$ b $ def contextMap = new StringToObjectMap(context)
def testCase2 = testRunner.testCase.testSuite.getTestCaseByName(TestCase 2)
//得到结果自运行同步
def result = testCase2.run(contextMap,false)
//从结果访问testCase,然后设置其中的属性
log.info result.getTestCase()。getPropertyValue(varSettedOnTestCase2)

在第二个 testCase 中,只需执行逻辑并设置将从第一个 testCase

  testRunner.testCase.setPropertyValue(varSettedOnTes tCase2,test)

希望这有助于您,


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?

解决方案

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,

这篇关于被调用的测试用例缺少上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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