Gr-oo-vy II – testrunner/context variable

Posted: May 19, 2011 in context, groovy, soapUI, testrunner
Tags: , , , ,

Use of the testrunner variable to get the response data of any specific teststep.

def request = testRunner.testCase.getTestStepByName( “myTestStepName” );
def responseData = request.getProperty( “Response” );
log.info(responseData.value)

To display the name of project, testsuite, testcase & teststep:

def project = context.testCase.testSuite.project
log.info(project.name + ”   ” + project)
def testSuite = project.getTestSuiteAt(1)  // 1 is the index number of testsuite
log.info(testSuite.name + ”   ” + testSuite)
def testCase = testSuite.getTestCaseAt(0)  // 0 is the index number of testcase
log.info(testCase.name + ”      ” + testCase)
def testStep = testCase.getTestStepAt(7) // 7 is the index number of teststep
log.info(testStep.name + ”    ” + testStep)

To count the number of testsuites, testcases, teststeps use the below code :

def project = context.testCase.testSuite.project
log.info(project.name + ”   ” + project.testSuiteCount)
def testSuite = project.getTestSuiteAt(1)
log.info(testSuite.name + ”   ” + testSuite.testCaseCount)
def testCase = testSuite.getTestCaseAt(0)
log.info(testCase.name + ”      ” + testCase.testStepCount)
def testStep = testCase.getTestStepAt(7)
log.info(testStep.name + ”    ” + testStep)

We can use the above code and put them into a loop (for/each) to iterate through all the elements. In below example, we iterate through all the test steps under a testcase :

for (int count in 0..<testCase.testStepCount)
{
log.info(testCase.getTestStepAt(count).getName() + ”  is our testStep number ” + count)
log.info(“Is this test step disabled? : ” + testCase.getTestStepAt(count).isDisabled())
}

OR

( 0..<testStep1 ).each{
    log.info(testCase.getTestStepAt(it).getName())
    }

Comments
  1. Pihu says:

    When I am trying to use the test Runner in one of my test step script assertion I am getting error No such property:TestRunner’ but whenI use context it worked.What is the reason for that what is the difference between the testrunner and context?

  2. Pihu says:

    import com.eviware.soapui.model.testsuite.TestRunner

Leave a comment