Forum Discussion

Kateryna's avatar
Kateryna
Contributor
10 years ago
Solved

Rerun keyword test in OnLogError script

Hello,



How can I rerun current test, if I receive a specific error in log?



I created event handler on Log error and it has following code, but it doesn't work:


procedure



GeneralEvents_OnLogError(Sender; LogParams);



var

TestItems2: OleVariant;

begin

if

LogParams.MessageText = 'Unable to terminate' then

begin



TestItems2:= Project.TestItems.Current.Name;

KeywordTests.TestItems2.Run();



end;

end;


  • Hi Kateryna,



    I believe that the correct syntax is (untested):

    TestItems2:= Project.TestItems.Current.Name;

    evaluate('KeywordTests.' + TestItems2 + '.Run()');



    However, considering that the test will be started from within the error handler, I am not sure that this is the best approach as it may cause recurrent execution of the same test and exaust memory resources on the test computer.



    As a side note: you should also check that TestItems.Current is not nil, which is true if a standalone test/keyword test was executed.

5 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Kateryna,



    I believe that the correct syntax is (untested):

    TestItems2:= Project.TestItems.Current.Name;

    evaluate('KeywordTests.' + TestItems2 + '.Run()');



    However, considering that the test will be started from within the error handler, I am not sure that this is the best approach as it may cause recurrent execution of the same test and exaust memory resources on the test computer.



    As a side note: you should also check that TestItems.Current is not nil, which is true if a standalone test/keyword test was executed.
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    I didn't notice that you are trying to execute a test item from script.


    The KeywordTests object you call doesn't have test items. You cannot call them here. Use the runTestItemRoutine function to implement your task (taken from this forum thread).


    //JScript


    function Test()


    {


      curTestItem = Project.TestItems.Current;


      runTestItemRoutine(curTestItem);


    }


     


    function runTestItemRoutine(testItemObject)


    {


      var caption = testItemObject.ElementToBeRun.Caption.split("\\");


     


      if (caption[0] == "Script") {


        var script = caption[1].split(" - ");


        Runner.CallMethod(script[0] + "." + script[1]);


     }


    }



  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Kateryna,


     


    Is the Tools | Current Project Propertes | Playback | Runtime | Stop on error option enabled? If it is, you need to uncheck it.


     

  • This option is uncheck. But I don't think that the matter is in options. During script execution I receive an error here: KeywordTests.TestItems2.Run();

    That there are no such property in KeywordTests.

  • I have a specific error, after which I want to rerun current test case. Thank you. I will try!