cancel
Showing results for 
Search instead for 
Did you mean: 

Need help to add tear down script in all the testcases

SOLVED
harry
Contributor

Need help to add tear down script in all the testcases

we have around 3000 testcases. we are planning to add the tear script in all the testcases. Is there a script that can  update in all the testcases tear down.

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
nmrao
Community Hero

Re: Need help to add tear down script in all the testcases

@harry 

It is difficult to add tear-down script for those many cases manually. However, It is possible to add the tear down script automatically with a simple script as below.

 

 

NOTE: The script will add the tear-down for all the tests cases in the project. i.e,, it will modify the project. So take a backup of your project before running the below script.

 

How to execute the script?

a. Make sure you have closed the soapui project for which you want to add the tear-down script.

b. Create an empty project -> suite -> test case -> groovy script and add the below content in there.

c. The groovy script need the following files as input.

i. SoapUi project file

ii. Create a file with the desired tear-down script which needs to be copied to all the tests.

And provide/update the above two file paths in the script.

 

 

import com.eviware.soapui.impl.wsdl.WsdlProject

//EDIT below two paths
def soapUIProject = '/home/apps/Documents/Project-5-soapui-project.xml'
def tearDown = '/home/apps/Documents/TeardownScript.txt'

//Do not edit beyond this
def tearDownScript = new File(tearDown).text
def project = new WsdlProject(soapUIProject)
project.testSuiteList.each { suite ->
	suite.testCaseList.each { caze ->
		caze.setTearDownScript(tearDownScript)
	}
}
project.save()
log.info 'Completed updating the project' + soapUIProject

 

As the your project is big, it might take a while to add the same to the project.

 

Once it is done, you may try opening your actual project and check.

 



Regards,
Rao.

View solution in original post

9 REPLIES 9
mattb
Staff

Re: Need help to add tear down script in all the testcases

Hi,

You can add teardown scripts at the Project level, TestSuite level, and TestCase level. If all of the testcases are within a single project, the project level teardown script will work. 
https://support.smartbear.com/readyapi/docs/functional/scripts.html 

If the testcases are across different projects we could use a custom groovy script library, so that there is only 1 script that would need updating, and it would automatically update every other teardown script.
https://support.smartbear.com/readyapi/docs/testing/scripts/libs/groovy-lib.html


nmrao
Community Hero

Re: Need help to add tear down script in all the testcases

Need the same script for all test cases? What does the script do? Possible to share the same for better understanding?
Are 3000 test cases in a project? Or multiple projects?
A simple project or a composite?


Regards,
Rao.
harry
Contributor

Re: Need help to add tear down script in all the testcases

Its a simple project.

harry
Contributor

Re: Need help to add tear down script in all the testcases

Based on the testcase log out. we want to run teardown script at the testcase level. If i put the script at the project level tear down. It will be applicable for the testcases?

nmrao
Community Hero

Re: Need help to add tear down script in all the testcases

Wish the reply included answers for other questions too.

Events feature can be used. In this particular case,
Add TestRunListener.afterRun event listener and write the script. You may ( or may not ) have to tweak the existing / proposed tear-down script . Which is why sought for more info in the previous reply.

For more details, refer documentation below if not already.
https://support.smartbear.com/readyapi/docs/testing/handling-events.html?sbsearch=Events#available-e...


Regards,
Rao.
nmrao
Community Hero

Re: Need help to add tear down script in all the testcases

Note that if the above mentioned event listener added, then no need to add tear down script to the test cases any more.


Regards,
Rao.
mattb
Staff

Re: Need help to add tear down script in all the testcases

If you were to put the teardown script at the project level, every time that project runs it will run that teardown script at the end. Since its a logout testcase, it sounds like you want to run the teardown at the testcase level. So I would recommend adding the teardown at the testcase level.  

nmrao
Community Hero

Re: Need help to add tear down script in all the testcases

@mattb,
Good you pointed out a case.
And I believe that original poster is of same opinion, but adding the script for 3000 cases manually might be challenging. So looking for the solution.

Do you have comments from my previous response i.e., implementing the script for Event TestRunListener.afterRun.


Regards,
Rao.
nmrao
Community Hero

Re: Need help to add tear down script in all the testcases

@harry 

It is difficult to add tear-down script for those many cases manually. However, It is possible to add the tear down script automatically with a simple script as below.

 

 

NOTE: The script will add the tear-down for all the tests cases in the project. i.e,, it will modify the project. So take a backup of your project before running the below script.

 

How to execute the script?

a. Make sure you have closed the soapui project for which you want to add the tear-down script.

b. Create an empty project -> suite -> test case -> groovy script and add the below content in there.

c. The groovy script need the following files as input.

i. SoapUi project file

ii. Create a file with the desired tear-down script which needs to be copied to all the tests.

And provide/update the above two file paths in the script.

 

 

import com.eviware.soapui.impl.wsdl.WsdlProject

//EDIT below two paths
def soapUIProject = '/home/apps/Documents/Project-5-soapui-project.xml'
def tearDown = '/home/apps/Documents/TeardownScript.txt'

//Do not edit beyond this
def tearDownScript = new File(tearDown).text
def project = new WsdlProject(soapUIProject)
project.testSuiteList.each { suite ->
	suite.testCaseList.each { caze ->
		caze.setTearDownScript(tearDownScript)
	}
}
project.save()
log.info 'Completed updating the project' + soapUIProject

 

As the your project is big, it might take a while to add the same to the project.

 

Once it is done, you may try opening your actual project and check.

 



Regards,
Rao.

View solution in original post

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