Forum Discussion

dhundley's avatar
dhundley
Regular Contributor
2 years ago
Solved

is it possible to perform special processing in the event of an error

here's what i want my execution plan to normally do:

login to my AUT

execute test case 1

execute test case 2

execute test case 3

etc.

logoff of my AUT

 

IF, for whatever reason, a test case fails, i want to continue running the next test case but i want to first logoff or terminate the AUT process and then log back into the AUT. is that possible to do? if so, how?

 

I was hoping the OnLogError event handler might be a solution but the support website states the following about it:

Under the "Handling Exceptions in Scripts" link it talks about using the Try, Catch, Finally (for JavaScript) . that might work if the error occurs in a script routine but what if it happens on a line in a keyword test?

 

  • i think i finally figure out how to properly use the OnStopTestCase event handler to stop and restart my AUT when any test case has an error and I don't want that error to adversely impact any subsequent test cases. Generally speaking the following event handler contains the basic steps needed. Mine is quite a bit more complicated at the point where i put the commented statement "//any other stuff necessary to get the AUT where it needs to be for the next test case" but i have tested it an it works. i did have to convert some keyword tests into scripts and then copy and paste those lines into my event handler at the appropriate location and i had to be careful even then that what I copied and pasted did not contain any KeywordTest.Run statements (as explained in the SmartBear documentation for OnTestCaseStop event handler)

     

     

     

    function GeneralEvents_OnStopTestCase(Sender, StopTestCaseParams)
    {

      if (StopTestCaseParams.Status !== 0)
      {

        let appProcess = Sys.WaitProcess("myappname", 500);
        if (appProcess.Exists)
        {
          Sys.Process("myappname").Close();
          Delay(3000);
          appProcess = Sys.WaitProcess("myappname", 500);
          if (appProcess.Exists)
          {
            Sys.Process("myappname").Terminate();
          }
        }

        TestedApps.myappname.Run();

        //any other stuff necessary to get the AUT where it needs to be for the next test case

      }

      else

      {

        //Do the normal stuff here when StopTestCaseParams.Status === 0

      }

    }

6 Replies

  • dhundley's avatar
    dhundley
    Regular Contributor

    conceptually, what i think there ought to be (and if no one has any existing solution then i would probably like to suggest this as an enhancement request) is an additional option in the On Error drop down list under the Properties pane of the Execution Plan that allows me to run a script function

    thoughts?

      • dhundley's avatar
        dhundley
        Regular Contributor

        ok. i guess i didn't realize that under Statements (for keyword tests) there is actually the set of Try, Catch and Finally options but I have been playing around with them in some test cases that generate an error and they don't seem to be getting "caught". my project's on error setting is to stop the current item and i have modified my keyword test to look something like this:

        Try

             do something

             do something

             do something

             do something (that raises the error)

             do something

             do something

        Catch

            log message

            run script routine

         

        on the line that generates the error, it calls the ontestcasestop event handler but the Catch block never gets entered. i might be able to accomplish what i want in the ontestcasestop handler but i would like to know just how to get the try/catch to work like its supposed to. does anyone have some examples? is there some project setting that i might need to change?

         

        on a similar note, can anyone tell me if there's any difference between onstarttestcase and onstarttest when the execution plan is being run by an azure pipeline? i would like very much to have an onstarttest event handler that ONLY runs once before all the following testcases in my execution plan but that event handler seems to run at the start of every test case in the pipeline (the same as the onstarttestcase event handler). as a workaround to that I have created a javascript function called initialize which i run at the top of my execution plan but for it to run in the pipeline it has to have the testcase checkbox checked when it's not really one of my test cases. ideally, i would like it's enabled checkbox to be checked but not it's test case checkbox. I want it to run but not be considered a test case since it's only doing some necessary initialization stuff but azure won't run it without the test case check box checked. if the onstarttest event handler would only run at the outset of the pipeline then i could use it but, alas, that runs at the start of every test case. any ideas about that?