cancel
Showing results for 
Search instead for 
Did you mean: 

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

SOLVED
_ivanovich_
Frequent Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions
ZDGN
Contributor

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

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.

View solution in original post

4 REPLIES 4
_ivanovich_
Frequent Contributor

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

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
Occasional Contributor

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

Hi,

 

Try to use runner in place of testRunner.

_ivanovich_
Frequent Contributor

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

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.

 

ZDGN
Contributor

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

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.

View solution in original post

New Here?
Join us and watch the welcome video:
Top Kudoed Authors