Forum Discussion

SumitM's avatar
SumitM
Occasional Contributor
7 years ago

Can Tear Down Script can be used as a Event?

I have multiple Test suites inside my Test project. As per my requirement I need to run the test suites from command line. While running the test from command line, the Project level tear down script is not running. 

 

To overcome the issue can I add a Project level event as "After Test run" and move my tear down script in that event?

 

Also,Please suggest me if there are better solutions then writing individual tear down scripts for each test suite.

  • Radford's avatar
    Radford
    Super Contributor

    When you run from the command line, are you using the -c or -s command line arguments? If so I could understand when the project tear down does not run.

     

    It feels that if you want a script to execute after every test case that runs (or test suite that runs) that code does belong in the "TestRunListener.afterRun" (or "TestSuiteRunListener.afterRun") event - not a tear down script. That way it's only a single script to write and maintain.

     

    Should you wish to run the same script after a selected number of specific test cases (or test suites), but don't want to write and maintain the script into multiple tear down script locations, you could write your script that you want to run as a external script that is stored in a Groovy Script Library and then in each of the required tear down scripts could call the single common script.

    • SumitM's avatar
      SumitM
      Occasional Contributor

      Hi Radford,

       Thanks for the reply. Actually  I need to create a Test run report after every test run. If I end up using "Groovy script Library" I am not sure if I can access all Test Suite properties there. 

       

      My current situation is, I have a Test project having multiple Test Suite. I am passing Test suite name in command prompt for running selective test suite. My tear down script is at Test project level which creates the test exit report. But when I am not running the whole Test project and only selective test suites, the tear down script is not running.

       

      For overcome this issue I am trying to write the tear down script at Test Project Event level. If anyone can suggest any better approach then its highly appreciated.