Forum Discussion

dinobear's avatar
dinobear
New Contributor
13 years ago

Creating groovy class to be used across test cases

My set up:
- test suite with several test cases
- properties defined at different levels
(as an example)
- test suite level: A, B, C
- test case level: M, N, O
- test step level: X, Y, Z
- test cases only differ slightly such that
- TC1 uses A, B, M, O, X
- TC1 uses A, C, N, O, Y, Z
- TC1 uses B, M, N, O, Z

Within each test case, I have a groovy script where I define some variables related to the properties mentioned earlier (e.g. testRunner.testCase.getTestStepByName("Load Details").getPropertyValue("X")). And so, on different test cases, I found myself repeating several lines. Thus, I was thinking of writing an external groovy script, put that in a jar file, then import it on the groovy step of the test case.

Roughly, I was thinking of this:

package com.trialscript

class GroovyScript{
// put all the variable definitions here
void loadProperties(){
def testSuite = testRunner.testCase.testSuite
def shiftDetails = testRunner.testCase.getTestStepByName("Load Details")
...
}

//other methods that are shared across the test cases
}

I was also thinking of importing either of these but I get errors when I do:
- import junit.textui.TestRunner
- import com.eviware.soapui.model.testsuite.testRunner

Am I missing something here? Or please advise what I'm doing wrong. Thanks!