Forum Discussion

EswarJ's avatar
EswarJ
New Contributor
13 years ago

Updating Setup/Tear down scripts

Hi there,
Is it possible to update the scripts inside the setup/teardown section using a groovy script?

For example:
I have a teardown script that needs to be run at the end of each test case. To copy this script into each test case, can I use a groovy script?
Currently I am manually copying the script into a new test case every time I add a test case. If I have a groovy to do this, I was wondering if I can run that groovy step alone?

Any inputs related to this will be helpful.

Thanks.
Eswar
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    You can certainly do that:

    testRunner.testCase.testSuite.project.getTestSuiteByName('MyTestSuite').getTestCaseByName('MyTestCase').setSetupScript('log.info "setup"')
    testRunner.testCase.testSuite.project.getTestSuiteByName('MyTestSuite').getTestCaseByName('MyTestCase').setTearDownScript('log.info "teardown"')

    If you are using the pro version, you can also configure the TestRun beforeRun and afterRun events to execute a script, which avoids having to copy anything to your test cases.

    If you are using the free version, here is another suggestion. Store your setup and teardown scripts in files, then in the project Load script put code like this:


    def su = new File("setup.txt").text
    def td = new File("teardown.txt").text

    project.getTestSuiteList().each { testSuite ->
    testSuite.getTestCaseList().each { testCase ->
    testCase.setSetupScript(su)
    testCase.setTearDownScript(td)
    }
    }

    This will cause every test case's setup and teardown scripts to be replaced when the project is first loaded.
    • suryvada's avatar
      suryvada
      New Contributor

      Is there a way to set up tear down script at project level using groovy.

       

      Thanks in advance,

      Surya

      • suryvada's avatar
        suryvada
        New Contributor

        Below works to update project tear down script using groovy

        testRunner.testCase.testSuite.project.setAfterRunScript("script");