Forum Discussion

lowres's avatar
lowres
Contributor
22 days ago

How to trigger Teardown

Hello,

I have an Execution plan with various keyword tests. It all ends with a teardown script (close application, close browser window close excel etc). This always works when things go to plan but not when for example there is an event which stops  the intial  login from succeeding.

Is there a way to ALLWAYS trigger the Teardown script. For example if My first keyword test fails I stop the project, but I would still like to close any applications that were opened.

Thanks Lowres.

7 Replies

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    I have something similar, but my clean-up occurs before TestExecute (or TestComplete) is run. I use a PowerShell script to perform the necessary clean-up operation, followed by running the automation, then emailing results. I found using TestComplete General Events not working the way I wanted it to work and this caused a number of issues.

    If an error had occurred while running, I can diagnose and see at what state it had stopped. Whether it's relating to the AUT or scripting, I can easily see the result. Whereas, if I had performed a clean-up operation after an error occurred, then it would have been tricky to diagnose!

    • scot1967's avatar
      scot1967
      Icon for Champion Level 3 rankChampion Level 3

      In some of my test suites I run an event handler before each test that verifies the environment is set for the next test.  "EventControl_OnStartTest"  [Edit:] I haven't noticed any problems. The powershell idea could come in handy for a few things though.  ☺️

      • lowres's avatar
        lowres
        Contributor

        Thanks Scot, That is a work in progress, being more proactive in my keyword tests is definitely something I am slowly building up. 

    • lowres's avatar
      lowres
      Contributor

      Excellent Idea, that's an annoyingly simple solution. Thanks rraghvani

      • rraghvani's avatar
        rraghvani
        Icon for Champion Level 3 rankChampion Level 3

        When I first started automation with TestComplete, I made the "framework" overly complicated for other users, for those that didn't have much experience in scripting. I refactored all coding to make it as simple as possible, and it works great. It's been 4 years, and no complaints yet from users!

  • scot1967's avatar
    scot1967
    Icon for Champion Level 3 rankChampion Level 3

    Hello lowres,

    Have you looked into setting up an event handler?  This will be global for all tests.

    https://support.smartbear.com/testcomplete/docs/testing-with/advanced/handling-events/about.html

    You can also look into using Try, Catch blocks in each of your tests...

    https://support.smartbear.com/testcomplete/docs/keyword-testing/reference/statements/try.html?sbsearch=Try%20Catch%20Finally

    These won't ALWAYS call the catch or fire the event in every circumstance but this should be used to run your treachdown scripts.  For instance if your tested app crashes TestComplete will keep running until it hits an error in checked in your script and then run the corresponding event or run the catch block.

    ... If you find my posts helpful drop me a like! πŸ‘ Be sure to mark or post the solution to help others out and/or to credit the one who helped you. 😎

  • scot1967's avatar
    scot1967
    Icon for Champion Level 3 rankChampion Level 3

    ...  Also, you should set TestComplete to keep running in your project playback settings so the KWT/Scripts will keep running so your events/Try Catch blocks will run instead of stopping the test run...