cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy script - How to run a teststep from another testsuite in your testsuite teardown script?

Occasional Contributor

Groovy script - How to run a teststep from another testsuite in your testsuite teardown script?

I'm able to run a testcase teardown script in my testsuite TS1 that runs a teststep from another testsuite TS2.

 

testRunner.testCase.testSuite.project.testSuites["TS2"].testCases["TC2"].testSteps["STEP2"].run(testRunner, context);

But as this teststep should run for all my testcases in TS1, I need to add the teardown script for each testcase.

I want to know if I could achieve the same thing directly from the testsuite teardown script, which would save me a lot of script maintenance.

 

Unfortunately the testrunner object is not available at testsuite level, but I don't know how (or if it's possible) to do it using the runner object.

 

Any help is much appreciated!

9 REPLIES 9
Super Contributor

Re: Groovy script - How to run a teststep from another testsuite in your testsuite teardown script?

Hi @d4vke,

 

I have found similiar Post in community. Go through below link it will solve you issue too

 

https://community.smartbear.com/t5/SoapUI-Pro/Resolved-running-testCase-from-testSuite-teardown/td-p...

 

Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

 

Thanks and Regards,

Himanshu Tayal


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal
Occasional Contributor

Re: Groovy script - How to run a teststep from another testsuite in your testsuite teardown script?

Sorry, but it is not helping for me.

Looks like this is not an easy one to solve :-(

Contributor

Re: Groovy script - How to run a teststep from another testsuite in your testsuite teardown script?

I have set up TearDown Script for TestSuite(TS2) :

With this TearDown Script, run all TestSteps of all TestCases of TestSuite(TS1)

Please see attach screenshot for more details.

In error log I am getting this error:

Wed Oct 10 12:10:25 IST 2018:ERROR:groovy.lang.MissingPropertyException: No such property: testRunner for class: Script2

But I check response of TestSteps of TestSuite(TS1), and see I am getting response properly.

 

Please have a look screenshot and I think it help you.

Occasional Contributor

Re: Groovy script - How to run a teststep from another testsuite in your testsuite teardown script?

Hi ranjit96,

 

Could you attach the code of the teardown script in a txt file rather then the screenshot, as I'm not able to see all the code in the screenshot.

 

Thanks! 

 

Contributor

Re: Groovy script - How to run a teststep from another testsuite in your testsuite teardown script?

Please see attach .txt file for teardown script. Thanks.

Occasional Contributor

Re: Groovy script - How to run a teststep from another testsuite in your testsuite teardown script?

This is very strange, I also get the error message 

ERROR:groovy.lang.MissingPropertyException: No such property: testRunner for class: Script2

But no results are shown since the script just stops when the error appears...

 

 

Is it really not possible to use the runner variable to execute a teststep from another testsuite...?

Contributor

Re: Groovy script - How to run a teststep from another testsuite in your testsuite teardown script?

Dunno if you are still looking for a solution, but maybe this workaround will help you.

 

I created a test suite, with 1 test case from which I can basically run as many test suites as I desire. Here is the code. See also the attached screenshot.

 

Code:

 

 

testRunner.testCase.testSuite.project.getTestSuiteList().each { testsuite ->
	if(['ts'].contains(testsuite.getName())) {											//filter testsuite we want to run
		testsuite.getTestCaseList().each { testcase ->
			if(testcase.getName().toLowerCase().startsWith('renderer')) {					//filter testcases we want to run
				testcase.getTestStepList().each { teststep ->
					if(teststep.getName().equalsIgnoreCase('request')) {					//finally filter all teststep we want to run
						log.info "running ${testcase.getName()} -> ${teststep.getName()}"
						def r = teststep.run(testRunner, context)
						log.info r.getStatus()
					}
				}
			}
		}
	}
}

runstuff.png

 

 

Occasional Contributor

Re: Groovy script - How to run a teststep from another testsuite in your testsuite teardown script?

Thanks Alex99,

 

I will give this a try and let you know what the outcome is.

Contributor

Re: Groovy script - How to run a teststep from another testsuite in your testsuite teardown script?

below is the script to run from test suite tear down script to run any groovy script 

 

 

"'mention the script where it resides"

testSuite = testSuite.project.getTestSuiteByName("Script Library");

 

"'mention the test case /groovy where it resides"
testCase = testSuite.getTestCaseByName("Test");
runner = testCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false);

 

 

hope it helps

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