Is it possible to run specific test steps in other Test Cases from a Groovy Script test step

Yes it is possible. From the groovy step you have access to the testRunner which you can use to access everything else in soapUI and yes run test steps in another test case.

So, this code is from the top my my head...

def tCase = testRunner.testCase.testSuite.project.testSuites["Name of the other test suite"].testCases["name of test case you want to access"]

or

def tCase = testRunner.testCase.testSuite.testCases["Name of test cases"]

def tStep = tCase.testSteps["test step you want to run"]

tStep.run(testRunner, context)

Check out this link it might be of some help...


For those of us who, like me, were looking for code for the current version of 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)

I realise I'm a little late to the party but i thought I'll expand on this topic by posting my solution to a similar problem. Hope this helps someone in the future. Solution can be scaled to cover more than two test steps, test cases and/or projects. This is also my first post on here so please excuse me in advance for any noob errors. Not the most pretty solution either. It may have some redundant variables. All code blocks comprise the whole solution.

Problem: I want to retrieve responses from two different test steps, each in different test cases, in two diff projects BUT in the same workspace. Got it? great!

SOLUTION:

Variables for first project

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"

Variables for second project

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"

Access Generic Test Step Name One

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)

Run Generic Test Step Name One

def runner = null
runner = firstTestStep.run(testRunner, context)

def firstTestStepResp = runner.getResponseContent()
runner = null

Print response to log

log.info(firstTestStepResp)

Same thing with the second test step

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)

We now have access to both responses as strings which we can play around with however we want. Compare, tokenize etc. There is also

getResponseContentAsXml()

if the response is wanted as xml instead of a string.

Tags:

Soapui