如何在具有相同上下文的单独 TestSuite 中 运行 TestCase
How to run TestCase in separate TestSuite WITH same context
在我的 SoapUI 项目中,我有两个测试套件 - CommonUtils 和 TestProper。我想从 TestProper->TestA 中调用测试用例 CommonUtils->UtilA,但我需要在这两个测试用例之间共享我的上下文。
https://imgur.com/a/LdzWIQ0
首先,我尝试向 TestA 添加一个 "Run TestCase" 测试步骤。但是,尽管我可以将测试用例属性传输到 UtilA,"Run TestCase" 不允许我将我的上下文传输到 UtilA。
然后,我尝试通过向 TestA 添加以下 Groovy 脚本来完成此操作:
def project = context.testCase.testSuite.project
def testCase = project.getTestSuiteByName('CommonUtils').getTestCaseByName('UtilA')
def contextMap = new StringToObjectMap(context)
testCase.run(contextMap, false)
虽然这个脚本允许我将我的上下文的副本传输到 UtilA,但 UtilA 仍然无法写入我的上下文。
现在,我不知道该怎么做。如何从 TestA 中执行 UtilA,在它们之间共享变量?
如果您将要传递的变量设置为上下文变量,它应该可以工作。
我在 ReadyAPI 中完成了此操作,但我希望它在 SoapUI 中也能正常工作。
我创建了两个测试套件。两者都持有一个 TestCase。
目标 TestCase 只包含一个 Properties 测试步骤,我尝试在其中设置一个变量,然后使用以下代码设置一个 Groovy 脚本测试步骤:
testRunner.testCase.getTestStepByName("Properties").setPropertyValue("varname",context.variable)
在另一个 TestSuite/TestCase 中,我有一个 Groovy 脚本测试步骤,只有这两行代码:
context.variable = "String set in testsuite StartTestCaseInAnotherTestSuite 2"
testRunner.testCase.testSuite.project.getTestSuiteByName("TestSuite Name").getTestCaseByName("TestCase Name").run(new com.eviware.soapui.support.types.StringToObjectMap(context),false)
// Remember to adjust the names of TestSuite and TestCase to suit your needs.
现在,当我 运行 后者时,我将 context.variable 设置为一个值,当第二个测试用例是 运行 时,该上下文变量在属性测试步骤中设置。
在我的 SoapUI 项目中,我有两个测试套件 - CommonUtils 和 TestProper。我想从 TestProper->TestA 中调用测试用例 CommonUtils->UtilA,但我需要在这两个测试用例之间共享我的上下文。 https://imgur.com/a/LdzWIQ0
首先,我尝试向 TestA 添加一个 "Run TestCase" 测试步骤。但是,尽管我可以将测试用例属性传输到 UtilA,"Run TestCase" 不允许我将我的上下文传输到 UtilA。
然后,我尝试通过向 TestA 添加以下 Groovy 脚本来完成此操作:
def project = context.testCase.testSuite.project
def testCase = project.getTestSuiteByName('CommonUtils').getTestCaseByName('UtilA')
def contextMap = new StringToObjectMap(context)
testCase.run(contextMap, false)
虽然这个脚本允许我将我的上下文的副本传输到 UtilA,但 UtilA 仍然无法写入我的上下文。
现在,我不知道该怎么做。如何从 TestA 中执行 UtilA,在它们之间共享变量?
如果您将要传递的变量设置为上下文变量,它应该可以工作。
我在 ReadyAPI 中完成了此操作,但我希望它在 SoapUI 中也能正常工作。
我创建了两个测试套件。两者都持有一个 TestCase。
目标 TestCase 只包含一个 Properties 测试步骤,我尝试在其中设置一个变量,然后使用以下代码设置一个 Groovy 脚本测试步骤:
testRunner.testCase.getTestStepByName("Properties").setPropertyValue("varname",context.variable)
在另一个 TestSuite/TestCase 中,我有一个 Groovy 脚本测试步骤,只有这两行代码:
context.variable = "String set in testsuite StartTestCaseInAnotherTestSuite 2"
testRunner.testCase.testSuite.project.getTestSuiteByName("TestSuite Name").getTestCaseByName("TestCase Name").run(new com.eviware.soapui.support.types.StringToObjectMap(context),false)
// Remember to adjust the names of TestSuite and TestCase to suit your needs.
现在,当我 运行 后者时,我将 context.variable 设置为一个值,当第二个测试用例是 运行 时,该上下文变量在属性测试步骤中设置。