【发布时间】:2014-02-26 16:30:18
【问题描述】:
是否可以通过 Groovy Script 测试步骤在其他测试用例中运行特定的测试步骤?
不知道怎么做
谢谢
【问题讨论】:
标签: soapui
是否可以通过 Groovy Script 测试步骤在其他测试用例中运行特定的测试步骤?
不知道怎么做
谢谢
【问题讨论】:
标签: soapui
是的,这是可能的。从 groovy 步骤中,您可以访问 testRunner,您可以使用它来访问soapUI 中的所有其他内容,并且可以在另一个测试用例中运行测试步骤。
所以,这段代码来自我的脑海中......
def tCase = testRunner.testCase.testSuite.project.testSuites["Name of the other test suite"].testCases["name of test case you want to access"]
或
def tCase = testRunner.testCase.testSuite.testCases["Name of test cases"]
def tStep = tCase.testSteps["test step you want to run"]
tStep.run(testRunner, context)
看看这个link它可能会有所帮助......
【讨论】:
对于我们这些像我一样正在寻找当前版本 Ready!API 的代码的人
def testStep = testRunner.testCase.testSuite.project.getTestSuiteByName("[OTHER_TEST_SUITE_NAME]").getTestCaseByName("[OTHER_TEST_CASE_NAME]").getTestStepByName("[OTHER_TEST_STEP_NAME]")
testStep.run(testRunner, context)
【讨论】:
我意识到我参加聚会有点晚了,但我想我会通过发布我对类似问题的解决方案来扩展这个主题。希望这对将来的某人有所帮助。解决方案可以扩展以涵盖两个以上的测试步骤、测试用例和/或项目。这也是我在这里的第一篇文章,所以请提前原谅我的任何菜鸟错误。也不是最漂亮的解决方案。它可能有一些冗余变量。所有代码块构成了整个解决方案。
问题:我想从两个不同的测试步骤中检索响应,每个测试步骤在不同的测试用例中,在两个不同的项目中但在同一个工作区中。知道了?太棒了!
解决方案:
第一个项目的变量
String firstProjName = "Generic Project One"
String firstProjTestSuiteName= "Generic Test Suite Name One"
String firstProjTestCaseName = "Generic Test Case Name One"
String firstProjTestStepName= "Generic Test Step Name One"
第二个项目的变量
String secondProjName= "Generic Project Two"
String secondProjTestSuiteName = "Generic Test Suite Name Two"
String secondProjTestCaseName= "Generic Test Case Name Two"
String secondProjTestStepName= "Generic Test Step Name Two"
访问通用测试步骤名称一
def firstProj= null
def workspace = testRunner.testCase.testSuite.project.getWorkspace();
firstProj= workspace.getProjectByName(firstProjName)
def firstTestCase = firstProj.testSuites[firstProjTestSuiteName].testCases[firstProjTestCaseName ]
def firstTestStep = firstTestCase.getTestStepByName(firstProjTestStepName)
运行通用测试步骤名称一
def runner = null
runner = firstTestStep.run(testRunner, context)
def firstTestStepResp = runner.getResponseContent()
runner = null
打印对日志的响应
log.info(firstTestStepResp)
与第二个测试步骤相同
def secondProj= null
secondProj= workspace.getProjectByName(secondProjName)
def secondTestCase = secondProj.testSuites[secondProjTestSuiteName ].testCases[secondProjTestCaseName]
def secondTestStep = secondTestCase.getTestStepByName(secondProjTestStepName)
runner = secondTestStep.run(testRunner, context)
def secondTestStepResp = runner.getResponseContent()
log.info(secondTestStepResp)
我们现在可以将这两个响应作为字符串访问,我们可以随心所欲地使用它们。比较,tokenize等。还有
getResponseContentAsXml()
如果想要响应为 xml 而不是字符串。
【讨论】:
// run Activation_TollContract Test Case
def testSuite = testRunner.testCase.testSuite.project.getTestSuiteByName("Write_name_of_test_suite_here"); //get test suite by name
//log.info "testSuite " + context.getTestCase().getTestStepAt(n).name
def testCase = testSuite.getTestCaseByName("Write_name_of_test_case_here"); //get test case by name
//log.info "testCase: " + testCase
def totalTestSteps = testCase.getTestSteps().size(); //get int total test steps for the given test case
//log.info "totalTestSteps " + totalTestSteps
def PROJECT = testRunner.testCase.testSuite.project.getTestSuiteByName("Write_name_of_test_suite_here")
for(n in (0..totalTestSteps - 1))
{
def testStepName = testCase.getTestStepAt(n).name;
if(n>=5){
if (PROJECT.getTestCaseByName("Write_name_of_test_case_here").getTestStepByName(testStepName).disabled != true){
log.info "testStepName: " + n + ": " + testStepName;
def testStep = testSuite.getTestCaseByName("Write_name_of_test_case_here").getTestStepByName(testStepName); //get nameMap of step
runner = testStep.run(testRunner, context);
log.info ("testStep >>> 1 " + runner.getStatus().toString());
}
}
}
【讨论】:
您可以使用以下代码:
def testStep = testRunner.testCase.testSuite.project.getTestSuiteByName("[OTHER_TEST_SUITE_NAME]").getTestCaseByName("[OTHER_TEST_CASE_NAME]").getTestStepByName("[OTHER_TEST_STEP_NAME]")
testStep.run(testRunner, context)
有关详细演示,请参阅: https://coderscamp.wixsite.com/codeit/post/how-to-run-a-test-step-from-groovy-script
【讨论】: