Forum Discussion

_ivanovich_'s avatar
_ivanovich_
Frequent Contributor
4 years ago

Groovy returns No such property: testRunner for class when using java class

Hi, in groovy if i use a java class, it returns groovy.lang.MissingPropertyException: No such property:tesRunner for class: Simple   here is the code: class Simple{ public void main(String[]arg...
  • ZDGN's avatar
    ZDGN
    4 years ago

    Hi _ivanovich_ 

     

    It's a bit tricky to deal with both groovy and SoapUI in this case.

    Here is what I can propose to you.

    So at first you can create a TestSuite and a TestCase to store your groovy classes.

    For example this one:

    context.setProperty("simpleClass", new Simple())
    
    class Simple{
    
    public void main(String[]args){}
    
    public void setProjectProperty(propertyName, propertyValue, testRunner) {
    	testRunner.testCase.testSuite.project.setPropertyValue(propertyName,propertyValue)
    	}
    
    }

     

    And then inside your script you can call your class this way:

    def currentProject = testRunner.testCase.testSuite.project
    currentProject.testSuites["TestSuite"].testCases["TestCase"].testSteps["Simple Class"].run(testRunner,context)
    
    def simple = context.simpleClass
    simple.setProjectProperty("TEST", "testing groovy class", testRunner)

     

    Keep in mind you won't be able to use things like the log.info command inside your class ğŸ˜‰

     

    Hope this helps.

     

     

    David.