Forum Discussion

dhundley's avatar
dhundley
Regular Contributor
3 years ago

In Execution Plan can one testcase be made contingent upon the successful completion of another?

I have a testcase that reverses the transaction entered by the preceding testcase. if the preceding testcase fails then I don't want the reversal testcase to even run. Is there a way to make the running of one test case contingent upon the success of another.

 

also, sort of the opposite situation, if a failure occurs within a given testcase is there a way (instead of it just ending and moving on to the next testcase) to have it run some closing statements before moving on? My concept of this is that I would have a few boolean variables that are false at the start of the testcase and are set to true as the testcase progresses. if a failure occurs at one point it might not need to run anything if all the variables are still false but if one is true then it needs to run certain code. this is how i picture it using pseudocode

 

blnHasLaunched = false

blnHasOpened = false

blnHasSignedIn = false

Run LaunchApp keyword test

blnHasLaunched = trud

    Run Open keyword test

    blnHasOpened = true

        Run SignIn keyword test

        blnHasSignedIn = true

            (Run several other keyword tests that perform transaction)

            * if HasSignedIn then

                Run SignOut keyword test

        * if HasOpened then

            Run Close keyword test

    * if HasLaunched then

        Run CloseApp keyword test

 

if there is no error all the final keyword tests will still run because the if logic will be true but if an error occurs during the several other tests then control passes directly to the the first if statement and performs an orderly end of testcase rather than just abruptly ending and moving on to the next.  if the error occurs while signing in and it never gets to the final statement that sets the boolean value to true then there is no need to sign out but it still needs to close some other things that were opened and then close the application

 

Let me know if you have any questions. my main concern right now is the first question but the second question would be nice to know. Thanks!

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Have a look at Handling Events, an event can be triggered if an error occurs, which you can then deal with programmatically. For example, restoring a database to it's original state for the next test.

     

    In my opinion, there's no point in making the automation complicated. Plus it could be a nightmare to maintain too.

  • Hi dhundley!

     

    As rraghvani mentioned, I would look into event handlers for the second portion of your inquiry. 

     

    As for the first, setting a test to only run if the preceding was successful, that is an easy one.

     

    In the Execution Plan, you can nest your tests. You can see in the image below I have a 'ContactUs' test that is nested under my 'Login' test. Since I have 'Login' setup to stop on errors, 'ContactUs' will only run if 'Login' is successful. You can DragnDrop or use the Arrows to move the tests around.

     

    I hope this helps!

    • dhundley's avatar
      dhundley
      Regular Contributor

      i had actually thought the same thing myself. even before posting this i tried that and when the parent test case failed i saw this on the report log

      and it made me think that it went ahead and tried to run the child but upon closer examination it does appear that what appears to be the child is simply the name of the keyword test that was executing in the parent when the failure occurred so I might have to go back to this and see how it behaves when i get the error corrected. thanks!