Forum Discussion

p_bremm11's avatar
p_bremm11
Contributor
10 years ago

Calling Userforms after Error?

In another post, it was suggested that for dealings errors I could use UserForms, really liked the idea.
So I use it, I did something like this:


Sample procedure:

CT_2_2 procedure;
begin

// test

end;

CT_2_4 procedure;
begin

// test

end;

CT_2_5 procedure;
begin

// test

end;


_________________________________________________

In another script I did so:

uses test;

procedure steps1;
begin
     try
       CT_2_2;
       CT_2_4;
       CT_2_5;
     except

       UserForms.TestUser.ShowModal;

     end;
end;

If an error occurs in CT_2_2 step CT_2_4, CT_2_5, I would like to open the UserForms, but that's not what happens.
Could someone help me? I thank the collaboration.

  • Hi,

     

    Not sure if I understood you right...

    Events and their handlers are global for the whole test project and event is handled immediately when it happens, without any further marshalling.

    So, you may have just

    uses test;

    procedure steps1;
    begin
    //     try
           CT_2_2;
           CT_2_4;
           CT_2_5;
    //     except

    //       UserForms.TestUser.ShowModal;

    //     end;
    end;

     

    and if the error happens, say, in CT_2_4 then the call stack will be:

    OnLogError

    CT_2_4

    steps1

     

    Depending on the scripting language used in your test you may or may not be able to get the name of the module/procedure where the error occurred (i.e. CT_2_4). In JScript this should be possible, in other languages supported in TestComplete - not possible.

     

    Note, that as TestComplete posts error messages about script runtime errors (e.g. if you try to divide by zero) to the log as well, this means that the OnLogError handler will be called for these errors as well.

     

    Does this help?

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    You must distinguish between scripting language runtime errors and TestComplete 'logical' test errors.

    The former errors happen when there is runtime error like zero division, attempt to access array element beyond array bounds, etc. Those errors are handled via the language means (except in your case).

    The latter errors happen when the test code tries to perform an operation that cannot be executed: e.g. reference some object that does not exist, call the method or address the property that the given object does not have, etc. Those errors are handled by TestComplete means and can be intercepted via the OnLogError event.

    My guess is that you are interested in the errors of the second type. If my guess is correct, then you should implement the handler for the OnLogError event in your test project and open user form from this handler. (Pay attention to not end with the endless recursion. This might happen if the code of your user form do something that will generate the 'logical' error.)

    • p_bremm11's avatar
      p_bremm11
      Contributor

      I understand, I got to read something related OnLogError, but did not quite understand.

      Can you give a basic example using these examples?

      I would have to do OnLogError for each CT?

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        > I would have to do OnLogError for each CT?

        No. Events and their  handlers are global for the test project. I.e. if you added the OnLogError event to the tests project and a handler procedure for it, then this procedure will be called every time before TestComplete posts an error to the log.

        A sample project can be found in the <Users>\Public\Public Documents\TestComplete 11 Samples\Common\Event Handling\ folder.

  • To make it complete this topic let down the solution that got to ride:

    I added an item in the project called Events. In it you will find all kinds of possible logs, then as I needed
    the most, in the event OnLogError I linked, as suggested above, and thus it was my event:

    GeneralEvents_OnLogError procedure (Sender; LogParams);
    var test, test1: OleVariant;
    begin
       UserForms.Error.capCt.Caption: = Project.Variables.NomeCT;
       UserForms.Error.capEtapa.Caption: = (+ UserForms.Error.capEtapa.Caption FloatToStr (Project.Variables.PrincipalEtapaAtual));
       UserForms.Error.CapError.Caption: = LogParams.MessageText;
       UserForms.Error.CapError.Caption: = TraduzCaption (UserForms.Error.CapError.Caption);
       UserForms.Error.capctOcorreErro.Caption: = Project.Variables.UltImagemVerificada;
       UserForms.Error.ShowModal;
    end;

    /// There is more detail, but in this example it is possible to understand how to call Forms to handle errors.