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[]args){

def x = ("test")

//log.info x

testRunner.testCase.testSuite.project.setPropertyValue("x",x)

}

}

 

How should we declare testRunner in this class?

It happens same thing with log.info

  • 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.

  • _ivanovich_'s avatar
    _ivanovich_
    Frequent Contributor

    Hi,

    am i missing something in my groovy code or is it not possbile to use class in groovy like in java?

    Any help please.

     

    • smtripathi99's avatar
      smtripathi99
      Occasional Contributor

      Hi,

       

      Try to use runner in place of testRunner.

      • _ivanovich_'s avatar
        _ivanovich_
        Frequent Contributor

        Hi,

        "replace testRunner by runner"

        that was the first answer found when i was searching in google but doesn`t work.

        Maybe i have to create another class from i have to call a variable and the variable should be declared as global or something else.

        I did not figure out yet.