Forum Discussion

harry's avatar
harry
Contributor
4 years ago

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.

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

     

  • nmrao's avatar
    nmrao
    Champion Level 3

    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.

     

  • nmrao's avatar
    nmrao
    Champion Level 3
    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?
  • 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


    • harry's avatar
      harry
      Contributor

      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?

      • mattb's avatar
        mattb
        Staff

        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.